aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/display.rs8
-rw-r--r--crates/hir_ty/src/lib.rs20
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs15
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs1
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs24
6 files changed, 32 insertions, 38 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index ee15f4f52..9b1e2ad05 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -11,9 +11,9 @@ use hir_def::{
11use hir_expand::name::Name; 11use hir_expand::name::Name;
12 12
13use crate::{ 13use crate::{
14 db::HirDatabase, primitive, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, 14 db::HirDatabase, from_foreign_def_id, primitive, utils::generics, AdtId, AliasTy,
15 GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, 15 CallableDefId, CallableSig, GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy,
16 Substs, TraitRef, Ty, TyKind, 16 OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind,
17}; 17};
18 18
19pub struct HirFormatter<'a> { 19pub struct HirFormatter<'a> {
@@ -491,7 +491,7 @@ impl HirDisplay for Ty {
491 } 491 }
492 } 492 }
493 TyKind::ForeignType(type_alias) => { 493 TyKind::ForeignType(type_alias) => {
494 let type_alias = f.db.type_alias_data(*type_alias); 494 let type_alias = f.db.type_alias_data(from_foreign_def_id(*type_alias));
495 write!(f, "{}", type_alias.name)?; 495 write!(f, "{}", type_alias.name)?;
496 } 496 }
497 TyKind::OpaqueType(opaque_ty_id, parameters) => { 497 TyKind::OpaqueType(opaque_ty_id, parameters) => {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 2309db492..94cbb21ca 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -51,6 +51,8 @@ pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariabl
51 51
52pub use crate::traits::chalk::Interner; 52pub use crate::traits::chalk::Interner;
53 53
54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
55
54#[derive(Clone, PartialEq, Eq, Debug, Hash)] 56#[derive(Clone, PartialEq, Eq, Debug, Hash)]
55pub enum Lifetime { 57pub enum Lifetime {
56 Parameter(LifetimeParamId), 58 Parameter(LifetimeParamId),
@@ -194,7 +196,7 @@ pub enum TyKind {
194 Closure(DefWithBodyId, ExprId, Substs), 196 Closure(DefWithBodyId, ExprId, Substs),
195 197
196 /// Represents a foreign type declared in external blocks. 198 /// Represents a foreign type declared in external blocks.
197 ForeignType(TypeAliasId), 199 ForeignType(ForeignDefId),
198 200
199 /// A pointer to a function. Written as `fn() -> i32`. 201 /// A pointer to a function. Written as `fn() -> i32`.
200 /// 202 ///
@@ -705,7 +707,7 @@ impl Ty {
705 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), 707 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
706 TyKind::FnDef(callable, ..) => Some(callable.into()), 708 TyKind::FnDef(callable, ..) => Some(callable.into()),
707 TyKind::AssociatedType(type_alias, ..) => Some(type_alias.into()), 709 TyKind::AssociatedType(type_alias, ..) => Some(type_alias.into()),
708 TyKind::ForeignType(type_alias, ..) => Some(type_alias.into()), 710 TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
709 _ => None, 711 _ => None,
710 } 712 }
711 } 713 }
@@ -724,8 +726,10 @@ impl Ty {
724 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true, 726 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true,
725 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, 727 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
726 (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2, 728 (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
727 (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) 729 (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
728 | (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2, 730 ty_id == ty_id2
731 }
732 (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2,
729 (TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => { 733 (TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => {
730 expr == expr2 && def == def2 734 expr == expr2 && def == def2
731 } 735 }
@@ -1116,3 +1120,11 @@ pub struct ReturnTypeImplTraits {
1116pub(crate) struct ReturnTypeImplTrait { 1120pub(crate) struct ReturnTypeImplTrait {
1117 pub(crate) bounds: Binders<Vec<GenericPredicate>>, 1121 pub(crate) bounds: Binders<Vec<GenericPredicate>>,
1118} 1122}
1123
1124pub(crate) fn to_foreign_def_id(id: TypeAliasId) -> chalk_ir::ForeignDefId<Interner> {
1125 chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
1126}
1127
1128pub(crate) fn from_foreign_def_id(id: chalk_ir::ForeignDefId<Interner>) -> TypeAliasId {
1129 salsa::InternKey::from_intern_id(id.0)
1130}
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 9fe7e3dce..a35d7266d 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1143,7 +1143,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
1143 let ctx = 1143 let ctx =
1144 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); 1144 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
1145 if db.type_alias_data(t).is_extern { 1145 if db.type_alias_data(t).is_extern {
1146 Binders::new(0, TyKind::ForeignType(t).intern(&Interner)) 1146 Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner))
1147 } else { 1147 } else {
1148 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1148 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1149 let type_ref = &db.type_alias_data(t).type_ref; 1149 let type_ref = &db.type_alias_data(t).type_ref;
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index f9877e760..c7055bee5 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -9,7 +9,7 @@ use base_db::CrateId;
9use chalk_ir::Mutability; 9use chalk_ir::Mutability;
10use hir_def::{ 10use hir_def::{
11 lang_item::LangItemTarget, AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule, 11 lang_item::LangItemTarget, AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule,
12 ImplId, Lookup, ModuleId, TraitId, TypeAliasId, 12 ImplId, Lookup, ModuleId, TraitId,
13}; 13};
14use hir_expand::name::Name; 14use hir_expand::name::Name;
15use rustc_hash::{FxHashMap, FxHashSet}; 15use rustc_hash::{FxHashMap, FxHashSet};
@@ -17,10 +17,11 @@ use rustc_hash::{FxHashMap, FxHashSet};
17use crate::{ 17use crate::{
18 autoderef, 18 autoderef,
19 db::HirDatabase, 19 db::HirDatabase,
20 from_foreign_def_id,
20 primitive::{self, FloatTy, IntTy, UintTy}, 21 primitive::{self, FloatTy, IntTy, UintTy},
21 utils::all_super_traits, 22 utils::all_super_traits,
22 AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, InEnvironment, Interner, Scalar, Substs, 23 AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, ForeignDefId, InEnvironment, Interner,
23 TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, 24 Scalar, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk,
24}; 25};
25 26
26/// This is used as a key for indexing impls. 27/// This is used as a key for indexing impls.
@@ -35,7 +36,7 @@ pub enum TyFingerprint {
35 Adt(hir_def::AdtId), 36 Adt(hir_def::AdtId),
36 Dyn(TraitId), 37 Dyn(TraitId),
37 Tuple(usize), 38 Tuple(usize),
38 ForeignType(TypeAliasId), 39 ForeignType(ForeignDefId),
39 FnPtr(usize, FnSig), 40 FnPtr(usize, FnSig),
40} 41}
41 42
@@ -236,8 +237,10 @@ impl Ty {
236 TyKind::Adt(AdtId(def_id), _) => { 237 TyKind::Adt(AdtId(def_id), _) => {
237 return mod_to_crate_ids(def_id.module(db.upcast())); 238 return mod_to_crate_ids(def_id.module(db.upcast()));
238 } 239 }
239 TyKind::ForeignType(type_alias_id) => { 240 TyKind::ForeignType(id) => {
240 return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast())); 241 return mod_to_crate_ids(
242 from_foreign_def_id(*id).lookup(db.upcast()).module(db.upcast()),
243 );
241 } 244 }
242 TyKind::Scalar(Scalar::Bool) => lang_item_crate!("bool"), 245 TyKind::Scalar(Scalar::Bool) => lang_item_crate!("bool"),
243 TyKind::Scalar(Scalar::Char) => lang_item_crate!("char"), 246 TyKind::Scalar(Scalar::Char) => lang_item_crate!("char"),
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index 54bd1c724..e891efb7b 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -12,7 +12,6 @@ pub struct Interner;
12 12
13pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; 13pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
14pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; 14pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
15pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
16pub(crate) type TraitId = chalk_ir::TraitId<Interner>; 15pub(crate) type TraitId = chalk_ir::TraitId<Interner>;
17pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; 16pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
18pub(crate) type AdtId = chalk_ir::AdtId<Interner>; 17pub(crate) type AdtId = chalk_ir::AdtId<Interner>;
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 44cfb9359..cf490f9c5 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -51,11 +51,7 @@ impl ToChalk for Ty {
51 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) 51 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
52 } 52 }
53 53
54 TyKind::ForeignType(type_alias) => { 54 TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner),
55 let foreign_type = TypeAliasAsForeignType(type_alias);
56 let foreign_type_id = foreign_type.to_chalk(db);
57 chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner)
58 }
59 55
60 TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), 56 TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner),
61 57
@@ -217,9 +213,7 @@ impl ToChalk for Ty {
217 TyKind::Closure(def, expr, from_chalk(db, subst)) 213 TyKind::Closure(def, expr, from_chalk(db, subst))
218 } 214 }
219 215
220 chalk_ir::TyKind::Foreign(foreign_def_id) => { 216 chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id),
221 TyKind::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
222 }
223 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME 217 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
224 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME 218 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
225 } 219 }
@@ -352,20 +346,6 @@ impl ToChalk for TypeAliasAsAssocType {
352 } 346 }
353} 347}
354 348
355pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId);
356
357impl ToChalk for TypeAliasAsForeignType {
358 type Chalk = ForeignDefId;
359
360 fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId {
361 chalk_ir::ForeignDefId(self.0.as_intern_id())
362 }
363
364 fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType {
365 TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0))
366 }
367}
368
369pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); 349pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
370 350
371impl ToChalk for TypeAliasAsValue { 351impl ToChalk for TypeAliasAsValue {