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

feat: add a panic method to the stdlib #5966

Merged
merged 3 commits into from
Sep 9, 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
1 change: 1 addition & 0 deletions noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod runtime;
mod meta;
mod append;
mod mem;
mod panic;

// Oracle calls are required to be wrapped in an unconstrained function
// Thus, the only argument to the `println` oracle is expected to always be an ident
Expand Down
6 changes: 4 additions & 2 deletions noir_stdlib/src/meta/op.nr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl UnaryOp {
} else if self.is_dereference() {
quote { * }
} else {
crate::mem::zeroed()
let op = self;
crate::panic::panic(f"Unexpected unary operator in UnaryOp::quoted: {op}")
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -181,7 +182,8 @@ impl BinaryOp {
} else if self.is_modulo() {
quote { % }
} else {
crate::mem::zeroed()
let op = self;
crate::panic::panic(f"Unexpected binary operator in BinaryOp::quoted: {op}")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions noir_stdlib/src/panic.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub fn panic<T, U, let N: u32>(message: fmtstr<N, T>) -> U {
assert(false, message);
crate::mem::zeroed()
}
1 change: 1 addition & 0 deletions noir_stdlib/src/prelude.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub use crate::cmp::{Eq, Ord};
pub use crate::default::Default;
pub use crate::convert::{From, Into};
pub use crate::meta::{derive, derive_via};
pub use crate::panic::panic;
Loading