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

Workaround for state vars from instances in incremental compilation (REPL) #1190

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
### Removed
### Fixed

- Fix a problem where state variables from instances didn't work properly in the REPL (#1190)

### Security

## v0.14.3 -- 2023-09-19
Expand Down
23 changes: 23 additions & 0 deletions quint/io-cli-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,26 @@ exit $exit_code

error: run failed
```

### Repl keeps right track of variables from instances

Incremental evaluation from the REPL interacting with instance flattening leads to state variables having different IDs on separate evaluations. This test ensures this case is well handled during evaluation.

<!-- !test in repl with instance vars -->

```
cd ../examples/cosmos/tendermint/
output=$(echo -e "n4_f1::Init\nn4_f1::round" | quint -r TendermintModels.qnt::TendermintModels 2>&1 | tail -n +3)
exit_code=$?
cd - > /dev/null
echo "$output"
exit $exit_code
```

<!-- !test out repl with instance vars -->

```
>>> true
>>> Map("p1" -> 0, "p2" -> 0, "p3" -> 0)
>>>
```
17 changes: 14 additions & 3 deletions quint/src/runtime/impl/compilerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,24 @@ export class CompilerVisitor implements IRVisitor {
}

exitVar(vardef: ir.QuintVar) {
const varName = vardef.name

// In the process of incremental compilation, we might revisit the same var
// definition. Don't overwrite the register if that happens.
if (this.context.has(kindName('var', vardef.id))) {
// definition. Don't overwrite the register if that happens. In some cases
// (with instances), the variable can have a different ID, but the same
// name. In that case, we assign the register with that name for the new ID.
if (this.context.has(kindName('var', varName))) {
const register = this.context.get(kindName('var', varName))!
this.context.set(kindName('var', vardef.id), register)

if (this.context.has(kindName('nextvar', varName))) {
const register = this.context.get(kindName('nextvar', varName))!
this.context.set(kindName('nextvar', vardef.id), register)
}

return
}

const varName = vardef.name
// simply introduce two registers:
// one for the variable, and
// one for its next-state version
Expand Down