Skip to content

Commit 1902254

Browse files
authored
Merge 5ca6c88 into c9a4d88
2 parents c9a4d88 + 5ca6c88 commit 1902254

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2564
-699
lines changed

.noir-sync-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
68c32b4ffd9b069fe4b119327dbf4018c17ab9d4
1+
dfc9ff7266d2b6694cae3da88418013664440daa

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

+3
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ jobs:
478478

479479
- name: Install Foundry
480480
uses: foundry-rs/foundry-toolchain@v1.2.0
481+
with:
482+
version: nightly-8660e5b941fe7f4d67e246cfd3dafea330fb53b1
483+
481484

482485
- name: Install `bb`
483486
run: |

noir/noir-repo/compiler/noirc_errors/src/position.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ impl Span {
9494
self.start() <= other.start() && self.end() >= other.end()
9595
}
9696

97+
/// Returns `true` if any point of `self` intersects a point of `other`.
98+
/// Adjacent spans are considered to intersect (so, for example, `0..1` intersects `1..3`).
9799
pub fn intersects(&self, other: &Span) -> bool {
98-
self.end() > other.start() && self.start() < other.end()
100+
self.end() >= other.start() && self.start() <= other.end()
99101
}
100102

101103
pub fn is_smaller(&self, other: &Span) -> bool {
@@ -140,3 +142,37 @@ impl Location {
140142
self.file == other.file && self.span.contains(&other.span)
141143
}
142144
}
145+
146+
#[cfg(test)]
147+
mod tests {
148+
use crate::Span;
149+
150+
#[test]
151+
fn test_intersects() {
152+
assert!(Span::from(5..10).intersects(&Span::from(5..10)));
153+
154+
assert!(Span::from(5..10).intersects(&Span::from(5..5)));
155+
assert!(Span::from(5..5).intersects(&Span::from(5..10)));
156+
157+
assert!(Span::from(10..10).intersects(&Span::from(5..10)));
158+
assert!(Span::from(5..10).intersects(&Span::from(10..10)));
159+
160+
assert!(Span::from(5..10).intersects(&Span::from(6..9)));
161+
assert!(Span::from(6..9).intersects(&Span::from(5..10)));
162+
163+
assert!(Span::from(5..10).intersects(&Span::from(4..11)));
164+
assert!(Span::from(4..11).intersects(&Span::from(5..10)));
165+
166+
assert!(Span::from(5..10).intersects(&Span::from(4..6)));
167+
assert!(Span::from(4..6).intersects(&Span::from(5..10)));
168+
169+
assert!(Span::from(5..10).intersects(&Span::from(9..11)));
170+
assert!(Span::from(9..11).intersects(&Span::from(5..10)));
171+
172+
assert!(!Span::from(5..10).intersects(&Span::from(3..4)));
173+
assert!(!Span::from(3..4).intersects(&Span::from(5..10)));
174+
175+
assert!(!Span::from(5..10).intersects(&Span::from(11..12)));
176+
assert!(!Span::from(11..12).intersects(&Span::from(5..10)));
177+
}
178+
}

noir/noir-repo/compiler/noirc_evaluator/src/acir/mod.rs

+11-48
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ mod big_int;
2424
mod brillig_directive;
2525
mod generated_acir;
2626

27+
use crate::brillig::brillig_gen::gen_brillig_for;
2728
use crate::brillig::{
2829
brillig_gen::brillig_fn::FunctionContext as BrilligFunctionContext,
29-
brillig_ir::{
30-
artifact::{BrilligParameter, GeneratedBrillig},
31-
BrilligContext,
32-
},
30+
brillig_ir::artifact::{BrilligParameter, GeneratedBrillig},
3331
Brillig,
3432
};
3533
use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport};
@@ -518,7 +516,7 @@ impl<'a> Context<'a> {
518516
let outputs: Vec<AcirType> =
519517
vecmap(main_func.returns(), |result_id| dfg.type_of_value(*result_id).into());
520518

521-
let code = self.gen_brillig_for(main_func, arguments.clone(), brillig)?;
519+
let code = gen_brillig_for(main_func, arguments.clone(), brillig)?;
522520

523521
// We specifically do not attempt execution of the brillig code being generated as this can result in it being
524522
// replaced with constraints on witnesses to the program outputs.
@@ -878,8 +876,7 @@ impl<'a> Context<'a> {
878876
None,
879877
)?
880878
} else {
881-
let code =
882-
self.gen_brillig_for(func, arguments.clone(), brillig)?;
879+
let code = gen_brillig_for(func, arguments.clone(), brillig)?;
883880
let generated_pointer =
884881
self.shared_context.new_generated_pointer();
885882
let output_values = self.acir_context.brillig_call(
@@ -999,47 +996,6 @@ impl<'a> Context<'a> {
999996
.collect()
1000997
}
1001998

1002-
fn gen_brillig_for(
1003-
&self,
1004-
func: &Function,
1005-
arguments: Vec<BrilligParameter>,
1006-
brillig: &Brillig,
1007-
) -> Result<GeneratedBrillig<FieldElement>, InternalError> {
1008-
// Create the entry point artifact
1009-
let mut entry_point = BrilligContext::new_entry_point_artifact(
1010-
arguments,
1011-
BrilligFunctionContext::return_values(func),
1012-
func.id(),
1013-
);
1014-
entry_point.name = func.name().to_string();
1015-
1016-
// Link the entry point with all dependencies
1017-
while let Some(unresolved_fn_label) = entry_point.first_unresolved_function_call() {
1018-
let artifact = &brillig.find_by_label(unresolved_fn_label.clone());
1019-
let artifact = match artifact {
1020-
Some(artifact) => artifact,
1021-
None => {
1022-
return Err(InternalError::General {
1023-
message: format!("Cannot find linked fn {unresolved_fn_label}"),
1024-
call_stack: CallStack::new(),
1025-
})
1026-
}
1027-
};
1028-
entry_point.link_with(artifact);
1029-
// Insert the range of opcode locations occupied by a procedure
1030-
if let Some(procedure_id) = &artifact.procedure {
1031-
let num_opcodes = entry_point.byte_code.len();
1032-
let previous_num_opcodes = entry_point.byte_code.len() - artifact.byte_code.len();
1033-
// We subtract one as to keep the range inclusive on both ends
1034-
entry_point
1035-
.procedure_locations
1036-
.insert(procedure_id.clone(), (previous_num_opcodes, num_opcodes - 1));
1037-
}
1038-
}
1039-
// Generate the final bytecode
1040-
Ok(entry_point.finish())
1041-
}
1042-
1043999
/// Handles an ArrayGet or ArraySet instruction.
10441000
/// To set an index of the array (and create a new array in doing so), pass Some(value) for
10451001
/// store_value. To just retrieve an index of the array, pass None for store_value.
@@ -2806,6 +2762,13 @@ impl<'a> Context<'a> {
28062762
Intrinsic::FieldLessThan => {
28072763
unreachable!("FieldLessThan can only be called in unconstrained")
28082764
}
2765+
Intrinsic::ArrayRefCount | Intrinsic::SliceRefCount => {
2766+
let zero = self.acir_context.add_constant(FieldElement::zero());
2767+
Ok(vec![AcirValue::Var(
2768+
zero,
2769+
AcirType::NumericType(NumericType::Unsigned { bit_size: 32 }),
2770+
)])
2771+
}
28092772
}
28102773
}
28112774

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen.rs

+50-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ mod variable_liveness;
99
use acvm::FieldElement;
1010

1111
use self::{brillig_block::BrilligBlock, brillig_fn::FunctionContext};
12-
use super::brillig_ir::{
13-
artifact::{BrilligArtifact, Label},
14-
BrilligContext,
12+
use super::{
13+
brillig_ir::{
14+
artifact::{BrilligArtifact, BrilligParameter, GeneratedBrillig, Label},
15+
BrilligContext,
16+
},
17+
Brillig,
18+
};
19+
use crate::{
20+
errors::InternalError,
21+
ssa::ir::{dfg::CallStack, function::Function},
1522
};
16-
use crate::ssa::ir::function::Function;
1723

1824
/// Converting an SSA function into Brillig bytecode.
1925
pub(crate) fn convert_ssa_function(
@@ -36,3 +42,43 @@ pub(crate) fn convert_ssa_function(
3642
artifact.name = func.name().to_string();
3743
artifact
3844
}
45+
46+
pub(crate) fn gen_brillig_for(
47+
func: &Function,
48+
arguments: Vec<BrilligParameter>,
49+
brillig: &Brillig,
50+
) -> Result<GeneratedBrillig<FieldElement>, InternalError> {
51+
// Create the entry point artifact
52+
let mut entry_point = BrilligContext::new_entry_point_artifact(
53+
arguments,
54+
FunctionContext::return_values(func),
55+
func.id(),
56+
);
57+
entry_point.name = func.name().to_string();
58+
59+
// Link the entry point with all dependencies
60+
while let Some(unresolved_fn_label) = entry_point.first_unresolved_function_call() {
61+
let artifact = &brillig.find_by_label(unresolved_fn_label.clone());
62+
let artifact = match artifact {
63+
Some(artifact) => artifact,
64+
None => {
65+
return Err(InternalError::General {
66+
message: format!("Cannot find linked fn {unresolved_fn_label}"),
67+
call_stack: CallStack::new(),
68+
})
69+
}
70+
};
71+
entry_point.link_with(artifact);
72+
// Insert the range of opcode locations occupied by a procedure
73+
if let Some(procedure_id) = &artifact.procedure {
74+
let num_opcodes = entry_point.byte_code.len();
75+
let previous_num_opcodes = entry_point.byte_code.len() - artifact.byte_code.len();
76+
// We subtract one as to keep the range inclusive on both ends
77+
entry_point
78+
.procedure_locations
79+
.insert(procedure_id.clone(), (previous_num_opcodes, num_opcodes - 1));
80+
}
81+
}
82+
// Generate the final bytecode
83+
Ok(entry_point.finish())
84+
}

0 commit comments

Comments
 (0)