Skip to content

ICE: unreacheable code #5008

Closed
Closed
@nventuro

Description

@nventuro

Aim

This is a follow up to #4497. I did some more trimming and arrived at a minimal example that results in a compiler crash.

Bug

The following program crashes:

struct Bar {
    value: Field,
}

struct Foo{
    bar: &mut Bar,
}

impl Foo {
    unconstrained fn crash_fn(self) {}
}

fn main() {
    let foo = Foo { bar: &mut Bar { value: 0 } };

    foo.crash_fn();
}

The error message is

The application panicked (crashed).
Message:  internal error: entered unreachable code: Expected all allocate instructions to be removed before acir_gen
Location: compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs:689

I couldn't distill this down any further. The crash is avoided with any of these changes:

  • if main is unconstrained
  • if crash_fn is not unconstrained
  • if bar takes a & and not a &mut
  • if Bar has no members
  • if crash_fn doesn't take self

So it seems like the bug is related to some odd combination of all of the above.

To Reproduce

Compile the program above.

Project Impact

Blocker

Impact Context

This blocks some currently open PRs, such as AztecProtocol/aztec-packages#4940.

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

Compiled from source

Nargo Version

nargo version = 0.28.0 noirc version = 0.28.0+98eb519766ae219d2f10550944bba83f30f7662c (git version hash: 98eb519766ae219d2f10550944bba83f30f7662c, is dirty: false)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions