Assert valid parameters - #214
Conversation
4b07cab to
974e2bb
Compare
| {% endif %} | ||
|
|
||
| {% endif %} | ||
| {% if set_id_bases %} |
There was a problem hiding this comment.
This is subtle. But can you look at what triggers this to have content in the component.py model. We need to mere existence of a parameters model to trigger this, even if a component doesn't have a Parameter_Update invoker connector. Weird case, but I want to make sure it is covered.
Currently the check is
365 if self.set_id_bases_parameters:
to which we might need to add or self.parameters or maybe CLAUDE has a more accurate solution here.
There was a problem hiding this comment.
Confirmed. Here's the path:
- gen/models/component.py:134 — set_id_bases_parameters starts empty during component load.
- gen/models/component.py:331 — every submodel attached to the component gets submodel.set_component(self) called.
- gen/models/parameters.py:44-51 — the parameters submodel's set_component unconditionally appends parameter_Id_Base to component.set_id_bases_parameters as its first statement. No branch, no way to skip it.
- gen/models/component.py:365-375 — runs after the submodel loop; since the list is non-empty, self.set_id_bases is set to a subprogram object (truthy). The None branch is unreachable for a parameterized component.
No need for or self.parameters there
| {% if component.parameters %} | ||
| -- Check the component's compiled-in default parameter values against the | ||
| -- component's parameter validation: | ||
| Self.Tester.Component_Instance.Assert_Valid_Parameter_Defaults; |
There was a problem hiding this comment.
This is also called at component-name-implementation-tester.adb:32, so would it run twice for every component with parameters? Might be able to drop the tester call, the one in name.adb also covers tests that never call Init_Base.
| {% for par in parameters %} | ||
| {{ par.name }} => Self.{{ par.name }}{{ "," if not loop.last }} | ||
| {% endfor %} | ||
| ) = Valid); |
There was a problem hiding this comment.
Maybe superfluous, but could add a message with the component type.
Custom validation in Validate_Parameters runs only for ground-commanded parameter operations, so nothing ever checks the defaults compiled in from the component model against it - an invalid default flies silently until the first update. Assert_Valid_Parameter_Defaults closes that gap: it asserts on a dispatching Validate_Parameters call against the component's working parameter copies, which hold the model defaults until the first parameter update. It lives in the base package because those copies are private there, and is exposed as a public primitive so initialization and test code outside the package can run the same check. The assertion carries no message string to keep it out of the binary; a failure is traceable through the subprogram symbol and the assertion's file and line.
Set_Id_Bases hosts the call because it is the one initialization step every parameterized component has (parameters always contribute Parameter_Id_Base to it), unlike Init_Base, which only exists for components needing heap setup. Running before the component is connected or initialized makes purity of Validate_Parameters - a function of its arguments alone, with no dependence on Init state and no connector calls - a design contract, now documented at the override point in both the base spec and the implementation template.
The check lives in two generated places because the two test compositions expose the component differently. For a regular component the tests base owns the tester, and its Set_Up calls Assert_Valid_Parameter_Defaults right after allocating it - the tests base regenerates on every build, so every existing test inherits the check without touching its committed tester. For a generic component the tester package is instantiated inside the developer's test implementation where the tests base cannot reach, so the call is emitted into the tester's Init_Base instead; testers are generated once and committed, so this path reaches existing generic tests as their testers are regenerated. Both hooks run before Set_Up_Test, while the working copies still hold the pristine model defaults, mirroring where Set_Id_Bases performs the same check in an assembly. The tester Init_Base generation conditions and the test skeleton's Init_Base call now also trigger on parameters, so a component whose only feature is parameters still receives the hook.
Testers are generated once and committed, so the tester Init_Base hook only reaches an existing test when its tester is regenerated. The limiter is the repository's only generic parameterized component - the composition the tests base cannot cover - so its committed tester is brought current directly rather than waiting on a regeneration.
974e2bb to
15320ed
Compare
Assert component default parameter values via Validate_Parameters
A component's Validate_Parameters function today runs only when a parameter operation arrives from the ground, so the default parameter values compiled in from the component model are never checked against any custom validation the developer implements there. An invalid default flies silently until the first parameter update. This PR closes that gap by asserting the defaults through Validate_Parameters both at assembly startup and in component unit tests.
What's generated
Components with parameters gain one new base-package primitive:
Where it's called
Design contract
Because the check runs before the component is connected or initialized, Validate_Parameters must be a pure function of its arguments — no dependence on Init state, no connector invocations. This was already the intended shape of the function; the calls make it load-bearing, and it is now documented at the override point in both the base spec and the implementation template.
Review notes
The four commits layer for review: (1) the primitive alone, (2) the startup integration, (3) the test integration, and (4) the patch to the limiter component. Generated doc comments in each commit describe only the behavior that exists at that point.
Verification