Skip to content

Commit b7a08c0

Browse files
Fix bug where we consider all mutable ops as replacements
1 parent 4c15018 commit b7a08c0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

python/egglog/egraph.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,17 +768,17 @@ def _add_default_rewrite_function(
768768
res_type: TypeOrVarRef,
769769
mutates_first_arg: bool,
770770
) -> None:
771-
args: list[object] = [RuntimeExpr.__from_values__(decls, a) for a in args]
772-
771+
args = list(args)
772+
arg_exprs: list[RuntimeExpr | RuntimeClass] = [RuntimeExpr.__from_values__(decls, a) for a in args]
773773
# If this is a classmethod, add the class as the first arg
774774
if isinstance(ref, ClassMethodRef):
775775
tp = decls.get_paramaterized_class(ref.ident)
776-
args.insert(0, RuntimeClass(Thunk.value(decls), tp))
776+
arg_exprs.insert(0, RuntimeClass(Thunk.value(decls), tp))
777777
with set_current_ruleset(ruleset):
778-
res = fn(*args)
779-
if mutates_first_arg:
778+
res = fn(*arg_exprs)
779+
# If the function mutates the first arg and we have overwritten it, then use that as the result
780+
if mutates_first_arg and arg_exprs[0].__egg_typed_expr__ != args[0]:
780781
res = args[0]
781-
# print(res)
782782
_add_default_rewrite(decls, ref, res_type, res, ruleset, subsume)
783783

784784

0 commit comments

Comments
 (0)