Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable code: logging this expression type is not supported #1035

Closed
1 task
jfecher opened this issue Mar 24, 2023 · 5 comments · Fixed by #2178
Closed
1 task

Unreachable code: logging this expression type is not supported #1035

jfecher opened this issue Mar 24, 2023 · 5 comments · Fixed by #2178
Assignees
Labels
bug Something isn't working

Comments

@jfecher
Copy link
Contributor

jfecher commented Mar 24, 2023

Aim

Trying to compile the program:

use dep::std;

struct RV<T> {
    value: T,
    count: comptime Field,
}

impl<T> RV<T> {
    fn new(value: T) -> Self {
        Self { value, count: 1 }
    }

    fn increment(mut this: Self) -> Self {
        this.count += 1;
        this
    }

    fn print(self) {
        for _i in 0 .. self.count {
            std::println(self.value);
        }
    }
}

fn main() {
    let mut rv = RV::new(5);
    rv = rv.increment();
    rv.print();
}

Expected behavior

Expected the program to be compile and for 5 to be printed twice.

Bug

Compiler crashes after hitting an unreachable! line:

The application panicked (crashed).
Message:  internal error: entered unreachable code: logging this expression type is not supported
Location: crates/noirc_evaluator/src/ssa/context.rs:1165

This is a bug. Consider opening an issue at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 13 frames hidden ⋮                              
  14: noirc_evaluator::ssa::context::SsaContext::get_builtin_opcode::h81d6c1bcd20b2110
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/context.rs:1165
  15: noirc_evaluator::ssa::function::<impl noirc_evaluator::ssa::ssa_gen::IrGenerator>::call::h1b26b3b2fd8da2c5
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/function.rs:233
  16: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_expression::h27c0e2dc747eea02
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:551
  17: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_expression::h27c0e2dc747eea02
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:575
  18: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_block::he32ad37f040a9f9e
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:737
  19: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_expression::h27c0e2dc747eea02
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:562
  20: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_for::h20d6e02271f201c2
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:702
  21: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_expression::h27c0e2dc747eea02
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:554
  22: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_block::he32ad37f040a9f9e
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:737
  23: noirc_evaluator::ssa::ssa_gen::IrGenerator::ssa_gen_expression::h27c0e2dc747eea02
      at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/ssa_gen.rs:562

To reproduce

Installation method

None

Nargo version

No response

@noir-lang/noir_wasm version

No response

@noir-lang/barretenberg version

No response

@noir-lang/aztec_backend version

No response

Additional context

No response

Submission Checklist

  • Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
@jfecher jfecher added the bug Something isn't working label Mar 24, 2023
@jfecher
Copy link
Contributor Author

jfecher commented Mar 24, 2023

The code is crashing at /Users/jakefecher/Code/Noir/noir/crates/noirc_evaluator/src/ssa/context.rs:1165:

builtin::Opcode::Println(_) => {
    // Compiler sanity check. This should be caught during typechecking
    assert_eq!(
        arguments.len(),
        1,
        "print statements currently only support one argument"
    );
    let is_string = match &arguments[0] {
        Expression::Ident(ident) => match ident.typ {
            Type::String(_) => true,
            Type::Tuple(_) => {
                unreachable!("logging structs/tuples is not supported")
            }
            Type::Function { .. } => {
                unreachable!("logging functions is not supported")
            }
            _ => false,
        },
        Expression::Literal(literal) => matches!(literal, Literal::Str(_)),
        _ => unreachable!("logging this expression type is not supported"),
    };
    Some(builtin::Opcode::Println(builtin::PrintlnInfo {
        is_string_output: is_string,
        show_output: true,
    }))
}

This is checking for variables/literals while constructing the ssa instead of after its optimizations are finished. If we delay this check until after the optimizations, the code used in the example will become literal values rather than a field access and this existing check should print it just fine.

@kevaundray
Copy link
Contributor

@vezenovm what is the status of this issue with the new ssa code?

@vezenovm
Copy link
Contributor

This looks like it may be a separate issue with the new SSA code @jfecher:

use dep::std;

struct RV<T> {
    value: T,
    count: comptime Field,
}

impl<T> RV<T> {
    fn new(value: T) -> Self {
        Self { value, count: 1 }
    }

    fn increment(mut this: Self) -> Self {
        this.count += 1;
        this
    }

    fn print(self) {
        for _i in 0..self.count {
            // std::println(self.value);
        }
    }
}

fn main() {
    let mut rv = RV::new(5);
    rv = rv.increment();
    rv.print();
}

I'm getting the same error with the std::println call and without it.

Message:  internal error: entered unreachable code: return encountered before a join point was found. This can only happen if early-return was added to the language without implementing it by jmping to a join block first
Location: crates/noirc_evaluator/src/ssa_refactor/opt/flatten_cfg/branch_analysis.rs:107

@vezenovm
Copy link
Contributor

The same error occurs for this issue: #1367, with or without the println

@jfecher
Copy link
Contributor Author

jfecher commented Jul 25, 2023

The join point error is a result of using the mutable comptime variable as a loop bound. Unfortunately mutability and comptime don't play well together since our pass to remove mutability is after unrolling rather than before. Adding this pass before unrolling fixes the issue but I'm unsure if it causes other bugs as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants