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

Implement variable scopes, declarations and updates #5

Open
wants to merge 76 commits into
base: main
Choose a base branch
from

Conversation

sonmarcho
Copy link
Contributor

This PR implements variable scopes, declarations and updates.
It also implements an induction principle for the interpreter (see ExprInduction), which was necessary to update the proofs in SimplifyEmptyBlocks.

Copy link
Member

@cpitclaudel cpitclaudel left a comment

Choose a reason for hiding this comment

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

Great PR. Let's start by addressing the comments, then let's clean up the history and merge.

src/AST/Predicates.dfy Show resolved Hide resolved
src/AST/Predicates.dfy Show resolved Hide resolved
src/AST/Syntax.dfy Show resolved Hide resolved
src/AST/Syntax.dfy Outdated Show resolved Hide resolved
// because we desugar let-bindings to a scope containing an initialized variable declaration.
// We could make ``Pure1`` pattern match on `VarDecl` followed by `Update` operating on the
// same variables, but then we couldn't use the `Predicates.Deep.All_Expr` function to lift
// this definition.
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually want to treat vardecls as pure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the time I wrote this comment, I had removed the Bind construct from the AST (before putting it back later).
Following the discussion we had this morning about using let-bindings to make the proofs simpler, then converting them to scope + vardecl later in the compilation process: this comment is even less relevant now.
I didn't have much problems with the fact that this duplicates a bit Update so far (the additional work is limited), but today I see no problem in removing the optional initialization values from VarDecl.

Copy link
Member

Choose a reason for hiding this comment

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

Note from chat: can't always decompose (var x := x + 1)

src/Semantics/Interp.dfy Outdated Show resolved Hide resolved
// DISCUSS: we need to check that the variables have been declared, but there is actually
// no way to do that for now (a variable declared but not initialized doesn't appear in the
// environment - a variable declaration may only update the rollback context). But is not
// checking that variables have been declared really a problem?
Copy link
Member

Choose a reason for hiding this comment

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

I think it is a problem: accepting programs with undeclared variables means that we won't catch passes that fail to declare their variables.

Of course it's not an issue if we separately check that, but if we make this an invariant of the expr type then local transformations become complicated.

Copy link
Contributor Author

@sonmarcho sonmarcho Aug 4, 2022

Choose a reason for hiding this comment

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

Let's discuss that: I can easily update the context to track this.

Copy link
Member

Choose a reason for hiding this comment

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

Let's table this for later; can you create an issue?

src/Semantics/Interp.dfy Show resolved Hide resolved
src/Semantics/Interp.dfy Outdated Show resolved Hide resolved
src/Semantics/Interp.dfy Outdated Show resolved Hide resolved
@cpitclaudel cpitclaudel self-assigned this Sep 6, 2022
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.

2 participants