Skip to content

Commit

Permalink
feat: Sync from noir (#7454)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: lsp hover wasn't always working
(noir-lang/noir#5515)
fix: Mutability in the comptime interpreter
(noir-lang/noir#5517)
chore: Noir version for Pedersen commitment and hash
(noir-lang/noir#5431)
chore: add benchmark for ecdsa
(noir-lang/noir#5113)
feat(nargo): Default expression width field in `Nargo.toml`
(noir-lang/noir#5505)
chore: bump hardhat version to `2.22.6`
(noir-lang/noir#5514)
chore: added regression test for check_for_underconstrained_values
resolve bug (noir-lang/noir#5490)
feat: add debug codelens action
(noir-lang/noir#5474)
chore(ci): remove bad colon in yaml file
(noir-lang/noir#5520)
chore(ci): add workflow to run `nargo check` on external repos
(noir-lang/noir#5355)
feat: add support for usage of `super` in import paths
(noir-lang/noir#5502)
feat: Allow comptime attributes on traits & functions
(noir-lang/noir#5496)
feat: skip reading values immediately after it being written into an
array (noir-lang/noir#5449)
fix: Don't type error when calling certain trait impls in the
interpreter (noir-lang/noir#5471)
feat: LSP hover (noir-lang/noir#5491)
chore: update typo PR script
(noir-lang/noir#5488)
feat: Handle ACIR calls in the debugger
(noir-lang/noir#5051)
feat: Add unquote function (noir-lang/noir#5497)
feat: Allow arguments to attribute functions
(noir-lang/noir#5494)
END_COMMIT_OVERRIDE

---------

Co-authored-by: TomAFrench <[email protected]>
Co-authored-by: guipublic <[email protected]>
Co-authored-by: guipublic <[email protected]>
Co-authored-by: Tom French <[email protected]>
  • Loading branch information
5 people authored Jul 17, 2024
1 parent 25e6684 commit 4ec86c0
Show file tree
Hide file tree
Showing 99 changed files with 3,199 additions and 1,612 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
90b636e71333cfe46c5e3062ded34b583fcb64d5
951e821a585fe7e0697291cadd4d3c3aa49fd8e4
53 changes: 53 additions & 0 deletions noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,59 @@ jobs:
working-directory: ./examples/codegen_verifier
run: ./test.sh

external-repo-checks:
needs: [build-nargo]
runs-on: ubuntu-22.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
project:
- { repo: AztecProtocol/aztec-nr, path: ./ }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-contracts }
# Disabled as aztec-packages requires a setup-step in order to generate a `Nargo.toml`
#- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits }
- { repo: zac-williamson/noir-edwards, path: ./, ref: 0016ce82cd58b6ebb0c43c271725590bcff4e755 }
# TODO: Enable these once they're passing against master again.
# - { repo: zac-williamson/noir-bignum, path: ./, ref: 030c2acce1e6b97c44a3bbbf3429ed96f20d72d3 }
# - { repo: vlayer-xyz/monorepo, path: ./, ref: ee46af88c025863872234eb05d890e1e447907cb }
# - { repo: hashcloak/noir-bigint, path: ./, ref: 940ddba3a5201b508e7b37a2ef643551afcf5ed8 }

name: Check external repo - ${{ matrix.project.repo }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ matrix.project.repo }}
path: test-repo
ref: ${{ matrix.project.ref }}

- name: Download nargo binary
uses: actions/download-artifact@v4
with:
name: nargo
path: ./nargo

- name: Set nargo on PATH
run: |
nargo_binary="${{ github.workspace }}/nargo/nargo"
chmod +x $nargo_binary
echo "$(dirname $nargo_binary)" >> $GITHUB_PATH
export PATH="$PATH:$(dirname $nargo_binary)"
nargo -V
- name: Remove requirements on compiler version
working-directory: ./test-repo
run: |
# Github actions seems to not expand "**" in globs by default.
shopt -s globstar
sed -i '/^compiler_version/d' ./**/Nargo.toml
- name: Run nargo check
working-directory: ./test-repo/${{ matrix.project.path }}
run: nargo check

# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
tests-end:
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ impl<F: Copy> BlackBoxFuncCall<F> {
| BlackBoxFuncCall::BigIntDiv { .. }
| BlackBoxFuncCall::BigIntToLeBytes { .. } => Vec::new(),
BlackBoxFuncCall::MultiScalarMul { points, scalars, .. } => {
let mut inputs: Vec<FunctionInput<F>> = Vec::with_capacity(points.len() * 2);
let mut inputs: Vec<FunctionInput<F>> =
Vec::with_capacity(points.len() + scalars.len());
inputs.extend(points.iter().copied());
inputs.extend(scalars.iter().copied());
inputs
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"eslint": "^8.57.0",
"eslint-plugin-prettier": "^5.1.3",
"ethers": "^6.7.1",
"hardhat": "^2.17.4",
"hardhat": "^2.22.6",
"prettier": "3.2.5",
"smol-toml": "^1.1.2",
"toml": "^3.0.0",
Expand Down
8 changes: 4 additions & 4 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ 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, default_value = "4")]
pub expression_width: ExpressionWidth,
/// Specify the backend expression width that should be targeted
#[arg(long, value_parser = parse_expression_width)]
pub expression_width: Option<ExpressionWidth>,

/// Force a full recompilation.
#[arg(long = "force")]
Expand Down Expand Up @@ -113,7 +113,7 @@ pub struct CompileOptions {
pub show_artifact_paths: bool,
}

fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
pub fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
use std::io::{Error, ErrorKind};
let width = input
.parse::<usize>()
Expand Down
19 changes: 13 additions & 6 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,19 @@ pub fn create_program(
let recursive = program.recursive;
let ArtifactsAndWarnings((generated_acirs, generated_brillig, error_types), ssa_level_warnings) =
optimize_into_acir(program, options)?;
assert_eq!(
generated_acirs.len(),
func_sigs.len(),
"The generated ACIRs should match the supplied function signatures"
);

if options.force_brillig_output {
assert_eq!(
generated_acirs.len(),
1,
"Only the main ACIR is expected when forcing Brillig output"
);
} else {
assert_eq!(
generated_acirs.len(),
func_sigs.len(),
"The generated ACIRs should match the supplied function signatures"
);
}
let mut program_artifact = SsaProgramArtifact::new(generated_brillig, error_types);

// Add warnings collected at the Ssa stage
Expand Down
71 changes: 51 additions & 20 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,27 +752,24 @@ impl<'f> Context<'f> {
Instruction::Call { func, arguments }
}
Value::Intrinsic(Intrinsic::BlackBox(BlackBoxFunc::MultiScalarMul)) => {
let mut array_with_predicate = im::Vector::new();
let array_typ;
if let Value::Array { array, typ } =
&self.inserter.function.dfg[arguments[0]]
{
array_typ = typ.clone();
for (i, value) in array.clone().iter().enumerate() {
if i % 3 == 2 {
array_with_predicate.push_back(self.var_or_one(
*value,
condition,
call_stack.clone(),
));
} else {
array_with_predicate.push_back(*value);
}
}
let points_array_idx = if matches!(
self.inserter.function.dfg[arguments[0]],
Value::Array { .. }
) {
0
} else {
unreachable!();
}
arguments[0] =
// if the first argument is not an array, we assume it is a slice
// which means the array is the second argument
1
};
let (array_with_predicate, array_typ) = self
.apply_predicate_to_msm_argument(
arguments[points_array_idx],
condition,
call_stack.clone(),
);

arguments[points_array_idx] =
self.inserter.function.dfg.make_array(array_with_predicate, array_typ);
Instruction::Call { func, arguments }
}
Expand All @@ -785,6 +782,40 @@ impl<'f> Context<'f> {
}
}

/// When a MSM is done under a predicate, we need to apply the predicate
/// to the is_infinity property of the input points in order to ensure
/// that the points will be on the curve no matter what.
fn apply_predicate_to_msm_argument(
&mut self,
argument: ValueId,
predicate: ValueId,
call_stack: CallStack,
) -> (im::Vector<ValueId>, Type) {
let array_typ;
let mut array_with_predicate = im::Vector::new();
if let Value::Array { array, typ } = &self.inserter.function.dfg[argument] {
array_typ = typ.clone();
for (i, value) in array.clone().iter().enumerate() {
if i % 3 == 2 {
array_with_predicate.push_back(self.var_or_one(
*value,
predicate,
call_stack.clone(),
));
} else {
array_with_predicate.push_back(*value);
}
}
} else {
unreachable!(
"Expected an array, got {}",
&self.inserter.function.dfg.type_of_value(argument)
);
};

(array_with_predicate, array_typ)
}

// Computes: if condition { var } else { 1 }
fn var_or_one(&mut self, var: ValueId, condition: ValueId, call_stack: CallStack) -> ValueId {
let field = self.insert_instruction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use acvm::{acir::AcirField, FieldElement};
use iter_extended::vecmap;
use noirc_errors::Location;
use noirc_frontend::ast::{BinaryOpKind, Signedness};
use noirc_frontend::monomorphization::ast::{self, LocalId, Parameters};
use noirc_frontend::monomorphization::ast::{self, InlineType, LocalId, Parameters};
use noirc_frontend::monomorphization::ast::{FuncId, Program};

use crate::errors::RuntimeError;
Expand Down Expand Up @@ -121,9 +121,14 @@ impl<'a> FunctionContext<'a> {
///
/// Note that the previous function cannot be resumed after calling this. Developers should
/// avoid calling new_function until the previous function is completely finished with ssa-gen.
pub(super) fn new_function(&mut self, id: IrFunctionId, func: &ast::Function) {
pub(super) fn new_function(
&mut self,
id: IrFunctionId,
func: &ast::Function,
force_brillig_runtime: bool,
) {
self.definitions.clear();
if func.unconstrained {
if func.unconstrained || (force_brillig_runtime && func.inline_type != InlineType::Inline) {
self.builder.new_brillig_function(func.name.clone(), id);
} else {
self.builder.new_function(func.name.clone(), id, func.inline_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) fn generate_ssa(
// to generate SSA for each function used within the program.
while let Some((src_function_id, dest_id)) = context.pop_next_function_in_queue() {
let function = &context.program[src_function_id];
function_context.new_function(dest_id, function);
function_context.new_function(dest_id, function, force_brillig_runtime);
function_context.codegen_function_body(&function.body)?;
}

Expand Down
2 changes: 2 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ pub enum PathKind {
Crate,
Dep,
Plain,
Super,
}

#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -748,6 +749,7 @@ impl Display for PathKind {
match self {
PathKind::Crate => write!(f, "crate"),
PathKind::Dep => write!(f, "dep"),
PathKind::Super => write!(f, "super"),
PathKind::Plain => write!(f, "plain"),
}
}
Expand Down
2 changes: 2 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::ast::{
BlockExpression, Expression, FunctionReturnType, Ident, NoirFunction, Path, UnresolvedGenerics,
UnresolvedType,
};
use crate::macros_api::SecondaryAttribute;
use crate::node_interner::TraitId;

/// AST node for trait definitions:
Expand All @@ -18,6 +19,7 @@ pub struct NoirTrait {
pub where_clause: Vec<UnresolvedTraitConstraint>,
pub span: Span,
pub items: Vec<TraitItem>,
pub attributes: Vec<SecondaryAttribute>,
}

/// Any declaration inside the body of a trait that a user is required to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl<'context> Elaborator<'context> {
let (mut object, mut object_type) = self.elaborate_expression(method_call.object);
object_type = object_type.follow_bindings();

let method_name_span = method_call.method_name.span();
let method_name = method_call.method_name.0.contents.as_str();
match self.lookup_method(&object_type, method_name, span) {
Some(method_ref) => {
Expand Down Expand Up @@ -385,6 +386,9 @@ impl<'context> Elaborator<'context> {

self.interner.push_expr_type(function_id, func_type.clone());

self.interner
.add_function_reference(func_id, Location::new(method_name_span, self.file));

// Type check the new call now that it has been changed from a method call
// to a function call. This way we avoid duplicating code.
let typ = self.type_check_call(&function_call, func_type, function_args, span);
Expand All @@ -399,7 +403,8 @@ impl<'context> Elaborator<'context> {
constructor: ConstructorExpression,
) -> (HirExpression, Type) {
let span = constructor.type_name.span();
let is_self_type = constructor.type_name.last_segment().is_self_type_name();
let last_segment = constructor.type_name.last_segment();
let is_self_type = last_segment.is_self_type_name();

let (r#type, struct_generics) = if let Some(struct_id) = constructor.struct_type {
let typ = self.interner.get_struct(struct_id);
Expand Down Expand Up @@ -430,7 +435,7 @@ impl<'context> Elaborator<'context> {
});

let struct_id = struct_type.borrow().id;
let reference_location = Location::new(span, self.file);
let reference_location = Location::new(last_segment.span(), self.file);
self.interner.add_struct_reference(struct_id, reference_location, is_self_type);

(expr, Type::Struct(struct_type, generics))
Expand Down
Loading

0 comments on commit 4ec86c0

Please sign in to comment.