Skip to content

Wire up accept() dispatch and add ASTVisualizer to bootstrap#1202

Merged
marcauberer merged 2 commits into
mainfrom
bootstrap/ast-visitor-accept-dispatch
Jun 14, 2026
Merged

Wire up accept() dispatch and add ASTVisualizer to bootstrap#1202
marcauberer merged 2 commits into
mainfrom
bootstrap/ast-visitor-accept-dispatch

Conversation

@marcauberer

Copy link
Copy Markdown
Member

What changed

  • New file abstract-ast-visitor-intf.spice: dependency-free base interface declaring IAbstractAstVisitor without importing ast-nodes, breaking the circular import that previously blocked wiring accept().
  • ast-node-intf.spice: added accept(IAbstractAstVisitor*) to IASTNode; fixed stringValueOffset type (0l0ul).
  • ast-nodes.spice: activated IVisitable interface and added accept() on all 77 concrete node types. Bodies return Any() stubs until vtable dispatch through ASTNode* base pointers is available in the bootstrap.
  • abstract-ast-visitor.spice: added visit(IASTNode*) to IAbstractAstVisitor; imports the new intf shim and ast-node-intf.
  • ast-visitor.spice: added visit(IASTNode*) implementation; documented that visitChildren() is structural-only until accept() dispatch through base pointers works.
  • ast-visualizer.spice (new): bootstrap port of src/visualizer/ASTVisualizer. Uses literal node-type strings instead of typename<T>() (unsupported in this build) and Any.set<string> to work around a free(heap byte*&) overload issue in the current host compiler. Includes a unit smoke test.
  • test/test-files/bootstrap-compiler/unit-wrapper-ast-visualizer/ (new): test wrapper picked up automatically by BootstrapCompilerTests.

Why

The bootstrap AST visitor infrastructure had accept() commented out on every node type due to a circular import: ast-nodes needed IAbstractAstVisitor from abstract-ast-visitor, which needed the node types from ast-nodes. The new abstract-ast-visitor-intf.spice shim breaks this cycle cleanly.

How it was validated

  • BootstrapCompilerTests.bootstrapCompiler_unitWrapperAstNodes — pass
  • BootstrapCompilerTests.bootstrapCompiler_unitWrapperAstVisitor — pass
  • BootstrapCompilerTests.bootstrapCompiler_unitWrapperAstVisualizer — pass (new)
  • Full bootstrap suite: 18/30 pass (was 13/30); all 12 remaining failures are pre-existing and unrelated to these changes.

Follow-up / known limitations

  • accept() bodies on concrete nodes are stubs (return Any()) because calling typed visitXxx methods from within ast-nodes.spice would recreate the circular import. Real dispatch is deferred until the bootstrap supports vtable dispatch through ASTNode* base pointers.
  • ASTVisualizer.visit(IASTNode*) is stubbed for the same reason; tree traversal goes through typed visitXxx calls directly.
  • ASTVisualizer uses bool initialized instead of String parentNodeId due to a free(heap byte*&) overload resolution bug in the current host compiler build. The parentNodeId field (needed for DOT edge generation) should be restored once that bug is fixed.
  • typename<T>() calls replaced by literal strings; restore once the builtin is stable in bootstrap compilation.

@marcauberer marcauberer requested a review from a team as a code owner June 13, 2026 14:28
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added tests Contains changes to the test cases bootstrap Change regarding the bootstrap labels Jun 13, 2026
@marcauberer marcauberer force-pushed the bootstrap/ast-visitor-accept-dispatch branch from 82c4455 to 533302d Compare June 14, 2026 21:58
- Introduce abstract-ast-visitor-intf.spice: a dependency-free base
  interface that declares IAbstractAstVisitor without importing ast-nodes,
  breaking the circular import that previously blocked wiring accept().

- ast-node-intf.spice: add accept(IAbstractAstVisitor*) to IASTNode so
  the interface participates in typed dispatch; fix stringValueOffset
  type (0l → 0ul).

- ast-nodes.spice: activate IVisitable interface and add accept() on all
  77 concrete node types. Bodies return Any() stubs until vtable dispatch
  through ASTNode* base pointers is available in the bootstrap.

- abstract-ast-visitor.spice: add visit(IASTNode*) to IAbstractAstVisitor
  and import the new intf shim and ast-node-intf.

- ast-visitor.spice: add visit(IASTNode*) implementation; document that
  visitChildren() traversal is structural-only until accept() dispatch
  through base pointers works.

- ast-visualizer.spice: port src/visualizer/ASTVisualizer to bootstrap.
  Uses literal node-type strings (typename<T>() unsupported in this build)
  and Any.set<string> to work around a free(heap byte*&) overload issue
  in the current host compiler. Adds unit smoke test.

- test/test-files/bootstrap-compiler/unit-wrapper-ast-visualizer/: new
  test wrapper; BootstrapCompilerTests picks it up automatically.

Bootstrap test results: 18/30 pass (was 13/30); all 12 remaining failures
are pre-existing and unrelated to these changes.
The Spice compiler does not insert a GEP adjustment when implicitly
upcasting from a struct whose first field is an interface (vtable ptr)
to a composed-in base type. In createNode<T>(), the line

    ASTNode* nodeBase = node;

compiled to a bare pointer copy instead of pointer + 8 (to skip the
8-byte IVisitable vtable prefix). addChild() then treated the vtable
pointer region as the ASTNode, making children.pushBack() dereference
null as Vector::contents and segfault.

Fix: remove ': IVisitable' from all 77 concrete node struct declarations.
The accept() stub methods are kept as plain methods; IVisitable
conformance is not currently exercised at runtime. This makes the
ASTNode subobject land at offset 0 in every concrete node, so the
upcasts in createNode() and concludeNode() are identity conversions.

Bootstrap tests: 20/30 pass (was 18/30). The two previously segfaulting
standaloneParserSmokeTest and standaloneParserStressTest now pass.
@marcauberer marcauberer force-pushed the bootstrap/ast-visitor-accept-dispatch branch from 533302d to 2b68c46 Compare June 14, 2026 22:40
@marcauberer marcauberer enabled auto-merge (squash) June 14, 2026 22:40
@marcauberer marcauberer merged commit 35379f9 into main Jun 14, 2026
8 checks passed
@marcauberer marcauberer deleted the bootstrap/ast-visitor-accept-dispatch branch June 14, 2026 22:54
@marcauberer marcauberer added this to the 0.27.0 milestone Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bootstrap Change regarding the bootstrap size/XL tests Contains changes to the test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant