fix(frontend): materialize object upcasts for fixed call arguments - #83
Merged
Merged
Conversation
- Capture the builtin constructor rejection for an object subclass argument and the runtime receiver-lifetime behavior of method-reference sugar - Document the planned call-boundary upcast fix while preserving Godot semantics and backend exact matching
- Clarify the subclass-to-ancestor upcast exception for fixed call arguments - Document its boundary-temp naming and limit it to exact fixed-parameter routes - Mark the documentation-first step complete in the implementation plan
- Lower subclass arguments into parameter-typed temporaries for builtin, engine, and GDCC calls - Preserve exact-match backend constructor handling and verify upcast temporary ownership - Add lowering and codegen coverage for Callable, Signal, and regression boundaries - Complete implementation documentation and acceptance checklist
- Replace the completed implementation plan with a source-of-truth contract - Update documentation links and remove obsolete lowering guidance
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Generated temporary allocation can collide with a user variable and overwrite its state.
Review effort: Lite
Findings: 1
What changed in this PR
Fixes frontend lowering by materializing strict object-subclass arguments into ancestor-typed temporaries for fixed call parameters.
Changes:
- Adds
AssignInsn-based upcast materialization. - Adds lowering, backend, and codegen tests.
- Documents conversion, ownership, and temporary naming contracts.
| File | Summary |
|---|---|
src/test/java/gd/script/gdcc/frontend/lowering/FrontendLoweringBodyInsnPassTest.java |
Tests lowering behavior and regression paths. |
src/test/java/gd/script/gdcc/backend/c/gen/CConstructInsnGenTest.java |
Tests constructor matching and ownership. |
src/test/java/gd/script/gdcc/backend/c/build/CallArgumentObjectUpcastCodegenTest.java |
Verifies generated C and ownership behavior. |
src/main/java/gd/script/gdcc/frontend/lowering/pass/body/FrontendBodyLoweringSession.java |
Implements fixed-call object upcast materialization. |
doc/module_impl/frontend/frontend_signal_support.md |
Documents Callable and Signal support anchors. |
doc/module_impl/frontend/frontend_rules.md |
Documents temporary naming rules. |
doc/module_impl/frontend/frontend_lowering_(un)pack_implementation.md |
Documents boundary materialization behavior. |
doc/module_impl/frontend/frontend_implicit_conversion_matrix.md |
Updates implicit conversion rules. |
doc/module_impl/frontend/frontend_call_argument_object_upcast_implementation.md |
Documents the implementation contract. |
doc/gdcc_ownership_lifecycle_spec.md |
Documents boundary temporary lifetime and ownership. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1476
to
+1477
| var upcastSlotId = nextBoundaryMaterializationSlotId(boundaryUse, "upcast"); | ||
| ensureVariable(upcastSlotId, targetType); |
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.

Summary
Frontend lowering now materializes strict object subclass arguments passed to ancestor-typed fixed call parameters into target-typed temporaries via
AssignInsn, covering builtin constructors, engine methods, and GDCC calls. This un-rejects previously failing calls such asCallable(subclass_instance, &"method")while preserving backend exact-match constructor semantics.What changed
FrontendBodyLoweringSession): addedmaterializeCallArgumentBoundaryValuewith a strict-object-subclass peek (isStrictObjectSubclassArgument); only the fixed-parameter loop routes here, vararg tails andDYNAMIC_FALLBACKcalls are untouched.cfg_boundary_<use>_upcast_<n>and follow standard slot-write ownership with function-scoped__finally__cleanup.CallArgumentObjectUpcastCodegenTest(end-to-end codegen), plus lowering (FrontendLoweringBodyInsnPassTest) and C codegen (CConstructInsnGenTest) coverage for Callable/Signal constructor rejection anchors and upcast temp ownership.frontend_call_argument_object_upcast_implementation.mdsource-of-truth; updated ownership spec §3.6, implicit conversion matrix, (un)pack implementation §4.2/§4.3, frontend rules, and signal support anchors.Why
Callable(token, &"bump")with a customObjectsubclass).Affected packages/files
src/main/java/gd/script/gdcc/frontend/lowering/pass/body/FrontendBodyLoweringSession.javasrc/test/java/gd/script/gdcc/backend/c/build/CallArgumentObjectUpcastCodegenTest.java(new)src/test/java/gd/script/gdcc/backend/c/gen/CConstructInsnGenTest.javasrc/test/java/gd/script/gdcc/frontend/lowering/FrontendLoweringBodyInsnPassTest.javadoc/gdcc_ownership_lifecycle_spec.md,doc/module_impl/frontend/frontend_call_argument_object_upcast_implementation.md(new),frontend_implicit_conversion_matrix.md,frontend_lowering_(un)pack_implementation.md,frontend_rules.md,frontend_signal_support.mdValidation
script/run-gradle-targeted-tests.sh --tests CallArgumentObjectUpcastCodegenTest,CConstructInsnGenTest,FrontendLoweringBodyInsnPassTest(wraps
./gradlew test --tests ... --no-daemon --info --console=plain)Result:
BUILD SUCCESSFULRisks / Notes
cfg_tmp_*evaluation-temp behavior, so no Godot-observable divergence.DYNAMIC_FALLBACKroutes.Key behaviors covered (Optional)
AssignInsnfor builtin, engine, and GDCC call routes.ALLOW_DIRECT; unrelated object types keep the shared entry's rejection behavior.CConstructInsnGenTestasserts noown_object/try_own_object).Diff stats (Optional)
Breaking changes (Optional)
Related docs (Optional)
doc/module_impl/frontend/frontend_call_argument_object_upcast_implementation.mddoc/gdcc_ownership_lifecycle_spec.md§3.6doc/module_impl/frontend/frontend_lowering_(un)pack_implementation.md§4.2/§4.3