Skip to content

feat(compiler): support vectori to vector implicit conversion#35

Merged
SuperIceCN merged 8 commits into
masterfrom
feat/backend/vector-int-float-convert
May 14, 2026
Merged

feat(compiler): support vectori to vector implicit conversion#35
SuperIceCN merged 8 commits into
masterfrom
feat/backend/vector-int-float-convert

Conversation

@Iridium-Zero
Copy link
Copy Markdown
Contributor

Summary

Adds same-dimension Vector*i -> Vector* implicit conversion support across frontend semantic boundaries, lowering, LIR intrinsics, C backend codegen, and inbound call_func wrappers. This keeps global assignability strict while materializing accepted conversions through explicit backend-owned intrinsic routes.

What changed

  • Added frontend ordinary-boundary compatibility for Vector2i/3i/4i -> Vector2/3/4, including overload specificity shared by bare calls, constructor resolution, and ScopeMethodResolver frontend paths.
  • Lowered accepted vector widening boundaries into CALL_INTRINSIC instructions and added parser/serializer coverage for the vector intrinsic names.
  • Registered C backend vector conversion intrinsics and generated gdextension-lite constructor conversions through CBodyBuilder.callAssign(...).
  • Extended generated call_func wrappers so Vector2/3/4 parameters accept same-dimension Vector*i Variant payloads without changing method metadata or r_error->expected.
  • Added runtime/test-suite anchors for source-level ordinary boundaries and inbound dynamic-call positive and negative cases.
  • Archived implicit conversion documentation into doc/module_impl/backend/implicit_conversion_implementation.md and updated LIR intrinsic references.

Why

  • Godot supports strict Variant conversion from integer vectors to matching float vectors, but GDCC previously only supported scalar int -> float widening at ordinary typed boundaries.
  • The conversion must be explicit in lowering/backend codegen because vector conversion is a builtin constructor conversion, not a C struct cast.
  • Inbound call_func wrappers bypass frontend lowering, so wrapper gates and local materialization need their own narrow compatibility rule.

Affected packages/files

  • gd.script.gdcc.frontend.sema.analyzer.support: boundary compatibility and constructor/call ranking coverage.
  • gd.script.gdcc.frontend.lowering.pass.body: intrinsic-cast materialization for vector boundaries.
  • gd.script.gdcc.backend.c.gen: intrinsic registry/codegen, wrapper gates, and helper materialization.
  • gd.script.gdcc.lir.parser: CALL_INTRINSIC parser/serializer coverage.
  • src/main/c/codegen/include_451/gdcc: wrapper-only inbound vector materialization helpers.
  • doc/gdcc_lir_intrinsic.md, doc/module_impl/backend/implicit_conversion_implementation.md, frontend/backend conversion contract docs.
  • src/test/test_suite/unit_test: runtime anchors for vector widening and guard cases.

Validation

  • script/run-gradle-targeted-tests.sh --tests FrontendVariantBoundaryCompatibilityTest,ClassRegistryTest,ScopeMethodResolverTest
  • script/run-gradle-targeted-tests.sh --tests FrontendBodyLoweringSessionTest,FrontendLoweringBodyInsnPassTest
  • script/run-gradle-targeted-tests.sh --tests SimpleLirBlockInsnParserTest,SimpleLirBlockInsnSerializerTest
  • script/run-gradle-targeted-tests.sh --tests CallIntrinsicInsnGenTest,CIntrinsicManagerTest,CVectorIToVectorIntrinsicTest
  • script/run-gradle-targeted-tests.sh --tests CGenHelperTest,CCodegenTest
  • script/run-gradle-targeted-tests.sh --tests GdScriptUnitTestCompileRunnerTest
  • script/run-gradle-targeted-tests.sh --tests FrontendAssignmentSemanticSupportTest,FrontendTypeCheckAnalyzerTest,FrontendExpressionSemanticSupportTest,ScopeMethodResolverTest
  • script/run-gradle-targeted-tests.sh --tests FrontendLoweringToCProjectBuilderIntegrationTest.lowerVectorIToVectorBoundariesBuildConstructorIntrinsicAndRunInGodot,GdScriptUnitTestCompileRunnerTest.listsExpectedBundledUnitScripts,GdScriptUnitTestCompileRunnerTest.compilesAndValidatesInitializerScripts
  • script/run-gradle-targeted-tests.sh --tests FrontendBodyLoweringSessionTest,FrontendLoweringBodyInsnPassTest,CCodegenTest,GdScriptUnitTestCompileRunnerTest.compilesAndValidatesRuntimeScripts
  • script/run-gradle-targeted-tests.sh --tests FrontendConstructorResolutionSupportTest
  • git diff --check

