Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ impl<'a> Interpreter<'a> {
match builtin.as_str() {
"array_len" => builtin::array_len(&arguments),
_ => {
let item = format!("Evaluation for builtin function {builtin}");
let item = format!("Comptime evaluation for builtin function {builtin}");
Err(InterpreterError::Unimplemented { item, location })
}
}
} else if let Some(foreign) = func_attrs.foreign() {
let item = format!("Evaluation for foreign functions like {foreign}");
let item = format!("Comptime evaluation for foreign functions like {foreign}");
Err(InterpreterError::Unimplemented { item, location })
} else if let Some(oracle) = func_attrs.oracle() {
if oracle == "print" {
self.print_oracle(arguments)
} else {
let item = format!("Evaluation for oracle functions like {oracle}");
let item = format!("Comptime evaluation for oracle functions like {oracle}");
Err(InterpreterError::Unimplemented { item, location })
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ impl Type {
pub enum QuotedType {
Expr,
TypeDefinition,
TopLevelItem,
Type,
}

/// A list of TypeVariableIds to bind to a type. Storing the
Expand Down Expand Up @@ -965,6 +967,8 @@ impl std::fmt::Display for QuotedType {
match self {
QuotedType::Expr => write!(f, "Expr"),
QuotedType::TypeDefinition => write!(f, "TypeDefinition"),
QuotedType::TopLevelItem => write!(f, "TopLevelItem"),
QuotedType::Type => write!(f, "Type"),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,10 @@ pub enum Keyword {
String,
Struct,
Super,
TopLevelItem,
Trait,
Type,
TypeType,
TypeDefinition,
Unchecked,
Unconstrained,
Expand Down Expand Up @@ -911,8 +913,10 @@ impl fmt::Display for Keyword {
Keyword::String => write!(f, "str"),
Keyword::Struct => write!(f, "struct"),
Keyword::Super => write!(f, "super"),
Keyword::TopLevelItem => write!(f, "TopLevelItem"),
Keyword::Trait => write!(f, "trait"),
Keyword::Type => write!(f, "type"),
Keyword::TypeType => write!(f, "Type"),
Keyword::TypeDefinition => write!(f, "TypeDefinition"),
Keyword::Unchecked => write!(f, "unchecked"),
Keyword::Unconstrained => write!(f, "unconstrained"),
Expand Down Expand Up @@ -960,8 +964,10 @@ impl Keyword {
"str" => Keyword::String,
"struct" => Keyword::Struct,
"super" => Keyword::Super,
"TopLevelItem" => Keyword::TopLevelItem,
"trait" => Keyword::Trait,
"type" => Keyword::Type,
"Type" => Keyword::TypeType,
"TypeDefinition" => Keyword::TypeDefinition,
"unchecked" => Keyword::Unchecked,
"unconstrained" => Keyword::Unconstrained,
Expand Down
6 changes: 2 additions & 4 deletions compiler/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,7 @@ enum TypeMethodKey {
Tuple,
Function,
Generic,
Expr,
TypeDefinition,
Quoted(QuotedType),
}

fn get_type_method_key(typ: &Type) -> Option<TypeMethodKey> {
Expand All @@ -1827,8 +1826,7 @@ fn get_type_method_key(typ: &Type) -> Option<TypeMethodKey> {
Type::Tuple(_) => Some(Tuple),
Type::Function(_, _, _) => Some(Function),
Type::NamedGeneric(_, _) => Some(Generic),
Type::Quoted(QuotedType::Expr) => Some(Expr),
Type::Quoted(QuotedType::TypeDefinition) => Some(TypeDefinition),
Type::Quoted(quoted) => Some(Quoted(*quoted)),
Type::MutableReference(element) => get_type_method_key(element),
Type::Alias(alias, _) => get_type_method_key(&alias.borrow().typ),

Expand Down
16 changes: 16 additions & 0 deletions compiler/noirc_frontend/src/parser/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub(super) fn parse_type_inner<'a>(
string_type(),
expr_type(),
type_definition_type(),
top_level_item_type(),
quoted_type(),
format_string_type(recursive_type_parser.clone()),
named_type(recursive_type_parser.clone()),
named_trait(recursive_type_parser.clone()),
Expand Down Expand Up @@ -82,6 +84,20 @@ pub(super) fn type_definition_type() -> impl NoirParser<UnresolvedType> {
})
}

/// This is the type `TopLevelItem` - the type of a quoted statement in the top level.
/// E.g. a type definition, trait definition, trait impl, function, etc.
fn top_level_item_type() -> impl NoirParser<UnresolvedType> {
keyword(Keyword::TopLevelItem).map_with_span(|_, span| {
UnresolvedTypeData::Quoted(QuotedType::TopLevelItem).with_span(span)
})
}

/// This is the type `Type` - the type of a quoted noir type.
fn quoted_type() -> impl NoirParser<UnresolvedType> {
keyword(Keyword::TypeType)
.map_with_span(|_, span| UnresolvedTypeData::Quoted(QuotedType::Type).with_span(span))
}

pub(super) fn string_type() -> impl NoirParser<UnresolvedType> {
keyword(Keyword::String)
.ignore_then(type_expression().delimited_by(just(Token::Less), just(Token::Greater)))
Expand Down
12 changes: 6 additions & 6 deletions tooling/nargo_fmt/tests/expected/impl.nr
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
impl Type {}
impl MyType {}

impl Type<A> {}
impl MyType<A> {}

impl Type<A, B> {}
impl MyType<A, B> {}

impl Type {
impl MyType {
fn method(self) {}

fn method(mut self) {}

fn method(&mut self) {}
}

impl Type {
impl MyType {
fn method(self) {}
}

impl Type {
impl MyType {
fn method(self) {}
}
14 changes: 7 additions & 7 deletions tooling/nargo_fmt/tests/input/impl.nr
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
impl Type {}
impl MyType {}

impl Type<A> {}
impl MyType<A> {}

impl Type<A, B> {}
impl MyType<A, B> {}

impl Type {
impl MyType {
fn method(self) {}

fn method(mut self) {}

fn method(&mut self) {}
}

impl Type {
impl MyType {
fn method(self) {}
}

impl Type {
impl MyType {
fn method(self) {}
}
}