Skip to content

Conversation

@ttuegel
Copy link
Contributor

@ttuegel ttuegel commented Jun 30, 2021

Fixes #2152.

Opening a new pull request to avoid spamming the original author with notifications.


Review checklist

The author performs the actions on the checklist. The reviewer evaluates the work and checks the boxes as they are completed.

  • Summary. Write a summary of the changes. Explain what you did to fix the issue, and why you did it. Present the changes in a logical order. Instead of writing a summary in the pull request, you may push a clean Git history.
  • Documentation. Write documentation for new functions. Update documentation for functions that changed, or complete documentation where it is missing.
  • Tests. Write unit tests for every change. Write the unit tests that were missing before the changes. Include any examples from the reported issue as integration tests.
  • Clean up. The changes are already clean. Clean up anything near the changes that you noticed while working. This does not mean only spatially near the changes, but logically near: any code that interacts with the changes!

Boarders and others added 30 commits June 26, 2021 13:45
Remove the predicate sort in favour of using known sorts at all call
sites. This mostly adds sort arguments to various functions that
previously implicitly used _PREDICATE sort. In turn this means removing
the various underbar methods previously in `Kore.Internal.TermLike`.
@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.003847 -0.004854
test/regression-evm/test-straight-line.sh -0.003739 -0.005195
test/regression-evm/test-straight-line-no-invalid.sh -0.003680 -0.004910
test/regression-evm/test-branching-invalid.sh -0.004121 -0.005313
test/regression-evm/test-sum-to-n.sh -0.016360 0.110953
test/regression-evm/test-branching-no-invalid.sh -0.004071 0.019726
test/regression-evm/test-add0.sh -0.004196 -0.016149
test/regression-evm/test-sumTo10.sh -0.007471 0.004080
test/regression-wasm/test-memory.sh -0.007040 -0.021684
test/regression-wasm/test-locals.sh -0.004711 -0.021793
test/regression-wasm/test-wrc20.sh -0.007667 0.020088
test/regression-wasm/test-loops.sh -0.009567 -0.021429
test/regression-wasm/test-simple-arithmetic.sh -0.005581 -0.021560

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.003847 -0.000758
test/regression-evm/test-straight-line.sh -0.003739 0.005956
test/regression-evm/test-straight-line-no-invalid.sh -0.003680 0.008287
test/regression-evm/test-branching-invalid.sh -0.004121 -0.000425
test/regression-evm/test-sum-to-n.sh -0.016353 0.008670
test/regression-evm/test-branching-no-invalid.sh -0.004071 0.019724
test/regression-evm/test-add0.sh -0.004196 -0.000615
test/regression-evm/test-sumTo10.sh -0.007471 0.003459
test/regression-wasm/test-memory.sh -0.007042 -0.021684
test/regression-wasm/test-locals.sh -0.004711 -0.021792
test/regression-wasm/test-wrc20.sh -0.007698 0.005233
test/regression-wasm/test-loops.sh -0.009587 -0.021428
test/regression-wasm/test-simple-arithmetic.sh -0.005506 -0.021340

, Pretty.indent 4 (unparse $ fromPredicate_ <$> termLikeF)
, Pretty.indent
4
(unparse $ fromPredicate (mkSortVariable "_") <$> termLikeF)
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 call pretty directly instead of fromPredicate and unparse?

Copy link
Contributor

Choose a reason for hiding this comment

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

termLikeF is a TermLikeF variable (Predicate variable). TermLikeF doesn't have a Pretty instance, and the use of its Unparse instance would require Predicate to have an Unparse instance as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. Thanks for explaning!

)
where
term = fromPredicate_ (synthesize predF)
term = fromPredicate (mkSortVariable "_") (synthesize predF)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

case predicate of
PredicateEquals t1 t2 ->
case retractLocalFunction (TermLike.mkEquals_ t1 t2) of
case retractLocalFunction (TermLike.mkEquals (TermLike.termLikeSort t1) t1 t2) of
Copy link
Contributor

Choose a reason for hiding this comment

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

I think retractLocalFunction should take a Predicate instead of a TermLike, so we should construct a Predicate \\equals here between the two terms, and send it to retractLocalFunction.

, provenValue = makeAuxReplOutput "Proven."
}
where
-- Dummy sort used to unparse configurations.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't call this a "dummy sort", it's just a variable.

Suggested change
-- Dummy sort used to unparse configurations.
-- Sort variable used to unparse configurations.

} = implication'
rightTerm =
case OrPattern.tryGetSort right of
Nothing -> error "to do"
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be an error, right?

lift $ Builtin.Map.unifyEquals childTransformers tools unifyData
| Just unifyData <- Builtin.Map.matchUnifyNotInKeys first second =
lift $ Builtin.Map.unifyNotInKeys childTransformers notSimplifier unifyData
lift $ Builtin.Map.unifyNotInKeys (termLikeSort first) childTransformers notSimplifier unifyData
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above.

