aot: const-owner handled string field reads cast to char *#3105
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #3101. A
stringfield read on a const handled owner emitted((const char * const)(...)), which cannot flow intochar *slots — dasstringalways lowers tochar *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 "boundconst 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(const char *)still picks the const-qualified conversion operator on class-typed members — theSimpleStringcase that motivated the const branch in f380818 (operator const char*() constis the only viable conversion on a const owner);(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— directequal(ann.name, ...)/equal(arg.name, ...)passes (compiled by test_aot);modules/dasLLVM/daslib/llvm_jit.das— directget_string_constant_ptr(g_builder, arg.name)etc. (compiled by thedaslang -exejit.exe build);ANNOTATION_INFO_REWORK.mdwart section updated.No codegen-version bump: the JIT change passes identical string content, generated code is unchanged.
Validation
-jit -jit-no-cache; jit.exe built viadaslang -exeand self-host-codegens annotation_info from a cold cache--verify+ lint clean on changed files🤖 Generated with Claude Code