egraphs-good / egglog

egraphs + datalog!
https://egraphs-good.github.io/egglog/
MIT License
400 stars 45 forks source link

No matching primitive: set-length #378

Closed cgyurgyik closed 3 months ago

cgyurgyik commented 3 months ago
(sort ISetBase (Set i64))

; Reify set
(sort ISet)
(function IS (ISetBase) ISet)

(function ISet-length (ISet i64) i64 :unextractable)
(rule ((IS x))
    ((set (ISet-length (IS x)) (set-length x))))

(let myset (IS (set-of 2 4 1 4 -1)))
(run 100)
(check (= 4 (ISet-length myset 0)))

Trying to build a smaller repro from the toy example, this leads to the following error with egglog 0.1.0:

(sort ISetBase (Set i64))
(sort ISet)
(function IS (ISetBase) ISet)
(function ISet-length (ISet i64) i64 :unextractable)
(rule ((IS x))
      ((set (ISet-length (IS x)) (set-length x)))
         )
(let myset (IS (set-of 2 4 1 4 -1)))
(run-schedule (repeat 100 (run)))
(check (= 4 (ISet-length myset 0)))
thread 'main' panicked at e-graph/egraph-cargo/src/main.rs:18:29:

No matching primitive for: (set-length ISetBase)

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
cgyurgyik commented 3 months ago

With BACKTRACE=1,

stack backtrace:
   0: rust_begin_unwind
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
   1: core::panicking::panic_fmt
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
   2: egraph_cargo::main::{{closure}}
             at ./src/main.rs:18:29
   3: core::result::Result<T,E>::unwrap_or_else
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1429:23
   4: egraph_cargo::main
             at ./src/main.rs:16:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
yihozhang commented 3 months ago

I was not able to reproduce this behavior. With the program you provided, I got error Arity mismatch, expected 2 args: (ISet-length $IS1).

Getting rid of the second parameter to ISet-length, the program runs as expected.

(sort ISetBase (Set i64))

; Reify set
(sort ISet)
(function IS (ISetBase) ISet)

(function ISet-length (ISet) i64 :unextractable)
(rule ((IS x))
    ((set (ISet-length (IS x)) (set-length x))))

(let myset (IS (set-of 2 4 1 4 -1)))
(run 100)
(check (= 4 (ISet-length myset)))

link

Maybe you are using an older version of egglog?

cgyurgyik commented 3 months ago

Indeed, I was using the latest Rust crate egglog 0.1.0, but it works fine when using the latest commit in this repository. Thanks!