Skip to content

aot: const-owner handled string field reads cast to char *#3105

Merged
borisbat merged 1 commit into
masterfrom
claude/aot-const-string-field
Jun 11, 2026
Merged

aot: const-owner handled string field reads cast to char *#3105
borisbat merged 1 commit into
masterfrom
claude/aot-const-string-field

Conversation

@borisbat

Copy link
Copy Markdown
Collaborator

Follow-up to #3101. A string field read on a const handled owner emitted ((const char * const)(...)), which cannot flow into char * slots — das string always lowers to char * in AOT C++. So passing such a field directly as a function argument (e.g. equal(ann.name, "comment")) compiled interpreted but failed AOT C++ compilation. This was the only reproducible failure behind the "bound const char* field" concern; the lifetime side is theoretical post-#3101 (everything rtti-backed is context-lifetime).

Fix (daslib/aot_cpp.das, both the by-value and pointer-to-handle field paths): emit a two-step cast

((char *)(const char *)(owner.field))
  • the inner (const char *) still picks the const-qualified conversion operator on class-typed members — the SimpleString case that motivated the const branch in f380818 (operator const char*() const is the only viable conversion on a const owner);
  • the outer (char *) strips pointee-const at the pointer level, which is always valid there and safe because das strings are immutable.

Non-const owners keep the existing single (char *) cast.

With the wart gone, the "{x}" interpolation workarounds are reverted and double as regression coverage:

  • tests/language/annotation_info.das — direct equal(ann.name, ...) / equal(arg.name, ...) passes (compiled by test_aot);
  • modules/dasLLVM/daslib/llvm_jit.das — direct get_string_constant_ptr(g_builder, arg.name) etc. (compiled by the daslang -exe jit.exe build);
  • ANNOTATION_INFO_REWORK.md wart section updated.

No codegen-version bump: the JIT change passes identical string content, generated code is unchanged.

Validation

  • interpreted: annotation_info 6/6, simple_string 18/18
  • AOT: full regen of every test with the new emitter (daslib glob dependency), suite 9406 tests — 9400 passed, 0 failed, 6 skipped (missing sf2 assets, pre-existing)
  • JIT: jit_tests 293/293; annotation_info 6/6 under -jit -jit-no-cache; jit.exe built via daslang -exe and self-host-codegens annotation_info from a cold cache
  • formatter --verify + lint clean on changed files

🤖 Generated with Claude Code

A string field read on a const handled owner emitted ((const char * const)(...)),
which cannot flow into char * slots (das string always lowers to char *): passing
such a field directly as a function argument compiled interpreted but failed AOT
C++ compilation. Emit a two-step cast ((char *)(const char *)(...)) instead — the
inner cast still picks the const-qualified conversion operator on class-typed
members (the SimpleString case from f380818), the outer strips pointee-const,
safe since das strings are immutable.

Drop the {x} interpolation workarounds in llvm_jit.das and annotation_info.das;
the direct field passes now double as regression coverage (test_aot compiles them,
jit.exe -exe build compiles llvm_jit.das).

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

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 fixes an AOT C++ codegen constness mismatch for string field reads on const handled owners, where the emitter previously produced a const char*-qualified cast that could not flow into daScript’s AOT string representation (char *). It updates the AOT emitter to use a two-step cast that preserves the const-qualified conversion selection while still yielding char *, and removes workaround interpolations that existed solely to avoid the AOT compilation failure.

Changes:

  • Update AOT C++ emitter to emit ((char *)(const char *)(...)) for const-owner handled string field reads (including pointer-to-handle field path).
  • Revert string-interpolation workarounds in tests and LLVM JIT daslib code, using direct field passes as regression coverage.
  • Update the rework/design doc to reflect the fix and remove the “interpolation required” guidance.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
daslib/aot_cpp.das Adjusts generated C++ casts for const-owner handled string field reads to produce char * via a two-step cast.
tests/language/annotation_info.das Removes interpolation workaround and asserts direct ann.name / arg.name usage (regression coverage for AOT).
modules/dasLLVM/daslib/llvm_jit.das Removes interpolation workaround when building string constants from annotation fields so -exe builds don’t rely on formatting.
ANNOTATION_INFO_REWORK.md Updates documentation to reflect that direct field passes now work in AOT; interpolation workaround no longer required.

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

@borisbat borisbat merged commit fc98c3f into master Jun 11, 2026
33 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