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: Sync from noir #6267

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c49d3a9ded819b828cffdfc031e86614da21e329
e43661d16c1cd07e2af2392b88d29c689889ff9a
2 changes: 1 addition & 1 deletion noir/noir-repo/.github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
save-if: ${{ github.event_name != 'merge_group' }}

- name: Run `cargo clippy`
run: cargo clippy --workspace --locked --release
run: cargo clippy --all-targets --workspace --locked --release

- name: Run `cargo fmt`
run: cargo fmt --all --check
Expand Down
1 change: 0 additions & 1 deletion noir/noir-repo/Cargo.lock

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

4 changes: 2 additions & 2 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub const NOIR_ARTIFACT_VERSION_STRING: &str =
#[derive(Args, Clone, Debug, Default)]
pub struct CompileOptions {
/// Override the expression width requested by the backend.
#[arg(long, value_parser = parse_expression_width)]
pub expression_width: Option<ExpressionWidth>,
#[arg(long, value_parser = parse_expression_width, default_value = "3")]
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
pub expression_width: ExpressionWidth,

/// Force a full recompilation.
#[arg(long = "force")]
Expand Down
3 changes: 3 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use iter_extended::vecmap;
pub enum IntegerBitSize {
One,
Eight,
Sixteen,
ThirtyTwo,
SixtyFour,
}
Expand All @@ -48,6 +49,7 @@ impl From<IntegerBitSize> for u32 {
match size {
One => 1,
Eight => 8,
Sixteen => 16,
ThirtyTwo => 32,
SixtyFour => 64,
}
Expand All @@ -64,6 +66,7 @@ impl TryFrom<u32> for IntegerBitSize {
match value {
1 => Ok(One),
8 => Ok(Eight),
16 => Ok(Sixteen),
32 => Ok(ThirtyTwo),
64 => Ok(SixtyFour),
_ => Err(InvalidIntegerBitSizeError(value)),
Expand Down

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ fn for_loop() {
assert_eq!(result, Value::U8(15));
}

#[test]
fn for_loop_u16() {
let program = "fn main() -> pub u16 {
let mut x = 0;
for i in 0 .. 6 {
x += i;
}
x
}";
let result = interpret(program, vec!["main".into()]);
assert_eq!(result, Value::U16(15));
}

#[test]
fn for_loop_with_break() {
let program = "unconstrained fn main() -> pub u32 {
Expand Down
13 changes: 13 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ pub enum Value {
Bool(bool),
Field(FieldElement),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
String(Rc<String>),
Expand All @@ -45,9 +47,11 @@ impl Value {
Value::Bool(_) => Type::Bool,
Value::Field(_) => Type::FieldElement,
Value::I8(_) => Type::Integer(Signedness::Signed, IntegerBitSize::Eight),
Value::I16(_) => Type::Integer(Signedness::Signed, IntegerBitSize::Sixteen),
Value::I32(_) => Type::Integer(Signedness::Signed, IntegerBitSize::ThirtyTwo),
Value::I64(_) => Type::Integer(Signedness::Signed, IntegerBitSize::SixtyFour),
Value::U8(_) => Type::Integer(Signedness::Unsigned, IntegerBitSize::Eight),
Value::U16(_) => Type::Integer(Signedness::Unsigned, IntegerBitSize::Sixteen),
Value::U32(_) => Type::Integer(Signedness::Unsigned, IntegerBitSize::ThirtyTwo),
Value::U64(_) => Type::Integer(Signedness::Unsigned, IntegerBitSize::SixtyFour),
Value::String(value) => {
Expand Down Expand Up @@ -87,6 +91,12 @@ impl Value {
let value = (value as u128).into();
HirExpression::Literal(HirLiteral::Integer(value, negative))
}
Value::I16(value) => {
let negative = value < 0;
let value = value.abs();
let value = (value as u128).into();
HirExpression::Literal(HirLiteral::Integer(value, negative))
}
Value::I32(value) => {
let negative = value < 0;
let value = value.abs();
Expand All @@ -102,6 +112,9 @@ impl Value {
Value::U8(value) => {
HirExpression::Literal(HirLiteral::Integer((value as u128).into(), false))
}
Value::U16(value) => {
HirExpression::Literal(HirLiteral::Integer((value as u128).into(), false))
}
Value::U32(value) => {
HirExpression::Literal(HirLiteral::Integer((value as u128).into(), false))
}
Expand Down
7 changes: 5 additions & 2 deletions noir/noir-repo/compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ mod test {
fresh_statement(),
true,
),
vec!["x as u8", "0 as Field", "(x + 3) as [Field; 8]"],
vec!["x as u8", "x as u16", "0 as Field", "(x + 3) as [Field; 8]"],
);
parse_all_failing(
atom_or_right_unary(
Expand Down Expand Up @@ -1546,7 +1546,10 @@ mod test {
// Let statements are not type checked here, so the parser will accept as
// long as it is a type. Other statements such as Public are type checked
// Because for now, they can only have one type
parse_all(declaration(expression()), vec!["let _ = 42", "let x = y", "let x : u8 = y"]);
parse_all(
declaration(expression()),
vec!["let _ = 42", "let x = y", "let x : u8 = y", "let x: u16 = y"],
);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ keywords: [noir, integer types, methods, examples, arithmetic]
sidebar_position: 1
---

An integer type is a range constrained field type. The Noir frontend supports both unsigned and signed integer types. The allowed sizes are 1, 8, 32 and 64 bits.
An integer type is a range constrained field type.
The Noir frontend supports both unsigned and signed integer types.
The allowed sizes are 1, 8, 16, 32 and 64 bits.

:::info

Expand Down
24 changes: 12 additions & 12 deletions noir/noir-repo/docs/docs/noir/standard_library/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ These traits abstract over addition, subtraction, multiplication, and division r
Implementing these traits for a given type will also allow that type to be used with the corresponding operator
for that trait (`+` for Add, etc) in addition to the normal method names.

#include_code add-trait noir_stdlib/src/ops.nr rust
#include_code sub-trait noir_stdlib/src/ops.nr rust
#include_code mul-trait noir_stdlib/src/ops.nr rust
#include_code div-trait noir_stdlib/src/ops.nr rust
#include_code add-trait noir_stdlib/src/ops/arith.nr rust
#include_code sub-trait noir_stdlib/src/ops/arith.nr rust
#include_code mul-trait noir_stdlib/src/ops/arith.nr rust
#include_code div-trait noir_stdlib/src/ops/arith.nr rust

The implementations block below is given for the `Add` trait, but the same types that implement
`Add` also implement `Sub`, `Mul`, and `Div`.
Expand All @@ -211,7 +211,7 @@ impl Add for u64 { .. }

### `std::ops::Rem`

#include_code rem-trait noir_stdlib/src/ops.nr rust
#include_code rem-trait noir_stdlib/src/ops/arith.nr rust

`Rem::rem(a, b)` is the remainder function returning the result of what is
left after dividing `a` and `b`. Implementing `Rem` allows the `%` operator
Expand All @@ -234,18 +234,18 @@ impl Rem for i64 { fn rem(self, other: i64) -> i64 { self % other } }

### `std::ops::Neg`

#include_code neg-trait noir_stdlib/src/ops.nr rust
#include_code neg-trait noir_stdlib/src/ops/arith.nr rust

`Neg::neg` is equivalent to the unary negation operator `-`.

Implementations:
#include_code neg-trait-impls noir_stdlib/src/ops.nr rust
#include_code neg-trait-impls noir_stdlib/src/ops/arith.nr rust

### `std::ops::{ BitOr, BitAnd, BitXor }`

#include_code bitor-trait noir_stdlib/src/ops.nr rust
#include_code bitand-trait noir_stdlib/src/ops.nr rust
#include_code bitxor-trait noir_stdlib/src/ops.nr rust
#include_code bitor-trait noir_stdlib/src/ops/bit.nr rust
#include_code bitand-trait noir_stdlib/src/ops/bit.nr rust
#include_code bitxor-trait noir_stdlib/src/ops/bit.nr rust

Traits for the bitwise operations `|`, `&`, and `^`.

Expand All @@ -272,8 +272,8 @@ impl BitOr for i64 { fn bitor(self, other: i64) -> i64 { self | other } }

### `std::ops::{ Shl, Shr }`

#include_code shl-trait noir_stdlib/src/ops.nr rust
#include_code shr-trait noir_stdlib/src/ops.nr rust
#include_code shl-trait noir_stdlib/src/ops/bit.nr rust
#include_code shr-trait noir_stdlib/src/ops/bit.nr rust

Traits for a bit shift left and bit shift right.

Expand Down
7 changes: 2 additions & 5 deletions noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ops::{Add, Sub, Neg};
use crate::ops::arith::{Add, Sub, Neg};

// TODO(https://github.com/noir-lang/noir/issues/4931)
struct EmbeddedCurvePoint {
Expand Down Expand Up @@ -76,7 +76,4 @@ fn embedded_curve_add(
}

#[foreign(embedded_curve_add)]
fn embedded_curve_add_array_return(
_point1: EmbeddedCurvePoint,
_point2: EmbeddedCurvePoint
) -> [Field; 2] {}
fn embedded_curve_add_array_return(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> [Field; 2] {}
Loading
Loading