Repository navigation
Conversation
predicateCombination matched collections by String(), which prints some different trees the same: a BuiltinNode's Map field, a folded (-2) left of **, and folded float or NaN constants. Compare the trees field by field instead.
Compare only a ConstantNode's value, not its location and type, so identical constant collections still merge. Bound the depth of the constant walk so a self-referential value cannot overflow the stack.
Remember visited pointer pairs, like reflect.DeepEqual, so constants that reuse a value in many places or refer to themselves compare in linear time. Match map keys that == does not compare exactly, such as 0.0 and -0.0, by searching.
Drop the visited set: a failed map key search left wrong entries in it, and it missed values shared through arrays. Constants now compare only when they hold plain data with exactly comparable map keys, and the whole comparison stops after a fixed number of steps. Anything else counts as different, which only skips the merge.
Treat the very same pointer, map or slice in two constants as the same value, so a cached ConstExpr result like []*User still merges. Build the large-constant test values twice so the comparison walks them.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The optimizer merges
all/any/nonecalls on the same collection, such asall(x, p) && all(x, q). It decided two collections were the same by comparing theirString()output, and some different trees still print the same after #1026:BuiltinNode.Map, set by the filterMap pass, is not printed, somap(filter(a, p), f)prints asfilter(a, p).(-2)left of**prints as-2 ** n, the same as-(2 ** n).2.0as2, and NaN like an identifier.Each of these gave a different result with the optimizer on than with it off. This compares the two collection trees field by field instead. Constants are compared by type and value, floats by bits so that
0.0and-0.0stay apart, and anything it can't compare counts as different.