Skip to content

Commit

Permalink
fix: Ignore no_predicates in brillig functions (#5012)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #5010

## Summary\*

Ignores no predicates for brillig functions to avoid trying to convert
to brillig flattened functions.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
sirasistant authored May 10, 2024
1 parent c8b70ac commit b541e79
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/noirc_evaluator/src/ssa/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::ssa::{
ir::{
basic_block::BasicBlockId,
dfg::{CallStack, InsertInstructionResult},
function::{Function, FunctionId},
function::{Function, FunctionId, RuntimeType},
instruction::{Instruction, InstructionId, TerminatorInstruction},
value::{Value, ValueId},
},
Expand Down Expand Up @@ -392,10 +392,11 @@ impl<'function> PerFunctionContext<'function> {
Some(func_id) => {
let function = &ssa.functions[&func_id];
// If we have not already finished the flattening pass, functions marked
// to not have predicates should be marked as entry points.
// to not have predicates should be marked as entry points unless we are inlining into brillig.
let no_predicates_is_entry_point =
self.context.no_predicates_is_entry_point
&& function.is_no_predicates();
&& function.is_no_predicates()
&& !matches!(self.source_function.runtime(), RuntimeType::Brillig);
if function.runtime().is_entry_point() || no_predicates_is_entry_point {
self.push_instruction(*id);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "no_predicates_brillig"
type = "bin"
authors = [""]
compiler_version = ">=0.27.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "10"
y = "20"
12 changes: 12 additions & 0 deletions test_programs/execution_success/no_predicates_brillig/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unconstrained fn main(x: u32, y: pub u32) {
basic_checks(x, y);
}

#[no_predicates]
fn basic_checks(x: u32, y: u32) {
if x > y {
assert(x == 10);
} else {
assert(y == 20);
}
}

0 comments on commit b541e79

Please sign in to comment.