Skip to content

Issue with CallDecl __eq__ #244

@Pusty

Description

@Pusty

The performance modification for CallDecl causes problems for cases where the hashes collide.
This is specifically a problem (for me at least) because for python (or at least CPython, but I was able to reproduce with pypy and ipython) hash(-1) == hash(-2).
I'm not sure if there are more problematic edge-cases but this specifically is causing problems for my use case.

from egglog import *

class Num(Expr):
    def __init__(self, value: i64Like) -> None: ...

egraph = EGraph()
expr1 = egraph.let("expr1", Num(-1))
expr2 = egraph.let("expr2", Num(-2))
egraph.check(eq(expr1).to(expr2))
print(egraph.extract(expr1))
print(egraph.extract(expr2))

Will not find a problem with the equality and print Num(-1) for both (which leads to wrong equalities).

https://github.com/egraphs-good/egglog-python/blob/8b1758054abe18d27ffb3d0c1f59a05b33e32947/python/egglog/declarations.py#L572C1-L576C41

seems to be the problematic code and replacing it with the unoptimized variant fixes the problem.

def __eq__(self, other: object) -> bool:
    if not isinstance(other, egglog.declarations.CallDecl):
        return False
    return self.callable == other.callable and self.args == other.args and self.bound_tp_params == other.bound_tp_params

Undoing the optimization obviously has a performance impact so I'm not sure if just changing it like this is ideal though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions