Skip to content

Commit

Permalink
feat(traits): multi module support for traits (#2844)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Vitkov <alexvitkov98@gmail.com>
Co-authored-by: Yordan Madzhunkov <ymadzhunkov@gmail.com>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent 7a9983a commit 4deb07f
Show file tree
Hide file tree
Showing 59 changed files with 638 additions and 313 deletions.
11 changes: 5 additions & 6 deletions compiler/noirc_frontend/src/ast/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use noirc_errors::Span;

use crate::{
node_interner::TraitId, BlockExpression, Expression, FunctionReturnType, Ident, NoirFunction,
UnresolvedGenerics, UnresolvedType,
Path, UnresolvedGenerics, UnresolvedType,
};

/// AST node for trait definitions:
Expand Down Expand Up @@ -57,11 +57,10 @@ pub struct TypeImpl {
pub struct NoirTraitImpl {
pub impl_generics: UnresolvedGenerics,

pub trait_name: Ident,
pub trait_name: Path,
pub trait_generics: Vec<UnresolvedType>,

pub object_type: UnresolvedType,
pub object_type_span: Span,

pub where_clause: Vec<UnresolvedTraitConstraint>,

Expand All @@ -83,7 +82,7 @@ pub struct UnresolvedTraitConstraint {
/// Represents a single trait bound, such as `TraitX` or `TraitY<U, V>`
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TraitBound {
pub trait_name: Ident,
pub trait_path: Path,
pub trait_id: Option<TraitId>, // initially None, gets assigned during DC
pub trait_generics: Vec<UnresolvedType>,
}
Expand Down Expand Up @@ -178,9 +177,9 @@ impl Display for TraitBound {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let generics = vecmap(&self.trait_generics, |generic| generic.to_string());
if !generics.is_empty() {
write!(f, "{}<{}>", self.trait_name, generics.join(", "))
write!(f, "{}<{}>", self.trait_path, generics.join(", "))
} else {
write!(f, "{}", self.trait_name)
write!(f, "{}", self.trait_path)
}
}
}
Expand Down
Loading

0 comments on commit 4deb07f

Please sign in to comment.