Stream: cranelift

Topic: Jumping to an earlier block from a later block?


view this post on Zulip osa1 (May 24 2020 at 14:40):

In my low-level IR I have this:

function #cc_g() -> W
b0:
    #an_f: int = 1
    jump b2
b1:
    return f_a
b2:
    #cc_h: ??? = #builtin[print_int].0
    f_a: () = #cc_h(#builtin[print_int], #an_f)
    jump b1

The mapping of this to cranelift is very direct, blocks map 1-1, so the cranelift function looks like:

function u0:0() -> i64 system_v {
    gv0 = symbol u1:0
    gv1 = symbol u1:0
    sig0 = (i64) -> i64 system_v
    sig1 = (i64, i64) -> i64 system_v
    fn0 = u0:0 sig0

block0:
    v0 = iconst.i64 1
    jump block2

Now at this point I get a panic while printing the next block, the error message just says "INVALID encountered". Any ideas what's wrong here?

view this post on Zulip osa1 (May 24 2020 at 14:40):

I'm guessing that use of the variable f_a in b1 is not quite correct (because it's declared in the next block), but I'm not sure

view this post on Zulip bjorn3 (May 24 2020 at 14:49):

I noticed you are using declare_var for every assignment: https://github.com/osa1/mincaml/blob/b8ef0a735cc5a88333f7aebaf89a5be062bebf03/src/codegen.rs#L299 If you can assign to the same variable multiple times, you should only call declare_var once. For some reason there is no assertion about this though.

The problem here is likely that you used use_var before the declare_var call though. This means that during the use_var call Cranelift thinks the type of the variable is INVALID, which is not allowed.

A MinCaml compiler implemented in Rust. Contribute to osa1/mincaml development by creating an account on GitHub.

view this post on Zulip bjorn3 (May 24 2020 at 14:50):

You need to call declare_var exactly once for a variable before you use either def_var or use_var.

view this post on Zulip bjorn3 (May 24 2020 at 14:51):

The code could use a couple of assertions.

view this post on Zulip osa1 (May 24 2020 at 14:52):

The problem here is likely that you used use_var before the declare_var call though

Ahh, you're probably right.

view this post on Zulip bjorn3 (May 24 2020 at 14:55):

bjorn3 said:

The code could use a couple of assertions.

https://github.com/bytecodealliance/wasmtime/pull/1751

cc https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/Jumping.20to.20an.20earlier.20block.20from.20a.20later.20block.3F/near/198585961 cc @osa1

view this post on Zulip osa1 (May 24 2020 at 14:56):

You were right about declarations -- I fixed the issue. Thanks!


Last updated: Nov 22 2024 at 16:03 UTC