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 integration tests for bitshift operators #1272

Merged
merged 4 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions crates/nargo_cli/tests/test_data/bit_shifts/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
2 changes: 2 additions & 0 deletions crates/nargo_cli/tests/test_data/bit_shifts/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = 64
y = 1
26 changes: 26 additions & 0 deletions crates/nargo_cli/tests/test_data/bit_shifts/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fn main(x: u64, y: u64) {
let two: u64 = 2;
let three: u64 = 3;

// comptime shifts on comptime values
constrain two << 2 == 8;
constrain (two << 3) / 8 == two;
constrain (three >> 1) == 1;

// comptime shifts on runtime values
constrain x << 1 == 128;
constrain x >> 2 == 16;

// runtime shifts on comptime values
// These are currently unimplemented and panic with "ShiftLeft and ShiftRight operations with shifts which are only known at runtime are not yet implemented."
// See: https://github.com/noir-lang/noir/issues/1265
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
// constrain 64 << y == 128;
// constrain 64 >> y == 32;

// runtime shifts on runtime values
// These are currently unimplemented and panic with "ShiftLeft and ShiftRight operations with shifts which are only known at runtime are not yet implemented."
// See: https://github.com/noir-lang/noir/issues/1265
// constrain x << y == 128;
// constrain x >> y == 32;
constrain y == 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub(crate) fn evaluate(
};
InternalVar::from(bitwise_result)
}
BinaryOp::Shl | BinaryOp::Shr(_) => unreachable!("ICE: ShiftLeft and ShiftRight are replaced by multiplications and divisions in optimization pass."),
BinaryOp::Shl | BinaryOp::Shr(_) => todo!("ShiftLeft and ShiftRight operations with shifts which are only known at runtime are not yet implemented."),
i @ BinaryOp::Assign => unreachable!("Invalid Instruction: {:?}", i),
};
Some(binary_output)
Expand Down