From 5906ce42fe04e8d4a4fe4b68b8ac54193598db56 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 22 Jan 2024 11:19:27 -0500 Subject: [PATCH] [ruby/prism] Static literal flag for string hash keys https://github.com/ruby/prism/commit/26a2d774cd --- prism/prism.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/prism/prism.c b/prism/prism.c index 4a6797896b..6b53417523 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -1352,6 +1352,13 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper end = key->location.end; } + // Hash string keys will be frozen, so we can mark them as frozen here so + // that the compiler picks them up and also when we check for static literal + // on the keys it gets factored in. + if (PM_NODE_TYPE_P(key, PM_STRING_NODE)) { + key->flags |= PM_STRING_FLAGS_FROZEN | PM_NODE_FLAG_STATIC_LITERAL; + } + // If the key and value of this assoc node are both static literals, then // we can mark this node as a static literal. pm_node_flags_t flags = 0; @@ -1359,11 +1366,6 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper flags = key->flags & value->flags & PM_NODE_FLAG_STATIC_LITERAL; } - // Hash string keys should be frozen - if (PM_NODE_TYPE_P(key, PM_STRING_NODE)) { - key->flags |= PM_STRING_FLAGS_FROZEN; - } - *node = (pm_assoc_node_t) { { .type = PM_ASSOC_NODE,