AndF andF -> do
let conjuncts = foldMap MultiAnd.fromTermLike andF
And.simplify Not.notSimplifier sideCondition
And.simplify sort Not.notSimplifier sideCondition
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a little weird and inconsistent that some of the simplifiers take that sort argument while others don't. Is there any reason for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

And.makeEvaluate might receive an empty MultiAnd, so this pr gave it a Sort parameter in order to be able to return a \top. And.simplify calls And.makeEvaluate, but its MultiAnd (OrPattern RewritingVariableName) might not contain any Pattern either. That's why now it has a Sort parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand. Could you add a small comment in each place where the sort argument is needed? For example, here we can say "MultiAnd doesn't preserve the sort so we need to send it as an external argument".

Copy link
Contributor

@ana-pantilie ana-pantilie Aug 16, 2021

Choose a reason for hiding this comment

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

Could you add ^?

Edit: sorry, the comment isn't visible in the review. Please take a look at my responses to our discussions above.

Top Sort child ->
OrPattern RewritingVariableName
simplify _ = OrPattern.top
simplify sort _ = OrPattern.topOf sort
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 just get the sort from the Top Sort child type?

Comment on lines +90 to +91
mkEquals
kSort
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about this, and I want to be 100% sure I understand this. I'd expect the ==_ (where _ is K, Int etc.) to return a Bool. The reason this doesn't return Bool here but kSort is because \\equals is a predicate and we can give it any result sort. If we did \\and unification instead, the resulting sort would be Bool, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, if I replace mkEquals with mkAnd, the result sort is Bool

Copy link
Contributor

@ana-pantilie ana-pantilie Aug 16, 2021

Choose a reason for hiding this comment

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

Cool. Could you add some similar tests with mkAnd as well?

