Skip to content
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

Ids for lambda parameters #689

Merged
merged 9 commits into from Mar 10, 2023
Merged

Ids for lambda parameters #689

merged 9 commits into from Mar 10, 2023

Conversation

bugarela
Copy link
Collaborator

@bugarela bugarela commented Mar 9, 2023

Hello :octocat:

Big diff because of tests and generated (antlr) code.

This PR introduces ids for lambda parameters, which unblocks several issues and allows us to report errors and provide information more precisely.

Closes #624

  • Tests added for any new code
  • Ran npm run format (or had formatting run automatically on all files edited)
  • Documentation added for any new functionality
  • Entries added to the respective CHANGELOG.md for any new functionality
  • Feature table on README.md updated for any listed functionality

@@ -147,7 +147,7 @@ module erc20 {
balanceOf' = balanceOf,
val failed = or {
tx.value < 0,
tx.sender > tx.spender,
tx.sender == tx.spender,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix for a type error that was not flagged by the type checker before, but is now. The reason why this PR change impacted this is not quite clear to me yet. However, @konnov reported a similar bug this morning which is not solved by this, so I'll further investigate this behavior when looking at that.

@@ -91,24 +91,6 @@ export class EffectInferrer implements IRVisitor {
}

switch (def.kind) {
case 'param': {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this special treatment/workaround anymore now that lambdas have their own IDs.

// an identifier or a hole '_'
identOrHole : '_' | IDENTIFIER
;

parameter: identOrHole;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not completely necessary, but makes the code in ToIRListener more consistent, and I think it makes some sense to differentiate parameters from simple identifiers at the grammar level: parameters will later become a QuintLambdaParameter, while identOrHole is just used as a string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call I think this makes great sense!

@@ -23,7 +23,16 @@ describe('inferEffects', () => {

const inferrer = new EffectInferrer(definitionsTable)
return inferrer.inferEffects(quintModule)
}

function effectForDef(quintModule: QuintModule, effects: Map<bigint, EffectScheme>, defName: string ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dealing with IDs was getting to hard, so I wrote this helper function instead.

.map(_ => assert.fail('Expected errors'))
})

it('find unresolved names inside lambdas', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was duplicated somehow, so I removed one copy of it.

@bugarela bugarela self-assigned this Mar 9, 2023
@bugarela
Copy link
Collaborator Author

bugarela commented Mar 9, 2023

@shonfeder This breaks compatibility with the Apalache translation, as we anticipated 😞. How can we handle the broken tests? Since we don't have backwards compatibility in neither side, it might be tricky to release a new Apalache version with this change that will break every other PR tests except for this. Perhaps this should be a non-required CI check?

@shonfeder
Copy link
Contributor

I'll start working on a fix and maybe we can discuss our testing and compatibility strategies in the meeting today?

@bugarela bugarela marked this pull request as ready for review March 9, 2023 13:19
Comment on lines +121 to +130
export interface QuintLambdaParameter extends WithId {
/** The name of the formal parameter */
name: string,
}

export interface QuintLambda extends WithId {
/** Expressions kind ('lambda' -- operator abstraction) */
kind: 'lambda',
/** Identifiers for the formal parameters */
params: string[],
/** The formal parameters */
params: QuintLambdaParameter[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use QuintName for the params?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, i expect there is a good reason, but i'm curious what it is :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use QuintName for the params?

That's an option indeed. Normally we are using QuintName to refer to something that has been defined before. QuintLambdaParameter defines a name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, so it would be tricky since, in many times we analyze a NameEx, we look for something already defined, which isn't the case here (i.e. the type inferrer, when visiting a NameEx, will use the lookup table to obtain the original definition and get the type for that)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks.

shonfeder pushed a commit to informalsystems/apalache that referenced this pull request Mar 9, 2023
shonfeder pushed a commit to informalsystems/apalache that referenced this pull request Mar 9, 2023
* Update QuintIR for new parameter representation

The apalache side fix corresponding to
informalsystems/quint#689

* update changelog
Copy link
Contributor

@shonfeder shonfeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the helpful comments!

// an identifier or a hole '_'
identOrHole : '_' | IDENTIFIER
;

parameter: identOrHole;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call I think this makes great sense!

@bugarela bugarela merged commit b26075b into main Mar 10, 2023
11 checks passed
@bugarela bugarela deleted the gabriela/parameter-ids branch March 10, 2023 20:24
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.

Introduce a structure for lambda parameters
3 participants