Commit 2f1e7850

2f1e785069dcMerged

Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

feat(parse): support ShareableConstantNode (# shareable_constant_value: comment)

Adds parser case that lowers ShareableConstantNode to its inner ConstantWriteNode by rewinding node_counter and re-flattening at the same slot. The wrapper carries no semantic information Spinel needs (no Ractor runtime), and 12+ codegen scanner passes look for ConstantWriteNode at top-level of statement lists; parser-side lowering lets them all work unchanged.

This is the same trick the existing PM_IT_LOCAL_VARIABLE_READ_NODE arm uses to rename it to _1.

Test: test/shareable_constant.rb (verifies the wrapped const write still produces working const reads/methods). Bootstrap: gen2.c == gen3.c.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
2f1e785069dc
Parent
40403f434501

spinel_parse.cmodifiedView file

@@ -804,6 +804,19 @@
804804 node->location.start - g_parser->start);
805805 exit(1);
806806 }
807+ case PM_SHAREABLE_CONSTANT_NODE: {
808+ /* `# shareable_constant_value: literal` magic comment that wraps
809+ a constant write. Spinel has no Ractor support, so the
810+ shareability state is a no-op. We lower at parse time by
811+ flattening the inner write directly into THIS node slot and
812+ discarding the wrapper. Many later codegen scanner passes
813+ look for ConstantWriteNode at the top level of statements;
814+ lowering here lets all of them work without modification. */
815+ pm_shareable_constant_node_t *n = (pm_shareable_constant_node_t *)node;
816+ /* Re-flatten the inner write at *this* id by rewinding the counter. */
817+ node_counter--;
818+ return flatten(n->write);
819+ }
807820 case PM_SPLAT_NODE: {
808821 pm_splat_node_t *n = (pm_splat_node_t *)node;
809822 N("SplatNode");