Skip to content

Commit

Permalink
Merge branch 'master' into tf/full-backprop
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Feb 26, 2024
2 parents d56c9f9 + 3386067 commit d9c244f
Show file tree
Hide file tree
Showing 74 changed files with 1,309 additions and 351 deletions.
8 changes: 8 additions & 0 deletions .github/scripts/wasm-opt-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -eu

cd $(dirname "$0")

./cargo-binstall-install.sh

cargo-binstall wasm-opt --version 0.116.0 -y
2 changes: 1 addition & 1 deletion .github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: ${{ matrix.target }}
components: clippy, rustfmt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gates_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-acvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
ref: ${{ inputs.noir-ref }}

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

# These steps are in a specific order so crate dependencies are updated first
- name: Publish acir_field
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/publish-es-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -32,6 +32,9 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build noirc_abi
run: ./.github/scripts/noirc-abi-build.sh

Expand All @@ -51,7 +54,7 @@ jobs:
ref: ${{ inputs.noir-ref }}

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -61,6 +64,9 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

Expand All @@ -83,7 +89,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -93,6 +99,9 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build acvm_js
run: ./.github/scripts/acvm_js-build.sh

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-nargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: ${{ matrix.target }}

Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
ref: ${{ inputs.tag || env.GITHUB_REF }}

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: ${{ matrix.target }}

Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -66,6 +66,9 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build noirc_abi
run: ./.github/scripts/noirc-abi-build.sh

Expand All @@ -86,7 +89,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -97,6 +100,9 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

Expand All @@ -121,7 +127,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0

- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -132,6 +138,9 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build acvm_js
run: ./.github/scripts/acvm_js-build.sh

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-rust-workspace-msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: x86_64-unknown-linux-gnu

Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: x86_64-unknown-linux-gnu

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-rust-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: x86_64-unknown-linux-gnu

Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/rust-toolchain@1.71.1
uses: dtolnay/rust-toolchain@1.73.0
with:
targets: x86_64-unknown-linux-gnu

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ version = "0.24.0"
# x-release-please-end
authors = ["The Noir Team <[email protected]>"]
edition = "2021"
rust-version = "1.71.1"
rust-version = "1.73.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/noir-lang/noir/"

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.71.1-slim-bookworm as base
FROM rust:1.73.0-slim-bookworm as base
RUN apt-get update && apt-get upgrade -y && apt-get install build-essential git -y
WORKDIR /usr/src/noir
ENV PATH="${PATH}:/usr/src/noir/target/release"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Concretely the following items are on the road map:

## Minimum Rust version

This crate's minimum supported rustc version is 1.71.1.
This crate's minimum supported rustc version is 1.73.0.

## Working on this project

