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

Rewrite regardless of variant #401

Open
AzizZayed opened this issue Jul 29, 2024 · 1 comment
Open

Rewrite regardless of variant #401

AzizZayed opened this issue Jul 29, 2024 · 1 comment

Comments

@AzizZayed
Copy link

Is it possible to also make the variant a variable in egglog? For example:

(datatype Shape
    (Shape2D i64 i64)
)

(datatype MatrixOp
    (Matrix String Shape)  ; (<name> <nrows> <ncols>)
    (MatrixTranspose MatrixOp Shape)
)

(let ma (Matrix "a" (Shape2D 5 10)))
(let mb (Matrix "b" (Shape2D 10 15)))
(let mc (Matrix "c" (Shape2D 15 2)))

(function shape-of (MatrixOp) Shape)

(rewrite
    (shape-of (?variant ?op ?s))  ; notice here the variant does is also a variable
    ?s
)

I'm sure there is no support for exactly what I wrote above. But is there any construct within egglog that can achieve the same goal: 1 rewrite rule can apply to many variants of a datatype?

@saulshanabrook
Copy link
Member

Not exactly, but the solution I would recommend would be to rewrite those variants into different constructors of the same type... Like for this example:

(datatype Shape
    (Shape2D i64 i64)
)

(datatype MatrixOp
    (matrix String)
    (MatrixTranspose MatrixOp)
)

(datatype Matrix
  (apply-op MatrixOp Shape))

(let ma (apply-op (matrix "a") (Shape2D 5 10))))

(function shape-of (Matrix) Shape)

(rewrite
    (shape-of (apple-op m s)) 
    s
)

If you want to keep the alternative construct you have above, you could also do that, but just rewrite it to this form so that you can apply the rewrite uniformly.

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

No branches or pull requests

2 participants