Skip to content

Predicates for pattern variables are not checked consistently #246

@gkronber

Description

@gkronber

I was surprised by some inconsistent behaviour of pattern variable predicates (when using the same pattern variable).
If a pattern variable occurs twice, it seems that only the predicate for the first occurrance is checked.
Here is a minimal example:

using Metatheory

is_nonzero(::EGraph, ::EClass) = false # just for the test

theory1 = @theory a begin
  a / a --> 1
end

theory2 = @theory a begin
  a::is_nonzero / a --> 1
end

theory3 = @theory a begin
  a / a::is_nonzero --> 1
end

theory4 = @theory a begin
  a::is_nonzero / a::is_nonzero --> 1
end

function test(theo)
  g = EGraph(:(x / x))
  saturate!(g, theo)
  extract!(g, astsize)
end

test(theory1) # --> 1 (as expected)
test(theory2) # --> :(x / x) (as expected because the predicate works)
test(theory3) # --> 1 (incorrect! predicate only used for the second variable)
test(theory4) # --> :(x / x) ok

There is also no warning about inconsistent predicates. People might use different predicates for different occurances of pattern variables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions