Skip to content

rtti: self-contained annotation info in debug info (AnnotationInfo/AnnotationArgumentInfo)#3101

Merged
borisbat merged 5 commits into
masterfrom
claude/hopeful-dewdney-b0681c
Jun 11, 2026
Merged

rtti: self-contained annotation info in debug info (AnnotationInfo/AnnotationArgumentInfo)#3101
borisbat merged 5 commits into
masterfrom
claude/hopeful-dewdney-b0681c

Conversation

@borisbat

Copy link
Copy Markdown
Collaborator

Debug info no longer aliases the AST. Struct / field / global / function / enum annotations are deep-copied into the context DebugInfoAllocator as POD AnnotationInfo / AnnotationArgumentInfo, so a Context can reflect them after its Program is released. options rtti is no longer required for annotation reflection (or for json field annotations like @rename / enum_as_int); its only remaining effect is keeping context.thisProgram for compile-time introspection (this_program(), ast_typedecl).

Design doc: ANNOTATION_INFO_REWORK.md (in this PR).

Core

  • VarInfo.annotation_arguments: void* into the AST → flat AnnotationArgumentInfo* + annotation_argument_count
  • StructInfo.annotation_list: void*AnnotationInfo* + annotation_count
  • FuncInfo / EnumInfo / globals gain annotation reflection (new coverage)
  • TypeInfo.annotation_or_nameAnnotationInfo* annotation_info; the ~-padded tagged-pointer hack dies. Module::resolveAnnotation resolves name+module against the bound environment, caching successful lookups in AnnotationInfo::resolved (write gated by g_resolve_annotations, as before)
  • DebugInfoHelper::rtti deleted; field init-value capture and builtin cppName are unconditional now

das API (rtti)

New: each_annotation(StructInfo|FuncInfo|EnumInfo), each_annotation_argument(AnnotationInfo|VarInfo), get_annotation, get_annotation_argument, resolve_annotation(AnnotationInfo) : Annotation?, plus a get_annotation_argument_value(AnnotationArgumentInfo) overload.

Deprecated (kept working): structure_for_each_annotation is now a [deprecated]/setDeprecated shim that env-resolves the Annotation* and reconstructs an AST-shaped AnnotationArgumentList per invoke — it works without options rtti now.

AOT / JIT

  • AOT emits pure static annotation data (dedup'd AnnotationInfo statics for handled types, per-field AnnotationArgumentInfo arrays, struct/func/enum lists). The init-time field-annotation fixup and DAS_MAKE_ANNOTATION are gone — no std::string construction at load
  • JIT: jit_initialize/free_varinfo_annotations shims and the wasm tagged-pointer handle_typeinfo_constructor deleted (everything is plain static data); JIT gains struct/enum annotation lists (previously always null); LLVM_JIT_CODEGEN_VERSION 0x25 → 0x26

Tests

  • tests/language/annotation_info.das — struct/field/function/enum annotations, all four argument value types, resolve_annotation, deprecated-shim parity; deliberately no options rtti
  • tests-cpp/small/test_annotation_lifetime — reflects annotations from a live Context after the ProgramPtr is released (thisProgram == null) — the actual bug being fixed

Validation

Gate Result
Interp sweep (CI flags) 10086 tests, 10080 passed, 0 failed
AOT sweep (test_aot -use-aot … --use-aot) 9406 tests, 9400 passed, 0 failed
JIT (annotation test + tests/jit_tests + tests/json, full link via clang-cl) 6/6, 285/285, 331/331
ctest -L small 59/59
utils suites (dascov/lint/detect-dupe/hygiene/find-dupe) all green
lint + formatter (pre-push hook) clean
doc gates 1–6 (das2rst, stubs, uncategorized, untracked, sphinx LaTeX+HTML -W) clean
Tutorial dry-runs clean
daScript-plugin 0.6.3 server smoke (external consumer) compiles + validates clean

Notes:

  • utils/mcp/test_tools.das: 372/402 locally; the 30 failures are missing local externals (das-fmt.exe, ast-grep custom-language lib) in the fresh worktree, not this change — CI's linux lane has them
  • Pre-existing wart documented in the rework doc: passing any const char*-bound das string field (e.g. VarInfo.name, now also AnnotationInfo.name) directly as a function argument fails AOT C++ compilation; convention is "{x}" interpolation
  • Known pre-existing gap kept as-is: AOT VarInfo statics set flag_hasInitValue but never emit the value payload
  • Externals heads-up: this changes debug_info.h struct layouts — external modules' C++ that reads these structs needs a rebuild (daspkg sweep planned post-merge, FIXED_ARRAY drill)

🤖 Generated with Claude Code

borisbat and others added 2 commits June 11, 2026 11:07
…notationArgumentInfo)

Debug info no longer aliases the AST: struct/field/global/function/enum
annotations are deep-copied into the context DebugInfoAllocator as POD
AnnotationInfo / AnnotationArgumentInfo, so a Context can reflect them
after its Program is released. 'options rtti' is no longer required for
annotation reflection (or json field annotations); its only remaining
effect is keeping context.thisProgram for compile-time introspection.

- VarInfo.annotation_arguments: void* -> AnnotationArgumentInfo* + count
- StructInfo.annotation_list: void* -> AnnotationInfo* + count
- FuncInfo/EnumInfo/globals gain annotation reflection (new)
- TypeInfo.annotation_or_name -> annotation_info; the ~-padded tagged
  pointer dies; Module::resolveAnnotation resolves name+module against
  the bound environment with a cached 'resolved' pointer
- DebugInfoHelper::rtti deleted; init values + builtin cppName un-gated
- new das API: each_annotation / each_annotation_argument /
  get_annotation / get_annotation_argument / resolve_annotation /
  get_annotation_argument_value(AnnotationArgumentInfo); old
  structure_for_each_annotation kept as a [deprecated] shim that
  reconstructs the AST-shaped pair per invoke
- AOT emits pure static annotation data; the init-time field-annotation
  fixup and DAS_MAKE_ANNOTATION are gone
- JIT: varinfo-annotation ctor/dtor shims and the wasm tagged-pointer
  handle_typeinfo ctor deleted (all static now); JIT gains struct/enum
  annotation lists; LLVM_JIT_CODEGEN_VERSION 0x25 -> 0x26
- tests: tests/language/annotation_info.das (no options rtti),
  tests-cpp/small/test_annotation_lifetime (reflect after ProgramPtr
  release); docs + handmade RST regenerated

Design doc: ANNOTATION_INFO_REWORK.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The das-side DebugInfoHelper.rtti field is gone; the leftover positional
doc line leaked into generated RST as stray text and failed sphinx -W.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 11, 2026 18:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reworks runtime debug-info annotation storage so it is self-contained (no longer aliases AST memory), enabling safe annotation reflection from a live Context even after its Program is released and without requiring options rtti.

Changes:

  • Introduces POD AnnotationInfo / AnnotationArgumentInfo in debug_info.h and updates VarInfo/StructInfo/FuncInfo/EnumInfo/TypeInfo layouts to store deep-copied annotation data plus counts.
  • Updates interpreter/JIT/AOT paths (including LLVM JIT data layouts and AOT emitters) to generate/consume static or debug-heap annotation data without runtime ctor/dtor shims.
  • Adds new rtti APIs (each_annotation, each_annotation_argument, get_annotation*, resolve_annotation) and test coverage validating lifetime safety and reflection behavior.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
utils/daslang-live/main.cpp Updates lifetime comment now that annotations no longer alias AST memory.
tutorials/integration/cpp/06_interop.cpp Updates TypeInfo union documentation comment to annotation_info.
tests/language/annotation_info.das Adds language-level tests for new annotation reflection APIs without options rtti.
tests-cpp/small/test_annotation_lifetime.das Adds fixture validating annotation reflection after Program release.
tests-cpp/small/test_annotation_lifetime.cpp Adds C++ doctest ensuring annotation data survives ProgramPtr reset.
src/simulate/json_scan.cpp Migrates JSON field rename handling to new AnnotationArgumentInfo array representation.
src/simulate/json_print.cpp Migrates JSON print options (rename, optional, etc.) to new annotation arg representation.
src/builtin/module_jit.cpp Removes obsolete JIT varinfo-annotation init/free shims and exports.
src/builtin/module_builtin_rtti.h Registers new external type factories for AnnotationInfo and AnnotationArgumentInfo.
src/builtin/module_builtin_rtti.cpp Adds managed bindings + new rtti externs (get_annotation*, resolve_annotation, new value overload).
src/ast/ast_simulate.cpp Removes DebugInfoHelper::rtti gating; debug capture becomes unconditional.
src/ast/ast_module.cpp Replaces tagged-pointer annotation_or_name resolution with AnnotationInfo-based resolution + caching.
src/ast/ast_debug_info_helper.cpp Implements deep-copy of annotation lists/args into DebugInfoAllocator and populates new debug-info fields.
skills/cpp_integration.md Updates documentation for TypeInfo union member rename and new semantics.
modules/dasLLVM/daslib/llvm_jit.das Updates LLVM JIT struct layouts and emits static annotation globals (removes ctor/dtor shims).
modules/dasLLVM/daslib/llvm_jit_run.das Bumps LLVM_JIT_CODEGEN_VERSION to invalidate caches after ABI/layout changes.
include/daScript/simulate/debug_info.h Adds AnnotationInfo/AnnotationArgumentInfo, updates debug-info struct layouts and constructors.
include/daScript/simulate/aot.h Removes DAS_MAKE_ANNOTATION macro no longer needed with name-based AnnotationInfo.
include/daScript/simulate/aot_builtin_rtti.h Declares new rtti AOT builtins for annotation access and value decoding.
include/daScript/ast/ast.h Removes DebugInfoHelper::rtti and adds Module::resolveAnnotation(const AnnotationInfo*).
include/daScript/ast/ast_visitor.h Removes now-obsolete helper.rtti = true in visitor init.
doc/source/stdlib/handmade/structure_annotation-rtti-StructInfo.rst Documents new annotation_count field.
doc/source/stdlib/handmade/structure_annotation-rtti-FuncInfo.rst Documents new annotation_count field.
doc/source/stdlib/handmade/structure_annotation-rtti-EnumInfo.rst Documents new annotation_count field.
doc/source/stdlib/handmade/structure_annotation-rtti-DebugInfoHelper.rst Removes obsolete rtti field documentation.
doc/source/stdlib/handmade/structure_annotation-rtti-AnnotationInfo.rst Adds docs for new AnnotationInfo structure.
doc/source/stdlib/handmade/structure_annotation-rtti-AnnotationArgumentInfo.rst Adds docs for new AnnotationArgumentInfo structure.
doc/source/stdlib/handmade/function-rtti-resolve_annotation-0xdf30cb3959a59b9e.rst Documents new resolve_annotation function.
doc/source/stdlib/handmade/function-rtti-get_annotation-0xdbc45dc33bc67300.rst Documents new get_annotation function.
doc/source/stdlib/handmade/function-rtti-get_annotation_argument-0xcf249595f05c3934.rst Documents new get_annotation_argument function.
doc/source/reference/tutorials/integration_cpp_06_interop.rst Updates tutorial docs for TypeInfo union and handled-type annotation resolution.
doc/source/reference/embedding/cpp_api.rst Updates embedding docs for TypeInfo union member rename.
doc/reflections/das2rst.das Extends rtti doc grouping to include the new annotation APIs.
daslib/rtti.das Adds each_annotation* iterators, get_annotation* accessors, and deprecates old shim API.
daslib/aot_standalone.das Removes obsolete rtti gating in AOT standalone generator and tidies unused-arg handling.
daslib/aot_cpp.das Updates AOT debug-info emission to generate static AnnotationInfo/AnnotationArgumentInfo and handled-type statics.
ANNOTATION_INFO_REWORK.md Adds design doc explaining motivation, design, tier impacts, and known limitations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ast/ast_debug_info_helper.cpp
Comment thread src/ast/ast_debug_info_helper.cpp
Comment thread src/builtin/module_builtin_rtti.cpp Outdated
borisbat and others added 2 commits June 11, 2026 13:21
…ionArgumentInfo)

Copilot review: use the (const char*, length) allocateString overload
instead of constructing a temporary string per call.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.

Comment thread daslib/aot_cpp.das
Comment thread modules/dasLLVM/daslib/llvm_jit.das
Comment thread modules/dasLLVM/daslib/llvm_jit.das
…e string passes

Copilot review round 2:
- aot_cpp writeAnnotationArgInit: sValue now goes through escape() (an
  annotation string with quotes/backslashes generated invalid C++ - same
  latent bug existed in the old options-rtti field emission), and floats
  emit via to_cpp_float for the FLT_DECIMAL_DIG=9 roundtrip guarantee
- llvm_jit: pass AnnotationInfo/AnnotationArgumentInfo string fields via
  interpolation - llvm_jit.das is AOT-compiled for jit.exe, and the
  const char*-backed fields fail that C++ compile when passed directly
  (the string() wraps removed for PERF020 were load-bearing)
- annotation_info.das: v_esc argument pins the escape roundtrip; also
  documents that annotation string_constant unescapes only \" -
  backslashes pass through literally

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.

Comment thread ANNOTATION_INFO_REWORK.md
Comment on lines +45 to +48
| struct | before | after |
|---|---|---|
| `VarInfo` | `void * annotation_arguments` | `AnnotationArgumentInfo * annotation_arguments; uint32_t annotation_count` |
| `StructInfo` | `void * annotation_list` | `AnnotationInfo * annotations; uint32_t annotation_count` |
@borisbat borisbat merged commit 2756e52 into master Jun 11, 2026
52 of 53 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