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 #7454

Merged
merged 34 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0b99c4f
[1 changes] feat: Handle ACIR calls in the debugger (https://github.c…
AztecBot Jul 12, 2024
20deda7
chore: apply sync fixes
AztecBot Jul 12, 2024
1f8785a
[1 changes] feat: LSP hover (https://github.com/noir-lang/noir/pull/5…
AztecBot Jul 12, 2024
511a0f0
chore: apply sync fixes
AztecBot Jul 12, 2024
067efe6
feat: LSP hover (https://github.com/noir-lang/noir/pull/5491)
AztecBot Jul 12, 2024
366694e
[1 changes] feat: Allow comptime attributes on traits & functions (ht…
AztecBot Jul 13, 2024
81778a2
chore: apply sync fixes
AztecBot Jul 13, 2024
56ba2cd
feat: Allow comptime attributes on traits & functions (https://github…
AztecBot Jul 13, 2024
f52b2b3
[1 changes] feat: Allow comptime attributes on traits & functions (ht…
AztecBot Jul 14, 2024
41abf2a
chore: apply sync fixes
AztecBot Jul 14, 2024
b3abc46
feat: Allow comptime attributes on traits & functions (https://github…
AztecBot Jul 14, 2024
cf5cc28
[1 changes] feat: Allow comptime attributes on traits & functions (ht…
AztecBot Jul 15, 2024
53ddb79
chore: apply sync fixes
AztecBot Jul 15, 2024
badf189
feat: Allow comptime attributes on traits & functions (https://github…
AztecBot Jul 15, 2024
41fd496
.
TomAFrench Jul 15, 2024
b8b0597
Merge branch 'master' into sync-noir
TomAFrench Jul 15, 2024
af234e3
[1 changes] chore: Noir version for Pedersen commitment and hash (htt…
AztecBot Jul 15, 2024
addd4fe
chore: apply sync fixes
AztecBot Jul 15, 2024
c87edd2
chore: Noir version for Pedersen commitment and hash (https://github.…
AztecBot Jul 15, 2024
73c4024
[1 changes] fix: lsp hover wasn't always working (https://github.com/…
AztecBot Jul 16, 2024
35a5e9d
chore: apply sync fixes
AztecBot Jul 16, 2024
768114c
fix: lsp hover wasn't always working (https://github.com/noir-lang/no…
AztecBot Jul 16, 2024
aba7dda
Merge branch 'master' into sync-noir
guipublic Jul 16, 2024
455103e
fix msm duplicate in stdlib
guipublic Jul 16, 2024
6a7a1ed
Merge branch 'master' into sync-noir
TomAFrench Jul 16, 2024
5caabe5
Merge branch 'master' into sync-noir
guipublic Jul 16, 2024
eb79cb5
Merge branch 'master' into sync-noir
TomAFrench Jul 16, 2024
516f8bb
chore: serial vk construction
TomAFrench Jul 16, 2024
89f8d34
revert #5449
guipublic Jul 17, 2024
6bb7eb7
Merge branch 'master' into sync-noir
guipublic Jul 17, 2024
5ff8a80
revert #5431: use blackbox for Pedersen
guipublic Jul 17, 2024
1e2f27b
Merge branch 'master' into sync-noir
guipublic Jul 17, 2024
250a654
fully revert to Pedersen blackbox, in case of
guipublic Jul 17, 2024
dc103cd
Revert "chore: serial vk construction"
TomAFrench Jul 17, 2024
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 @@
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
Loading