CSE join: canonicalise the primitives in both environments #3182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3181.
As explained in a comment there, when joining CSE equations we want to transform equations at the use site into equations at the join site (in the env at fork). There are multiple ways to do that: all aliases of primitive arguments that are in scope in the env at fork could be considered, which would yield the most precise result but risks exploding the number of CSE equations.
Before this PR we canonicalise in the environment at use, which handles the cases where primitives were called on local aliases of a "global" variable.
But we're failing in cases like the one from #3181, where a CSE equation is common to all branches but some branches have equations that change which element is canonical.
So this PR proposes to canonicalise in the env at fork in addition to the env at use. This potentially doubles the number of primitives, but in the common case where the branch doesn't introduce new relevant aliases the primitives are the same (using
EP.Set.t
to represent these possibilities means we don't actually have to check that manually).