Skip to content

[spectec] Dynamically check side conditions on type fields/cases#2158

Open
rossberg wants to merge 2 commits intomainfrom
il.side
Open

[spectec] Dynamically check side conditions on type fields/cases#2158
rossberg wants to merge 2 commits intomainfrom
il.side

Conversation

@rossberg
Copy link
Copy Markdown
Member

@rossberg rossberg commented May 6, 2026

SpecTec IL: Implement and formalise the semantics of dynamic checking of type side conditions, as discussed with @zilinc and @conrad-watt. Now, when e.g. a type

syntax digit = DIG nat  -- if nat < 10

is defined, every application of DIG will actually evaluate the premises associated with the constructor. If that fails, the application fails. IOW, constructors with side conditions are partial. The motivation is to actually check and preserve defined invariants. This is necessary to get the right failure behaviour for undefined constructor applications. To give a silly but simple example, a rule like

rule R:
  n ~~ m
  -- if DIG n = DIG m

will now properly be rejected for n, m ≥ 10, where previously it succeeded according to the operational semantics.

The implementation in the evaluator is simple. It does not affect the frontend much, since that only does simple evaluations for type-checking purposes. However, middlends/backends translating constructors (or records) should now respect this refined semantics if they don't already (@zilinc, @DCupello1, FYI).

The formalisation got a bit more complicated than I'd like, due to the need to express it via a reduction semantics. For this purpose, INJ and STR forms can now carry a temporary list of yet-to-check premises. Also, they now have a type annotation, since reduction has to know where to look for the premises initially.

@zilinc, @conrad-watt, @DCupello1, PTAL.

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.

1 participant