Skip to content

Commit e19f7e3

Browse files
authored
Merge branch 'master' into gd/issue_7272
2 parents 7884d9f + 4c1c76e commit e19f7e3

File tree

37 files changed

+316
-188
lines changed

37 files changed

+316
-188
lines changed

.github/benchmark_projects.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ projects:
1515
path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail
1616
num_runs: 5
1717
timeout: 4
18-
compilation-timeout: 1.2
18+
compilation-timeout: 1.5
1919
execution-timeout: 0.04
2020
compilation-memory-limit: 250
2121
execution-memory-limit: 230

.github/workflows/test-js-packages.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ jobs:
521521
working-directory: ./examples/prove_and_verify
522522
run: ./test.sh
523523

524-
- name: Run `codegen_verifier`
525-
working-directory: ./examples/codegen_verifier
524+
- name: Run `solidity_verifier`
525+
working-directory: ./examples/solidity_verifier
526526
run: ./test.sh
527527

528528
- name: Run `oracle_transcript`

EXTERNAL_NOIR_LIBRARIES.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ libraries:
3838
timeout: 2
3939
noir_rsa:
4040
repo: noir-lang/noir_rsa
41-
timeout: 2
41+
timeout: 4
4242
noir_json_parser:
4343
repo: noir-lang/noir_json_parser
4444
timeout: 12
@@ -60,7 +60,7 @@ libraries:
6060
repo: AztecProtocol/aztec-packages
6161
ref: *AZ_COMMIT
6262
path: noir-projects/noir-contracts
63-
timeout: 80
63+
timeout: 90
6464
blob:
6565
repo: AztecProtocol/aztec-packages
6666
ref: *AZ_COMMIT

compiler/noirc_evaluator/src/ssa/checks/check_for_underconstrained_values.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,12 @@ impl DependencyContext {
316316
function: &Function,
317317
all_functions: &BTreeMap<FunctionId, Function>,
318318
) {
319-
trace!("processing instructions of block {} of function {}", block, function.id());
319+
trace!(
320+
"processing instructions of block {} of function {} {}",
321+
block,
322+
function.name(),
323+
function.id()
324+
);
320325

321326
// First, gather information on all Brillig calls in the block
322327
// to be able to follow their arguments first appearing in the
@@ -548,8 +553,9 @@ impl DependencyContext {
548553

549554
if !self.tainted.is_empty() {
550555
trace!(
551-
"number of Brillig calls in function {} left unchecked: {}",
552-
function,
556+
"number of Brillig calls in function {} {} left unchecked: {}",
557+
function.name(),
558+
function.id(),
553559
self.tainted.len()
554560
);
555561
}
@@ -573,9 +579,10 @@ impl DependencyContext {
573579
.collect();
574580

575581
trace!(
576-
"making {} reports on underconstrained Brillig calls for function {}",
582+
"making {} reports on underconstrained Brillig calls for function {} {}",
577583
warnings.len(),
578-
function.name()
584+
function.name(),
585+
function.id()
579586
);
580587
warnings
581588
}

compiler/noirc_frontend/src/elaborator/lints.rs

-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ fn can_return_without_recursing(interner: &NodeInterner, func_id: FuncId, expr_i
307307
HirExpression::Index(e) => check(e.collection) && check(e.index),
308308
HirExpression::MemberAccess(e) => check(e.lhs),
309309
HirExpression::Call(e) => check(e.func) && e.arguments.iter().cloned().all(check),
310-
HirExpression::MethodCall(e) => check(e.object) && e.arguments.iter().cloned().all(check),
311310
HirExpression::Constrain(e) => check(e.0) && e.2.map(check).unwrap_or(true),
312311
HirExpression::Cast(e) => check(e.lhs),
313312
HirExpression::If(e) => {
@@ -323,7 +322,6 @@ fn can_return_without_recursing(interner: &NodeInterner, func_id: FuncId, expr_i
323322
| HirExpression::EnumConstructor(_)
324323
| HirExpression::Quote(_)
325324
| HirExpression::Unquote(_)
326-
| HirExpression::Comptime(_)
327325
| HirExpression::Error => true,
328326
}
329327
}

compiler/noirc_frontend/src/hir/comptime/hir_to_display_ast.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::ast::{
66
ArrayLiteral, AssignStatement, BlockExpression, CallExpression, CastExpression, ConstrainKind,
77
ConstructorExpression, ExpressionKind, ForLoopStatement, ForRange, GenericTypeArgs, Ident,
88
IfExpression, IndexExpression, InfixExpression, LValue, Lambda, Literal, MatchExpression,
9-
MemberAccessExpression, MethodCallExpression, Path, PathSegment, Pattern, PrefixExpression,
10-
UnresolvedType, UnresolvedTypeData, UnresolvedTypeExpression, UnsafeExpression, WhileStatement,
9+
MemberAccessExpression, Path, PathSegment, Pattern, PrefixExpression, UnresolvedType,
10+
UnresolvedTypeData, UnresolvedTypeExpression, UnsafeExpression, WhileStatement,
1111
};
1212
use crate::ast::{ConstrainExpression, Expression, Statement, StatementKind};
1313
use crate::hir_def::expr::{
@@ -148,19 +148,6 @@ impl HirExpression {
148148
let is_macro_call = false;
149149
ExpressionKind::Call(Box::new(CallExpression { func, arguments, is_macro_call }))
150150
}
151-
HirExpression::MethodCall(method_call) => {
152-
ExpressionKind::MethodCall(Box::new(MethodCallExpression {
153-
object: method_call.object.to_display_ast(interner),
154-
method_name: method_call.method.clone(),
155-
arguments: vecmap(method_call.arguments.clone(), |arg| {
156-
arg.to_display_ast(interner)
157-
}),
158-
generics: method_call.generics.clone().map(|option| {
159-
option.iter().map(|generic| generic.to_display_ast()).collect()
160-
}),
161-
is_macro_call: false,
162-
}))
163-
}
164151
HirExpression::Constrain(constrain) => {
165152
let expr = constrain.0.to_display_ast(interner);
166153
let mut arguments = vec![expr];
@@ -198,9 +185,6 @@ impl HirExpression {
198185
ExpressionKind::Lambda(Box::new(Lambda { parameters, return_type, body }))
199186
}
200187
HirExpression::Error => ExpressionKind::Error,
201-
HirExpression::Comptime(block) => {
202-
ExpressionKind::Comptime(block.to_display_ast(interner), location)
203-
}
204188
HirExpression::Unsafe(block) => ExpressionKind::Unsafe(UnsafeExpression {
205189
block: block.to_display_ast(interner),
206190
unsafe_keyword_location: location,

compiler/noirc_frontend/src/hir/comptime/interpreter.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ use crate::{
2929
expr::{
3030
HirArrayLiteral, HirBlockExpression, HirCallExpression, HirCastExpression,
3131
HirConstructorExpression, HirExpression, HirIdent, HirIfExpression, HirIndexExpression,
32-
HirInfixExpression, HirLambda, HirLiteral, HirMemberAccess, HirMethodCallExpression,
33-
HirPrefixExpression,
32+
HirInfixExpression, HirLambda, HirLiteral, HirMemberAccess, HirPrefixExpression,
3433
},
3534
stmt::{
3635
HirAssignStatement, HirForStatement, HirLValue, HirLetStatement, HirPattern,
@@ -528,15 +527,13 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
528527
HirExpression::Constructor(constructor) => self.evaluate_constructor(constructor, id),
529528
HirExpression::MemberAccess(access) => self.evaluate_access(access, id),
530529
HirExpression::Call(call) => self.evaluate_call(call, id),
531-
HirExpression::MethodCall(call) => self.evaluate_method_call(call, id),
532530
HirExpression::Constrain(constrain) => self.evaluate_constrain(constrain),
533531
HirExpression::Cast(cast) => self.evaluate_cast(&cast, id),
534532
HirExpression::If(if_) => self.evaluate_if(if_, id),
535533
HirExpression::Match(match_) => todo!("Evaluate match in comptime code"),
536534
HirExpression::Tuple(tuple) => self.evaluate_tuple(tuple),
537535
HirExpression::Lambda(lambda) => self.evaluate_lambda(lambda, id),
538536
HirExpression::Quote(tokens) => self.evaluate_quote(tokens, id),
539-
HirExpression::Comptime(block) => self.evaluate_block(block),
540537
HirExpression::Unsafe(block) => self.evaluate_block(block),
541538
HirExpression::EnumConstructor(constructor) => {
542539
self.evaluate_enum_constructor(constructor, id)
@@ -1369,33 +1366,6 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
13691366
});
13701367
}
13711368

1372-
fn evaluate_method_call(
1373-
&mut self,
1374-
call: HirMethodCallExpression,
1375-
id: ExprId,
1376-
) -> IResult<Value> {
1377-
let object = self.evaluate(call.object)?;
1378-
let arguments = try_vecmap(call.arguments, |arg| {
1379-
Ok((self.evaluate(arg)?, self.elaborator.interner.expr_location(&arg)))
1380-
})?;
1381-
let location = self.elaborator.interner.expr_location(&id);
1382-
1383-
let typ = object.get_type().follow_bindings();
1384-
let method_name = &call.method.0.contents;
1385-
let check_self_param = true;
1386-
1387-
let method = self
1388-
.elaborator
1389-
.lookup_method(&typ, method_name, location, check_self_param)
1390-
.and_then(|method| method.func_id(self.elaborator.interner));
1391-
1392-
if let Some(method) = method {
1393-
self.call_function(method, arguments, TypeBindings::new(), location)
1394-
} else {
1395-
Err(InterpreterError::NoMethodFound { name: method_name.clone(), typ, location })
1396-
}
1397-
}
1398-
13991369
fn evaluate_cast(&mut self, cast: &HirCastExpression, id: ExprId) -> IResult<Value> {
14001370
let evaluated_lhs = self.evaluate(cast.lhs)?;
14011371
let location = self.elaborator.interner.expr_location(&id);

compiler/noirc_frontend/src/hir_def/expr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub enum HirExpression {
3434
EnumConstructor(HirEnumConstructorExpression),
3535
MemberAccess(HirMemberAccess),
3636
Call(HirCallExpression),
37-
MethodCall(HirMethodCallExpression),
3837
Constrain(HirConstrainExpression),
3938
Cast(HirCastExpression),
4039
If(HirIfExpression),
@@ -43,7 +42,6 @@ pub enum HirExpression {
4342
Lambda(HirLambda),
4443
Quote(Tokens),
4544
Unquote(Tokens),
46-
Comptime(HirBlockExpression),
4745
Unsafe(HirBlockExpression),
4846
Error,
4947
}

compiler/noirc_frontend/src/monomorphization/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -606,19 +606,11 @@ impl<'interner> Monomorphizer<'interner> {
606606

607607
HirExpression::Lambda(lambda) => self.lambda(lambda, expr)?,
608608

609-
HirExpression::MethodCall(hir_method_call) => {
610-
unreachable!(
611-
"Encountered HirExpression::MethodCall during monomorphization {hir_method_call:?}"
612-
)
613-
}
614609
HirExpression::Error => unreachable!("Encountered Error node during monomorphization"),
615610
HirExpression::Quote(_) => unreachable!("quote expression remaining in runtime code"),
616611
HirExpression::Unquote(_) => {
617612
unreachable!("unquote expression remaining in runtime code")
618613
}
619-
HirExpression::Comptime(_) => {
620-
unreachable!("comptime expression remaining in runtime code")
621-
}
622614
HirExpression::EnumConstructor(constructor) => {
623615
self.enum_constructor(constructor, expr)?
624616
}

compiler/noirc_frontend/src/parser/parser/expression.rs

+19
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,25 @@ impl Parser<'_> {
147147
self.parse_index(atom, start_location)
148148
}
149149

150+
pub(super) fn parse_member_accesses_or_method_calls_after_expression(
151+
&mut self,
152+
mut atom: Expression,
153+
start_location: Location,
154+
) -> Expression {
155+
let mut parsed;
156+
157+
loop {
158+
(atom, parsed) = self.parse_member_access_or_method_call(atom, start_location);
159+
if parsed {
160+
continue;
161+
} else {
162+
break;
163+
}
164+
}
165+
166+
atom
167+
}
168+
150169
/// CallExpression = Atom CallArguments
151170
fn parse_call(&mut self, atom: Expression, start_location: Location) -> (Expression, bool) {
152171
if let Some(call_arguments) = self.parse_call_arguments() {

compiler/noirc_frontend/src/parser/parser/function.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ fn empty_body() -> BlockExpression {
324324
mod tests {
325325
use crate::{
326326
ast::{
327-
IntegerBitSize, ItemVisibility, NoirFunction, Signedness, UnresolvedTypeData,
328-
Visibility,
327+
ExpressionKind, IntegerBitSize, ItemVisibility, NoirFunction, Signedness,
328+
StatementKind, UnresolvedTypeData, Visibility,
329329
},
330330
parse_program_with_dummy_file,
331331
parser::{
@@ -570,4 +570,42 @@ mod tests {
570570
UnresolvedTypeData::Integer(Signedness::Signed, IntegerBitSize::SixtyFour)
571571
);
572572
}
573+
574+
#[test]
575+
fn parses_block_followed_by_call() {
576+
let src = "fn foo() { { 1 }.bar() }";
577+
let noir_function = parse_function_no_error(src);
578+
let statements = &noir_function.def.body.statements;
579+
assert_eq!(statements.len(), 1);
580+
581+
let StatementKind::Expression(expr) = &statements[0].kind else {
582+
panic!("Expected expression statement");
583+
};
584+
585+
let ExpressionKind::MethodCall(call) = &expr.kind else {
586+
panic!("Expected method call expression");
587+
};
588+
589+
assert!(matches!(call.object.kind, ExpressionKind::Block(_)));
590+
assert_eq!(call.method_name.to_string(), "bar");
591+
}
592+
593+
#[test]
594+
fn parses_if_followed_by_call() {
595+
let src = "fn foo() { if 1 { 2 } else { 3 }.bar() }";
596+
let noir_function = parse_function_no_error(src);
597+
let statements = &noir_function.def.body.statements;
598+
assert_eq!(statements.len(), 1);
599+
600+
let StatementKind::Expression(expr) = &statements[0].kind else {
601+
panic!("Expected expression statement");
602+
};
603+
604+
let ExpressionKind::MethodCall(call) = &expr.kind else {
605+
panic!("Expected method call expression");
606+
};
607+
608+
assert!(matches!(call.object.kind, ExpressionKind::If(_)));
609+
assert_eq!(call.method_name.to_string(), "bar");
610+
}
573611
}

compiler/noirc_frontend/src/parser/parser/statement.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,12 @@ impl Parser<'_> {
146146
return Some(StatementKind::While(while_));
147147
}
148148

149-
if let Some(kind) = self.parse_if_expr() {
150-
let location = self.location_since(start_location);
151-
return Some(StatementKind::Expression(Expression { kind, location }));
152-
}
153-
154-
if let Some(kind) = self.parse_match_expr() {
149+
if let Some(kind) = self.parse_block_like() {
155150
let location = self.location_since(start_location);
156-
return Some(StatementKind::Expression(Expression { kind, location }));
157-
}
158-
159-
if let Some(block) = self.parse_block() {
160-
return Some(StatementKind::Expression(Expression {
161-
kind: ExpressionKind::Block(block),
162-
location: self.location_since(start_location),
163-
}));
151+
let expression = Expression { kind, location };
152+
let expression = self
153+
.parse_member_accesses_or_method_calls_after_expression(expression, start_location);
154+
return Some(StatementKind::Expression(expression));
164155
}
165156

166157
if let Some(token) = self.eat_kind(TokenKind::InternedLValue) {
@@ -214,6 +205,24 @@ impl Parser<'_> {
214205
Some(StatementKind::Expression(expression))
215206
}
216207

208+
/// Parses an expression that looks like a block (ends with '}'):
209+
/// `{ ... }`, `if { ... }` and `match { ... }`.
210+
fn parse_block_like(&mut self) -> Option<ExpressionKind> {
211+
if let Some(kind) = self.parse_if_expr() {
212+
return Some(kind);
213+
}
214+
215+
if let Some(kind) = self.parse_match_expr() {
216+
return Some(kind);
217+
}
218+
219+
if let Some(block) = self.parse_block() {
220+
return Some(ExpressionKind::Block(block));
221+
}
222+
223+
None
224+
}
225+
217226
fn next_is_op_assign(&mut self) -> Option<BinaryOp> {
218227
let start_location = self.current_token_location;
219228
let operator = if self.next_is(Token::Assign) {

cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"cpus",
6565
"cranelift",
6666
"critesjosh",
67+
"crypdoku",
6768
"csat",
6869
"ctstring",
6970
"curvegroup",

docs/docs/explainers/explainer-writing-noir.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ A few things to do when converting Rust code to Noir:
7070
- No early `return` in function. Use constrain via assertion instead
7171
- No passing by reference. Remove `&` operator to pass by value (copy)
7272
- No boolean operators (`&&`, `||`). Use bitwise operators (`&`, `|`) with boolean values
73-
- No type `usize`. Use types `u8`, `u32`, `u64`, ...
73+
- No type `usize`. Use types `u8`, `u32`, `u64`, ...
7474
- `main` return must be public, `pub`
7575
- No `const`, use `global`
7676
- Noir's LSP is your friend, so error message should be informative enough to resolve syntax issues.
@@ -203,6 +203,5 @@ The compiler will mostly be correct and optimal, but this may help some near ter
203203
Note: When used incorrectly it will create **less** efficient circuits (higher gate count).
204204

205205
## References
206-
- Guillaume's ["`Cryptdoku`" talk](https://www.youtube.com/watch?v=MrQyzuogxgg) (Jun'23)
207-
- Tips from Tom, Jake and Zac.
206+
- Guillaume's ["`Crypdoku`" talk](https://www.youtube.com/watch?v=MrQyzuogxgg) (Jun'23)
208207
- [Idiomatic Noir](https://www.vlayer.xyz/blog/idiomatic-noir-part-1-collections) blog post

0 commit comments

Comments
 (0)