feat(compiler): implement GDScript function parameter default values from semantics to C codegen - #71
Merged
Merged
Conversation
- Define supported semantics and MVP boundaries for source function defaults - Map frontend, lowering, backend, and binding integration work - Document implementation steps, validation criteria, limitations, and test coverage
- Validate parameter default ordering and variadic constraints - Resolve defaults in a dedicated visibility context - Publish helper metadata for omitted arguments - Add diagnostics and regression coverage for supported and rejected defaults - Update frontend implementation documentation
- Rescan published parameter default facts while preserving upstream ownership for rejected islands - Block unsupported coroutine and constructor default routes without duplicate diagnostics - Expand compile-check coverage for supported, rejected, and wrapped default expressions - Update frontend rules and implementation documentation - Delegate parameter default type resolution in prepared test contexts
- Materialize hidden instance and static shells for accepted parameter defaults - Build expression-rooted CFGs and return-producing bodies with self support - Add fail-fast validation for metadata drift and shell name collisions - Expand lowering regression coverage and update implementation documentation
- Route source defaults through argc-aware C wrappers with per-method userdata - Isolate source defaults from the bind-time Variant channel - Support exact, static, dynamic, and virtual dispatch default completion - Preserve receiver handling, ownership cleanup, and per-call reevaluation - Add backend regression coverage, end-to-end fixtures, and documentation
- Replace the completed rollout plan with a maintained implementation specification - Update frontend, lowering, backend, and binding references for the closed pipeline - Align implementation comments with finalized default-slot and synthetic-function contracts - Document parameter-default diagnostics and fail-closed boundaries
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
Implement source-function parameter default values (
func f(a, b = 5):) end-to-end across frontend semantics, lowering, LIR, and C backend binding. Omitted trailing arguments are completed by hidden synthetic default functions; dynamic and engine-side calls use argc-aware callee wrappers rather than bind-time Variant defaults.What changed
FrontendParameterDefaultMetadataOwner,FrontendVisibleValueResolver,FrontendTypeCheckAnalyzer,FrontendCompileCheckAnalyzer): validate default-argument order and variadic constraints; resolve defaults in a dedicated visibility island; publishdefaultValueFuncmetadata for omitted arguments; type-check accepted defaults; rescan published facts onto the compile surface without duplicating diagnostics on rejected islands.FrontendLoweringFunctionPreparationPass, CFG/body passes): materialize hidden instance/static shells for accepted defaults, publishPARAMETER_DEFAULT_INITcontexts, and lower expression-rooted CFGs that return the evaluated default. Instance shells take owning-classself; static shells take no parameters.BindingData,CGenHelper,entry.h.ftl/entry.c.ftl): isolate source defaults from the bind-time Variant channel (default_argument_countstays 0;defaultVariablesstays empty and fail-fasts if non-empty). Exact/static calls complete omitted args at the call site; dynamic/engine/virtual dispatch complete them in argc-aware wrappers with per-method userdata (defaultSlotCount,_K_defslot, file-scope<Class>_<method>$default_ud).default_args/(dynamic fill, exact/static,ClassDB.class_call_static, per-call reevaluation, TOO_FEW/TOO_MANY, engine virtual_process(delta: float = 0.0)).frontend_parameter_default_implementation.mdas the long-term fact source; retarget frontend, lowering, binding, diagnostic, and test-suite contracts.Why
method_info.default_argumentscannot express that, so GDCC keeps ClassDB default-argument count at 0 and completes missing args through synthetic functions._initdefaults remain permanently out of scope: GDExtension class constructor callbacks have no argument channel and only invoke zero-arg_init.Affected packages/files
gd.script.gdcc.frontend.sema.analyzer(FrontendParameterDefaultMetadataOwner,FrontendCompileCheckAnalyzer,FrontendTypeCheckAnalyzer,FrontendSuiteResolver,FrontendVariableAnalyzer)gd.script.gdcc.frontend.sema.resolver(FrontendVisibleValueResolver)gd.script.gdcc.frontend.lowering(FunctionLoweringContext,FrontendLoweringFunctionPreparationPass, CFG/body passes)gd.script.gdcc.backend.c.gen(CGenHelper,CCodegen,BindingData)src/main/c/codegen/template_451/entry.c.ftl,entry.h.ftlFrontendParameterDefaultMetadataOwnerTest,FrontendCompileCheckAnalyzerTest,FrontendLowering*PassTest,CGenHelperTest,CCodegenTest,CallMethodInsnGenTest,CallStaticMethodInsnGenTest,FrontendLoweringToCProjectBuilderIntegrationTest,GdScriptUnitTestCompileRunnerTest,src/test/test_suite/unit_test/{script,validation}/default_args/doc/module_impl/frontend/frontend_parameter_default_implementation.md, related frontend/backend/diagnostic contracts,doc/gdcc_low_ir.md,doc/test_suite.mdValidation
script/run-gradle-targeted-tests.sh --tests FrontendParameterDefaultMetadataOwnerTest,FrontendCompileCheckAnalyzerTest,FrontendTypeCheckAnalyzerTest,FrontendLoweringFunctionPreparationPassTest,FrontendLoweringBuildCfgPassTest,FrontendLoweringBodyInsnPassTest,CGenHelperTest,CCodegenTest,CallMethodInsnGenTest,CallStaticMethodInsnGenTest,FrontendLoweringToCProjectBuilderIntegrationTest,GdScriptUnitTestCompileRunnerTest./gradlew classes --no-daemon --info --console=plain./gradlew clean build --no-daemon --console=plainResult:
BUILD SUCCESSFULRisks / Notes
_initdefaults (permanent); lambda parameter defaults;awaitinside defaults; referencing earlier parameters (func f(a, b = a)); ClassDBmethod_info.default_argumentsregistration; signal/@rpc/Callable.bindomitted-argument surfaces; inferring untyped parameter types from defaults (stayVariant); override default inheritance/merging.LirParameterDef.defaultValueFuncis a hidden synthetic function, not call-site inline-only;defaultVariablesis always empty;default_argument_countstays 0; wrapper dedup keys includedefaultSlotCount.GDExtensionMethodBind::calldoes not pre-check argc;Object.callwith too few arguments aborts the current GDScript function. GDCC wrappers complete omitted source defaults before forwarding.$/%in parameter defaults stay fail-closed.Key behaviors covered
sema.invalid_parameter_default_orderself/instance members; static defaults may not; parameters/locals/captures/await/get-node diagnosesema.unsupported_parameter_default_expressionClassDB.class_call_static/engine virtual dispatch complete them in callee wrappersDiff stats
Breaking changes
Related docs
doc/module_impl/frontend/frontend_parameter_default_implementation.mddoc/module_impl/frontend/frontend_rules.mddoc/module_impl/backend/godot_binding_implementation.mddoc/module_impl/backend/call_method_implementation.mddoc/module_impl/frontend/diagnostic_manager.mddoc/gdcc_low_ir.mddoc/test_suite.md