Skip to content

Commit

Permalink
Merge branch 'master' into kw/change-to-lowercase-field
Browse files Browse the repository at this point in the history
* master:
  chore(docs): address visibility issues in docs (#3643)
  chore: type formatting (#3618)
  fix: Restrict fill_internal_slices pass to acir functions (#3634)
  chore(docs): docs for v0.19.4 (#3601)
  feat: aztec-packages (#3626)
  chore: Move tests to the correct root (#3633)
  feat: Implement integer printing (#3577)
  fix: corrected the formatting of error message parameters in index out of bounds error (#3630)
  chore: Update ACIR artifacts (#3619)
  chore(debugger): Run debugger REPL in thread (#3611)
  chore: remove deprecated method (#3625)
  • Loading branch information
TomAFrench committed Nov 30, 2023
2 parents 06e5dda + 6e3aea5 commit b6330d0
Show file tree
Hide file tree
Showing 164 changed files with 6,366 additions and 207 deletions.
69 changes: 0 additions & 69 deletions acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,75 +120,6 @@ pub enum BlackBoxFuncCall {
}

impl BlackBoxFuncCall {
#[deprecated = "BlackBoxFuncCall::dummy() is unnecessary and will be removed in ACVM 0.24.0"]
pub fn dummy(bb_func: BlackBoxFunc) -> Self {
match bb_func {
BlackBoxFunc::AND => BlackBoxFuncCall::AND {
lhs: FunctionInput::dummy(),
rhs: FunctionInput::dummy(),
output: Witness(0),
},
BlackBoxFunc::XOR => BlackBoxFuncCall::XOR {
lhs: FunctionInput::dummy(),
rhs: FunctionInput::dummy(),
output: Witness(0),
},
BlackBoxFunc::RANGE => BlackBoxFuncCall::RANGE { input: FunctionInput::dummy() },
BlackBoxFunc::SHA256 => BlackBoxFuncCall::SHA256 { inputs: vec![], outputs: vec![] },
BlackBoxFunc::Blake2s => BlackBoxFuncCall::Blake2s { inputs: vec![], outputs: vec![] },
BlackBoxFunc::SchnorrVerify => BlackBoxFuncCall::SchnorrVerify {
public_key_x: FunctionInput::dummy(),
public_key_y: FunctionInput::dummy(),
signature: vec![],
message: vec![],
output: Witness(0),
},
BlackBoxFunc::PedersenCommitment => BlackBoxFuncCall::PedersenCommitment {
inputs: vec![],
domain_separator: 0,
outputs: (Witness(0), Witness(0)),
},
BlackBoxFunc::PedersenHash => BlackBoxFuncCall::PedersenHash {
inputs: vec![],
domain_separator: 0,
output: Witness(0),
},
BlackBoxFunc::HashToField128Security => {
BlackBoxFuncCall::HashToField128Security { inputs: vec![], output: Witness(0) }
}
BlackBoxFunc::EcdsaSecp256k1 => BlackBoxFuncCall::EcdsaSecp256k1 {
public_key_x: vec![],
public_key_y: vec![],
signature: vec![],
hashed_message: vec![],
output: Witness(0),
},
BlackBoxFunc::EcdsaSecp256r1 => BlackBoxFuncCall::EcdsaSecp256r1 {
public_key_x: vec![],
public_key_y: vec![],
signature: vec![],
hashed_message: vec![],
output: Witness(0),
},
BlackBoxFunc::FixedBaseScalarMul => BlackBoxFuncCall::FixedBaseScalarMul {
low: FunctionInput::dummy(),
high: FunctionInput::dummy(),
outputs: (Witness(0), Witness(0)),
},
BlackBoxFunc::Keccak256 => {
BlackBoxFuncCall::Keccak256 { inputs: vec![], outputs: vec![] }
}
BlackBoxFunc::RecursiveAggregation => BlackBoxFuncCall::RecursiveAggregation {
verification_key: vec![],
proof: vec![],
public_inputs: vec![],
key_hash: FunctionInput::dummy(),
input_aggregation_object: None,
output_aggregation_object: vec![],
},
}
}

pub fn get_black_box_func(&self) -> BlackBoxFunc {
match self {
BlackBoxFuncCall::AND { .. } => BlackBoxFunc::AND,
Expand Down
4 changes: 4 additions & 0 deletions compiler/noirc_errors/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ impl Span {
Span::inclusive(start, start)
}

pub fn empty(position: u32) -> Span {
Span::from(position..position)
}

#[must_use]
pub fn merge(self, other: Span) -> Span {
Span(self.0.merge(other.0))
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum RuntimeError {
},
#[error(transparent)]
InternalError(#[from] InternalError),
#[error("Index out of bounds, array has size {index:?}, but index was {array_size:?}")]
#[error("Index out of bounds, array has size {array_size}, but index was {index}")]
IndexOutOfBounds { index: usize, array_size: usize, call_stack: CallStack },
#[error("Range constraint of {num_bits} bits is too large for the Field size")]
InvalidRangeConstraint { num_bits: u32, call_stack: CallStack },
Expand Down
12 changes: 9 additions & 3 deletions compiler/noirc_evaluator/src/ssa/opt/fill_internal_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::ssa::{
ir::{
basic_block::BasicBlockId,
dfg::CallStack,
function::Function,
function::{Function, RuntimeType},
function_inserter::FunctionInserter,
instruction::{Instruction, InstructionId, Intrinsic},
post_order::PostOrder,
Expand All @@ -62,8 +62,14 @@ use fxhash::FxHashMap as HashMap;
impl Ssa {
pub(crate) fn fill_internal_slices(mut self) -> Ssa {
for function in self.functions.values_mut() {
let mut context = Context::new(function);
context.process_blocks();
// This pass is only necessary for generating ACIR and thus we should not
// process Brillig functions.
// The pass is also currently only setup to handle a function with a single flattened block.
// For complex Brillig functions we can expect this pass to panic.
if function.runtime() == RuntimeType::Acir {
let mut context = Context::new(function);
context.process_blocks();
}
}
self
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum UnresolvedTypeData {
FormatString(UnresolvedTypeExpression, Box<UnresolvedType>),
Unit,

Parenthesized(Box<UnresolvedType>),

/// A Named UnresolvedType can be a struct type or a type variable
Named(Path, Vec<UnresolvedType>),

Expand Down Expand Up @@ -152,6 +154,7 @@ impl std::fmt::Display for UnresolvedTypeData {
Unit => write!(f, "()"),
Error => write!(f, "error"),
Unspecified => write!(f, "unspecified"),
Parenthesized(typ) => write!(f, "({typ})"),
}
}
}
Expand Down
32 changes: 18 additions & 14 deletions compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ impl From<Ident> for Expression {
fn from(i: Ident) -> Expression {
Expression {
span: i.0.span(),
kind: ExpressionKind::Variable(Path { segments: vec![i], kind: PathKind::Plain }),
kind: ExpressionKind::Variable(Path {
span: i.span(),
segments: vec![i],
kind: PathKind::Plain,
}),
}
}
}
Expand Down Expand Up @@ -311,6 +315,7 @@ impl UseTree {
pub struct Path {
pub segments: Vec<Ident>,
pub kind: PathKind,
pub span: Span,
}

impl Path {
Expand All @@ -330,18 +335,11 @@ impl Path {
}

pub fn from_ident(name: Ident) -> Path {
Path { segments: vec![name], kind: PathKind::Plain }
Path { span: name.span(), segments: vec![name], kind: PathKind::Plain }
}

pub fn span(&self) -> Span {
let mut segments = self.segments.iter();
let first_segment = segments.next().expect("ice : cannot have an empty path");
let mut span = first_segment.0.span();

for segment in segments {
span = span.merge(segment.0.span());
}
span
self.span
}

pub fn last_segment(&self) -> Ident {
Expand Down Expand Up @@ -545,8 +543,11 @@ impl ForRange {

// array.len()
let segments = vec![array_ident];
let array_ident =
ExpressionKind::Variable(Path { segments, kind: PathKind::Plain });
let array_ident = ExpressionKind::Variable(Path {
segments,
kind: PathKind::Plain,
span: array_span,
});

let end_range = ExpressionKind::MethodCall(Box::new(MethodCallExpression {
object: Expression::new(array_ident.clone(), array_span),
Expand All @@ -561,8 +562,11 @@ impl ForRange {

// array[i]
let segments = vec![Ident::new(index_name, array_span)];
let index_ident =
ExpressionKind::Variable(Path { segments, kind: PathKind::Plain });
let index_ident = ExpressionKind::Variable(Path {
segments,
kind: PathKind::Plain,
span: array_span,
});

let loop_element = ExpressionKind::Index(Box::new(IndexExpression {
collection: Expression::new(array_ident, array_span),
Expand Down
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/hir/resolution/import.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iter_extended::partition_results;
use noirc_errors::CustomDiagnostic;
use noirc_errors::{CustomDiagnostic, Span};

use crate::graph::CrateId;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -202,7 +202,11 @@ fn resolve_external_dep(
// Create an import directive for the dependency crate
let path_without_crate_name = &path[1..]; // XXX: This will panic if the path is of the form `use dep::std` Ideal algorithm will not distinguish between crate and module

let path = Path { segments: path_without_crate_name.to_vec(), kind: PathKind::Plain };
let path = Path {
segments: path_without_crate_name.to_vec(),
kind: PathKind::Plain,
span: Span::default(),
};
let dep_directive =
ImportDirective { module_id: dep_module.local_id, path, alias: directive.alias.clone() };

Expand Down
2 changes: 2 additions & 0 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<'a> Resolver<'a> {
MutableReference(element) => {
Type::MutableReference(Box::new(self.resolve_type_inner(*element, new_variables)))
}
Parenthesized(typ) => self.resolve_type_inner(*typ, new_variables),
}
}

Expand Down Expand Up @@ -1787,6 +1788,7 @@ impl<'a> Resolver<'a> {
self.verify_type_valid_for_program_input(element);
}
}
UnresolvedTypeData::Parenthesized(typ) => self.verify_type_valid_for_program_input(typ),
}
}

Expand Down
27 changes: 20 additions & 7 deletions compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,21 +726,21 @@ fn token_kind(token_kind: TokenKind) -> impl NoirParser<Token> {

fn path() -> impl NoirParser<Path> {
let idents = || ident().separated_by(just(Token::DoubleColon)).at_least(1);
let make_path = |kind| move |segments| Path { segments, kind };
let make_path = |kind| move |segments, span| Path { segments, kind, span };

let prefix = |key| keyword(key).ignore_then(just(Token::DoubleColon));
let path_kind = |key, kind| prefix(key).ignore_then(idents()).map(make_path(kind));
let path_kind = |key, kind| prefix(key).ignore_then(idents()).map_with_span(make_path(kind));

choice((
path_kind(Keyword::Crate, PathKind::Crate),
path_kind(Keyword::Dep, PathKind::Dep),
idents().map(make_path(PathKind::Plain)),
idents().map_with_span(make_path(PathKind::Plain)),
))
}

fn empty_path() -> impl NoirParser<Path> {
let make_path = |kind| move |_| Path { segments: Vec::new(), kind };
let path_kind = |key, kind| keyword(key).map(make_path(kind));
let make_path = |kind| move |_, span| Path { segments: Vec::new(), kind, span };
let path_kind = |key, kind| keyword(key).map_with_span(make_path(kind));

choice((path_kind(Keyword::Crate, PathKind::Crate), path_kind(Keyword::Dep, PathKind::Dep)))
}
Expand Down Expand Up @@ -1015,13 +1015,24 @@ fn parse_type_inner(
named_type(recursive_type_parser.clone()),
named_trait(recursive_type_parser.clone()),
array_type(recursive_type_parser.clone()),
recursive_type_parser.clone().delimited_by(just(Token::LeftParen), just(Token::RightParen)),
parenthesized_type(recursive_type_parser.clone()),
tuple_type(recursive_type_parser.clone()),
function_type(recursive_type_parser.clone()),
mutable_reference_type(recursive_type_parser),
))
}

fn parenthesized_type(
recursive_type_parser: impl NoirParser<UnresolvedType>,
) -> impl NoirParser<UnresolvedType> {
recursive_type_parser
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
.map_with_span(|typ, span| UnresolvedType {
typ: UnresolvedTypeData::Parenthesized(Box::new(typ)),
span: span.into(),
})
}

fn optional_visibility() -> impl NoirParser<Visibility> {
keyword(Keyword::Pub).or_not().map(|opt| match opt {
Some(_) => Visibility::Public,
Expand Down Expand Up @@ -1177,7 +1188,9 @@ where
.ignore_then(type_parser.clone())
.then_ignore(just(Token::RightBracket))
.or_not()
.map_with_span(|t, span| t.unwrap_or_else(|| UnresolvedTypeData::Unit.with_span(span)));
.map_with_span(|t, span| {
t.unwrap_or_else(|| UnresolvedTypeData::Unit.with_span(Span::empty(span.end())))
});

keyword(Keyword::Fn)
.ignore_then(env)
Expand Down
39 changes: 27 additions & 12 deletions compiler/noirc_printable_type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,24 @@ fn fetch_printable_type(
fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
let mut output = String::new();
match (value, typ) {
(
PrintableValue::Field(f),
PrintableType::Field
// TODO(#2401): We should print the sign for these and probably print normal integers instead of field strings
| PrintableType::SignedInteger { .. }
| PrintableType::UnsignedInteger { .. },
) => {
(PrintableValue::Field(f), PrintableType::Field) => {
output.push_str(&format_field_string(*f));
}
(PrintableValue::Field(f), PrintableType::UnsignedInteger { width }) => {
let uint_cast = f.to_u128() & ((1 << width) - 1); // Retain the lower 'width' bits
output.push_str(&uint_cast.to_string());
}
(PrintableValue::Field(f), PrintableType::SignedInteger { width }) => {
let mut uint = f.to_u128(); // Interpret as uint

// Extract sign relative to width of input
if (uint >> (width - 1)) == 1 {
output.push('-');
uint = (uint ^ ((1 << width) - 1)) + 1; // Two's complement relative to width of input
}

output.push_str(&uint.to_string());
}
(PrintableValue::Field(f), PrintableType::Boolean) => {
if f.is_one() {
output.push_str("true");
Expand All @@ -187,8 +196,11 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
(PrintableValue::Vec(vector), PrintableType::Array { typ, .. }) => {
output.push('[');
let mut values = vector.iter().peekable();
while let Some(value) = values.next() {
output.push_str(&format!("{}", PrintableValueDisplay::Plain(value.clone(), *typ.clone())));
while let Some(value) = values.next() {
output.push_str(&format!(
"{}",
PrintableValueDisplay::Plain(value.clone(), *typ.clone())
));
if values.peek().is_some() {
output.push_str(", ");
}
Expand All @@ -204,9 +216,12 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
output.push_str(&format!("{name} {{ "));

let mut fields = fields.iter().peekable();
while let Some((key, field_type)) = fields.next() {
while let Some((key, field_type)) = fields.next() {
let value = &map[key];
output.push_str(&format!("{key}: {}", PrintableValueDisplay::Plain(value.clone(), field_type.clone())));
output.push_str(&format!(
"{key}: {}",
PrintableValueDisplay::Plain(value.clone(), field_type.clone())
));
if fields.peek().is_some() {
output.push_str(", ");
}
Expand All @@ -215,7 +230,7 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
output.push_str(" }");
}

_ => return None
_ => return None,
};

Some(output)
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/language_concepts/01_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ All parameters in a function must have a type and all types are known at compile
is pre-pended with a colon and the parameter type. Multiple parameters are separated using a comma.

```rust
fn foo(x : Field, y : pub Field){}
fn foo(x : Field, y : Field){}
```

The return type of a function can be stated by using the `->` arrow notation. The function below
states that the foo function must return a `Field`. If the function returns no value, then the arrow
is omitted.

```rust
fn foo(x : Field, y : pub Field) -> Field {
fn foo(x : Field, y : Field) -> Field {
x + y
}
```
Expand Down
Loading

0 comments on commit b6330d0

Please sign in to comment.