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
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/elaborator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@
| Type::TypeVariable(_)
| Type::FmtString(_, _)
| Type::TraitAsType(_, _, _)
| Type::NamedGeneric(_, _)
| Type::NamedGeneric(_)
| Type::CheckedCast { .. }
| Type::Function(_, _, _, _)
| Type::Reference(..)
Expand Down Expand Up @@ -968,7 +968,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 971 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
20 changes: 15 additions & 5 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use crate::{
DataType, StructField, TypeBindings,
DataType, NamedGeneric, StructField, TypeBindings,
ast::{IntegerBitSize, ItemVisibility, UnresolvedType},
graph::CrateGraph,
hir_def::traits::ResolvedTraitBound,
Expand Down Expand Up @@ -659,7 +659,11 @@ impl<'context> Elaborator<'context> {
generics.push(new_generic.clone());

let name = format!("impl {trait_path}");
let generic_type = Type::NamedGeneric(new_generic, Rc::new(name));
let generic_type = Type::NamedGeneric(NamedGeneric {
type_var: new_generic,
name: Rc::new(name),
implicit: false,
});
let trait_bound = TraitBound { trait_path, trait_id: None, trait_generics };

if let Some(trait_bound) = self.resolve_trait_bound(&trait_bound) {
Expand Down Expand Up @@ -728,7 +732,9 @@ impl<'context> Elaborator<'context> {
// previous macro call being inserted into a generics list.
UnresolvedGeneric::Resolved(id, location) => {
match self.interner.get_quoted_type(*id).follow_bindings() {
Type::NamedGeneric(type_variable, name) => Ok((type_variable.clone(), name)),
Type::NamedGeneric(NamedGeneric { type_var, name, .. }) => {
Ok((type_var.clone(), name))
}
other => Err(ResolverError::MacroResultInGenericsListNotAGeneric {
location: *location,
typ: other.clone(),
Expand Down Expand Up @@ -886,7 +892,11 @@ impl<'context> Elaborator<'context> {
let location = bound.trait_path.location;
let name = format!("<{object} as {trait_name}>::{}", associated_type.name);
let name = Rc::new(name);
let typ = Type::NamedGeneric(type_var.clone(), name.clone());
let typ = Type::NamedGeneric(NamedGeneric {
type_var: type_var.clone(),
name: name.clone(),
implicit: true,
});
let typ = self.interner.push_quoted_type(typ);
let typ = UnresolvedTypeData::Resolved(typ).with_location(location);
let ident = Ident::new(associated_type.name.as_ref().clone(), location);
Expand Down Expand Up @@ -2242,7 +2252,7 @@ impl<'context> Elaborator<'context> {
idents.insert(ident.clone());
}
UnresolvedGeneric::Resolved(quoted_type_id, span) => {
if let Type::NamedGeneric(_type_variable, name) =
if let Type::NamedGeneric(NamedGeneric { name, .. }) =
self.interner.get_quoted_type(*quoted_type_id).follow_bindings()
{
idents.insert(Ident::new(name.to_string(), *span));
Expand Down
13 changes: 10 additions & 3 deletions compiler/noirc_frontend/src/elaborator/trait_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
ResolvedGeneric,
NamedGeneric, ResolvedGeneric,
ast::{Ident, UnresolvedType, UnresolvedTypeData, UnresolvedTypeExpression},
graph::CrateId,
hir::def_collector::{
Expand Down Expand Up @@ -161,7 +161,11 @@ impl Elaborator<'_> {
) in method.direct_generics.iter().zip(&override_meta.direct_generics)
{
let trait_fn_kind = trait_fn_generic.kind();
let arg = Type::NamedGeneric(impl_fn_generic.clone(), name.clone());
let arg = Type::NamedGeneric(NamedGeneric {
type_var: impl_fn_generic.clone(),
name: name.clone(),
implicit: false,
});
bindings.insert(
trait_fn_generic.id(),
(trait_fn_generic.clone(), trait_fn_kind.clone(), arg),
Expand Down Expand Up @@ -193,10 +197,13 @@ impl Elaborator<'_> {
continue;
}

let override_trait_generics =
override_trait_constraint.trait_bound.trait_generics.clone();

if !substituted_method_ids.contains(&(
override_trait_constraint.typ.clone(),
override_trait_constraint.trait_bound.trait_id,
override_trait_constraint.trait_bound.trait_generics.clone(),
override_trait_generics,
)) {
let the_trait =
self.interner.get_trait(override_trait_constraint.trait_bound.trait_id);
Expand Down
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/elaborator/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iter_extended::vecmap;
use noirc_errors::Location;

use crate::{
ResolvedGeneric, Type, TypeBindings,
NamedGeneric, ResolvedGeneric, Type, TypeBindings,
ast::{
BlockExpression, FunctionDefinition, FunctionKind, FunctionReturnType, Ident,
ItemVisibility, NoirFunction, TraitItem, UnresolvedGeneric, UnresolvedGenerics,
Expand Down Expand Up @@ -330,7 +330,11 @@ pub(crate) fn check_trait_impl_method_matches_declaration(
) in trait_fn_meta.direct_generics.iter().zip(&meta.direct_generics)
{
let trait_fn_kind = trait_fn_generic.kind();
let arg = Type::NamedGeneric(impl_fn_generic.clone(), name.clone());
let arg = Type::NamedGeneric(NamedGeneric {
type_var: impl_fn_generic.clone(),
name: name.clone(),
implicit: false,
});
bindings.insert(trait_fn_generic.id(), (trait_fn_generic.clone(), trait_fn_kind, arg));
}

Expand Down
11 changes: 6 additions & 5 deletions compiler/noirc_frontend/src/elaborator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use noirc_errors::Location;
use rustc_hash::FxHashMap as HashMap;

use crate::{
Generics, Kind, ResolvedGeneric, Type, TypeBinding, TypeBindings, UnificationError,
Generics, Kind, NamedGeneric, ResolvedGeneric, Type, TypeBinding, TypeBindings,
UnificationError,
ast::{
AsTraitPath, BinaryOpKind, GenericTypeArgs, Ident, IntegerBitSize, Path, PathKind, UnaryOp,
UnresolvedGeneric, UnresolvedGenerics, UnresolvedType, UnresolvedTypeData,
Expand Down Expand Up @@ -155,7 +156,7 @@ impl Elaborator<'_> {
let env = Box::new(self.resolve_type_with_kind_inner(*env, kind, mode));

match *env {
Type::Unit | Type::Tuple(_) | Type::NamedGeneric(_, _) => {
Type::Unit | Type::Tuple(_) | Type::NamedGeneric(_) => {
Type::Function(args, ret, env, unconstrained)
}
_ => {
Expand Down Expand Up @@ -498,7 +499,7 @@ impl Elaborator<'_> {
let name = path.last_name();
if let Some(generic) = self.find_generic(name) {
let generic = generic.clone();
return Some(Type::NamedGeneric(generic.type_var, generic.name));
return Some(generic.as_named_generic());
}
} else if let Some(typ) = self.lookup_associated_type_on_self(path) {
return Some(typ);
Expand Down Expand Up @@ -744,7 +745,7 @@ impl Elaborator<'_> {
}

for constraint in self.trait_bounds.clone() {
if let Type::NamedGeneric(_, name) = &constraint.typ {
if let Type::NamedGeneric(NamedGeneric { name, .. }) = &constraint.typ {
// if `path` is `T::method_name`, we're looking for constraint of the form `T: SomeTrait`
if path.segments[0].ident.as_str() != name.as_str() {
continue;
Expand Down Expand Up @@ -1515,7 +1516,7 @@ impl Elaborator<'_> {
});
None
}
Type::NamedGeneric(_, _) => self.lookup_method_in_trait_constraints(
Type::NamedGeneric(_) => self.lookup_method_in_trait_constraints(
object_type,
method_name,
location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use fm::FileId;
use iter_extended::vecmap;
use noirc_errors::{Located, Location, Span};

use crate::NamedGeneric;
use crate::ast::{
ArrayLiteral, AssignStatement, BlockExpression, CallExpression, CastExpression, ConstrainKind,
ConstructorExpression, ExpressionKind, ForLoopStatement, ForRange, GenericTypeArgs, Ident,
Expand Down Expand Up @@ -438,7 +439,7 @@ impl Type {
let name = Path::from_single(name.as_ref().clone(), Location::dummy());
UnresolvedTypeData::TraitAsType(name, generics)
}
Type::NamedGeneric(_var, name) => {
Type::NamedGeneric(NamedGeneric { name, .. }) => {
let name = Path::from_single(name.as_ref().clone(), Location::dummy());
UnresolvedTypeData::Named(name, GenericTypeArgs::default(), true)
}
Expand Down Expand Up @@ -479,7 +480,7 @@ impl Type {

match self.follow_bindings() {
Type::Constant(length, _kind) => UnresolvedTypeExpression::Constant(length, location),
Type::NamedGeneric(_var, name) => {
Type::NamedGeneric(NamedGeneric { name, .. }) => {
let path = Path::from_single(name.as_ref().clone(), location);
UnresolvedTypeExpression::Variable(path)
}
Expand Down
14 changes: 8 additions & 6 deletions compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use num_bigint::BigUint;
use rustc_hash::FxHashMap as HashMap;

use crate::{
Kind, QuotedType, ResolvedGeneric, Shared, Type, TypeVariable,
Kind, NamedGeneric, QuotedType, ResolvedGeneric, Shared, Type, TypeVariable,
ast::{
ArrayLiteral, BlockExpression, ConstrainKind, Expression, ExpressionKind, ForRange,
FunctionKind, FunctionReturnType, Ident, IntegerBitSize, ItemVisibility, LValue, Literal,
Expand Down Expand Up @@ -446,7 +446,11 @@ fn type_def_add_generic(

let type_var_kind = Kind::Normal;
let type_var = TypeVariable::unbound(interner.next_type_variable_id(), type_var_kind);
let typ = Type::NamedGeneric(type_var.clone(), name.clone());
let typ = Type::NamedGeneric(NamedGeneric {
type_var: type_var.clone(),
name: name.clone(),
implicit: false,
});
let new_generic = ResolvedGeneric { name, type_var, location: generic_location };
the_struct.generics.push(new_generic);

Expand All @@ -464,9 +468,7 @@ fn type_def_as_type(
let type_def_rc = interner.get_type(struct_id);
let type_def = type_def_rc.borrow();

let generics = vecmap(&type_def.generics, |generic| {
Type::NamedGeneric(generic.type_var.clone(), generic.name.clone())
});
let generics = vecmap(&type_def.generics, |generic| generic.clone().as_named_generic());

drop(type_def);
Ok(Value::Type(Type::DataType(type_def_rc, generics)))
Expand Down Expand Up @@ -1503,7 +1505,7 @@ fn zeroed(return_type: Type, location: Location) -> Value {
| Type::Quoted(_)
| Type::Error
| Type::TraitAsType(..)
| Type::NamedGeneric(_, _) => Value::Zeroed(return_type),
| Type::NamedGeneric(_) => Value::Zeroed(return_type),
}
}

Expand Down
Loading
Loading