Repository: ruby/yarp
Pull request #1376 (2023-09-01 13:40:26)

Add global variables to the constant pool


Patch:
diff --git a/config.yml b/config.yml
index e6517730..f1df755d 100644
--- a/config.yml
+++ b/config.yml
@@ -1166,6 +1166,8 @@ nodes:
           ^^^^^
   - name: GlobalVariableAndWriteNode
     fields:
+      - name: name
+        type: constant
       - name: name_loc
         type: location
       - name: operator_loc
@@ -1179,6 +1181,8 @@ nodes:
           ^^^^^^^^^^^^^^^^^
   - name: GlobalVariableOperatorWriteNode
     fields:
+      - name: name
+        type: constant
       - name: name_loc
         type: location
       - name: operator_loc
@@ -1194,6 +1198,8 @@ nodes:
           ^^^^^^^^^^^^^^^^
   - name: GlobalVariableOrWriteNode
     fields:
+      - name: name
+        type: constant
       - name: name_loc
         type: location
       - name: operator_loc
@@ -1206,12 +1212,18 @@ nodes:
           $target ||= value
           ^^^^^^^^^^^^^^^^^
   - name: GlobalVariableReadNode
+    fields:
+      - name: name
+        type: constant
     comment: |
       Represents referencing a global variable.
 
           $foo
           ^^^^
   - name: GlobalVariableTargetNode
+    fields:
+      - name: name
+        type: constant
     comment: |
       Represents writing to a global variable in a context that doesn't have an explicit value.
 
@@ -1219,6 +1231,8 @@ nodes:
           ^^^^  ^^^^
   - name: GlobalVariableWriteNode
     fields:
+      - name: name
+        type: constant
       - name: name_loc
         type: location
       - name: value
diff --git a/lib/yarp/desugar_visitor.rb b/lib/yarp/desugar_visitor.rb
index a988449d..9aabda59 100644
--- a/lib/yarp/desugar_visitor.rb
+++ b/lib/yarp/desugar_visitor.rb
@@ -62,7 +62,7 @@ module YARP
     #
     # $foo && $foo = bar
     def visit_global_variable_and_write_node(node)
-      desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode)
+      desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name])
     end
 
     # $foo ||= bar
@@ -71,7 +71,7 @@ module YARP
     #
     # defined?($foo) ? $foo : $foo = bar
     def visit_global_variable_or_write_node(node)
-      desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode)
+      desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name])
     end
 
     # $foo += bar
@@ -80,7 +80,7 @@ module YARP
     #
     # $foo = $foo + bar
     def visit_global_variable_operator_write_node(node)
-      desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode)
+      desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name])
     end
 
     # @foo &&= bar
diff --git a/src/yarp.c b/src/yarp.c
index 176e9f76..4b2b3fed 100644
--- a/src/yarp.c
+++ b/src/yarp.c
@@ -2310,10 +2310,23 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc
     return node;
 }
 
+// Retrieve the name from a node that will become a global variable write node.
+static yp_constant_id_t
+yp_global_variable_write_name(yp_parser_t *parser, yp_node_t *target) {
+    if (YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE)) {
+        return ((yp_global_variable_read_node_t *) target)->name;
+    }
+
+    assert(YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
+
+    // This will only ever happen in the event of a syntax error, but we
+    // still need to provide something for the node.
+    return yp_parser_constant_id_location(parser, target->location.start, target->location.end);
+}
+
 // Allocate and initialize a new GlobalVariableAndWriteNode node.
 static yp_global_variable_and_write_node_t *
 yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
-    assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
     assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
     yp_global_variable_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_and_write_node_t);
 
@@ -2325,6 +2338,7 @@ yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target,
                 .end = value->location.end
             }
         },
+        .name = yp_global_variable_write_name(parser, target),
         .name_loc = target->location,
         .operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
         .value = value
@@ -2346,6 +2360,7 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta
                 .end = value->location.end
             }
         },
+        .name = yp_global_variable_write_name(parser, target),
         .name_loc = target->location,
         .operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
         .value = value,
@@ -2358,7 +2373,6 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta
 // Allocate and initialize a new GlobalVariableOrWriteNode node.
 static yp_global_variable_or_write_node_t *
 yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
