-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constrain operator parameters by their type annotations #1371
Conversation
Keeping the exact same meaning, but greater clarity on the rules.
Remove unneeded mutable vars and checks.
// stack of names used as parameters and assumptions | ||
protected identOrHoleStack: string[] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this stack, because these are just string values we can grab directly.
quint/src/parsing/ToIrListener.ts
Outdated
.map(_ => popOrFail(this.paramStack, 'violated grammar of annotated AnnotatedOperDef')) | ||
.reverse() | ||
const res = this.popType().unwrap(() => 'violated grammar of annotated params return type') | ||
const args = params.map(p => { | ||
assert(isAnnotatedDef(p), 'violated grammar of annotated param type') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These unwraps and asserts are just like the ones in all the exitType*
methods: the grammar will not bring us to visit this context without these pre-requisites unless we've messed up something badly. It should have no impact on incremental parsing, unless we have a bigger problem that we want to know about.
@@ -64,12 +64,15 @@ describe('findParameterWithId', () => { | |||
const modules = [buildModuleWithDecls(['pure def x(a: int): int = a'])] | |||
|
|||
it('finds definition for existing id', () => { | |||
const def = findParameterWithId(modules, 1n) | |||
|
|||
const def = findParameterWithId(modules, 2n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number is shifted because the type annotation in the param is now the first leaf we hit while parsing this example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks amazing ✨. I'm so happy you found such a simple fix here, really worth the time invested!
Co-authored-by: Gabriela Moreira <[email protected]>
Thanks for the review and the fix! |
Followup for #1371 I forgot to add visitor logic for the parameter type annotations
Followup for #1371 I forgot to add visitor logic for the parameter type annotations
Followup for #1371 I forgot to add visitor logic for the parameter type annotations
Followup for #1371 I forgot to add visitor logic for the parameter type annotations
Closes #1177
Reviewing
The PR is smaller than it looks! Almost everything here is either generated by the parser generator or minor cleanup. Review by commit could be helpful.
The change
The new behavior is easiest to illustrate with reference to the operator
definition used in the regression test added here:
Prior to this fix, typechecking locates the error at
val y
, because it is notaccounting for the constraint
s : str
before it begins solving constraints inthe body of the declaration:
With this fix, we now correctly account for the constraint on
s
, so we catchthe misuse at
val x
:The fix is achieved primarily via a small improvement to the IR (which does not
impact the integration with Apalache): we add an optional
typeAnnotation
fieldto
QuintLambdaParam
s. This is a natural fix, since we are already parsingthese out together.
Along the way there was some minor cleanup and preparation for
#923
This change will also make it very easy to support selective annotation of parameters or return values, and to support annotating params of lambdas.
CHANGELOG.md
for any new functionalityREADME.md
updated for any listed functionality