[ prettyOr or1 or2
, "to become:"
, Unparser.unparse $ OrPattern.toTermLike expected
, Unparser.unparse $ OrPattern.toTermLike (mkSortVariable "_") expected
Copy link
Contributor

Choose a reason for hiding this comment

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

If we have a sort here, we should use that. I guess we should use a sort variable only if the OrPattern is \\bottom.

Comment on lines 260 to 267
evaluateExpectTopK ::
(MonadSMT smt, MonadLog smt, MonadProf smt, MonadMask smt) =>
TermLike RewritingVariableName ->
Hedgehog.PropertyT smt ()
evaluateExpectTopK termLike = do
actual <- evaluateT termLike
OrPattern.topOf kSort Hedgehog.=== actual

Copy link
Member

Choose a reason for hiding this comment

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

Let us give this function the HasCallStack constraint. This allows the test-suite to print more precise source locations of failed tests.

(first', second') =
minMaxBy (on compareForEquals (OrPattern.toTermLike sort)) first second

{- TODO (virgil): Preserve pattern sorts under simplification.
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 this change resolves the TODO from the comment, so we should remove it.

secondCeil <- makeEvaluateCeil sideCondition second'
firstCeilNegation <- Not.simplifyEvaluated sideCondition firstCeil
secondCeilNegation <- Not.simplifyEvaluated sideCondition secondCeil
let termSort = termLikeSort firstTerm
Copy link
Member

Choose a reason for hiding this comment

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

Is there a difference between termSort and sort from the where-clause? Otherwise, I'd suggest keeping only one definition.

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.004091 0.003787
test/regression-evm/test-straight-line.sh -0.003940 0.000310
test/regression-evm/test-straight-line-no-invalid.sh -0.003881 0.024561
test/regression-evm/test-branching-invalid.sh -0.004353 0.018583
test/regression-evm/test-sum-to-n.sh -0.024183 0.004238
test/regression-evm/test-branching-no-invalid.sh -0.004294 -0.011724
test/regression-evm/test-add0.sh -0.004427 -0.000801
test/regression-evm/test-sumTo10.sh -0.007893 -0.003546
test/regression-wasm/test-memory.sh -0.008694 -0.021852
test/regression-wasm/test-locals.sh -0.005145 -0.021150
test/regression-wasm/test-wrc20.sh -0.009926 0.003112
test/regression-wasm/test-loops.sh -0.012111 -0.021469
test/regression-wasm/test-simple-arithmetic.sh -0.006361 -0.021202

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.004071 0.014048
test/regression-evm/test-straight-line.sh -0.003940 0.000310
test/regression-evm/test-straight-line-no-invalid.sh -0.003882 0.013606
test/regression-evm/test-branching-invalid.sh -0.004353 0.012607
test/regression-evm/test-sum-to-n.sh -0.024169 -0.006507
test/regression-evm/test-branching-no-invalid.sh -0.004294 -0.011726
test/regression-evm/test-add0.sh -0.004427 -0.000801
test/regression-evm/test-sumTo10.sh -0.007894 -0.005123
test/regression-wasm/test-memory.sh -0.008654 -0.021853
test/regression-wasm/test-locals.sh -0.005144 -0.021149
test/regression-wasm/test-wrc20.sh -0.009810 0.021128
test/regression-wasm/test-loops.sh -0.012033 -0.021469
test/regression-wasm/test-simple-arithmetic.sh -0.006358 -0.021256

case elementListAsInternal tools (termLikeSort first) remainder2Terms of
case elementListAsInternal
tools
(sameSort (termLikeSort first) (termLikeSort first))
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean

Suggested change
(sameSort (termLikeSort first) (termLikeSort first))
(sameSort (termLikeSort first) (termLikeSort second))

This function is suitable only for equality simplification.
-}
unifyEqTerm ::
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did this go?

lift $ bottomTermEquals SideCondition.topTODO unifyData
lift $
bottomTermEquals
(sameSort (termLikeSort first) (termLikeSort first))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is checking first and first again.

lift $ Builtin.Map.unifyNotInKeys childTransformers notSimplifier unifyData
lift $
Builtin.Map.unifyNotInKeys
(sameSort (termLikeSort first) (termLikeSort first))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is checking first and first again.

AndF andF -> do
let conjuncts = foldMap MultiAnd.fromTermLike andF
And.simplify Not.notSimplifier sideCondition
And.simplify sort Not.notSimplifier sideCondition
Copy link
Contributor

@ana-pantilie ana-pantilie Aug 16, 2021

Choose a reason for hiding this comment

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

Could you add ^?

Edit: sorry, the comment isn't visible in the review. Please take a look at my responses to our discussions above.

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.004066 0.008987
test/regression-evm/test-straight-line.sh -0.003938 -0.004452
test/regression-evm/test-straight-line-no-invalid.sh -0.003878 0.013606
test/regression-evm/test-branching-invalid.sh -0.004350 0.003323
test/regression-evm/test-sum-to-n.sh -0.024168 -0.001223
test/regression-evm/test-branching-no-invalid.sh -0.004291 -0.011725
test/regression-evm/test-add0.sh -0.004425 -0.000800
test/regression-evm/test-sumTo10.sh -0.007889 -0.002923
test/regression-wasm/test-memory.sh -0.008653 -0.021852
test/regression-wasm/test-locals.sh -0.005139 -0.021150
test/regression-wasm/test-wrc20.sh -0.009798 0.000215
test/regression-wasm/test-loops.sh -0.012021 -0.021468
test/regression-wasm/test-simple-arithmetic.sh -0.006323 -0.021202

@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.004066 -0.001280
test/regression-evm/test-straight-line.sh -0.003938 -0.004452
test/regression-evm/test-straight-line-no-invalid.sh -0.003878 0.013605
test/regression-evm/test-branching-invalid.sh -0.004350 0.008598
test/regression-evm/test-sum-to-n.sh -0.024174 -0.001223
test/regression-evm/test-branching-no-invalid.sh -0.004292 -0.005860
test/regression-evm/test-add0.sh -0.004425 -0.000802
test/regression-evm/test-sumTo10.sh -0.007891 -0.002619
test/regression-wasm/test-memory.sh -0.008650 -0.021854
test/regression-wasm/test-locals.sh -0.005139 -0.021150
test/regression-wasm/test-wrc20.sh -0.009809 -0.028056
test/regression-wasm/test-loops.sh -0.011981 -0.021468
test/regression-wasm/test-simple-arithmetic.sh -0.006273 -0.021202

@ana-pantilie ana-pantilie self-requested a review August 17, 2021 14:19
@github-actions
Copy link

name diff_allocated_bytes diff_max_live_bytes
test/regression-evm/test-pop1.sh -0.004066 0.018629
test/regression-evm/test-straight-line.sh -0.003946 -0.000575
test/regression-evm/test-straight-line-no-invalid.sh -0.003854 0.011004
test/regression-evm/test-branching-invalid.sh -0.004349 0.019923
test/regression-evm/test-sum-to-n.sh -0.024153 -0.006386
test/regression-evm/test-branching-no-invalid.sh -0.004294 0.019886
test/regression-evm/test-add0.sh -0.004425 0.006251
test/regression-evm/test-sumTo10.sh -0.007885 -0.003810
test/regression-wasm/test-memory.sh -0.008583 0.000238
test/regression-wasm/test-locals.sh -0.005141 -0.000002
test/regression-wasm/test-wrc20.sh -0.010605 -0.003598
test/regression-wasm/test-loops.sh -0.012029 -0.080699
test/regression-wasm/test-simple-arithmetic.sh -0.006295 -0.000102

@rv-jenkins rv-jenkins merged commit 6394bf2 into master Aug 17, 2021
@rv-jenkins rv-jenkins deleted the remove-predicate-sort branch August 17, 2021 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the bogus _PREDICATE sort

7 participants