egraphs-good / eggcc

MIT License
51 stars 11 forks source link

RVSDG translation error: Function returning loaded value doesn't return state edge #621

Closed rtjoa closed 4 months ago

rtjoa commented 5 months ago

The following program panics with RunType egglog:

@load(p: ptr<int>) {
    v: int = load p;
    ret v;
}

@main(p: ptr<int>) {
    v: int = call @load p;
}

with this message:

thread 'main' panicked at dag_in_context/src/typechecker.rs:331:21:
Index out of bounds. Tuple has type (TupleT (TCons (StateT) (TNil))), index is 1. Expr:
(Get (Call "load" (Concat (Single (Get (Arg (Unknown) (InFunc "dummy")) 0)) (Single (Get (Arg (Unknown) (InFunc "dummy")) 1)))) 1)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I think we see the problem - that a function returning a loaded value doesn't return a state edge - when we print this simple program as RVSDG:

@main(p: ptr<int>) {
    v: int = load p;
    ret v;
}

image

ezrosent commented 5 months ago

I think the issue is with the load function, which returns something but doesn't declare a return type. I get errors when I try to interpret calls to load in a main that doesn't take a pointer param.

If I add the following test to eggcc it passes:

@load(p: ptr<int>): int {
    v: int = load p;
    ret v;
}

@main() {
    one: int = const 1;
    p: ptr<int> = alloc one;
    store p one;
    v: int = call @load p;
    free p;
    print v;
}

Thoughts @rtjoa?

rtjoa commented 4 months ago

Oops, you're right. Closing