Open ezrosent opened 6 months ago
Unfortunately using set
on datatypes is going to be disallowed with the semantics we decided on recently.
Perhaps query compilation can recognize this optimization later in the pipeline?
I thought set
would still be allowed, we just don't get lookups after a set?
set
should be allowed for functions with custom merge functions, but constructors like Add
should not be set
, only union
ed
We desugar code like
(rewrite (Add x y) (Add y x))
into something like:But using
union
is only needed if the right-hand side of a rewrite is an identifier. When it's an expression, we could do:This should be safe, but it gives egglog less work to do: if
(Add y x)
is in the database already, setting it will call union anyway as part of the merge process. If it isn't we skip creating a new noncanonical id that rebuilding has to clean up.On the following program, this is a significant speedup:
This program takes 22.5 seconds to saturate on my machine. The usual rules for associativity and commutativity take 29s.