egglog-python
egglog-python copied to clipboard
Simplifying an expression with a Map argument.
m = egraph.let("map", Map[String, i64].empty().insert(String("a"), i64(42)))
egraph.simplify(m, 5)
Results in:
Traceback (most recent call last):
File "/.../egg/working-version/../list.py", line 265, in <module>
egraph.simplify(m, 5)
File "/.../venv/lib/python3.10/site-packages/egglog/egraph.py", line 1025, in simplify
(new_typed_expr,) = self._state.exprs_from_egg(extract_report.termdag, [extract_report.term], typed_expr.tp)
File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 340, in exprs_from_egg
return [state.from_expr(tp, term) for term in terms]
File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 340, in <listcomp>
return [state.from_expr(tp, term) for term in terms]
File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 421, in from_expr
expr_decl = self.from_call(tp, term)
File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 465, in from_call
args = tuple(self.resolve_term(a, tp)
File "/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 465, in <genexpr>
args = tuple(self.resolve_term(a, tp)
File "/.../venv/lib/python3.10/site-packages/egglog/type_constraint_solver.py", line 83, in <genexpr>
self._subtitute_typevars(a, cls_name) for a in chain(fn_args, repeat(fn_var_args) if fn_var_args else [])
File "/.../venv/lib/python3.10/site-packages/egglog/type_constraint_solver.py", line 136, in _subtitute_typevars
assert cls_name is not None
Interestingly, if I make it an argument to an Expr class and saturate(), i.e.,
class CMap(Expr):
def __init__(self, m: Map[String, i64]) -> None: ...
egraph.let("map", CMap(Map[String, i64].empty().insert(String("a"), i64(42))))
egraph.saturate()
...then it works as expected (since I'm not simplifying).
I get a (perhaps) related error when using Set and simplifying:
/.../venv/lib/python3.10/site-packages/egglog/egraph_state.py", line 468, in from_call
raise ValueError(f"Could not find callable ref for call {term}")
ValueError: Could not find callable ref for call App("set-insert", [21, 3])
Thanks for opening this! I'll take a look. I don't use the builtin collections much, so they haven't gotten as much testing.
This was fixed in #168 and I just released version 7.2.0 which includes this bugfix.