Expand Down
5 changes: 0 additions & 5 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ pub(crate) fn optimize_into_acir(
.try_run_pass(Ssa::evaluate_assert_constant, "After Assert Constant:")?
.try_run_pass(Ssa::unroll_loops, "After Unrolling:")?
.run_pass(Ssa::simplify_cfg, "After Simplifying:")
// Run mem2reg before flattening to handle any promotion
// of values that can be accessed after loop unrolling.
// If there are slice mergers uncovered by loop unrolling
// and this pass is missed, slice merging will fail inside of flattening.
.run_pass(Ssa::mem2reg, "After Mem2Reg:")
.run_pass(Ssa::flatten_cfg, "After Flattening:")
.run_pass(Ssa::remove_bit_shifts, "After Removing Bit Shifts:")
// Run mem2reg once more with the flattened CFG to catch any remaining loads/stores
Expand Down
5 changes: 5 additions & 0 deletions compiler/noirc_evaluator/src/ssa/function_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ impl FunctionBuilder {
self.numeric_constant(value.into(), Type::field())
}

/// Insert a numeric constant into the current function of type Type::length_type()
pub(crate) fn length_constant(&mut self, value: impl Into<FieldElement>) -> ValueId {
self.numeric_constant(value.into(), Type::length_type())
}

/// Insert an array constant into the current function with the given element values.
pub(crate) fn array_constant(&mut self, elements: im::Vector<ValueId>, typ: Type) -> ValueId {
self.current_function.dfg.make_array(elements, typ)
Expand Down
12 changes: 6 additions & 6 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(super) fn simplify_call(
Intrinsic::ArrayLen => {
if let Some(length) = dfg.try_get_array_length(arguments[0]) {
let length = FieldElement::from(length as u128);
SimplifyResult::SimplifiedTo(dfg.make_constant(length, Type::field()))
SimplifyResult::SimplifiedTo(dfg.make_constant(length, Type::length_type()))
} else if matches!(dfg.type_of_value(arguments[1]), Type::Slice(_)) {
SimplifyResult::SimplifiedTo(arguments[0])
} else {
Expand Down Expand Up @@ -283,7 +283,7 @@ fn update_slice_length(
operator: BinaryOp,
block: BasicBlockId,
) -> ValueId {
let one = dfg.make_constant(FieldElement::one(), Type::field());
let one = dfg.make_constant(FieldElement::one(), Type::length_type());
let instruction = Instruction::Binary(Binary { lhs: slice_len, operator, rhs: one });
let call_stack = dfg.get_value_call_stack(slice_len);
dfg.insert_instruction_and_results(instruction, block, None, call_stack).first()
Expand All @@ -296,8 +296,8 @@ fn simplify_slice_push_back(
dfg: &mut DataFlowGraph,
block: BasicBlockId,
) -> SimplifyResult {
// The capacity must be an integer so that we can compare it against the slice length which is represented as a field
let capacity = dfg.make_constant((slice.len() as u128).into(), Type::unsigned(64));
// The capacity must be an integer so that we can compare it against the slice length
let capacity = dfg.make_constant((slice.len() as u128).into(), Type::length_type());
let len_equals_capacity_instr =
Instruction::Binary(Binary { lhs: arguments[0], operator: BinaryOp::Eq, rhs: capacity });
let call_stack = dfg.get_value_call_stack(arguments[0]);
Expand Down Expand Up @@ -362,7 +362,7 @@ fn simplify_slice_pop_back(

let new_slice_length = update_slice_length(arguments[0], dfg, BinaryOp::Sub, block);

let element_size = dfg.make_constant((element_count as u128).into(), Type::field());
let element_size = dfg.make_constant((element_count as u128).into(), Type::length_type());
let flattened_len_instr = Instruction::binary(BinaryOp::Mul, arguments[0], element_size);
let mut flattened_len = dfg
.insert_instruction_and_results(flattened_len_instr, block, None, CallStack::new())
Expand Down Expand Up @@ -478,7 +478,7 @@ fn make_constant_slice(

let typ = Type::Slice(Rc::new(vec![typ]));
let length = FieldElement::from(result_constants.len() as u128);
(dfg.make_constant(length, Type::field()), dfg.make_array(result_constants.into(), typ))
(dfg.make_constant(length, Type::length_type()), dfg.make_array(result_constants.into(), typ))
}

/// Returns a slice (represented by a tuple (len, slice)) of constants corresponding to the limbs of the radix decomposition.
Expand Down
5 changes: 5 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ impl Type {
Type::Numeric(NumericType::NativeField)
}

/// Creates the type of an array's length.
pub(crate) fn length_type() -> Type {
Type::unsigned(64)
}

/// Returns the bit size of the provided numeric type.
///
/// # Panics
Expand Down
10 changes: 5 additions & 5 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'a> FunctionContext<'a> {
ast::Type::Slice(elements) => {
let element_types = Self::convert_type(elements).flatten();
Tree::Branch(vec![
Tree::Leaf(f(Type::field())),
Tree::Leaf(f(Type::length_type())),
Tree::Leaf(f(Type::Slice(Rc::new(element_types)))),
])
}
Expand Down Expand Up @@ -640,13 +640,13 @@ impl<'a> FunctionContext<'a> {
let result_alloc = self.builder.set_location(location).insert_allocate(Type::bool());
let true_value = self.builder.numeric_constant(1u128, Type::bool());
self.builder.insert_store(result_alloc, true_value);
let zero = self.builder.field_constant(0u128);
let zero = self.builder.length_constant(0u128);
self.builder.terminate_with_jmp(loop_start, vec![zero]);

// loop_start
self.builder.switch_to_block(loop_start);
let i = self.builder.add_block_parameter(loop_start, Type::field());
let array_length = self.builder.field_constant(array_length as u128);
let i = self.builder.add_block_parameter(loop_start, Type::length_type());
let array_length = self.builder.length_constant(array_length as u128);
let v0 = self.builder.insert_binary(i, BinaryOp::Lt, array_length);
self.builder.terminate_with_jmpif(v0, loop_body, loop_end);

Expand All @@ -658,7 +658,7 @@ impl<'a> FunctionContext<'a> {
let v4 = self.builder.insert_load(result_alloc, Type::bool());
let v5 = self.builder.insert_binary(v4, BinaryOp::And, v3);
self.builder.insert_store(result_alloc, v5);
let one = self.builder.field_constant(1u128);
let one = self.builder.length_constant(1u128);
let v6 = self.builder.insert_binary(i, BinaryOp::Add, one);
self.builder.terminate_with_jmp(loop_start, vec![v6]);

Expand Down
6 changes: 3 additions & 3 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<'a> FunctionContext<'a> {
}
ast::Type::Slice(_) => {
let slice_length =
self.builder.field_constant(array.contents.len() as u128);
self.builder.length_constant(array.contents.len() as u128);
let slice_contents =
self.codegen_array_checked(elements, typ[1].clone())?;
Tree::Branch(vec![slice_length.into(), slice_contents])
Expand All @@ -221,7 +221,7 @@ impl<'a> FunctionContext<'a> {
// A caller needs multiple pieces of information to make use of a format string
// The message string, the number of fields to be formatted, and the fields themselves
let string = self.codegen_string(string);
let field_count = self.builder.field_constant(*number_of_fields as u128);
let field_count = self.builder.length_constant(*number_of_fields as u128);
let fields = self.codegen_expression(fields)?;

Ok(Tree::Branch(vec![string, field_count.into(), fields]))
Expand Down Expand Up @@ -615,7 +615,7 @@ impl<'a> FunctionContext<'a> {
{
match intrinsic {
Intrinsic::SliceInsert => {
let one = self.builder.field_constant(1u128);
let one = self.builder.length_constant(1u128);

// We add one here in the case of a slice insert as a slice insert at the length of the slice
// can be converted to a slice push back
Expand Down
Loading

0 comments on commit d9c244f

Please sign in to comment.