Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dfa3f03
feat: Field is no longer a keyword
asterite May 12, 2025
5654287
CtString is no longer a keyword
asterite May 12, 2025
b96364c
Removed the "char" keyword
asterite May 12, 2025
02239c9
Remove the "EnumDefinition" keyword
asterite May 12, 2025
07d9d4f
bool is no longer a keyword
asterite May 12, 2025
ef93b1a
Expr is no longer a keyword
asterite May 12, 2025
d03424d
FunctionDefinition is no longer a keyword
asterite May 12, 2025
a0cdabb
Module is no longer a keyword
asterite May 12, 2025
dec2b59
Quoted is no longer a keyword
asterite May 12, 2025
6e77569
Remove the StructDefinition keyword
asterite May 12, 2025
8f7a313
Remove the TopLevelItem keyword
asterite May 12, 2025
e68fc19
TraitConstraint is no longer a keyword
asterite May 12, 2025
15001a2
TraitDefinition is no longer a keyword
asterite May 12, 2025
aa62c3f
TraitImpl is no longer a keyword
asterite May 12, 2025
fa2b109
TypeDefinition is no longer a keyword
asterite May 12, 2025
33cacf8
TypedExpr is no longer a keyword
asterite May 12, 2025
b5c484a
Type is no longer a keyword
asterite May 12, 2025
d869927
UnresolvedType is no longer a keyword
asterite May 12, 2025
07e6932
i32, i8, u8, etc., are no longer keywords
asterite May 12, 2025
b4011ba
clippy
asterite May 12, 2025
e17c0a1
Remove UnresolvedDataType::Quoted
asterite May 12, 2025
8e42593
Disallow generic types in cast
asterite May 12, 2025
dd6efc7
Update stderr
asterite May 12, 2025
7d01b75
Update snapshot
asterite May 12, 2025
0d9a242
Error on generics count mismatch for primitive types
asterite May 12, 2025
88785d3
str is no longer a keyword
asterite May 12, 2025
79e0a1c
Check turbofish on `str` type
asterite May 12, 2025
93619ab
fmtstr is no longer a keyword
asterite May 12, 2025
78472fb
Error on unknown primitive method
asterite May 12, 2025
56d1e43
Reduce code length and add comment
asterite May 12, 2025
8285e93
Fix tests
asterite May 12, 2025
f5e6699
Extract `lookup_type_variable`
asterite May 12, 2025
e1caf2c
Refactor
asterite May 12, 2025
06435c2
Merge branch 'master' into ab/primitive-types-are-not-keywords
asterite May 13, 2025
9b75bde
.
May 13, 2025
6135c5e
Merge branch 'master' into ab/primitive-types-are-not-keywords
asterite May 13, 2025
4892e3c
Merge branch 'ab/primitive-types-are-not-keywords' of github.com:noir…
asterite May 13, 2025
b3e0c3f
Merge branch 'master' into ab/primitive-types-are-not-keywords
asterite May 13, 2025
55fd92d
Bump Aztec-Packages commit
asterite May 13, 2025
7bfa307
Bring back `StructDefinitionDeprecated`
asterite May 13, 2025
f64b02b
Remove unused error
asterite May 14, 2025
f738b71
PrimitiveType as path lookup result
asterite May 14, 2025
b52a07a
Reduce nesting
asterite May 14, 2025
bbc40dd
Attach issues to TODOs
asterite May 14, 2025
63c791d
Update compiler/noirc_frontend/src/elaborator/path_resolution.rs
asterite May 14, 2025
9b71e03
Merge branch 'ab/primitive-types-are-not-keywords' of github.com:noir…
asterite May 14, 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
2 changes: 1 addition & 1 deletion .github/benchmark_projects.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define: &AZ_COMMIT b67afe429d431c7516b95f9c6d1b6e358907ef33
define: &AZ_COMMIT 9f0dcc87221b4ccbe61713a77a52527176bad535
projects:
private-kernel-inner:
repo: AztecProtocol/aztec-packages
Expand Down
2 changes: 1 addition & 1 deletion EXTERNAL_NOIR_LIBRARIES.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define: &AZ_COMMIT b67afe429d431c7516b95f9c6d1b6e358907ef33
define: &AZ_COMMIT 9f0dcc87221b4ccbe61713a77a52527176bad535
libraries:
noir_check_shuffle:
repo: noir-lang/noir_check_shuffle
Expand Down
28 changes: 18 additions & 10 deletions compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::ast::{
Ident, ItemVisibility, Path, Pattern, Statement, StatementKind, UnresolvedTraitConstraint,
UnresolvedType, UnresolvedTypeData,
};
use crate::elaborator::PrimitiveType;
use crate::node_interner::{ExprId, InternedExpressionKind, InternedStatementKind, QuotedTypeId};
use crate::shared::Visibility;
use crate::signed_field::SignedField;
Expand Down Expand Up @@ -116,17 +117,24 @@ impl UnresolvedGeneric {
&self,
typ: &UnresolvedType,
) -> Result<Type, UnsupportedNumericGenericType> {
use crate::ast::UnresolvedTypeData::{FieldElement, Integer};

match typ.typ {
FieldElement => Ok(Type::FieldElement),
Integer(sign, bits) => Ok(Type::Integer(sign, bits)),
// Only fields and integers are supported for numeric kinds
_ => Err(UnsupportedNumericGenericType {
ident: self.ident().clone(),
typ: typ.typ.clone(),
}),
// TODO: this should be done with resolved types
// See https://github.com/noir-lang/noir/issues/8504
use crate::ast::UnresolvedTypeData::Named;

if let Named(path, _generics, _) = &typ.typ {
if path.segments.len() == 1 {
if let Some(primitive_type) =
PrimitiveType::lookup_by_name(path.segments[0].ident.as_str())
{
if let Some(typ) = primitive_type.to_integer_or_field() {
return Ok(typ);
}
}
}
}

// Only fields and integers are supported for numeric kinds
Err(UnsupportedNumericGenericType { ident: self.ident().clone(), typ: typ.typ.clone() })
}

pub(crate) fn ident(&self) -> &Ident {
Expand Down
123 changes: 78 additions & 45 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ pub use structure::*;
pub use traits::*;
pub use type_alias::*;

use crate::QuotedType;
use crate::{
BinaryTypeOperator,
node_interner::{InternedUnresolvedTypeData, QuotedTypeId},
parser::{ParserError, ParserErrorReason},
shared::Signedness,
token::IntType,
};

use acvm::acir::AcirField;
Expand Down Expand Up @@ -122,14 +122,9 @@ impl core::fmt::Display for IntegerBitSize {
/// for structs within, but are otherwise identical to Types.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum UnresolvedTypeData {
FieldElement,
Array(UnresolvedTypeExpression, Box<UnresolvedType>), // [Field; 4] = Array(4, Field)
Slice(Box<UnresolvedType>),
Integer(Signedness, IntegerBitSize), // u32 = Integer(unsigned, ThirtyTwo)
Bool,
Expression(UnresolvedTypeExpression),
String(UnresolvedTypeExpression),
FormatString(UnresolvedTypeExpression, Box<UnresolvedType>),
Unit,

Parenthesized(Box<UnresolvedType>),
Expand All @@ -153,9 +148,6 @@ pub enum UnresolvedTypeData {
/*unconstrained:*/ bool,
),

/// The type of quoted code for metaprogramming
Quoted(crate::QuotedType),

/// An "as Trait" path leading to an associated type.
/// E.g. `<Foo as Trait>::Bar`
AsTraitPath(Box<crate::ast::AsTraitPath>),
Expand Down Expand Up @@ -281,23 +273,15 @@ impl std::fmt::Display for UnresolvedTypeData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use UnresolvedTypeData::*;
match self {
FieldElement => write!(f, "Field"),
Array(len, typ) => write!(f, "[{typ}; {len}]"),
Slice(typ) => write!(f, "[{typ}]"),
Integer(sign, num_bits) => match sign {
Signedness::Signed => write!(f, "i{num_bits}"),
Signedness::Unsigned => write!(f, "u{num_bits}"),
},
Named(s, args, _) => write!(f, "{s}{args}"),
TraitAsType(s, args) => write!(f, "impl {s}{args}"),
Tuple(elements) => {
let elements = vecmap(elements, ToString::to_string);
write!(f, "({})", elements.join(", "))
}
Expression(expression) => expression.fmt(f),
Bool => write!(f, "bool"),
String(len) => write!(f, "str<{len}>"),
FormatString(len, elements) => write!(f, "fmtstr<{len}, {elements}>"),
Function(args, ret, env, unconstrained) => {
if *unconstrained {
write!(f, "unconstrained ")?;
Expand All @@ -318,7 +302,6 @@ impl std::fmt::Display for UnresolvedTypeData {
}
Reference(element, false) => write!(f, "&{element}"),
Reference(element, true) => write!(f, "&mut {element}"),
Quoted(quoted) => write!(f, "{}", quoted),
Unit => write!(f, "()"),
Error => write!(f, "error"),
Unspecified => write!(f, "unspecified"),
Expand Down Expand Up @@ -385,24 +368,82 @@ impl UnresolvedType {
}

impl UnresolvedTypeData {
pub fn from_int_token(
token: IntType,
) -> Result<UnresolvedTypeData, InvalidIntegerBitSizeError> {
use {IntType::*, UnresolvedTypeData::Integer};
match token {
Signed(num_bits) => {
if num_bits == 128 {
Err(InvalidIntegerBitSizeError(128))
} else if num_bits == 1 {
Err(InvalidIntegerBitSizeError(1))
} else {
Ok(Integer(Signedness::Signed, IntegerBitSize::try_from(num_bits)?))
}
}
Unsigned(num_bits) => {
Ok(Integer(Signedness::Unsigned, IntegerBitSize::try_from(num_bits)?))
}
}
pub fn bool(location: Location) -> Self {
Self::named("bool".to_string(), location)
}

pub fn integer(signedness: Signedness, size: IntegerBitSize, location: Location) -> Self {
let name = match signedness {
Signedness::Signed => match size {
IntegerBitSize::One => "i1",
IntegerBitSize::Eight => "i8",
IntegerBitSize::Sixteen => "i16",
IntegerBitSize::ThirtyTwo => "i32",
IntegerBitSize::SixtyFour => "i64",
IntegerBitSize::HundredTwentyEight => "i128",
},
Signedness::Unsigned => match size {
IntegerBitSize::One => "u1",
IntegerBitSize::Eight => "u8",
IntegerBitSize::Sixteen => "u16",
IntegerBitSize::ThirtyTwo => "u32",
IntegerBitSize::SixtyFour => "u64",
IntegerBitSize::HundredTwentyEight => "u128",
},
};
Self::named(name.to_string(), location)
}

pub fn field(location: Location) -> Self {
Self::named("Field".to_string(), location)
}

pub fn quoted(quoted: QuotedType, location: Location) -> Self {
Self::named(quoted.to_string(), location)
}

pub fn str(length: UnresolvedTypeExpression, location: Location) -> Self {
let ident = Ident::new("str".to_string(), location);
let path = Path::from_ident(ident);
Self::Named(
path,
GenericTypeArgs {
ordered_args: vec![UnresolvedType {
typ: UnresolvedTypeData::Expression(length),
location,
}],
named_args: vec![],
kinds: vec![GenericTypeArgKind::Ordered],
},
false,
)
}

pub fn fmtstr(
length: UnresolvedTypeExpression,
element: UnresolvedType,
location: Location,
) -> Self {
let ident = Ident::new("str".to_string(), location);
let path = Path::from_ident(ident);
Self::Named(
path,
GenericTypeArgs {
ordered_args: vec![
UnresolvedType { typ: UnresolvedTypeData::Expression(length), location },
element,
],
named_args: vec![],
kinds: vec![GenericTypeArgKind::Ordered],
},
false,
)
}

fn named(name: String, location: Location) -> Self {
let ident = Ident::new(name, location);
let path = Path::from_ident(ident);
Self::Named(path, GenericTypeArgs::default(), false)
}

pub fn with_location(&self, location: Location) -> UnresolvedType {
Expand All @@ -420,10 +461,6 @@ impl UnresolvedTypeData {
}
UnresolvedTypeData::Slice(typ) => typ.contains_unspecified(),
UnresolvedTypeData::Expression(expr) => expr.contains_unspecified(),
UnresolvedTypeData::String(length) => length.contains_unspecified(),
UnresolvedTypeData::FormatString(typ, length) => {
typ.contains_unspecified() || length.contains_unspecified()
}
UnresolvedTypeData::Parenthesized(typ) => typ.contains_unspecified(),
UnresolvedTypeData::Named(path, args, _is_synthesized) => {
// '_' is unspecified
Expand All @@ -442,11 +479,7 @@ impl UnresolvedTypeData {
}
UnresolvedTypeData::Unspecified => true,

UnresolvedTypeData::FieldElement
| UnresolvedTypeData::Integer(_, _)
| UnresolvedTypeData::Bool
| UnresolvedTypeData::Unit
| UnresolvedTypeData::Quoted(_)
UnresolvedTypeData::Unit
| UnresolvedTypeData::AsTraitPath(_)
| UnresolvedTypeData::Resolved(_)
| UnresolvedTypeData::Interned(_)
Expand Down
50 changes: 5 additions & 45 deletions compiler/noirc_frontend/src/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use acvm::FieldElement;
use noirc_errors::Span;

use crate::{
BinaryTypeOperator, ParsedModule, QuotedType,
BinaryTypeOperator, ParsedModule,
ast::{
ArrayLiteral, AsTraitPath, AssignStatement, BlockExpression, CallExpression,
CastExpression, ConstrainExpression, ConstructorExpression, Expression, ExpressionKind,
Expand All @@ -25,10 +25,10 @@ use crate::{
};

use super::{
ForBounds, FunctionReturnType, GenericTypeArgs, IntegerBitSize, ItemVisibility,
MatchExpression, NoirEnumeration, Pattern, Signedness, TraitBound, TraitImplItemKind, TypePath,
UnresolvedGeneric, UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType,
UnresolvedTypeData, UnresolvedTypeExpression, UnsafeExpression,
ForBounds, FunctionReturnType, GenericTypeArgs, ItemVisibility, MatchExpression,
NoirEnumeration, Pattern, TraitBound, TraitImplItemKind, TypePath, UnresolvedGeneric,
UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData,
UnresolvedTypeExpression, UnsafeExpression,
};

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -424,29 +424,8 @@ pub trait Visitor {
true
}

fn visit_format_string_type(
&mut self,
_: &UnresolvedTypeExpression,
_: &UnresolvedType,
_: Span,
) -> bool {
true
}

fn visit_string_type(&mut self, _: &UnresolvedTypeExpression, _: Span) -> bool {
true
}

fn visit_unspecified_type(&mut self, _: Span) {}

fn visit_quoted_type(&mut self, _: &QuotedType, _: Span) {}

fn visit_field_element_type(&mut self, _: Span) {}

fn visit_integer_type(&mut self, _: Signedness, _: IntegerBitSize, _: Span) {}

fn visit_bool_type(&mut self, _: Span) {}

fn visit_unit_type(&mut self, _: Span) {}

fn visit_resolved_type(&mut self, _: QuotedTypeId, _: Span) {}
Expand Down Expand Up @@ -1466,26 +1445,7 @@ impl UnresolvedType {
expr.accept(visitor);
}
}
UnresolvedTypeData::FormatString(expr, typ) => {
if visitor.visit_format_string_type(expr, typ, self.location.span) {
expr.accept(visitor);
typ.accept(visitor);
}
}
UnresolvedTypeData::String(expr) => {
if visitor.visit_string_type(expr, self.location.span) {
expr.accept(visitor);
}
}
UnresolvedTypeData::Unspecified => visitor.visit_unspecified_type(self.location.span),
UnresolvedTypeData::Quoted(typ) => visitor.visit_quoted_type(typ, self.location.span),
UnresolvedTypeData::FieldElement => {
visitor.visit_field_element_type(self.location.span);
}
UnresolvedTypeData::Integer(signdness, size) => {
visitor.visit_integer_type(*signdness, *size, self.location.span);
}
UnresolvedTypeData::Bool => visitor.visit_bool_type(self.location.span),
UnresolvedTypeData::Unit => visitor.visit_unit_type(self.location.span),
UnresolvedTypeData::Resolved(id) => {
visitor.visit_resolved_type(*id, self.location.span);
Expand Down
4 changes: 3 additions & 1 deletion compiler/noirc_frontend/src/elaborator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,12 @@
PathResolutionItem::Module(_)
| PathResolutionItem::Type(_)
| PathResolutionItem::TypeAlias(_)
| PathResolutionItem::PrimitiveType(_)
| PathResolutionItem::Trait(_)
| PathResolutionItem::ModuleFunction(_)
| PathResolutionItem::TypeAliasFunction(_, _, _)
| PathResolutionItem::TraitFunction(_, _, _) => {
| PathResolutionItem::TraitFunction(_, _, _)
| PathResolutionItem::PrimitiveFunction(..) => {
// This variable refers to an existing item
if let Some(name) = name {
// If name is set, shadow the existing item
Expand Down Expand Up @@ -1003,7 +1005,7 @@

/// Compiles the cases and fallback cases for integer and range patterns.
///
/// Integers have an infinite number of constructors, so we specialise the

Check warning on line 1008 in compiler/noirc_frontend/src/elaborator/enums.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (specialise)
/// compilation of integer and range patterns.
fn compile_int_cases(
&mut self,
Expand Down
2 changes: 2 additions & 0 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod lints;
mod options;
mod path_resolution;
mod patterns;
mod primitive_types;
mod scope;
mod statements;
mod trait_impls;
Expand All @@ -77,6 +78,7 @@ use types::bind_ordered_generics;

use self::traits::check_trait_impl_method_matches_declaration;
pub(crate) use path_resolution::{TypedPath, TypedPathSegment};
pub use primitive_types::PrimitiveType;

/// ResolverMetas are tagged onto each definition to track how many times they are used
#[derive(Debug, PartialEq, Eq)]
Expand Down
Loading
Loading