Skip to content

Commit

Permalink
[1 changes] feat: use visibility (noir-lang/noir#5856)
Browse files Browse the repository at this point in the history
chore: use `new_let` more widely (noir-lang/noir#5882)
feat: Sync from aztec-packages (noir-lang/noir#5883)
feat!: return arrays instead of slices from `to_be_radix` functions (noir-lang/noir#5851)
chore: add a span to track timing of brillig gen (noir-lang/noir#5835)
feat: add `Expr::as_assert_eq` (noir-lang/noir#5880)
feat: LSP diagnostics now have "unnecessary" and "deprecated" tags (noir-lang/noir#5878)
feat: LSP code actions to import or qualify unresolved paths (noir-lang/noir#5876)
  • Loading branch information
AztecBot committed Sep 3, 2024
1 parent f5bbb89 commit d5be690
Show file tree
Hide file tree
Showing 116 changed files with 1,934 additions and 1,586 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0c268606a71381ab4504396695a0adb9b3258b6
e349f30b60a473e2068afafb6fae4a4ea50d185b
53 changes: 0 additions & 53 deletions noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -509,59 +509,6 @@ 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
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
#require_command wasm-opt
require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
26 changes: 9 additions & 17 deletions noir/noir-repo/aztec_macros/src/utils/ast_utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use noirc_errors::{Span, Spanned};
use noirc_frontend::ast::{
BinaryOpKind, CallExpression, CastExpression, Expression, ExpressionKind, FunctionReturnType,
Ident, IndexExpression, InfixExpression, Lambda, LetStatement, MemberAccessExpression,
MethodCallExpression, NoirTraitImpl, Path, PathSegment, Pattern, PrefixExpression, Statement,
StatementKind, TraitImplItem, UnaryOp, UnresolvedType, UnresolvedTypeData,
Ident, IndexExpression, InfixExpression, Lambda, MemberAccessExpression, MethodCallExpression,
NoirTraitImpl, Path, PathSegment, Pattern, PrefixExpression, Statement, StatementKind,
TraitImplItem, UnaryOp, UnresolvedType, UnresolvedTypeData,
};
use noirc_frontend::token::SecondaryAttribute;

Expand Down Expand Up @@ -73,13 +73,11 @@ pub fn mutable(name: &str) -> Pattern {
}

pub fn mutable_assignment(name: &str, assigned_to: Expression) -> Statement {
make_statement(StatementKind::Let(LetStatement {
pattern: mutable(name),
r#type: make_type(UnresolvedTypeData::Unspecified),
expression: assigned_to,
comptime: false,
attributes: vec![],
}))
make_statement(StatementKind::new_let(
mutable(name),
make_type(UnresolvedTypeData::Unspecified),
assigned_to,
))
}

pub fn mutable_reference(variable_name: &str) -> Expression {
Expand All @@ -98,13 +96,7 @@ pub fn assignment_with_type(
typ: UnresolvedTypeData,
assigned_to: Expression,
) -> Statement {
make_statement(StatementKind::Let(LetStatement {
pattern: pattern(name),
r#type: make_type(typ),
expression: assigned_to,
comptime: false,
attributes: vec![],
}))
make_statement(StatementKind::new_let(pattern(name), make_type(typ), assigned_to))
}

pub fn return_type(path: Path) -> FunctionReturnType {
Expand Down
6 changes: 3 additions & 3 deletions noir/noir-repo/aztec_macros/src/utils/parse_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn empty_item(item: &mut Item) {
empty_parsed_submodule(parsed_submodule);
}
ItemKind::ModuleDecl(module_declaration) => empty_module_declaration(module_declaration),
ItemKind::Import(use_tree) => empty_use_tree(use_tree),
ItemKind::Import(use_tree, _) => empty_use_tree(use_tree),
ItemKind::Struct(noir_struct) => empty_noir_struct(noir_struct),
ItemKind::TypeAlias(noir_type_alias) => empty_noir_type_alias(noir_type_alias),
}
Expand Down Expand Up @@ -404,9 +404,9 @@ fn empty_pattern(pattern: &mut Pattern) {
}

fn empty_unresolved_trait_constraints(
unresolved_trait_constriants: &mut [UnresolvedTraitConstraint],
unresolved_trait_constraints: &mut [UnresolvedTraitConstraint],
) {
for trait_constraint in unresolved_trait_constriants.iter_mut() {
for trait_constraint in unresolved_trait_constraints.iter_mut() {
empty_unresolved_trait_constraint(trait_constraint);
}
}
Expand Down
28 changes: 5 additions & 23 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ pub struct CompileOptions {
pub skip_underconstrained_check: bool,
}

#[derive(Clone, Debug, Default)]
pub struct CheckOptions {
pub compile_options: CompileOptions,
pub error_on_unused_imports: bool,
}

impl CheckOptions {
pub fn new(compile_options: &CompileOptions, error_on_unused_imports: bool) -> Self {
Self { compile_options: compile_options.clone(), error_on_unused_imports }
}
}

pub fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
use std::io::{Error, ErrorKind};
let width = input
Expand Down Expand Up @@ -290,20 +278,19 @@ pub fn add_dep(
pub fn check_crate(
context: &mut Context,
crate_id: CrateId,
check_options: &CheckOptions,
options: &CompileOptions,
) -> CompilationResult<()> {
let options = &check_options.compile_options;

let macros: &[&dyn MacroProcessor] =
if options.disable_macros { &[] } else { &[&aztec_macros::AztecMacro] };

let mut errors = vec![];
let error_on_unused_imports = true;
let diagnostics = CrateDefMap::collect_defs(
crate_id,
context,
options.debug_comptime_in_file.as_deref(),
options.arithmetic_generics,
check_options.error_on_unused_imports,
error_on_unused_imports,
macros,
);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
Expand Down Expand Up @@ -337,10 +324,7 @@ pub fn compile_main(
options: &CompileOptions,
cached_program: Option<CompiledProgram>,
) -> CompilationResult<CompiledProgram> {
let error_on_unused_imports = true;
let check_options = CheckOptions::new(options, error_on_unused_imports);

let (_, mut warnings) = check_crate(context, crate_id, &check_options)?;
let (_, mut warnings) = check_crate(context, crate_id, options)?;

let main = context.get_main_function(&crate_id).ok_or_else(|| {
// TODO(#2155): This error might be a better to exist in Nargo
Expand Down Expand Up @@ -375,9 +359,7 @@ pub fn compile_contract(
crate_id: CrateId,
options: &CompileOptions,
) -> CompilationResult<CompiledContract> {
let error_on_unused_imports = true;
let check_options = CheckOptions::new(options, error_on_unused_imports);
let (_, warnings) = check_crate(context, crate_id, &check_options)?;
let (_, warnings) = check_crate(context, crate_id, options)?;

// TODO: We probably want to error if contracts is empty
let contracts = context.get_all_contracts(&crate_id);
Expand Down
8 changes: 8 additions & 0 deletions noir/noir-repo/compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct CustomDiagnostic {
pub secondaries: Vec<CustomLabel>,
notes: Vec<String>,
pub kind: DiagnosticKind,
pub deprecated: bool,
pub unnecessary: bool,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand All @@ -35,6 +37,8 @@ impl CustomDiagnostic {
secondaries: Vec::new(),
notes: Vec::new(),
kind: DiagnosticKind::Error,
deprecated: false,
unnecessary: false,
}
}

Expand All @@ -49,6 +53,8 @@ impl CustomDiagnostic {
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
notes: Vec::new(),
kind,
deprecated: false,
unnecessary: false,
}
}

Expand Down Expand Up @@ -101,6 +107,8 @@ impl CustomDiagnostic {
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
notes: Vec::new(),
kind: DiagnosticKind::Bug,
deprecated: false,
unnecessary: false,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ impl<'block> BrilligBlock<'block> {
);
}
Value::Intrinsic(Intrinsic::ToRadix(endianness)) => {
let results = dfg.instruction_results(instruction_id);

let source = self.convert_ssa_single_addr_value(arguments[0], dfg);

let radix: u32 = dfg
Expand All @@ -512,88 +514,43 @@ impl<'block> BrilligBlock<'block> {
.try_into()
.expect("Radix should be u32");

let limb_count: usize = dfg
.get_numeric_constant(arguments[2])
.expect("Limb count should be known")
.try_to_u64()
.expect("Limb count should fit in u64")
.try_into()
.expect("Limb count should fit in usize");

let results = dfg.instruction_results(instruction_id);

let target_len = self.variables.define_single_addr_variable(
self.function_context,
self.brillig_context,
results[0],
dfg,
);

let target_vector = self
let target_array = self
.variables
.define_variable(
self.function_context,
self.brillig_context,
results[1],
results[0],
dfg,
)
.extract_vector();

// Update the user-facing slice length
self.brillig_context
.usize_const_instruction(target_len.address, limb_count.into());
.extract_array();

self.brillig_context.codegen_to_radix(
source,
target_vector,
target_array,
radix,
limb_count,
matches!(endianness, Endian::Big),
false,
);
}
Value::Intrinsic(Intrinsic::ToBits(endianness)) => {
let source = self.convert_ssa_single_addr_value(arguments[0], dfg);
let limb_count: usize = dfg
.get_numeric_constant(arguments[1])
.expect("Limb count should be known")
.try_to_u64()
.expect("Limb count should fit in u64")
.try_into()
.expect("Limb count should fit in usize");

let results = dfg.instruction_results(instruction_id);

let target_len_variable = self.variables.define_variable(
self.function_context,
self.brillig_context,
results[0],
dfg,
);
let target_len = target_len_variable.extract_single_addr();

let target_vector = match self.variables.define_variable(
self.function_context,
self.brillig_context,
results[1],
dfg,
) {
BrilligVariable::BrilligArray(array) => {
self.brillig_context.array_to_vector_instruction(&array)
}
BrilligVariable::BrilligVector(vector) => vector,
BrilligVariable::SingleAddr(..) => unreachable!("ICE: ToBits on non-array"),
};
let source = self.convert_ssa_single_addr_value(arguments[0], dfg);

// Update the user-facing slice length
self.brillig_context
.usize_const_instruction(target_len.address, limb_count.into());
let target_array = self
.variables
.define_variable(
self.function_context,
self.brillig_context,
results[0],
dfg,
)
.extract_array();

self.brillig_context.codegen_to_radix(
source,
target_vector,
target_array,
2,
limb_count,
matches!(endianness, Endian::Big),
true,
);
Expand Down
Loading

0 comments on commit d5be690

Please sign in to comment.