Metatheory.jl icon indicating copy to clipboard operation
Metatheory.jl copied to clipboard

Issues in E-graph matching for parametrized types

Open ChenZhao44 opened this issue 1 year ago • 5 comments

Here is an example.

using Metatheory, TermInterface

struct Foo{A}
    x::A
end

TermInterface.istree(::Foo{T}) where T = true
TermInterface.istree(::Type{Foo{T}}) where T = true
TermInterface.exprhead(::Foo) = :call
TermInterface.operation(::Foo{T}) where T = :(Foo{$T})
TermInterface.arguments(f::Foo) = f.x

function TermInterface.similarterm(::Type{Foo{T}}, f, args; metadata=nothing, exprhead = :call) where T
    return Foo(args...)
end

t = @theory T A begin
    Foo{T}(A) => A
end

f = Foo([:x])
eg = EGraph(f)
saturate!(eg, t)
extract!(eg, astsize) # this returns Foo([:x]) instead of [:x]

ChenZhao44 avatar Sep 28 '22 23:09 ChenZhao44