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

Remove chain IR operator #1354

Merged
merged 9 commits into from
Feb 18, 2022
Merged

Remove chain IR operator #1354

merged 9 commits into from
Feb 18, 2022

Conversation

rodrigo7491
Copy link
Collaborator

@rodrigo7491 rodrigo7491 commented Feb 16, 2022

  • Tests added for any new code
  • Ran make fmt-fix (or had formatting run automatically on all files edited)
  • Documentation added for any new functionality
  • Entry added to UNRELEASED.md for any new functionality

This PR removes the chain IR operator. All uses of SMT select and store over many cells are now done iteratively, as done prior to #1171. The most complex change was done in SetFilterRule, due to the interaction with SMT maps. Closes #1339.

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.

With the caveat that I'm lacking some context on specifics of the rewriting, this LGTM!

I do have one question about the naming tho.

Copy link
Collaborator

@konnov konnov left a comment

Choose a reason for hiding this comment

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

Looks good and easier to read!

val cons = consChain(cells)
solverContext.assertGroundExpr(tla.apalacheAssignChain(set.toNameEx, cons))
}
solverContext.assertGroundExpr(tla.and(cells.map(c => tla.apalacheStoreInSet(c.toNameEx, set.toNameEx)): _*))
Copy link
Collaborator

Choose a reason for hiding this comment

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

shall we introduce a loop over cells that pushes assertions over individual cells? By doing so, we will avoid the same bottleneck with recursion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call, will change it to
for (cell <- cells) solverContext.assertGroundExpr(tla.apalacheStoreInSet(cell.toNameEx, set.toNameEx))

}

val pointingSets = (sets.zip(elemsOfSets) filter (isPointedBySet _).tupled) map (_._1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

pointingSets is always non-empty, right? Maybe add an assertion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, thanks!

val cons = consChain(elemsCells)
rewriter.solverContext.assertGroundExpr(tla.apalacheAssignChain(newSetCell.toNameEx, cons))
def addOneElemCons(elemCell: ArenaCell): Unit = {
def isPointedBySet(set: ArenaCell, setElems: Set[ArenaCell]): Boolean = setElems.contains(elemCell)
Copy link
Collaborator

Choose a reason for hiding this comment

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

setElems.contains(elemCell) is linear in setElems, and addOneElemCons is called for every element. Shall we worry about that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is not nice, but at least it does not affect solving time. It is not obvious to me how we can improve this.

Copy link
Collaborator

@konnov konnov Feb 18, 2022

Choose a reason for hiding this comment

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

A quick fix is just to introduce a set like val setElemsAsSet = setElems.toSet (outside this loop!). It should decrease the cost of contains.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what this will do. setElems is already a Set[ArenaCell].

I imagine you meant to have val setElemsAsSet = elemsOfSets.toSet outside addOneElemCons, and use setElemsAsSet instead of elemsOfSets in the definition of pointingSets. Doesn't the call to isPointedBySet typecast to Set[ArenaCell] regardless?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, setElems is already a set. I got confused. Ignore the above comments then!

…olverContext.scala

Co-authored-by: Igor Konnov <igor@informal.systems>
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #1354 (447d7b7) into unstable (6f59ec9) will decrease coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##           unstable    #1354      +/-   ##
============================================
- Coverage     75.24%   75.12%   -0.13%     
============================================
  Files           334      333       -1     
  Lines         10855    10768      -87     
  Branches        538      544       +6     
============================================
- Hits           8168     8089      -79     
+ Misses         2687     2679       -8     
Impacted Files Coverage Δ
...syte/apalache/tla/bmcmt/caches/IntRangeCache.scala 100.00% <100.00%> (ø)
...forsyte/apalache/tla/bmcmt/rules/SetCtorRule.scala 81.25% <100.00%> (-3.75%) ⬇️
.../forsyte/apalache/tla/bmcmt/rules/SetCupRule.scala 88.57% <100.00%> (-2.34%) ⬇️
...rsyte/apalache/tla/bmcmt/rules/SetFilterRule.scala 90.69% <100.00%> (-0.61%) ⬇️
...orsyte/apalache/tla/bmcmt/rules/SetUnionRule.scala 86.66% <100.00%> (-0.84%) ⬇️
...syte/apalache/tla/bmcmt/rules/aux/CherryPick.scala 90.68% <100.00%> (-0.15%) ⬇️
...syte/apalache/tla/bmcmt/rules/aux/PowSetCtor.scala 86.20% <100.00%> (-2.99%) ⬇️
...rsyte/apalache/tla/bmcmt/smt/Z3SolverContext.scala 78.61% <100.00%> (-0.55%) ⬇️
...in/scala/at/forsyte/apalache/tla/lir/Builder.scala 99.06% <100.00%> (-0.01%) ⬇️
...t/forsyte/apalache/tla/lir/oper/ApalacheOper.scala 71.15% <100.00%> (+0.24%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f59ec9...447d7b7. Read the comment docs.

…into ro/remove-chain

� Conflicts:
�	tla-bmcmt/src/main/scala/at/forsyte/apalache/tla/bmcmt/rules/SetUnionRule.scala
�	tla-bmcmt/src/main/scala/at/forsyte/apalache/tla/bmcmt/rules/aux/CherryPick.scala
�	tla-bmcmt/src/main/scala/at/forsyte/apalache/tla/bmcmt/smt/Z3SolverContext.scala
@konnov
Copy link
Collaborator

konnov commented Feb 18, 2022

I am totally ok with merging it

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.

[FEATURE] Replace the chaining with a loop again?
4 participants