evaluation
syside.evaluation – evaluate asserted constraints against concrete instances.
This package checks whether the assert constraint { ... } constraints in a
model actually hold for the instances that should satisfy them. It is built on
syside.Compiler.evaluate(), which defines exactly the fragment of
constraints that can be checked; anything outside that fragment is reported
Verdict.UNDECIDABLE rather than silently passed.
The public surface is small:
check_model()– check every constraint against every concrete instance.check_instance()– check the constraints applying to one instance.evaluate_assertion()– evaluate one assertion in an explicit scope.ConstraintResult/Verdict– the result type (HOLDS,VIOLATED,UNDECIDABLE, orUNSUPPORTED).
Index
Classes ¶
One |
||
Raised for an instance whose value this module cannot yet evaluate soundly. |
Functions ¶
Check every constraint that applies to a single concrete |
||
Check every constraint assertion against every concrete instance in |
||
Evaluate one |
Functions
- check_instance(instance: syside.Usage, *, compiler: syside.Compiler | None = None) list[syside.evaluation.ConstraintResult]
Check every constraint that applies to a single concrete
instance.The evaluation scope is chosen so the instance’s bindings are native:
if
instanceis writtennew Def(...)(its feature value is asyside.ConstructorExpression), the constructor is evaluated to its constructed object and that object’s scope is used;otherwise the instance’s own scope is used, where declarative bindings (redefinitions, feature values) already resolve.
Returns one
ConstraintResultper applicable assertion. An instance with no applicable assertions yields an empty list. If anew Def(...)value cannot itself be evaluated, each of the definition’s assertions is reportedVerdict.UNDECIDABLErather than skipped.- Raises:
UnsupportedInstanceError – if
instanceboth constructs a value and overrides it with declarative bindings in its body – a shape whose merged effective value this module cannot yet evaluate soundly (seeUnsupportedInstanceError). Raising, rather than returning a verdict, prevents a silently wrong result.
Cost is linear in the instance’s feature count to find the applicable assertions, plus one
syside.Compiler.evaluate()per assertion (and one more to evaluate the constructor, if any); the evaluate calls dominate.
- check_model(model: syside.Model, *, compiler: syside.Compiler | None = None) list[syside.evaluation.ConstraintResult]
Check every constraint assertion against every concrete instance in
model.Iterates the model’s non-library usages and, for each, evaluates the assertions that apply to it via
check_instance(). Usages that carry no applicable assertion contribute nothing. The result is flat, in model-traversal order; callers typically filter forVerdict.VIOLATEDto report problems andVerdict.UNDECIDABLEto report what could not be checked.Unlike
check_instance(), this never raisesUnsupportedInstanceError: an instance with an unsupported shape is recorded asVerdict.UNSUPPORTED(one result per applicable assertion) so a single such instance does not abort the scan or discard the verdicts already collected.Note
This scans all usages, so cost is linear in model size times the per- instance evaluation cost. It is intended for whole-file checking (e.g. an on-save lint), not for hot loops.
- evaluate_assertion(assertion: syside.AssertConstraintUsage, scope: syside.Type, *, compiler: syside.Compiler, instance: syside.Usage | None = None) syside.evaluation.ConstraintResult
Evaluate one
assert constraintagainstscopeand classify the result.scopemust be a type in which the constraint’s feature references resolve to concrete values – typically a constructed object (seecheck_instance()) or an instance carrying declarative bindings.instanceis the usage recorded on the result as the subject being checked. It is distinct fromscopebecause the scope of anew Def(...)instance is the ephemeral constructed object, not the usage the modeller wrote; pass the original usage so the result points back at the source. When omitted it defaults toscope(correct for the declarative path, where the instance is its own scope).The result is three-valued. A body the compiler cannot reduce, or one that reduces to anything other than a single
bool(for example a collection, a number, orNone), isVerdict.UNDECIDABLE– never reported as holding.assert notnegation is applied to a concrete boolean only.Cost is one
syside.Compiler.evaluate()call, which dominates; the surrounding classification is O(1).
Enumerations
- class Verdict
The outcome of evaluating one asserted constraint against one instance.
HOLDS¶The outcome of evaluating one asserted constraint against one instance.
VIOLATED¶The outcome of evaluating one asserted constraint against one instance.
UNDECIDABLE¶The outcome of evaluating one asserted constraint against one instance.
UNSUPPORTED¶The outcome of evaluating one asserted constraint against one instance.