Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Make anti-unification more sort-aware #598

Merged
merged 20 commits into from
Aug 16, 2023
Merged

Conversation

nwatson22
Copy link
Contributor

@nwatson22 nwatson22 commented Aug 10, 2023

  • Changed anti_unify and anti_unify_with_constraints to require a KDefinition which they use to grab the tightest sort for the terms they are abstracting
  • Since these actions are now associated with a specific K definition, moved them into KDefinition as methods.
  • Adds KDefinition.least_common_supersort which returns the most specific sort that will cover two terms (as long as one sort is a subsort of the other).
  • Uses this function in KDefinition.sort to determine the sort of a KRewrite.
  • Rewrote the tests for anti_unify and anti_unify_with_constraints to use KDefinition and test that the abstracted variables are now more tightly typed based on the original terms.

This is an attempt to fix an issue in runtimeverification/evm-semantics#1934 where the looser sort bound is preventing simplification after the merging (anti-unification) of two nodes.

@nwatson22 nwatson22 self-assigned this Aug 10, 2023
@nwatson22 nwatson22 marked this pull request as ready for review August 10, 2023 21:02
@ehildenb
Copy link
Member

I think this problem can also be solved without creating a circular dependency by just calling KDefinition.sort_vars on the resulting anti-unifier after it's produced (wherever we are calling this routine).

@nwatson22
Copy link
Contributor Author

nwatson22 commented Aug 10, 2023

I think this problem can also be solved without creating a circular dependency by just calling KDefinition.sort_vars on the resulting anti-unifier after it's produced (wherever we are calling this routine).

@ehildenb That might work in some cases if a tight enough sort is able to be inferred based on the position of the new variable, but in general it doesn't (e.g. in this case it is appearing as the value of a Map, and ==K is not sort parametric).

@ehildenb
Copy link
Member

Introducing circular imports like this feels like pretty bad coding practice, and I think we sholud avoid it when possible. It also is making this routine more complicated than it needs to be perhaps.

I think we need to explore alternative solutions to this.

One option may be to change where anti_unify lives, this PR moves it to cterm.py: #544

@nwatson22
Copy link
Contributor Author

Introducing circular imports like this feels like pretty bad coding practice, and I think we sholud avoid it when possible. It also is making this routine more complicated than it needs to be perhaps.

I think we need to explore alternative solutions to this.

One option may be to change where anti_unify lives, this PR moves it to cterm.py: #544

@ehildenb I looked at #544 and moved both the anti_unification functions into cterm.py to avoid the circular imports. It looks like #544 gets rid of the flags we currently have for anti_unify_with_constraints but is always including the implications. I don't know all what we are trying to do with anti-unification besides my use case so I don't understand the thought process behind these flags/variants.

@nwatson22
Copy link
Contributor Author

I added the code from #544 that removes constraints from no longer used variables and integrated it with the system that produces the disjunction, so now those constraints on variables getting abstracted during the merge will no longer be removed, unless the option to include the disjunction is disabled.

@ehildenb
Copy link
Member

@nwatson22 it would be good to add some tests of the sort inference algorithm at this point.

You can do it by adding tests of kast_to_kore that have rewrites in them, because those invoke the sort inference directly.

@nwatson22
Copy link
Contributor Author

@nwatson22 it would be good to add some tests of the sort inference algorithm at this point.

You can do it by adding tests of kast_to_kore that have rewrites in them, because those invoke the sort inference directly.

@ehildenb kast_to_kore does not support rewrites currently. Also, it does not call the KDefinition.sort(KInner) function that this new logic is being added under, so as I understand it there are two separate sort inference algorithms here, sort_vars() which does what I guess you could call "top-down" sort inference and sort() which does "bottom-up" sort inference, and these are being used in disjoint cases. Currently the only uses of sort() are in anti_unify() and EqualityProof.from_claim(), and sort_vars() only operates on variables which have no constituent parts to do bottom-up inference on anyway.

So, I've added tests for sort() under a separate test.

@rv-jenkins rv-jenkins merged commit fde07ec into master Aug 16, 2023
@rv-jenkins rv-jenkins deleted the noah/anti-unify-sort-fix branch August 16, 2023 19:03
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
- Changed `anti_unify` and `anti_unify_with_constraints` to require a
`KDefinition` which they use to grab the tightest sort for the terms
they are abstracting
- Since these actions are now associated with a specific K definition,
moved them into `KDefinition` as methods.
- Adds `KDefinition.least_common_supersort` which returns the most
specific sort that will cover two terms (as long as one sort is a
subsort of the other).
- Uses this function in `KDefinition.sort` to determine the sort of a
`KRewrite`.
- Rewrote the tests for `anti_unify` and `anti_unify_with_constraints`
to use `KDefinition` and test that the abstracted variables are now more
tightly typed based on the original terms.

This is an attempt to fix an issue in
runtimeverification/evm-semantics#1934 where the
looser sort bound is preventing simplification after the merging
(anti-unification) of two nodes.

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 9, 2024
- Changed `anti_unify` and `anti_unify_with_constraints` to require a
`KDefinition` which they use to grab the tightest sort for the terms
they are abstracting
- Since these actions are now associated with a specific K definition,
moved them into `KDefinition` as methods.
- Adds `KDefinition.least_common_supersort` which returns the most
specific sort that will cover two terms (as long as one sort is a
subsort of the other).
- Uses this function in `KDefinition.sort` to determine the sort of a
`KRewrite`.
- Rewrote the tests for `anti_unify` and `anti_unify_with_constraints`
to use `KDefinition` and test that the abstracted variables are now more
tightly typed based on the original terms.

This is an attempt to fix an issue in
runtimeverification/evm-semantics#1934 where the
looser sort bound is preventing simplification after the merging
(anti-unification) of two nodes.

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
- Changed `anti_unify` and `anti_unify_with_constraints` to require a
`KDefinition` which they use to grab the tightest sort for the terms
they are abstracting
- Since these actions are now associated with a specific K definition,
moved them into `KDefinition` as methods.
- Adds `KDefinition.least_common_supersort` which returns the most
specific sort that will cover two terms (as long as one sort is a
subsort of the other).
- Uses this function in `KDefinition.sort` to determine the sort of a
`KRewrite`.
- Rewrote the tests for `anti_unify` and `anti_unify_with_constraints`
to use `KDefinition` and test that the abstracted variables are now more
tightly typed based on the original terms.

This is an attempt to fix an issue in
runtimeverification/evm-semantics#1934 where the
looser sort bound is preventing simplification after the merging
(anti-unification) of two nodes.

---------

Co-authored-by: devops <[email protected]>
Baltoli pushed a commit to runtimeverification/k that referenced this pull request Apr 10, 2024
- Changed `anti_unify` and `anti_unify_with_constraints` to require a
`KDefinition` which they use to grab the tightest sort for the terms
they are abstracting
- Since these actions are now associated with a specific K definition,
moved them into `KDefinition` as methods.
- Adds `KDefinition.least_common_supersort` which returns the most
specific sort that will cover two terms (as long as one sort is a
subsort of the other).
- Uses this function in `KDefinition.sort` to determine the sort of a
`KRewrite`.
- Rewrote the tests for `anti_unify` and `anti_unify_with_constraints`
to use `KDefinition` and test that the abstracted variables are now more
tightly typed based on the original terms.

This is an attempt to fix an issue in
runtimeverification/evm-semantics#1934 where the
looser sort bound is preventing simplification after the merging
(anti-unification) of two nodes.

---------

Co-authored-by: devops <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants