Skip to content

Commit

Permalink
Remove check_type
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 29, 2024
1 parent 9fbdfec commit e011f24
Showing 1 changed file with 3 additions and 80 deletions.
83 changes: 3 additions & 80 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl<'interner> Monomorphizer<'interner> {
// Not all generic arguments may be used in a struct's fields so we have to check
// the arguments as well as the fields in case any need to be defaulted or are unbound.
for arg in args {
Self::check_type(arg, location)?;
Self::convert_type(arg, location)?;
}

let fields = def.borrow().get_fields(args);
Expand All @@ -992,7 +992,7 @@ impl<'interner> Monomorphizer<'interner> {
// Similar to the struct case above: generics of an alias might not end up being
// used in the type that is aliased.
for arg in args {
Self::check_type(arg, location)?;
Self::convert_type(arg, location)?;
}

Self::convert_type(&def.borrow().get_type(args), location)?
Expand Down Expand Up @@ -1033,83 +1033,6 @@ impl<'interner> Monomorphizer<'interner> {
})
}

// Similar to `convert_type` but returns an error if any type variable can't be defaulted.
fn check_type(typ: &HirType, location: Location) -> Result<(), MonomorphizationError> {
match typ {
HirType::FieldElement
| HirType::Integer(..)
| HirType::Bool
| HirType::String(..)
| HirType::Unit
| HirType::TraitAsType(..)
| HirType::Forall(_, _)
| HirType::Constant(_)
| HirType::Error
| HirType::Quoted(_) => Ok(()),
HirType::FmtString(_size, fields) => Self::check_type(fields.as_ref(), location),
HirType::Array(_length, element) => Self::check_type(element.as_ref(), location),
HirType::Slice(element) => Self::check_type(element.as_ref(), location),
HirType::NamedGeneric(binding, _, _) => {
if let TypeBinding::Bound(binding) = &*binding.borrow() {
return Self::check_type(binding, location);
}

Ok(())
}

HirType::TypeVariable(binding, kind) => {
if let TypeBinding::Bound(binding) = &*binding.borrow() {
return Self::check_type(binding, location);
}

// Default any remaining unbound type variables.
// This should only happen if the variable in question is unused
// and within a larger generic type.
let default = match kind.default_type() {
Some(typ) => typ,
None => return Err(MonomorphizationError::TypeAnnotationsNeeded { location }),
};

Self::check_type(&default, location)
}

HirType::Struct(_def, args) => {
for arg in args {
Self::check_type(arg, location)?;
}

Ok(())
}

HirType::Alias(_def, args) => {
for arg in args {
Self::check_type(arg, location)?;
}

Ok(())
}

HirType::Tuple(fields) => {
for field in fields {
Self::check_type(field, location)?;
}

Ok(())
}

HirType::Function(args, ret, env) => {
for arg in args {
Self::check_type(arg, location)?;
}

Self::check_type(ret, location)?;
Self::check_type(env, location)
}

HirType::MutableReference(element) => Self::check_type(element, location),
}
}

fn is_function_closure(&self, t: ast::Type) -> bool {
if self.is_function_closure_type(&t) {
true
Expand Down Expand Up @@ -1852,7 +1775,7 @@ fn unwrap_struct_type(
HirType::Struct(def, args) => {
// Some of args might not be mentioned in fields, so we need to check that they aren't unbound.
for arg in &args {
Monomorphizer::check_type(arg, location)?;
Monomorphizer::convert_type(arg, location)?;
}

Ok(def.borrow().get_fields(&args))
Expand Down

0 comments on commit e011f24

Please sign in to comment.