Skip to content

Commit 1130c14

Browse files
Merge branch 'master' into michaeljklein/noir-cfg
2 parents b56e794 + 4c1c76e commit 1130c14

File tree

39 files changed

+348
-188
lines changed

39 files changed

+348
-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

+44-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
@@ -336,6 +341,12 @@ impl DependencyContext {
336341

337342
if !visited {
338343
let results = function.dfg.instruction_results(*instruction);
344+
345+
// Calls with no results (e.g. print) shouldn't be checked
346+
if results.is_empty() {
347+
return;
348+
}
349+
339350
let current_tainted =
340351
BrilligTaintedIds::new(function, arguments, results);
341352

@@ -542,8 +553,9 @@ impl DependencyContext {
542553

543554
if !self.tainted.is_empty() {
544555
trace!(
545-
"number of Brillig calls in function {} left unchecked: {}",
546-
function,
556+
"number of Brillig calls in function {} {} left unchecked: {}",
557+
function.name(),
558+
function.id(),
547559
self.tainted.len()
548560
);
549561
}
@@ -567,9 +579,10 @@ impl DependencyContext {
567579
.collect();
568580

569581
trace!(
570-
"making {} reports on underconstrained Brillig calls for function {}",
582+
"making {} reports on underconstrained Brillig calls for function {} {}",
571583
warnings.len(),
572-
function.name()
584+
function.name(),
585+
function.id()
573586
);
574587
warnings
575588
}
@@ -1418,4 +1431,30 @@ mod test {
14181431
let ssa_level_warnings = ssa.check_for_missing_brillig_constraints(true);
14191432
assert_eq!(ssa_level_warnings.len(), 0);
14201433
}
1434+
1435+
#[test]
1436+
#[traced_test]
1437+
/// No-result calls (e.g. print) shouldn't trigger the check
1438+
fn test_no_result_brillig_calls() {
1439+
let program = r#"
1440+
acir(inline) fn main f0 {
1441+
b0():
1442+
call f1(Field 1)
1443+
return Field 1
1444+
}
1445+
acir(inline) fn println f1 {
1446+
b0(v0: Field):
1447+
call f2(u1 1, v0)
1448+
return
1449+
}
1450+
brillig(inline) fn print_unconstrained f2 {
1451+
b0(v0: u1, v1: Field):
1452+
return
1453+
}
1454+
"#;
1455+
1456+
let mut ssa = Ssa::from_str(program).unwrap();
1457+
let ssa_level_warnings = ssa.check_for_missing_brillig_constraints(false);
1458+
assert_eq!(ssa_level_warnings.len(), 0);
1459+
}
14211460
}

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::{
@@ -577,4 +577,42 @@ mod tests {
577577
UnresolvedTypeData::Integer(Signedness::Signed, IntegerBitSize::SixtyFour)
578578
);
579579
}
580+
581+
#[test]
582+
fn parses_block_followed_by_call() {
583+
let src = "fn foo() { { 1 }.bar() }";
584+
let noir_function = parse_function_no_error(src);
585+
let statements = &noir_function.def.body.statements;
586+
assert_eq!(statements.len(), 1);
587+
588+
let StatementKind::Expression(expr) = &statements[0].kind else {
589+
panic!("Expected expression statement");
590+
};
591+
592+
let ExpressionKind::MethodCall(call) = &expr.kind else {
593+
panic!("Expected method call expression");
594+
};
595+
596+
assert!(matches!(call.object.kind, ExpressionKind::Block(_)));
597+
assert_eq!(call.method_name.to_string(), "bar");
598+
}
599+
600+
#[test]
601+
fn parses_if_followed_by_call() {
602+
let src = "fn foo() { if 1 { 2 } else { 3 }.bar() }";
603+
let noir_function = parse_function_no_error(src);
604+
let statements = &noir_function.def.body.statements;
605+
assert_eq!(statements.len(), 1);
606+
607+
let StatementKind::Expression(expr) = &statements[0].kind else {
608+
panic!("Expected expression statement");
609+
};
610+
611+
let ExpressionKind::MethodCall(call) = &expr.kind else {
612+
panic!("Expected method call expression");
613+
};
614+
615+
assert!(matches!(call.object.kind, ExpressionKind::If(_)));
616+
assert_eq!(call.method_name.to_string(), "bar");
617+
}
580618
}

0 commit comments

Comments
 (0)