Skip to content

Commit 0f9a339

Browse files
authored
Merge branch 'master' into mv/brillig-opcode-docs
2 parents bc085e5 + 51c68c8 commit 0f9a339

File tree

53 files changed

+371
-195
lines changed

Some content is hidden

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

53 files changed

+371
-195
lines changed

acvm-repo/acvm/src/compiler/transformers/csat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use indexmap::IndexMap;
1010
pub const MIN_EXPRESSION_WIDTH: usize = 3;
1111

1212
/// A transformer which processes any [`Expression`]s to break them up such that they
13-
/// fit within the [`ProofSystemCompiler`][crate::ProofSystemCompiler]'s width.
13+
/// fit within the backend's width.
1414
///
15-
/// This transformer is only used when targeting the [`Bounded`][crate::ExpressionWidth::Bounded] configuration.
15+
/// This transformer is only used when targeting the [`Bounded`][acir::circuit::ExpressionWidth::Bounded] configuration.
1616
///
1717
/// This is done by creating intermediate variables to hold partial calculations and then combining them
1818
/// to calculate the original expression.

acvm-repo/acvm/src/pwg/brillig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct BrilligSolver<'b, F, B: BlackBoxFunctionSolver<F>> {
3535
}
3636

3737
impl<'b, B: BlackBoxFunctionSolver<F>, F: AcirField> BrilligSolver<'b, F, B> {
38-
/// Assigns the zero value to all outputs of the given [`Brillig`] bytecode.
38+
/// Assigns the zero value to all outputs of a given [brillig call][acir::circuit::opcodes::Opcode::BrilligCall].
3939
pub(super) fn zero_out_brillig_outputs(
4040
initial_witness: &mut WitnessMap<F>,
4141
outputs: &[BrilligOutputs],

compiler/noirc_arena/src/lib.rs

-11
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ use std::fmt;
99
pub struct Index(usize);
1010

1111
impl Index {
12-
#[cfg(test)]
13-
pub fn test_new(index: usize) -> Index {
14-
Self(index)
15-
}
16-
1712
/// Return a dummy index (max value internally).
1813
/// This should be avoided over `Option<Index>` if possible.
1914
pub fn dummy() -> Self {
2015
Self(usize::MAX)
2116
}
22-
23-
/// Return the zeroed index. This is unsafe since we don't know
24-
/// if this is a valid index for any particular map yet.
25-
pub fn unsafe_zeroed() -> Self {
26-
Self(0)
27-
}
2817
}
2918

3019
impl fmt::Display for Index {

compiler/noirc_evaluator/src/acir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,7 @@ impl<'a> Context<'a> {
28272827
Ok(())
28282828
}
28292829

2830-
/// Convert a Vec<AcirVar> into a Vec<AcirValue> using the given result ids.
2830+
/// Convert a `Vec<AcirVar>` into a `Vec<AcirValue>` using the given result ids.
28312831
/// If the type of a result id is an array, several acir vars are collected into
28322832
/// a single AcirValue::Array of the same length.
28332833
/// If the type of a result id is a slice, the slice length must precede it and we can

compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<
260260
self.deallocate_register(index_at_end_of_array);
261261
}
262262

263-
/// Converts a BrilligArray (pointer to [RC, ...items]) to a HeapArray (pointer to [items])
263+
/// Converts a BrilligArray (pointer to `[RC, ...items]`) to a HeapArray (pointer to `[items]`)
264264
pub(crate) fn codegen_brillig_array_to_heap_array(&mut self, array: BrilligArray) -> HeapArray {
265265
let heap_array = HeapArray { pointer: self.allocate_register(), size: array.size };
266266
self.codegen_usize_op(array.pointer, heap_array.pointer, BrilligBinaryOp::Add, 1);

compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use super::{
2525
impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<F, Registers> {
2626
/// Processes a binary instruction according `operation`.
2727
///
28-
/// This method will compute lhs <operation> rhs
28+
/// This method will compute lhs `<operation>` rhs
2929
/// and store the result in the `result` register.
3030
pub(crate) fn binary_instruction(
3131
&mut self,

compiler/noirc_evaluator/src/ssa/ir/dfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use serde_with::serde_as;
3232
#[serde_as]
3333
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
3434
pub(crate) struct DataFlowGraph {
35-
/// Runtime of the [Function] that owns this [DataFlowGraph].
35+
/// Runtime of the [function][super::function::Function] that owns this [DataFlowGraph].
3636
/// This might change during the `runtime_separation` pass where
3737
/// ACIR functions are cloned as Brillig functions.
3838
runtime: RuntimeType,

compiler/noirc_evaluator/src/ssa/ir/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use thiserror::Error;
99

1010
/// A unique ID corresponding to a value of type T.
1111
/// This type can be used to retrieve a value of type T from
12-
/// either a DenseMap<T> or SparseMap<T>.
12+
/// either a `DenseMap<T>` or `SparseMap<T>`.
1313
///
1414
/// Note that there is nothing in an Id binding it to a particular
1515
/// DenseMap or SparseMap. If an Id was created to correspond to one
@@ -123,7 +123,7 @@ pub(crate) enum IdDisplayFromStrErr {
123123
InvalidId(String),
124124
}
125125

126-
/// The implementation of display and FromStr allows serializing and deserializing an Id<T> to a string.
126+
/// The implementation of display and FromStr allows serializing and deserializing an `Id<T>` to a string.
127127
/// This is useful when used as key in a map that has to be serialized to JSON/TOML.
128128
impl FromStr for Id<super::basic_block::BasicBlock> {
129129
type Err = IdDisplayFromStrErr;

compiler/noirc_evaluator/src/ssa/ir/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Type {
132132
Type::unsigned(8)
133133
}
134134

135-
/// Creates the str<N> type, of the given length N
135+
/// Creates the `str<N>` type, of the given length N
136136
pub(crate) fn str(length: u32) -> Type {
137137
Type::Array(Arc::new(vec![Type::char()]), length)
138138
}

compiler/noirc_evaluator/src/ssa/ir/value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{
1515
pub(crate) type ValueId = Id<Value>;
1616

1717
/// Value is the most basic type allowed in the IR.
18-
/// Transition Note: A Id<Value> is similar to `NodeId` in our previous IR.
18+
/// Transition Note: A `Id<Value>` is similar to `NodeId` in our previous IR.
1919
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
2020
pub(crate) enum Value {
2121
/// This value was created due to an instruction

compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
//! without the need for multiple passes.
1414
//!
1515
//! Other passes perform a certain amount of constant folding automatically as they insert instructions
16-
//! into the [`DataFlowGraph`] but this pass can become needed if [`DataFlowGraph::set_value`] or
17-
//! [`DataFlowGraph::set_value_from_id`] are used on a value which enables instructions dependent on the value to
18-
//! now be simplified.
16+
//! into the [`DataFlowGraph`] but this pass can become needed if [`DataFlowGraph::set_value_from_id`]
17+
//! is used on a value which enables instructions dependent on the value to now be simplified.
1918
//!
2019
//! This is the only pass which removes duplicated pure [`Instruction`]s however and so is needed when
2120
//! different blocks are merged, i.e. after the [`flatten_cfg`][super::flatten_cfg] pass.

compiler/noirc_evaluator/src/ssa/opt/inlining/inline_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) type InlineInfos = BTreeMap<FunctionId, InlineInfo>;
4141
/// - main
4242
/// - Any Brillig function called from Acir
4343
/// - Some Brillig functions depending on aggressiveness and some metrics
44-
/// - Any Acir functions with a [fold inline type][InlineType::Fold],
44+
/// - Any Acir functions with a [fold inline type][noirc_frontend::monomorphization::ast::InlineType],
4545
///
4646
/// The returned `InlineInfos` won't have every function in it, only the ones which the algorithm visited.
4747
pub(crate) fn compute_inline_infos(

compiler/noirc_evaluator/src/ssa/opt/remove_enable_side_effects.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
//! instructions such that they cover the minimum number of instructions possible.
33
//!
44
//! The pass works as follows:
5-
//! - Insert instructions until an [Instruction::EnableSideEffectsIf] is encountered, save this [InstructionId].
5+
//! - Insert instructions until an [Instruction::EnableSideEffectsIf] is encountered, save this [InstructionId][crate::ssa::ir::instruction::InstructionId].
66
//! - Continue inserting instructions until either
7-
//! - Another [Instruction::EnableSideEffectsIf] is encountered, if so then drop the previous [InstructionId] in favour
7+
//! - Another [Instruction::EnableSideEffectsIf] is encountered, if so then drop the previous [InstructionId][crate::ssa::ir::instruction::InstructionId] in favour
88
//! of this one.
99
//! - An [Instruction] with side-effects is encountered, if so then insert the currently saved [Instruction::EnableSideEffectsIf]
1010
//! before the [Instruction]. Continue inserting instructions until the next [Instruction::EnableSideEffectsIf] is encountered.
11+
//!
1112
use std::collections::HashSet;
1213

1314
use acvm::{FieldElement, acir::AcirField};

compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl<'a> FunctionContext<'a> {
597597
/// Inserts a call instruction at the end of the current block and returns the results
598598
/// of the call.
599599
///
600-
/// Compared to self.builder.insert_call, this version will reshape the returned Vec<ValueId>
600+
/// Compared to self.builder.insert_call, this version will reshape the returned `Vec<ValueId>`
601601
/// back into a Values tree of the proper shape.
602602
pub(super) fn insert_call(
603603
&mut self,
@@ -728,10 +728,12 @@ impl<'a> FunctionContext<'a> {
728728
/// Method: First `extract_current_value` must recurse on the lvalue to extract the current
729729
/// value contained:
730730
///
731+
/// ```text
731732
/// v0 = foo.bar ; allocate instruction for bar
732733
/// v1 = load v0 ; loading the bar array
733734
/// v2 = add i1, baz_index ; field offset for index i1, field baz
734735
/// v3 = array_get v1, index v2 ; foo.bar[i1].baz
736+
/// ```
735737
///
736738
/// Method (part 2): Then, `assign_new_value` will recurse in the opposite direction to
737739
/// construct the larger value as needed until we can `store` to the nearest
@@ -790,7 +792,7 @@ impl<'a> FunctionContext<'a> {
790792
}
791793

792794
/// Compile the given `array[index]` expression as a reference.
793-
/// This will return a triple of (array, index, lvalue_ref, Option<length>) where the lvalue_ref records the
795+
/// This will return a triple of (array, index, lvalue_ref, `Option<length>`) where the lvalue_ref records the
794796
/// structure of the lvalue expression for use by `assign_new_value`.
795797
/// The optional length is for indexing slices rather than arrays since slices
796798
/// are represented as a tuple in the form: (length, slice contents).

compiler/noirc_evaluator/src/ssa/ssa_gen/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<T> Tree<T> {
9898

9999
/// Calls the given function on each leaf node, mapping this tree into a new one.
100100
///
101-
/// Because the given function returns a Tree<U> rather than a U, it is possible
101+
/// Because the given function returns a `Tree<U>` rather than a U, it is possible
102102
/// to use this function to turn Leaf nodes into either other Leaf nodes or even Branch nodes.
103103
pub(super) fn map<U>(self, mut f: impl FnMut(T) -> Tree<U>) -> Tree<U> {
104104
self.map_helper(&mut f)
@@ -173,7 +173,7 @@ impl Tree<Type> {
173173
}
174174

175175
impl Tree<Value> {
176-
/// Flattens and evaluates this Tree<Value> into a list of ir values
176+
/// Flattens and evaluates this `Tree<Value>` into a list of ir values
177177
/// for return statements, branching instructions, or function parameters.
178178
pub(super) fn into_value_list(self, ctx: &mut FunctionContext) -> Vec<IrValueId> {
179179
vecmap(self.flatten(), |value| value.eval(ctx))

compiler/noirc_frontend/src/ast/statement.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,21 @@ impl StatementKind {
104104
ParserError::with_reason(ParserErrorReason::MissingSeparatingSemi, location);
105105

106106
match self {
107-
StatementKind::Let(_)
108-
| StatementKind::Assign(_)
107+
StatementKind::Let(_) => {
108+
// To match rust, a let statement always requires a semicolon, even at the end of a block
109+
if semi.is_none() {
110+
let reason = ParserErrorReason::MissingSemicolonAfterLet;
111+
emit_error(ParserError::with_reason(reason, location));
112+
}
113+
self
114+
}
115+
StatementKind::Assign(_)
109116
| StatementKind::Semi(_)
110117
| StatementKind::Break
111118
| StatementKind::Continue
112119
| StatementKind::Error => {
113-
// To match rust, statements always require a semicolon, even at the end of a block
114-
if semi.is_none() {
120+
// These statements can omit the semicolon if they are the last statement in a block
121+
if !last_statement_in_block && semi.is_none() {
115122
emit_error(missing_semicolon);
116123
}
117124
self
@@ -791,13 +798,15 @@ impl ForRange {
791798
/// Create a 'for' expression taking care of desugaring a 'for e in array' loop
792799
/// into the following if needed:
793800
///
801+
/// ```text
794802
/// {
795803
/// let fresh1 = array;
796804
/// for fresh2 in 0 .. std::array::len(fresh1) {
797805
/// let elem = fresh1[fresh2];
798806
/// ...
799807
/// }
800808
/// }
809+
/// ````
801810
pub(crate) fn into_for(
802811
self,
803812
identifier: Ident,

compiler/noirc_frontend/src/elaborator/enums.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ impl Elaborator<'_> {
794794

795795
/// Compiles the rows of a match expression, outputting a decision tree for the match.
796796
///
797-
/// This is an adaptation of https://github.com/yorickpeterse/pattern-matching-in-rust/tree/main/jacobs2021
798-
/// which is an implementation of https://julesjacobs.com/notes/patternmatching/patternmatching.pdf
797+
/// This is an adaptation of <https://github.com/yorickpeterse/pattern-matching-in-rust/tree/main/jacobs2021>
798+
/// which is an implementation of <https://julesjacobs.com/notes/patternmatching/patternmatching.pdf>
799799
pub(super) fn elaborate_match_rows(
800800
&mut self,
801801
rows: Vec<Row>,

compiler/noirc_frontend/src/elaborator/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1544,12 +1544,12 @@ impl<'context> Elaborator<'context> {
15441544

15451545
pub fn get_module(&self, module: ModuleId) -> &ModuleData {
15461546
let message = "A crate should always be present for a given crate id";
1547-
&self.def_maps.get(&module.krate).expect(message).modules[module.local_id.0]
1547+
&self.def_maps.get(&module.krate).expect(message)[module.local_id]
15481548
}
15491549

15501550
fn get_module_mut(def_maps: &mut DefMaps, module: ModuleId) -> &mut ModuleData {
15511551
let message = "A crate should always be present for a given crate id";
1552-
&mut def_maps.get_mut(&module.krate).expect(message).modules[module.local_id.0]
1552+
&mut def_maps.get_mut(&module.krate).expect(message)[module.local_id]
15531553
}
15541554

15551555
fn declare_methods_on_struct(

compiler/noirc_frontend/src/elaborator/patterns.rs

+2
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,11 @@ impl Elaborator<'_> {
599599

600600
/// Solve any generics that are part of the path before the function, for example:
601601
///
602+
/// ```rust
602603
/// foo::Bar::<i32>::baz
603604
/// ^^^^^
604605
/// solve these
606+
/// ```
605607
fn resolve_item_turbofish(&mut self, item: PathResolutionItem) -> Vec<Type> {
606608
match item {
607609
PathResolutionItem::Method(struct_id, Some(generics), _func_id) => {

compiler/noirc_frontend/src/elaborator/traits.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ impl Elaborator<'_> {
260260
/// `impl<C> Foo<D> for Bar<E> { fn foo<F>(...); } `
261261
///
262262
/// We have to substitute:
263-
/// - Self for Bar<E>
264-
/// - A for D
265-
/// - B for F
263+
/// - `Self` for `Bar<E>`
264+
/// - `A` for `D`
265+
/// - `B` for `F`
266266
///
267267
/// Before we can type check. Finally, we must also check that the unification
268268
/// result does not introduce any new bindings. This can happen if the impl

compiler/noirc_frontend/src/graph/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ pub struct CrateGraph {
116116
impl CrateGraph {
117117
/// Tries to find the requested crate in the current one's dependencies,
118118
/// otherwise walks down the crate dependency graph from crate_id until we reach it.
119-
/// This is needed in case a library (lib1) re-export a structure defined in another library (lib2)
120-
/// In that case, we will get [lib1,lib2] when looking for a struct defined in lib2,
119+
/// This is needed in case a library (`lib1`) re-export a structure defined in another library (`lib2`)
120+
/// In that case, we will get `[lib1,lib2]` when looking for a struct defined in lib2,
121121
/// re-exported by lib1 and used by the main crate.
122122
/// Returns the path from crate_id to target_crate_id
123123
pub(crate) fn find_dependencies(

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ fn type_def_as_type(
471471
Ok(Value::Type(Type::DataType(type_def_rc, generics)))
472472
}
473473

474-
/// fn generics(self) -> [(Type, Option<Type>)]
474+
/// fn generics(self) -> [(Type, `Option<Type>`)]
475475
fn type_def_generics(
476476
interner: &NodeInterner,
477477
arguments: Vec<(Value, Location)>,
@@ -3002,7 +3002,7 @@ pub(crate) fn option(option_type: Type, value: Option<Value>, location: Location
30023002
Value::Struct(fields, option_type)
30033003
}
30043004

3005-
/// Given a type, assert that it's an Option<T> and return the Type for T
3005+
/// Given a type, assert that it's an `Option<T>` and return the Type for T
30063006
pub(crate) fn extract_option_generic_type(typ: Type) -> Type {
30073007
let Type::DataType(struct_type, mut generics) = typ else {
30083008
panic!("Expected type to be a struct");

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

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#![cfg(test)]
22

3-
use std::collections::{BTreeMap, HashMap};
3+
use std::collections::HashMap;
44
use std::path::PathBuf;
55

66
use fm::{FileId, FileManager};
7-
use noirc_arena::Index;
87
use noirc_errors::Location;
98

109
use super::Interpreter;
@@ -13,7 +12,7 @@ use super::value::Value;
1312
use crate::elaborator::{Elaborator, ElaboratorOptions};
1413
use crate::hir::def_collector::dc_crate::{CompilationError, DefCollector};
1514
use crate::hir::def_collector::dc_mod::collect_defs;
16-
use crate::hir::def_map::{CrateDefMap, LocalModuleId, ModuleData};
15+
use crate::hir::def_map::{CrateDefMap, ModuleData};
1716
use crate::hir::{Context, ParsedFiles};
1817
use crate::node_interner::FuncId;
1918
use crate::parse_program;
@@ -27,19 +26,15 @@ pub(crate) fn with_interpreter<T>(
2726
) -> T {
2827
let file = FileId::default();
2928

30-
// Can't use Index::test_new here for some reason, even with #[cfg(test)].
31-
let module_id = LocalModuleId(Index::unsafe_zeroed());
32-
let mut modules = noirc_arena::Arena::default();
3329
let location = Location::new(Default::default(), file);
34-
let root = LocalModuleId(modules.insert(ModuleData::new(
30+
let root_module = ModuleData::new(
3531
None,
3632
location,
3733
Vec::new(),
3834
Vec::new(),
3935
false, // is contract
4036
false, // is struct
41-
)));
42-
assert_eq!(root, module_id);
37+
);
4338

4439
let file_manager = FileManager::new(&PathBuf::new());
4540
let parsed_files = ParsedFiles::new();
@@ -52,10 +47,11 @@ pub(crate) fn with_interpreter<T>(
5247
assert_eq!(errors.len(), 0);
5348
let ast = module.into_sorted();
5449

55-
let def_map = CrateDefMap { root: module_id, modules, krate, extern_prelude: BTreeMap::new() };
50+
let def_map = CrateDefMap::new(krate, root_module);
51+
let root_module_id = def_map.root();
5652
let mut collector = DefCollector::new(def_map);
5753

58-
collect_defs(&mut collector, ast, FileId::dummy(), module_id, krate, &mut context);
54+
collect_defs(&mut collector, ast, FileId::dummy(), root_module_id, krate, &mut context);
5955
context.def_maps.insert(krate, collector.def_map);
6056

6157
let main = context.get_main_function(&krate).expect("Expected 'main' function");

0 commit comments

Comments
 (0)