Result: BUILD SUCCESSFUL for the targeted Gradle suites that were run.

Risks / Notes

  • ClassRegistry.checkAssignable(...) remains strict; vector widening is only a frontend ordinary-boundary and inbound call_func wrapper rule.
  • Reverse Vector* -> Vector*i, wrong-dimension vector conversion, Rect2i -> Rect2, container recursive covariance, and operator promotion remain unsupported.
  • Wrapper-only vector helpers rely on generated wrapper runtime gates and are materializers, not independent validators.
  • Metadata and r_error->expected continue to publish the target parameter type.

Key behaviors covered (Optional)

  • Exact overloads outrank vector widening; vector widening outranks Variant pack.
  • Constructor routes share the same boundary rank behavior as call overloads.
  • Lowering emits target-typed temps and c_vector*i_to_vector* intrinsics for local, assignment, call, return, and dictionary subscript boundaries.
  • C backend emits godot_new_VectorN_with_VectorNi(...) constructor conversions instead of C casts.
  • Inbound dynamic calls accept Object.call(..., Vector*i(...)) for Vector* parameters while rejecting reverse and adjacent strict conversions.

Diff stats (Optional)

  • 45 files changed, 2577 insertions, 423 deletions.

Breaking changes (Optional)

  • None

Related docs (Optional)

  • doc/module_impl/backend/implicit_conversion_implementation.md
  • doc/gdcc_lir_intrinsic.md
  • doc/module_impl/frontend/frontend_implicit_conversion_matrix.md
  • doc/module_impl/backend/variant_abi_contract.md

- Add gdcc_lir_intrinsic.md as the shared call_intrinsic surface and registry catalog.
- Link low IR, frontend lowering, and int-to-float docs to the new intrinsic fact source.
- Add the Vector*i -> Vector* implementation plan with intrinsic maintenance steps.
- Add Vector2i/3i/4i to Vector2/3/4 frontend intrinsic-cast compatibility.
- Rename boundary decision wording to ALLOW_WITH_INTRINSIC_CAST across docs and code.
- Keep ClassRegistry assignability strict and cover vector specificity/negative cases.
- Emit vector intrinsic casts for Vector2i/3i/4i typed boundaries.
- Cover local, assignment, call, return, and subscript lowering paths.
- Add LIR parser and serializer roundtrip coverage for vector intrinsics.
- Register Vector2i/3i/4i to Vector2/3/4 C backend intrinsics.
- Emit gdextension-lite constructor conversions through CBodyBuilder.callAssign.
- Cover registry, CALL_INTRINSIC dispatch, and invalid signature cases.
- Accept same-dimension Vector2i/3i/4i payloads for Vector2/3/4 call_func params.
- Materialize widened vector args through gdcc_intrinsic helper constructors.
- Guard backend vector wrapper generation with builtin dimension validation.
- Cover generated gates, include syncing, and runtime positive/negative anchors.
- Add frontend sema tests for assignment, type-check, and fixed-call overload behavior.
- Add C build/runtime and test-suite anchors for ordinary Vector*i to Vector* boundaries.
- Update vector conversion plan and test-suite guidance with completed step status.
- Add constructor route regressions for exact Vector*i, widening Vector*, and Variant fallback ranking.
- Document call_func wrapper gate ordering before wrapper-only vector helper materialization.
- Clarify vector inbound widening metadata and runtime gate contracts.
- Merge scalar and vector implicit conversion notes into one maintained backend contract.
- Remove completed implementation-plan documents and update LIR intrinsic references.
- Clarify call_func vector helper gate ordering in code comments.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@SuperIceCN SuperIceCN merged commit be228e6 into master May 14, 2026
4 of 5 checks passed
@SuperIceCN SuperIceCN deleted the feat/backend/vector-int-float-convert branch May 14, 2026 06:35
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.

3 participants