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

fix: Allow comptime code to use break without also being unconstrained #5744

Merged
merged 1 commit into from
Aug 16, 2024
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
11 changes: 7 additions & 4 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,9 +1458,12 @@ impl<'context> Elaborator<'context> {
/// True if we're currently within a constrained function.
/// Defaults to `true` if the current function is unknown.
fn in_constrained_function(&self) -> bool {
self.current_item.map_or(true, |id| match id {
DependencyId::Function(id) => !self.interner.function_modifiers(&id).is_unconstrained,
_ => true,
})
!self.in_comptime_context()
&& self.current_item.map_or(true, |id| match id {
DependencyId::Function(id) => {
!self.interner.function_modifiers(&id).is_unconstrained
}
_ => true,
})
}
}
2 changes: 1 addition & 1 deletion noir_stdlib/src/meta/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub comptime fn derive(s: StructDefinition, traits: [TraitDefinition]) -> Quoted
result
}

unconstrained pub comptime fn derive_via(t: TraitDefinition, f: DeriveFunction) {
pub comptime fn derive_via(t: TraitDefinition, f: DeriveFunction) {
HANDLERS.insert(t, f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {

// Call a different function from the interpreter, then have the
// elaborator switch to the middle of foo from its previous scope in main
unconstrained comptime fn foo<let N: Field>(x: Field) {
comptime fn foo<let N: Field>(x: Field) {
assert(modulus_num_bits() != 0);

let cond = quote { modulus_num_bits() != 0 };
Expand Down
Loading