Skip to content

validate_ast: AST uniqueness validator pass#2418

Merged
borisbat merged 1 commit intomasterfrom
validator-validator
Apr 14, 2026
Merged

validate_ast: AST uniqueness validator pass#2418
borisbat merged 1 commit intomasterfrom
validator-validator

Conversation

@borisbat
Copy link
Copy Markdown
Collaborator

@borisbat borisbat commented Apr 14, 2026

Summary

  • Adds a post-compilation AST validation pass (CodeOfPolicies::validate_ast) that checks every TypeDecl and Expression is unique (not shared) across the AST — catches accidental aliasing bugs early
  • Visitor-based duplicate detection + gc_root cross-check for completeness
  • Off by default (slow); enable with options validate_ast
  • Enables deep-clone optimization in TypeDecl::clone (was commented out) — safe now that uniqueness is enforced
  • Fixes several bugs found by the validator: SimNode_AstGetTypeDecl sharing TypeDecls, Variable::source ownership (now weak ref + new loop_source), block folding source sync, apply_qmacro_function sharing returnType, bitfield aliasSubstitution sharing
  • Adds Annotation::visitTypeDecls virtual for validator to reach annotation-owned TypeDecls
  • Extracts print_backtrace_frames and print_current_stack_trace in crash_handler.h to eliminate duplicated stack trace code from gc_node.cpp (also adds demangling + daScript stack walk callback to gc_break_on_id)
  • Updates handmade docs for CodeOfPolicies::validate_ast and Variable::loop_source

Test plan

  • 6040 tests pass (dastest -- --test tests/)
  • 5455 AOT tests pass (test_aot.exe -use-aot)
  • Lint clean (1 minor PERF006 in macro code, not actionable)
  • Documentation generated (das2rst.das + Sphinx, zero warnings)
  • All .das files formatted

🤖 Generated with Claude Code

@borisbat borisbat force-pushed the validator-validator branch from cc9fe0a to d35665b Compare April 14, 2026 08:10
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@borisbat borisbat force-pushed the validator-validator branch from d35665b to 7ddf367 Compare April 14, 2026 16:16
@borisbat borisbat merged commit 77d7563 into master Apr 14, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants