Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7b7e2bc
Function values are now pairs of (constrained, unconstrained)
jfecher Aug 13, 2025
e459dc4
Fix some typos that resulted in bugs
jfecher Aug 14, 2025
b16b052
Update snapshots
jfecher Aug 14, 2025
d97f64c
Merge branch 'master' into jf/double-lambdas
Aug 15, 2025
f2fc8ef
Experimental: ignore runtime pairs in monomorphized printer
jfecher Aug 15, 2025
dda4aa1
Merge branch 'jf/double-lambdas' of https://github.com/noir-lang/noir…
jfecher Aug 15, 2025
132ba09
Merge branch 'master' into jf/double-lambdas
jfecher Aug 15, 2025
c909ad3
Revert "Experimental: ignore runtime pairs in monomorphized printer"
jfecher Aug 15, 2025
9ede1a0
Add 'avoid_lambdas' to ast_fuzzer args
jfecher Aug 15, 2025
043c9c9
Clippy
jfecher Aug 15, 2025
16795c4
Update frontend test, format
jfecher Aug 18, 2025
3bd2fd5
Snaps
jfecher Aug 18, 2025
564b65f
Format
jfecher Aug 18, 2025
4bd7067
Function is now a tuple type
jfecher Aug 18, 2025
b62f7a7
Merge branch 'master' into jf/double-lambdas
Aug 19, 2025
cd576a1
Merge branch 'master' into jf/double-lambdas
jfecher Aug 20, 2025
4058ff9
Merge branch 'jf/double-lambdas' of https://github.com/noir-lang/noir…
jfecher Aug 20, 2025
be88050
Extend time for parity lib
jfecher Aug 20, 2025
ae7431d
Update compiler/noirc_frontend/src/monomorphization/printer.rs
jfecher Aug 20, 2025
b26ec72
Update compiler/noirc_frontend/src/monomorphization/mod.rs
jfecher Aug 20, 2025
a2b30ac
constrainedness
jfecher Aug 20, 2025
c7a7428
Merge branch 'jf/double-lambdas' of https://github.com/noir-lang/noir…
jfecher Aug 20, 2025
348ab59
Snap conflicts
jfecher Aug 22, 2025
f21f687
I just fixed these
jfecher Aug 22, 2025
adf99d9
Merge branch 'master' into jf/double-lambdas
jfecher Aug 26, 2025
a3d6a6b
Merge branch 'master' of https://github.com/noir-lang/noir into jf/do…
jfecher Aug 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'a> FunctionContext<'a> {
// otherwise we cannot move it multiple times each loop of vecmap.
fn map_type_helper<T>(typ: &ast::Type, f: &mut dyn FnMut(Type) -> T) -> Tree<T> {
match typ {
ast::Type::Tuple(fields) => {
ast::Type::Tuple { elements: fields, .. } => {
Tree::Branch(vecmap(fields, |field| Self::map_type_helper(field, f)))
}
ast::Type::Unit => Tree::empty(),
Expand All @@ -219,7 +219,7 @@ impl<'a> FunctionContext<'a> {
// then the encapsulated fields themselves
let final_fmt_str_fields =
vec![ast::Type::String(*len), ast::Type::Field, *fields.clone()];
let fmt_str_tuple = ast::Type::Tuple(final_fmt_str_fields);
let fmt_str_tuple = ast::Type::tuple(final_fmt_str_fields);
Self::map_type_helper(&fmt_str_tuple, f)
}
ast::Type::Slice(elements) => {
Expand Down Expand Up @@ -260,7 +260,7 @@ impl<'a> FunctionContext<'a> {
panic!("convert_non_tuple_type called on a fmt string: {typ}")
}
ast::Type::Unit => panic!("convert_non_tuple_type called on a unit type"),
ast::Type::Tuple(_) => panic!("convert_non_tuple_type called on a tuple: {typ}"),
ast::Type::Tuple { .. } => panic!("convert_non_tuple_type called on a tuple: {typ}"),
ast::Type::Function(_, _, _, _) => Type::Function,
ast::Type::Slice(_) => panic!("convert_non_tuple_type called on a slice: {typ}"),
ast::Type::Reference(element, _) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl FunctionContext<'_> {
Expression::While(while_) => self.codegen_while(while_),
Expression::If(if_expr) => self.codegen_if(if_expr),
Expression::Match(match_expr) => self.codegen_match(match_expr),
Expression::Tuple(tuple) => self.codegen_tuple(tuple),
Expression::Tuple { elements, .. } => self.codegen_tuple(elements),
Expression::ExtractTupleField(tuple, index) => {
self.codegen_extract_tuple_field(tuple, *index)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,7 @@ pub mod test_utils {
};

let mut monomorphizer =
Monomorphizer::new(elaborator.interner, DebugTypeTracker::default());
Monomorphizer::new(elaborator.interner, DebugTypeTracker::default(), false);
Ok(monomorphizer.expr(expr_id).expect("monomorphization error while converting interpreter execution result, should not be possible"))
}
}
45 changes: 36 additions & 9 deletions compiler/noirc_frontend/src/monomorphization/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum Expression {
While(While),
If(If),
Match(Match),
Tuple(Vec<Expression>),
Tuple { elements: Vec<Expression>, is_function_runtime_pair: bool },
ExtractTupleField(Box<Expression>, usize),
Call(Call),
Let(Let),
Expand All @@ -57,6 +57,15 @@ pub enum Expression {
}

impl Expression {
pub fn tuple(elements: Vec<Expression>) -> Expression {
Expression::Tuple { elements, is_function_runtime_pair: false }
}

pub fn function_runtime_pair(constrained: Expression, unconstrained: Expression) -> Expression {
let elements = vec![constrained, unconstrained];
Expression::Tuple { elements, is_function_runtime_pair: true }
}

pub fn is_array_or_slice_literal(&self) -> bool {
matches!(self, Expression::Literal(Literal::Array(_) | Literal::Slice(_)))
}
Expand Down Expand Up @@ -93,13 +102,13 @@ impl Expression {
Expression::Cast(cast) => borrowed(&cast.r#type),
Expression::If(if_) => borrowed(&if_.typ),
Expression::ExtractTupleField(x, idx) => match x.as_ref() {
Expression::Tuple(xs) => {
Expression::Tuple { elements: xs, .. } => {
assert!(xs.len() > *idx, "index out of bounds in tuple return type");
xs[*idx].return_type()
}
x => {
let typ = x.return_type()?;
let Type::Tuple(types) = typ.as_ref() else {
let Type::Tuple { elements: types, .. } = typ.as_ref() else {
unreachable!("unexpected type for tuple field extraction: {typ}");
};
assert!(types.len() > *idx, "index out of bounds in tuple return type");
Expand All @@ -110,7 +119,7 @@ impl Expression {
Expression::Call(call) => borrowed(&call.return_type),
Expression::Match(m) => borrowed(&m.typ),

Expression::Tuple(xs) => {
Expression::Tuple { elements: xs, .. } => {
let types = xs
.iter()
.filter_map(|x| x.return_type())
Expand All @@ -119,7 +128,7 @@ impl Expression {
if types.len() != xs.len() {
return None;
}
owned(Type::Tuple(types))
owned(Type::tuple(types))
}

Expression::For(_)
Expand Down Expand Up @@ -174,7 +183,9 @@ impl Expression {
&& m.default_case.as_ref().is_none_or(|x| x.needs_type_inference_from_literal())
}

Expression::Tuple(xs) => xs.iter().any(|x| x.needs_type_inference_from_literal()),
Expression::Tuple { elements: xs, .. } => {
xs.iter().any(|x| x.needs_type_inference_from_literal())
}

Expression::ExtractTupleField(x, _) => x.needs_type_inference_from_literal(),

Expand Down Expand Up @@ -504,7 +515,10 @@ pub enum Type {
String(/*len:*/ u32), // String(4) = str[4]
FmtString(/*len:*/ u32, Box<Type>),
Unit,
Tuple(Vec<Type>),
Tuple {
elements: Vec<Type>,
is_function_runtime_pair: bool,
},
Slice(Box<Type>),
Reference(Box<Type>, /*mutable:*/ bool),
Function(
Expand All @@ -516,9 +530,19 @@ pub enum Type {
}

impl Type {
pub fn tuple(elements: Vec<Type>) -> Type {
Type::Tuple { elements, is_function_runtime_pair: false }
}

pub fn function_runtime_pair(constrained: Type, unconstrained: Type) -> Type {
Type::Tuple { elements: vec![constrained, unconstrained], is_function_runtime_pair: true }
}

pub fn flatten(&self) -> Vec<Type> {
match self {
Type::Tuple(fields) => fields.iter().flat_map(|field| field.flatten()).collect(),
Type::Tuple { elements, .. } => {
elements.iter().flat_map(|field| field.flatten()).collect()
}
_ => vec![self.clone()],
}
}
Expand Down Expand Up @@ -651,14 +675,17 @@ impl std::fmt::Display for Type {
write!(f, "fmtstr<{len}, {elements}>")
}
Type::Unit => write!(f, "()"),
Type::Tuple(elements) => {
Type::Tuple { elements, is_function_runtime_pair: false } => {
let elements = vecmap(elements, ToString::to_string);
if elements.len() == 1 {
write!(f, "({},)", elements[0])
} else {
write!(f, "({})", elements.join(", "))
}
}
Type::Tuple { elements, is_function_runtime_pair: true } => {
write!(f, "{}", &elements[0])
}
Type::Function(args, ret, env, unconstrained) => {
if *unconstrained {
write!(f, "unconstrained ")?;
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/monomorphization/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ impl Monomorphizer<'_> {
pub(super) fn patch_debug_instrumentation_call(
&mut self,
call: &HirCallExpression,
function: &Expression,
arguments: &mut [Expression],
) -> Result<(), MonomorphizationError> {
let original_func = Box::new(self.expr(call.func)?);
if let Expression::Ident(Ident { name, .. }) = original_func.as_ref() {
if let Expression::Ident(Ident { name, .. }) = function {
if name == "__debug_var_assign" {
self.patch_debug_var_assign(call, arguments)?;
} else if name == "__debug_var_drop" {
Expand Down
Loading
Loading