Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove eval and rework primitive extraction #265

Merged
merged 5 commits into from
Feb 27, 2025
Merged

Conversation

saulshanabrook
Copy link
Member

@saulshanabrook saulshanabrook commented Feb 26, 2025

This PR reworks how primitives are extracted. Previously you would use egraph.eval(x) if x is a primitive like an i64 to get the python int value from it. This used some private methods of the egraph at runtime to inspect the rust value.

Instead, we now just extract the primitive and use python to "parse" it from the AST. So this also works for things like vecs. This adds support for python builtin methods like int and list so they can be used to implicitly extract things from the egraph:

>>> from egglog import *
>>> i64(1) + 2
i64(1) + 2
>>> int(i64(1) + 2)
3
>>> Vec(i64(1)).push(i64(2))
Vec(1).push(2)
>>> list(Vec(i64(1)).push(i64(2)))
[i64(1), i64(2)]

To do this, we refine the concept of a "current" e-graph in the context. If none exists, one will be created. But we can use one with the egraph.set_current() context manager.

We also add support for translating == into eq and != into ne for all types. If you need to override these operations on your type, you still can, and then just use the functions.

Copy link

codspeed-hq bot commented Feb 26, 2025

CodSpeed Performance Report

Merging #265 will not alter performance

Comparing current_egraph (87edb7d) with main (af2cdc8)

Summary

✅ 8 untouched benchmarks

@saulshanabrook saulshanabrook merged commit 3489a6b into main Feb 27, 2025
13 checks passed
@saulshanabrook saulshanabrook deleted the current_egraph branch February 27, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant