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

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@
9704bd0abfe2dba1e7a4aef6cdb6cc83d70b929e
5985e4285de9e29f7c986103a49fdaec59228887
5 changes: 4 additions & 1 deletion noir/noir-repo/.github/actions/install-playwright/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ runs:
- name: Install playwright deps
shell: bash
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: ./.github/scripts/playwright-install.sh
run: |
# Workaround: https://github.com/microsoft/playwright/issues/30503#issuecomment-2074783821
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
./.github/scripts/playwright-install.sh

4 changes: 2 additions & 2 deletions noir/noir-repo/.github/workflows/gates_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ jobs:
run: |
./gates_report.sh
mv gates_report.json ../gates_report.json

- name: Compare gates reports
id: gates_diff
uses: vezenovm/noir-gates-diff@f80ea702d579873ff80f0261c62e2bae5203748e
uses: vezenovm/noir-gates-diff@acf12797860f237117e15c0d6e08d64253af52b6
with:
report: gates_report.json
summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%)
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
uses: ./.github/actions/setup

- name: Install Playwright
run: ./.github/scripts/playwright-install.sh
uses: ./.github/actions/install-playwright

- name: Run browser tests
run: yarn workspace @noir-lang/acvm_js test:browser
Expand Down
56 changes: 43 additions & 13 deletions noir/noir-repo/Cargo.lock

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

3 changes: 3 additions & 0 deletions noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
# require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand All @@ -48,3 +49,5 @@ BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm
run_or_fail cargo build --lib --release --target $TARGET --package ${pname}
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web
run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O
run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
9 changes: 4 additions & 5 deletions noir/noir-repo/aztec_macros/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use iter_extended::vecmap;
use noirc_errors::Location;
use noirc_frontend::ast;
use noirc_frontend::macros_api::{HirExpression, HirLiteral};
use noirc_frontend::node_interner::{NodeInterner, TraitImplKind};
use noirc_frontend::{
graph::CrateId,
hir::{
def_map::{LocalModuleId, ModuleId},
resolution::{path_resolver::StandardPathResolver, resolver::Resolver},
type_check::type_check_func,
},
macros_api::{
FileId, HirContext, HirExpression, HirLiteral, MacroError, ModuleDefId, NodeInterner,
StructId,
},
node_interner::{FuncId, TraitId, TraitImplKind},
macros_api::{FileId, HirContext, MacroError, ModuleDefId, StructId},
node_interner::{FuncId, TraitId},
Shared, StructType, Type,
};

Expand Down
2 changes: 2 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum ExpressionKind {
Lambda(Box<Lambda>),
Parenthesized(Box<Expression>),
Quote(BlockExpression),
Comptime(BlockExpression),
Error,
}

Expand Down Expand Up @@ -504,6 +505,7 @@ impl Display for ExpressionKind {
Lambda(lambda) => lambda.fmt(f),
Parenthesized(sub_expr) => write!(f, "({sub_expr})"),
Quote(block) => write!(f, "quote {block}"),
Comptime(block) => write!(f, "comptime {block}"),
Error => write!(f, "Error"),
}
}
Expand Down
53 changes: 53 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::Type;
use acvm::FieldElement;
use noirc_errors::Location;

use super::value::Value;

/// The possible errors that can halt the interpreter.
#[derive(Debug)]
pub enum InterpreterError {
ArgumentCountMismatch { expected: usize, actual: usize, call_location: Location },
TypeMismatch { expected: Type, value: Value, location: Location },
NonComptimeVarReferenced { name: String, location: Location },
IntegerOutOfRangeForType { value: FieldElement, typ: Type, location: Location },
ErrorNodeEncountered { location: Location },
NonFunctionCalled { value: Value, location: Location },
NonBoolUsedInIf { value: Value, location: Location },
NonBoolUsedInConstrain { value: Value, location: Location },
FailingConstraint { message: Option<Value>, location: Location },
NoMethodFound { object: Value, typ: Type, location: Location },
NonIntegerUsedInLoop { value: Value, location: Location },
NonPointerDereferenced { value: Value, location: Location },
NonTupleOrStructInMemberAccess { value: Value, location: Location },
NonArrayIndexed { value: Value, location: Location },
NonIntegerUsedAsIndex { value: Value, location: Location },
NonIntegerIntegerLiteral { typ: Type, location: Location },
NonIntegerArrayLength { typ: Type, location: Location },
NonNumericCasted { value: Value, location: Location },
IndexOutOfBounds { index: usize, length: usize, location: Location },
ExpectedStructToHaveField { value: Value, field_name: String, location: Location },
TypeUnsupported { typ: Type, location: Location },
InvalidValueForUnary { value: Value, operator: &'static str, location: Location },
InvalidValuesForBinary { lhs: Value, rhs: Value, operator: &'static str, location: Location },
CastToNonNumericType { typ: Type, location: Location },
QuoteInRuntimeCode { location: Location },
NonStructInConstructor { typ: Type, location: Location },
CannotInlineMacro { value: Value, location: Location },
UnquoteFoundDuringEvaluation { location: Location },

Unimplemented { item: &'static str, location: Location },

// Perhaps this should be unreachable! due to type checking also preventing this error?
// Currently it and the Continue variant are the only interpreter errors without a Location field
BreakNotInLoop { location: Location },
ContinueNotInLoop { location: Location },

// These cases are not errors, they are just used to prevent us from running more code
// until the loop can be resumed properly. These cases will never be displayed to users.
Break,
Continue,
}

#[allow(unused)]
pub(super) type IResult<T> = std::result::Result<T, InterpreterError>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::ast::{
UnresolvedTypeData, UnresolvedTypeExpression,
};
use crate::ast::{ConstrainStatement, Expression, Statement, StatementKind};
use crate::hir_def::expr::{HirArrayLiteral, HirExpression, HirIdent};
use crate::hir_def::expr::{HirArrayLiteral, HirBlockExpression, HirExpression, HirIdent};
use crate::hir_def::stmt::{HirLValue, HirPattern, HirStatement};
use crate::hir_def::types::Type;
use crate::macros_api::HirLiteral;
Expand All @@ -26,7 +26,7 @@ impl StmtId {
#[allow(unused)]
fn to_ast(self, interner: &NodeInterner) -> Statement {
let statement = interner.statement(&self);
let span = interner.statement_span(&self);
let span = interner.statement_span(self);

let kind = match statement {
HirStatement::Let(let_stmt) => {
Expand Down Expand Up @@ -108,10 +108,7 @@ impl ExprId {
ExpressionKind::Literal(Literal::FmtStr(string))
}
HirExpression::Literal(HirLiteral::Unit) => ExpressionKind::Literal(Literal::Unit),
HirExpression::Block(expr) => {
let statements = vecmap(expr.statements, |statement| statement.to_ast(interner));
ExpressionKind::Block(BlockExpression { statements })
}
HirExpression::Block(expr) => ExpressionKind::Block(expr.into_ast(interner)),
HirExpression::Prefix(prefix) => ExpressionKind::Prefix(Box::new(PrefixExpression {
operator: prefix.operator,
rhs: prefix.rhs.to_ast(interner),
Expand Down Expand Up @@ -172,8 +169,12 @@ impl ExprId {
let body = lambda.body.to_ast(interner);
ExpressionKind::Lambda(Box::new(Lambda { parameters, return_type, body }))
}
HirExpression::Quote(block) => ExpressionKind::Quote(block),
HirExpression::Error => ExpressionKind::Error,
HirExpression::Comptime(block) => ExpressionKind::Comptime(block.into_ast(interner)),
HirExpression::Quote(block) => ExpressionKind::Quote(block),

// A macro was evaluated here!
HirExpression::Unquote(block) => ExpressionKind::Block(block),
};

Expression::new(kind, span)
Expand Down Expand Up @@ -353,3 +354,10 @@ impl HirArrayLiteral {
}
}
}

impl HirBlockExpression {
fn into_ast(self, interner: &NodeInterner) -> BlockExpression {
let statements = vecmap(self.statements, |statement| statement.to_ast(interner));
BlockExpression { statements }
}
}
Loading
Loading