Skip to content

Commit

Permalink
frontend: Add Assoc type
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Oct 13, 2024
1 parent 4bad5ca commit 82d4e0f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dora-frontend/src/aliasck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn expand_type(
| SourceType::This
| SourceType::TypeParam(..) => ty,

SourceType::Any | SourceType::Ptr => {
SourceType::Assoc(..) | SourceType::Any | SourceType::Ptr => {
panic!("unexpected type = {:?}", ty);
}
}
Expand Down
5 changes: 3 additions & 2 deletions dora-frontend/src/extensiondefck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub fn package_for_type(sa: &Sema, ty: SourceType) -> Option<PackageDefinitionId
SourceType::Enum(id, ..) => Some(sa.enum_(id).package_id),
SourceType::TraitObject(id, ..) => Some(sa.trait_(id).package_id),
SourceType::Alias(id, ..) => Some(sa.alias(id).package_id),
SourceType::Assoc(..) => unimplemented!(),
}
}

Expand All @@ -100,7 +101,7 @@ impl<'x> ExtensionCheck<'x> {
);
}
SourceType::Alias(..) => unimplemented!(),
SourceType::Any | SourceType::Ptr | SourceType::This => {
SourceType::Any | SourceType::Ptr | SourceType::This | SourceType::Assoc(..) => {
unreachable!()
}
SourceType::Error
Expand Down Expand Up @@ -237,7 +238,7 @@ fn discover_type_params(sa: &Sema, ty: SourceType, used_type_params: &mut FixedB
SourceType::TypeParam(tp_id) => {
used_type_params.insert(tp_id.index());
}
SourceType::Alias(..) => unreachable!(),
SourceType::Alias(..) | SourceType::Assoc(..) => unreachable!(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions dora-frontend/src/impldefck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn check_definition(sa: &Sema) {
fn check_impl_definition(sa: &Sema, impl_: &ImplDefinition) {
match impl_.extended_ty() {
SourceType::Alias(..) => unimplemented!(),
SourceType::Any | SourceType::Ptr | SourceType::This => {
SourceType::Any | SourceType::Ptr | SourceType::This | SourceType::Assoc(..) => {
unreachable!()
}
SourceType::Error
Expand Down Expand Up @@ -326,7 +326,7 @@ fn trait_and_impl_arg_ty_compatible(
| SourceType::Float64
| SourceType::Error => trait_arg_ty == impl_arg_ty,

SourceType::Any | SourceType::Ptr => unreachable!(),
SourceType::Any | SourceType::Ptr | SourceType::Assoc(..) => unreachable!(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions dora-frontend/src/parsety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ fn check_type_inner(
parsed_ty: &ParsedTypeAst,
) -> SourceType {
match ty.clone() {
SourceType::Any | SourceType::Ptr => {
SourceType::Any | SourceType::Ptr | SourceType::Assoc(..) => {
unreachable!()
}
SourceType::This => SourceType::This,
Expand Down Expand Up @@ -1172,7 +1172,7 @@ fn expand_st(
| SourceType::TypeParam(..) => ty,
SourceType::This => replace_self.expect("self expected"),

SourceType::Any | SourceType::Ptr => {
SourceType::Any | SourceType::Ptr | SourceType::Assoc(..) => {
panic!("unexpected type = {:?}", ty);
// unreachable!()
}
Expand Down
2 changes: 1 addition & 1 deletion dora-frontend/src/sema/impl_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn implements_trait(

SourceType::TypeParam(tp_id) => check_type_param_defs.implements_trait(tp_id, trait_ty),

SourceType::Alias(..) => unreachable!(),
SourceType::Alias(..) | SourceType::Assoc(..) => unreachable!(),

SourceType::Error => false,

Expand Down
2 changes: 1 addition & 1 deletion dora-frontend/src/sema/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn match_concrete_types(
_ => false,
},

SourceType::Alias(..) => {
SourceType::Alias(..) | SourceType::Assoc(..) => {
unimplemented!()
}

Expand Down
6 changes: 3 additions & 3 deletions dora-frontend/src/specialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn replace_type(
| SourceType::Float64
| SourceType::Error => ty,

SourceType::Any | SourceType::Ptr => unreachable!(),
SourceType::Any | SourceType::Ptr | SourceType::Assoc(..) => unreachable!(),
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn specialize_for_element(
| SourceType::Float64
| SourceType::Error => ty,

SourceType::Any | SourceType::Ptr => unreachable!(),
SourceType::Any | SourceType::Ptr | SourceType::Assoc(..) => unreachable!(),
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ pub fn specialize_for_trait_object(sa: &Sema, ty: SourceType, trait_ty: SourceTy
| SourceType::Float64
| SourceType::Error => ty,

SourceType::Any | SourceType::Ptr => unreachable!(),
SourceType::Any | SourceType::Ptr | SourceType::Assoc(..) => unreachable!(),
}
}

Expand Down
12 changes: 9 additions & 3 deletions dora-frontend/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub enum TyKind {
TraitObject,
TypeParam,
Alias,
Assoc,
Lambda,
Enum,
}
Expand Down Expand Up @@ -147,6 +148,7 @@ pub enum SourceType {

// Type alias.
Alias(AliasDefinitionId, SourceTypeArray),
Assoc(AliasDefinitionId, SourceTypeArray),

// some lambda
Lambda(SourceTypeArray, Box<SourceType>),
Expand Down Expand Up @@ -177,6 +179,7 @@ impl SourceType {
SourceType::Enum(..) => TyKind::Enum,
SourceType::Class(..) => TyKind::Class,
SourceType::Unit | SourceType::Tuple(..) => TyKind::Tuple,
SourceType::Assoc(..) => TyKind::Assoc,
}
}

Expand Down Expand Up @@ -538,6 +541,8 @@ impl SourceType {
// sub class for return type
*self == other
}

SourceType::Assoc(..) => unimplemented!(),
}
}

Expand All @@ -555,7 +560,7 @@ impl SourceType {
| SourceType::TraitObject(..)
| SourceType::Lambda(..)
| SourceType::TypeParam(_) => true,
SourceType::Alias(..) => unreachable!(),
SourceType::Alias(..) | SourceType::Assoc(..) => unreachable!(),
SourceType::Enum(_, params)
| SourceType::Class(_, params)
| SourceType::Struct(_, params) => {
Expand Down Expand Up @@ -637,7 +642,7 @@ impl SourceType {

return_type.is_concrete_type()
}
SourceType::TypeParam(_) => false,
SourceType::TypeParam(_) | SourceType::Assoc(..) => false,
}
}
}
Expand All @@ -656,7 +661,7 @@ pub fn contains_self(sa: &Sema, ty: SourceType) -> bool {
| SourceType::Float32
| SourceType::Float64
| SourceType::TypeParam(..) => false,
SourceType::Alias(..) => unimplemented!(),
SourceType::Alias(..) | SourceType::Assoc(..) => unimplemented!(),
SourceType::Class(_, params)
| SourceType::Enum(_, params)
| SourceType::Struct(_, params) => {
Expand Down Expand Up @@ -1023,6 +1028,7 @@ impl<'a> SourceTypePrinter<'a> {
format!("{}[{}]", name, params)
}
}
SourceType::Assoc(..) => unimplemented!(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions dora-frontend/src/typeck/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ fn arg_allows(sa: &Sema, def: SourceType, arg: SourceType, self_ty: Option<Sourc
let alias = sa.alias(id);
arg_allows(sa, alias.ty(), arg, self_ty.clone())
}

SourceType::Assoc(..) => unimplemented!(),
}
}

Expand Down

0 comments on commit 82d4e0f

Please sign in to comment.