Skip to content

Give Predicate a distinct internal representation #2099

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

Merged
merged 98 commits into from
Jan 14, 2021
Merged

Conversation

MirceaS
Copy link
Contributor

@MirceaS MirceaS commented Aug 27, 2020

Fixes #1442


Reviewer checklist
  • Test coverage: stack test --coverage
  • Public API documentation: stack haddock

Comment on lines 51 to 52
-- TODO (thomas.tuegel): Lift 'simplified' to the 'Conditional' level once we
-- treat the latter as an aggregate root.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-- TODO (thomas.tuegel): Lift 'simplified' to the 'Conditional' level once we
-- treat the latter as an aggregate root.

@MirceaS
Copy link
Contributor Author

MirceaS commented Sep 21, 2020

TODO:

  • Add back the tests removed from Predicate.hs to the simplification stage

@ttuegel
Copy link
Contributor

ttuegel commented Sep 21, 2020

Here is the actual error message:

    Internal error: expected simplified results, but found:                                                                                                               
        \and{SortK{}}(                   
            /* term: */                 
            /* Fl Fn D Sfa */
            Lbl'Hash'if'UndsHash'then'UndsHash'else'UndsHash'fi'Unds'K-EQUAL-SYNTAX'Unds'Sort'Unds'Bool'Unds'Sort'Unds'Sort{SortK{}}(
                /* Fl Fn D Sfa */ X0:SortBool{},                                                                                                                          
                /* Fl Fn D Sfa */ X1:SortK{},
                /* Fl Fn D Sfa */ X2:SortK{}                               
            ),                         
        \and{SortK{}}(                                                               
            /* predicate: */
            /* Spa */                                                                
            \and(                      
                /* Sfa */ \top(),                                                    
                /* Spa */  
                \and(                                                                
                    /* Spa */ \and(/* Sfa */ \top(), /* Sfa */ \top()),
                    /* Spa */                                                        
                    \and(  
                        /* Spa */ \and(/* Sfa */ \top(), /* Sfa */ \top()),   
                        /* Spa */ \and(/* Sfa */ \top(), /* Sfa */ \top())
                    )                                                                
                )
            ),
            /* substitution: */
            \top{SortK{}}()
        ))
      while simplifying:
        /* Fl Fn D Spa */
        Lbl'Hash'if'UndsHash'then'UndsHash'else'UndsHash'fi'Unds'K-EQUAL-SYNTAX'Unds'Sort'Unds'Bool'Unds'Sort'Unds'Sort{SortK{}}(
            /* Fl Fn D Sfa */ X0:SortBool{},
            /* Fl Fn D Sfa */ X1:SortK{},
            /* Fl Fn D Sfa */ X2:SortK{}
        )
    CallStack (from HasCallStack):
      error, called at src/Kore/Step/Simplification/TermLike.hs:446:6 in kore-0.29.0.0-HuCMzubZJvo5rOwRZcR8X6:Kore.Step.Simplification.TermLike

It's not shown in Jenkins because many of the tests produce a lot of useless warnings, but you can copy and paste the failing command to remove the redirection.

This unsimplified predicate is a case which was handled by makeAndPredicate which must now be handled in the simplifier. As I said at the time, we need to add unit tests for these simplification cases.

@MirceaS MirceaS marked this pull request as ready for review December 18, 2020 12:41
@MirceaS MirceaS changed the title sketched out first draft of the new Predicate representation changed the internal representation of Predicates Dec 18, 2020
@ttuegel ttuegel self-requested a review December 18, 2020 15:06
@ttuegel ttuegel changed the title changed the internal representation of Predicates Give Predicate a distinct internal representation Dec 18, 2020
@ttuegel
Copy link
Contributor

ttuegel commented Dec 21, 2020

@MirceaS The next thing we need to do here is check for performance regressions. You can start with the tests/regression-* tests in our own repository, but we also need to check these: https://github.com/kframework/evm-semantics/tree/master/tests/specs/benchmarks

We don't need to collect precise statistics here, just run everything once with the old and new versions to compare.

@MirceaS
Copy link
Contributor Author

MirceaS commented Jan 5, 2021

@ttuegel runs of tests in test/regression-evm-semantics-39dd1e5/ and test/regression-wasm-semantics-5372938/ are pretty much identical on both master and this branch in terms of time and memory allocation.
Also, looking on Jenkins, the integration tests took about 30 minutes on this branch while on master they seem to take about 32 minutes, so I don't think there's any performance regressions being introduced.
The EVM benchmark tests (test-prove-benchmarks make target) are very similar on both master and this branch.

where
sort = termLikeSort termLikePredicate
termLikePredicate = Predicate.unwrapPredicate predicate
prettyConditional'
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between prettyConditional and prettyConditional'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

prettyConditional' doesn't take a sort as input and is used to pretty print Conditionals that don't contain a TermLike that can be used to derive a sort (that is, Conditional variable (Predicate variable)).
See line 310 below.

{-|'PredicateFalse' is a pattern for matching 'bottom' predicates.
-}
pattern PredicateFalse :: Predicate variable
data HasChanged = Changed | NotChanged
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add documentation to new types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the comment I added good?

Comment on lines 517 to 518
makeTruePredicate' = (synthesize (TopF Top {topSort = ()})
, NotChanged)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
makeTruePredicate' = (synthesize (TopF Top {topSort = ()})
, NotChanged)
makeTruePredicate' =
(synthesize (TopF Top {topSort = ()}), NotChanged)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I wrote it like that is so that it is consistent in style with all the other maker functions: the body of the function followed by an extra, separate line where we specify whether the term changed or not. Should I still change it as in your example?

Copy link
Contributor

Choose a reason for hiding this comment

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

All of the make functions in this module should change to follow our style guide.

| isTop p1 = (p2, Changed)
| isBottom p2 = (makeNotPredicate p1, Changed)
| isTop p2 = (p1, Changed)
-- | p1 == p2 = (makeTruePredicate, Changed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For two reasons:

  1. It might be inefficient to compare two entire predicate trees when calling this maker function (which I believe happens quite often).
  2. This is not a simplification that existed in the original code, so this would change the behavior of the function. It might not break anything but it requires testing.

I left it in as a comment in case we decide at some point that we do want it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the comment.

MirceaS and others added 6 commits January 8, 2021 15:29
@ttuegel ttuegel merged commit f3b6373 into master Jan 14, 2021
@ttuegel ttuegel deleted the PredicateNew branch January 14, 2021 17:38
@MirceaS MirceaS restored the PredicateNew branch July 13, 2021 09:35
@ana-pantilie ana-pantilie deleted the PredicateNew branch May 25, 2022 10:20
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.

Predicate should have a distinguished representation
3 participants