-    assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
     assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
     yp_global_variable_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_or_write_node_t);
 
@@ -2370,6 +2384,7 @@ yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target,
                 .end = value->location.end
             }
         },
+        .name = yp_global_variable_write_name(parser, target),
         .name_loc = target->location,
         .operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
         .value = value
@@ -2387,7 +2402,8 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name)
         {
             .type = YP_NODE_GLOBAL_VARIABLE_READ_NODE,
             .location = YP_LOCATION_TOKEN_VALUE(name),
-        }
+        },
+        .name = yp_parser_constant_id_location(parser, name->start, name->end)
     };
 
     return node;
@@ -2395,18 +2411,19 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name)
 
 // Allocate a new GlobalVariableWriteNode node.
 static yp_global_variable_write_node_t *
-yp_global_variable_write_node_create(yp_parser_t *parser, const yp_location_t *name_loc, const yp_token_t *operator, yp_node_t *value) {
+yp_global_variable_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
     yp_global_variable_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_write_node_t);
 
     *node = (yp_global_variable_write_node_t) {
         {
             .type = YP_NODE_GLOBAL_VARIABLE_WRITE_NODE,
             .location = {
-                .start = name_loc->start,
+                .start = target->location.start,
                 .end = value->location.end
             },
         },
-        .name_loc = *name_loc,
+        .name = yp_global_variable_write_name(parser, target),
+        .name_loc = YP_LOCATION_NODE_VALUE(target),
         .operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator),
         .value = value
     };
@@ -8057,16 +8074,15 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod
         case YP_NODE_MISSING_NODE:
             return target;
         case YP_NODE_CLASS_VARIABLE_READ_NODE: {
-            yp_class_variable_write_node_t *write_node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value);
+            yp_class_variable_write_node_t *node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value);
             yp_node_destroy(parser, target);
-            return (yp_node_t *) write_node;
+            return (yp_node_t *) node;
         }
         case YP_NODE_CONSTANT_PATH_NODE:
             return (yp_node_t *) yp_constant_path_write_node_create(parser, (yp_constant_path_node_t *) target, operator, value);
         case YP_NODE_CONSTANT_READ_NODE: {
             yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value);
             yp_node_destroy(parser, target);
-
             return (yp_node_t *) node;
         }
         case YP_NODE_BACK_REFERENCE_READ_NODE:
@@ -8074,10 +8090,9 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod
             yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable");
             /* fallthrough */
         case YP_NODE_GLOBAL_VARIABLE_READ_NODE: {
-            yp_global_variable_write_node_t *result = yp_global_variable_write_node_create(parser, &target->location, operator, value);
+            yp_global_variable_write_node_t *node = yp_global_variable_write_node_create(parser, target, operator, value);
             yp_node_destroy(parser, target);
-
-            return (yp_node_t *) result;
+            return (yp_node_t *) node;
         }
         case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
             yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target;


Test patch:
diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb
index faf840e9..4a7c73f1 100644
--- a/test/yarp/errors_test.rb
+++ b/test/yarp/errors_test.rb
@@ -1003,8 +1003,8 @@ module YARP
       expected = BeginNode(
         Location(),
         StatementsNode([
-          GlobalVariableWriteNode(Location(), NilNode(), Location()),
-          GlobalVariableWriteNode(Location(), NilNode(), Location())
+          GlobalVariableWriteNode(:$+, Location(), NilNode(), Location()),
+          GlobalVariableWriteNode(:$1466, Location(), NilNode(), Location())
         ]),
         nil,
         nil,
diff --git a/test/yarp/snapshots/alias.txt b/test/yarp/snapshots/alias.txt
index 639311e6..224c2069 100644
--- a/test/yarp/snapshots/alias.txt
+++ b/test/yarp/snapshots/alias.txt
@@ -31,7 +31,7 @@ ProgramNode(0...199)(
        (61...66)
      ),
      AliasNode(86...97)(
-       GlobalVariableReadNode(92...94)(),
+       GlobalVariableReadNode(92...94)(:$a),
        BackReferenceReadNode(95...97)(),
        (86...91)
      ),
@@ -41,8 +41,8 @@ ProgramNode(0...199)(
        (99...104)
      ),
      AliasNode(114...129)(
-       GlobalVariableReadNode(120...124)(),
-       GlobalVariableReadNode(125...129)(),
+       GlobalVariableReadNode(120...124)(:$foo),
+       GlobalVariableReadNode(125...129)(:$bar),
        (114...119)
      ),
      AliasNode(131...143)(
diff --git a/test/yarp/snapshots/global_variables.txt b/test/yarp/snapshots/global_variables.txt
index d0a9f782..578f02e9 100644
--- a/test/yarp/snapshots/global_variables.txt
+++ b/test/yarp/snapshots/global_variables.txt
@@ -1,30 +1,30 @@
 ProgramNode(0...349)(
   [],
   StatementsNode(0...349)(
-    [GlobalVariableReadNode(0...16)(),
-     GlobalVariableReadNode(18...20)(),
-     GlobalVariableReadNode(22...25)(),
-     GlobalVariableReadNode(27...37)(),
-     GlobalVariableReadNode(39...45)(),
-     GlobalVariableReadNode(47...54)(),
-     GlobalVariableReadNode(56...63)(),
-     GlobalVariableReadNode(65...67)(),
-     GlobalVariableReadNode(69...71)(),
-     GlobalVariableReadNode(73...75)(),
+    [GlobalVariableReadNode(0...16)(:$global_variable),
+     GlobalVariableReadNode(18...20)(:$_),
+     GlobalVariableReadNode(22...25)(:$-w),
+     GlobalVariableReadNode(27...37)(:$LOAD_PATH),
+     GlobalVariableReadNode(39...45)(:$stdin),
+     GlobalVariableReadNode(47...54)(:$stdout),
+     GlobalVariableReadNode(56...63)(:$stderr),
+     GlobalVariableReadNode(65...67)(:$!),
+     GlobalVariableReadNode(69...71)(:$?),
+     GlobalVariableReadNode(73...75)(:$~),
      BackReferenceReadNode(77...79)(),
      BackReferenceReadNode(81...83)(),
      BackReferenceReadNode(85...87)(),
      BackReferenceReadNode(89...91)(),
-     GlobalVariableReadNode(93...95)(),
-     GlobalVariableReadNode(97...99)(),
-     GlobalVariableReadNode(101...103)(),
-     GlobalVariableReadNode(105...111)(),
-     GlobalVariableReadNode(113...122)(),
-     GlobalVariableReadNode(124...126)(),
-     GlobalVariableReadNode(128...131)(),
-     GlobalVariableReadNode(133...149)(),
-     GlobalVariableReadNode(151...159)(),
-     GlobalVariableReadNode(161...164)(),
+     GlobalVariableReadNode(93...95)(:$:),
+     GlobalVariableReadNode(97...99)(:$;),
+     GlobalVariableReadNode(101...103)(:$,),
+     GlobalVariableReadNode(105...111)(:$DEBUG),
+     GlobalVariableReadNode(113...122)(:$FILENAME),
+     GlobalVariableReadNode(124...126)(:$0),
+     GlobalVariableReadNode(128...131)(:$-0),
+     GlobalVariableReadNode(133...149)(:$LOADED_FEATURES),
+     GlobalVariableReadNode(151...159)(:$VERBOSE),
+     GlobalVariableReadNode(161...164)(:$-K),
      SymbolNode(166...183)((166...167), (167...183), nil, "$global_variable"),
      SymbolNode(185...188)((185...186), (186...188), nil, "$_"),
      SymbolNode(190...194)((190...191), (191...194), nil, "$-w"),
diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt
index 79d11f10..15042a2c 100644
--- a/test/yarp/snapshots/methods.txt
+++ b/test/yarp/snapshots/methods.txt
@@ -173,7 +173,7 @@ ProgramNode(0...1194)(
      ),
      DefNode(161...175)(
        (170...171),
-       GlobalVariableReadNode(165...169)(),
+       GlobalVariableReadNode(165...169)(:$var),
        nil,
        nil,
        [],
diff --git a/test/yarp/snapshots/patterns.txt b/test/yarp/snapshots/patterns.txt
index 01292cbf..efcae6d0 100644
--- a/test/yarp/snapshots/patterns.txt
+++ b/test/yarp/snapshots/patterns.txt
@@ -959,7 +959,7 @@ ProgramNode(0...3743)(
          "foo"
        ),
        PinnedVariableNode(988...993)(
-         GlobalVariableReadNode(989...993)(),
+         GlobalVariableReadNode(989...993)(:$bar),
          (988...989)
        ),
        (985...987)
diff --git a/test/yarp/snapshots/regex.txt b/test/yarp/snapshots/regex.txt
index 6ba39427..37e32c4d 100644
--- a/test/yarp/snapshots/regex.txt
+++ b/test/yarp/snapshots/regex.txt
@@ -21,7 +21,7 @@ ProgramNode(0...293)(
        [StringNode(29...33)(nil, (29...33), nil, "aaa "),
         EmbeddedVariableNode(33...38)(
           (33...34),
-          GlobalVariableReadNode(34...38)()
+          GlobalVariableReadNode(34...38)(:$bbb)
         )],
        (38...39),
        0
diff --git a/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt b/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt
index c055a649..d4890ed5 100644
--- a/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt
+++ b/test/yarp/snapshots/seattlerb/alias_gvar_backref.txt
@@ -2,7 +2,7 @@ ProgramNode(0...15)(
   [],
   StatementsNode(0...15)(
     [AliasNode(0...15)(
-       GlobalVariableReadNode(6...12)(),
+       GlobalVariableReadNode(6...12)(:$MATCH),
        BackReferenceReadNode(13...15)(),
        (0...5)
      )]
diff --git a/test/yarp/snapshots/seattlerb/bug202.txt b/test/yarp/snapshots/seattlerb/bug202.txt
index cbed9a67..08bcfd6b 100644
--- a/test/yarp/snapshots/seattlerb/bug202.txt
+++ b/test/yarp/snapshots/seattlerb/bug202.txt
@@ -1,7 +1,12 @@
 ProgramNode(0...22)(
   [:测试],
   StatementsNode(0...22)(
-    [GlobalVariableWriteNode(0...11)((0...7), IntegerNode(10...11)(), (8...9)),
+    [GlobalVariableWriteNode(0...11)(
+       :$测试,
+       (0...7),
+       IntegerNode(10...11)(),
+       (8...9)
+     ),
      LocalVariableWriteNode(12...22)(
        :测试,
        0,
diff --git a/test/yarp/snapshots/seattlerb/case_in.txt b/test/yarp/snapshots/seattlerb/case_in.txt
index aaee410e..1262e453 100644
--- a/test/yarp/snapshots/seattlerb/case_in.txt
+++ b/test/yarp/snapshots/seattlerb/case_in.txt
@@ -498,7 +498,7 @@ ProgramNode(0...747)(
                (628...629)
              ),
              PinnedVariableNode(633...636)(
-               GlobalVariableReadNode(634...636)(),
+               GlobalVariableReadNode(634...636)(:$b),
                (633...634)
              ),
              PinnedVariableNode(638...642)(
diff --git a/test/yarp/snapshots/strings.txt b/test/yarp/snapshots/strings.txt
index 86a732d8..ca98151c 100644
--- a/test/yarp/snapshots/strings.txt
+++ b/test/yarp/snapshots/strings.txt
@@ -177,7 +177,7 @@ ProgramNode(0...498)(
        (405...406),
        [EmbeddedVariableNode(406...411)(
           (406...407),
-          GlobalVariableReadNode(407...411)()
+          GlobalVariableReadNode(407...411)(:$foo)
         )],
        (411...412)
      ),
diff --git a/test/yarp/snapshots/unparser/corpus/literal/alias.txt b/test/yarp/snapshots/unparser/corpus/literal/alias.txt
index cf6c04cd..18e16e1d 100644
--- a/test/yarp/snapshots/unparser/corpus/literal/alias.txt
+++ b/test/yarp/snapshots/unparser/corpus/literal/alias.txt
@@ -2,8 +2,8 @@ ProgramNode(0...31)(
   [],
   StatementsNode(0...31)(
     [AliasNode(0...15)(
-       GlobalVariableReadNode(6...10)(),
-       GlobalVariableReadNode(11...15)(),
+       GlobalVariableReadNode(6...10)(:$foo),
+       GlobalVariableReadNode(11...15)(:$bar),
        (0...5)
      ),
      AliasNode(16...31)(
diff --git a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt
index 7680b90f..c08204cf 100644
--- a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt
+++ b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt
@@ -1,10 +1,15 @@
 ProgramNode(0...704)(
   [:a, :b, :foo, :c, :x],
   StatementsNode(0...704)(
-    [GlobalVariableWriteNode(0...6)((0...2), IntegerNode(5...6)(), (3...4)),
+    [GlobalVariableWriteNode(0...6)(
+       :$a,
+       (0...2),
+       IntegerNode(5...6)(),
+       (3...4)
+     ),
      MultiWriteNode(7...24)(
-       [GlobalVariableTargetNode(8...10)(),
-        GlobalVariableTargetNode(12...14)()],
+       [GlobalVariableTargetNode(8...10)(:$a),
+        GlobalVariableTargetNode(12...14)(:$b)],
        (16...17),
        ArrayNode(18...24)(
          [IntegerNode(19...20)(), IntegerNode(22...23)()],
diff --git a/test/yarp/snapshots/unparser/corpus/literal/dstr.txt b/test/yarp/snapshots/unparser/corpus/literal/dstr.txt
index 396ebcd3..369e1491 100644
--- a/test/yarp/snapshots/unparser/corpus/literal/dstr.txt
+++ b/test/yarp/snapshots/unparser/corpus/literal/dstr.txt
@@ -66,7 +66,7 @@ ProgramNode(0...299)(
        [StringNode(153...154)(nil, (153...154), nil, "a"),
         EmbeddedVariableNode(154...157)(
           (154...155),
-          GlobalVariableReadNode(155...157)()
+          GlobalVariableReadNode(155...157)(:$a)
         )],
        (157...158)
      ),
diff --git a/test/yarp/snapshots/unparser/corpus/literal/literal.txt b/test/yarp/snapshots/unparser/corpus/literal/literal.txt
index 3b85d3e9..8af9ea3c 100644
--- a/test/yarp/snapshots/unparser/corpus/literal/literal.txt
+++ b/test/yarp/snapshots/unparser/corpus/literal/literal.txt
@@ -163,7 +163,7 @@ ProgramNode(0...916)(
         StringNode(215...216)(nil, (215...216), nil, " "),
         EmbeddedVariableNode(216...219)(
           (216...217),
-          GlobalVariableReadNode(217...219)()
+          GlobalVariableReadNode(217...219)(:$a)
         )],
        (219...220)
      ),
diff --git a/test/yarp/snapshots/unparser/corpus/literal/variables.txt b/test/yarp/snapshots/unparser/corpus/literal/variables.txt
index fe98a8cd..21738f74 100644
--- a/test/yarp/snapshots/unparser/corpus/literal/variables.txt
+++ b/test/yarp/snapshots/unparser/corpus/literal/variables.txt
@@ -4,7 +4,7 @@ ProgramNode(0...66)(
     [CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"),
      InstanceVariableReadNode(2...4)(:@a),
      ClassVariableReadNode(5...8)(:@@a),
-     GlobalVariableReadNode(9...11)(),
+     GlobalVariableReadNode(9...11)(:$a),
      NumberedReferenceReadNode(12...14)(1),
      BackReferenceReadNode(15...17)(),
      ConstantReadNode(18...23)(),
diff --git a/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt b/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt
index 8822eb53..8edb0134 100644
--- a/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt
+++ b/test/yarp/snapshots/unparser/corpus/semantic/dstr.txt
@@ -234,7 +234,7 @@ ProgramNode(0...608)(
          [StringNode(587...588)(nil, (587...588), nil, "a"),
           EmbeddedVariableNode(588...591)(
             (588...589),
-            GlobalVariableReadNode(589...591)()
+            GlobalVariableReadNode(589...591)(:$a)
           )],
          (591...592)
        ),
diff --git a/test/yarp/snapshots/variables.txt b/test/yarp/snapshots/variables.txt
index edd27690..11e232c1 100644
--- a/test/yarp/snapshots/variables.txt
+++ b/test/yarp/snapshots/variables.txt
@@ -27,11 +27,12 @@ ProgramNode(0...293)(
        (42...43)
      ),
      GlobalVariableWriteNode(50...58)(
+       :$abc,
        (50...54),
        IntegerNode(57...58)(),
        (55...56)
      ),
-     GlobalVariableReadNode(60...64)(),
+     GlobalVariableReadNode(60...64)(:$abc),
      InstanceVariableReadNode(66...70)(:@abc),
      InstanceVariableWriteNode(72...80)(
        :@abc,
@@ -48,14 +49,15 @@ ProgramNode(0...293)(
        (89...90)
      ),
      MultiWriteNode(94...108)(
-       [GlobalVariableTargetNode(94...98)(),
-        GlobalVariableTargetNode(100...104)()],
+       [GlobalVariableTargetNode(94...98)(:$foo),
+        GlobalVariableTargetNode(100...104)(:$bar)],
        (105...106),
        IntegerNode(107...108)(),
        nil,
        nil
      ),
      GlobalVariableWriteNode(110...121)(
+       :$foo,
        (110...114),
        ArrayNode(117...121)(
          [IntegerNode(117...118)(), IntegerNode(120...121)()],
diff --git a/test/yarp/snapshots/whitequark/alias_gvar.txt b/test/yarp/snapshots/whitequark/alias_gvar.txt
index c615e526..06482181 100644
--- a/test/yarp/snapshots/whitequark/alias_gvar.txt
+++ b/test/yarp/snapshots/whitequark/alias_gvar.txt
@@ -2,13 +2,13 @@ ProgramNode(0...24)(
   [],
   StatementsNode(0...24)(
     [AliasNode(0...11)(
-       GlobalVariableReadNode(6...8)(),
+       GlobalVariableReadNode(6...8)(:$a),
        BackReferenceReadNode(9...11)(),
        (0...5)
      ),
      AliasNode(13...24)(
-       GlobalVariableReadNode(19...21)(),
-       GlobalVariableReadNode(22...24)(),
+       GlobalVariableReadNode(19...21)(:$a),
+       GlobalVariableReadNode(22...24)(:$b),
        (13...18)
      )]
   )
diff --git a/test/yarp/snapshots/whitequark/gvar.txt b/test/yarp/snapshots/whitequark/gvar.txt
index 2ac61ed4..dbc16e65 100644
--- a/test/yarp/snapshots/whitequark/gvar.txt
+++ b/test/yarp/snapshots/whitequark/gvar.txt
@@ -1,4 +1,4 @@
 ProgramNode(0...4)(
   [],
-  StatementsNode(0...4)([GlobalVariableReadNode(0...4)()])
+  StatementsNode(0...4)([GlobalVariableReadNode(0...4)(:$foo)])
 )
diff --git a/test/yarp/snapshots/whitequark/gvasgn.txt b/test/yarp/snapshots/whitequark/gvasgn.txt
index c4030831..b416ac55 100644
--- a/test/yarp/snapshots/whitequark/gvasgn.txt
+++ b/test/yarp/snapshots/whitequark/gvasgn.txt
@@ -1,6 +1,11 @@
 ProgramNode(0...9)(
   [],
   StatementsNode(0...9)(
-    [GlobalVariableWriteNode(0...9)((0...4), IntegerNode(7...9)(), (5...6))]
+    [GlobalVariableWriteNode(0...9)(
+       :$var,
+       (0...4),
+       IntegerNode(7...9)(),
+       (5...6)
+     )]
   )
 )
diff --git a/test/yarp/snapshots/whitequark/string_dvar.txt b/test/yarp/snapshots/whitequark/string_dvar.txt
index 12f08366..66cd00b5 100644
--- a/test/yarp/snapshots/whitequark/string_dvar.txt
+++ b/test/yarp/snapshots/whitequark/string_dvar.txt
@@ -15,7 +15,7 @@ ProgramNode(0...14)(
         StringNode(9...10)(nil, (9...10), nil, " "),
         EmbeddedVariableNode(10...13)(
           (10...11),
-          GlobalVariableReadNode(11...13)()
+          GlobalVariableReadNode(11...13)(:$a)
         )],
        (13...14)
      )]