Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/dfg/simplify/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ fn array_is_constant(dfg: &DataFlowGraph, values: &im::Vector<ValueId>) -> bool
values.iter().all(|value| dfg.get_numeric_constant(*value).is_some())
}

/// Replaces a call to `derive_pedersen_generators` with the results of the computation.
///
/// It only works if the arguments to the call are both constants, which means that the
/// function which contains this call needs to be inlined into its caller, where the
/// arguments are known. This is taken care of by the `#[no_predicates]` attribute,
/// which forces inlining after flattening.
///
/// This intrinsic must not reach Brillig-gen.
fn simplify_derive_generators(
dfg: &mut DataFlowGraph,
arguments: &[ValueId],
Expand Down
22 changes: 22 additions & 0 deletions compiler/noirc_frontend/src/monomorphization/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,28 @@ impl InlineType {
InlineType::NoPredicates => false,
}
}

/// Produce an `InlineType` which we can use with an unconstrained version of a function.
pub fn into_unconstrained(self) -> Self {
match self {
InlineType::Inline | InlineType::InlineAlways => self,
InlineType::Fold => {
// The #[fold] attribute is about creating separate ACIR circuits for proving,
// not relevant in Brillig. Leaving it violates some expectations that each
// will become its own entry point.
Self::default()
}
InlineType::NoPredicates => {
// The #[no_predicates] are guaranteed to be inlined after flattening,
// which is needed for some of the programs even in Brillig, otherwise
// some intrinsics can survive until Brillig-gen that weren't supposed to.
// We can keep these, or try inlining more aggressively, since we don't
// have to wait until after flattening in Brillig, but InlineAlways
// resulted in some Brillig bytecode size regressions.
self
}
}
}
}

impl Display for InlineType {
Expand Down
5 changes: 4 additions & 1 deletion compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ impl<'interner> Monomorphizer<'interner> {
let unconstrained = self.in_unconstrained_function;

let attributes = self.interner.function_attributes(&f);
let inline_type = InlineType::from(attributes);
let mut inline_type = InlineType::from(attributes);
if unconstrained {
inline_type = inline_type.into_unconstrained();
}

let parameters = self.parameters(&meta.parameters)?;
let body = self.expr(body_expr_id)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "regression_10153"
type = "bin"
authors = [""]

[dependencies]
17 changes: 17 additions & 0 deletions test_programs/compile_success_no_bug/regression_10153/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub fn main() -> pub Field {
let _f = foo; // function pointer with #[fold]

// Safety: test
unsafe {
bar()
}
}

#[fold]
fn foo() -> Field {
0
}

unconstrained fn bar() -> Field {
foo() // #[fold] called from unconstrained
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading