aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-13 16:55:50 +0000
committerFlorian Diebold <[email protected]>2021-03-13 16:56:48 +0000
commit9719ce9fc731a400c9744ba1a6569e978c1a97e7 (patch)
treea9c674c83723e2ed145793f72450c873da62a6fc /crates/hir_ty
parent19664e276aba21a42cad5351a2c91995d1ce5d52 (diff)
Use chalk_ir::FnDefId
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/db.rs6
-rw-r--r--crates/hir_ty/src/diagnostics/unsafe_check.rs2
-rw-r--r--crates/hir_ty/src/display.rs9
-rw-r--r--crates/hir_ty/src/infer/expr.rs7
-rw-r--r--crates/hir_ty/src/lib.rs24
-rw-r--r--crates/hir_ty/src/lower.rs15
-rw-r--r--crates/hir_ty/src/traits/chalk.rs4
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs1
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs5
9 files changed, 47 insertions, 26 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index 06714409f..a038674cf 100644
--- a/crates/hir_ty/src/db.rs
+++ b/crates/hir_ty/src/db.rs
@@ -12,7 +12,7 @@ use la_arena::ArenaMap;
12use crate::{ 12use crate::{
13 method_resolution::{InherentImpls, TraitImpls}, 13 method_resolution::{InherentImpls, TraitImpls},
14 traits::chalk, 14 traits::chalk,
15 Binders, CallableDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, 15 Binders, CallableDefId, FnDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig,
16 ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, 16 ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
17}; 17};
18use hir_expand::name::Name; 18use hir_expand::name::Name;
@@ -100,10 +100,10 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
100 fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>; 100 fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>;
101 101
102 #[salsa::invoke(crate::traits::chalk::fn_def_datum_query)] 102 #[salsa::invoke(crate::traits::chalk::fn_def_datum_query)]
103 fn fn_def_datum(&self, krate: CrateId, fn_def_id: chalk::FnDefId) -> Arc<chalk::FnDefDatum>; 103 fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk::FnDefDatum>;
104 104
105 #[salsa::invoke(crate::traits::chalk::fn_def_variance_query)] 105 #[salsa::invoke(crate::traits::chalk::fn_def_variance_query)]
106 fn fn_def_variance(&self, krate: CrateId, fn_def_id: chalk::FnDefId) -> chalk::Variances; 106 fn fn_def_variance(&self, krate: CrateId, fn_def_id: FnDefId) -> chalk::Variances;
107 107
108 #[salsa::invoke(crate::traits::chalk::adt_variance_query)] 108 #[salsa::invoke(crate::traits::chalk::adt_variance_query)]
109 fn adt_variance(&self, krate: CrateId, adt_id: chalk::AdtId) -> chalk::Variances; 109 fn adt_variance(&self, krate: CrateId, adt_id: chalk::AdtId) -> chalk::Variances;
diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs
index e095bee28..20bb64827 100644
--- a/crates/hir_ty/src/diagnostics/unsafe_check.rs
+++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs
@@ -85,7 +85,7 @@ fn walk_unsafe(
85 let expr = &body.exprs[current]; 85 let expr = &body.exprs[current];
86 match expr { 86 match expr {
87 &Expr::Call { callee, .. } => { 87 &Expr::Call { callee, .. } => {
88 if let Some(func) = infer[callee].as_fn_def() { 88 if let Some(func) = infer[callee].as_fn_def(db) {
89 if db.function_data(func).is_unsafe { 89 if db.function_data(func).is_unsafe {
90 unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); 90 unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
91 } 91 }
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 2022069d8..b7e85e024 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -12,8 +12,9 @@ use hir_expand::name::Name;
12 12
13use crate::{ 13use crate::{
14 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id, 14 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id,
15 utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, GenericPredicate, Interner, 15 traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig,
16 Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, 16 GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar,
17 Substs, TraitRef, Ty, TyKind,
17}; 18};
18 19
19pub struct HirFormatter<'a> { 20pub struct HirFormatter<'a> {
@@ -363,7 +364,7 @@ impl HirDisplay for Ty {
363 sig.hir_fmt(f)?; 364 sig.hir_fmt(f)?;
364 } 365 }
365 TyKind::FnDef(def, parameters) => { 366 TyKind::FnDef(def, parameters) => {
366 let def = *def; 367 let def = from_chalk(f.db, *def);
367 let sig = f.db.callable_item_signature(def).subst(parameters); 368 let sig = f.db.callable_item_signature(def).subst(parameters);
368 match def { 369 match def {
369 CallableDefId::FunctionId(ff) => { 370 CallableDefId::FunctionId(ff) => {
@@ -431,7 +432,7 @@ impl HirDisplay for Ty {
431 || f.omit_verbose_types() 432 || f.omit_verbose_types()
432 { 433 {
433 match self 434 match self
434 .as_generic_def() 435 .as_generic_def(f.db)
435 .map(|generic_def_id| f.db.generic_defaults(generic_def_id)) 436 .map(|generic_def_id| f.db.generic_defaults(generic_def_id))
436 .filter(|defaults| !defaults.is_empty()) 437 .filter(|defaults| !defaults.is_empty())
437 { 438 {
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index a72424dc7..153f22f25 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -19,7 +19,7 @@ use crate::{
19 method_resolution, op, 19 method_resolution, op,
20 primitive::{self, UintTy}, 20 primitive::{self, UintTy},
21 to_assoc_type_id, 21 to_assoc_type_id,
22 traits::{FnTrait, InEnvironment}, 22 traits::{chalk::from_chalk, FnTrait, InEnvironment},
23 utils::{generics, variant_data, Generics}, 23 utils::{generics, variant_data, Generics},
24 AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, OpaqueTyId, Rawness, 24 AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, OpaqueTyId, Rawness,
25 Scalar, Substs, TraitRef, Ty, TyKind, 25 Scalar, Substs, TraitRef, Ty, TyKind,
@@ -932,8 +932,9 @@ impl<'a> InferenceContext<'a> {
932 } 932 }
933 933
934 fn register_obligations_for_call(&mut self, callable_ty: &Ty) { 934 fn register_obligations_for_call(&mut self, callable_ty: &Ty) {
935 if let TyKind::FnDef(def, parameters) = callable_ty.interned(&Interner) { 935 if let TyKind::FnDef(fn_def, parameters) = callable_ty.interned(&Interner) {
936 let generic_predicates = self.db.generic_predicates((*def).into()); 936 let def: CallableDefId = from_chalk(self.db, *fn_def);
937 let generic_predicates = self.db.generic_predicates(def.into());
937 for predicate in generic_predicates.iter() { 938 for predicate in generic_predicates.iter() {
938 let predicate = predicate.clone().subst(parameters); 939 let predicate = predicate.clone().subst(parameters);
939 if let Some(obligation) = Obligation::from_predicate(predicate) { 940 if let Some(obligation) = Obligation::from_predicate(predicate) {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 5752ddc4e..6b3485264 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -53,6 +53,7 @@ pub use crate::traits::chalk::Interner;
53 53
54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; 54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
55pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; 55pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
56pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>;
56 57
57#[derive(Clone, PartialEq, Eq, Debug, Hash)] 58#[derive(Clone, PartialEq, Eq, Debug, Hash)]
58pub enum Lifetime { 59pub enum Lifetime {
@@ -182,7 +183,7 @@ pub enum TyKind {
182 /// fn foo() -> i32 { 1 } 183 /// fn foo() -> i32 { 1 }
183 /// let bar = foo; // bar: fn() -> i32 {foo} 184 /// let bar = foo; // bar: fn() -> i32 {foo}
184 /// ``` 185 /// ```
185 FnDef(CallableDefId, Substs), 186 FnDef(FnDefId, Substs),
186 187
187 /// The pointee of a string slice. Written as `str`. 188 /// The pointee of a string slice. Written as `str`.
188 Str, 189 Str,
@@ -703,10 +704,12 @@ impl Ty {
703 } 704 }
704 } 705 }
705 706
706 pub fn as_generic_def(&self) -> Option<GenericDefId> { 707 pub fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
707 match *self.interned(&Interner) { 708 match *self.interned(&Interner) {
708 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), 709 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
709 TyKind::FnDef(callable, ..) => Some(callable.into()), 710 TyKind::FnDef(callable, ..) => {
711 Some(db.lookup_intern_callable_def(callable.into()).into())
712 }
710 TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()), 713 TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()),
711 TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()), 714 TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
712 _ => None, 715 _ => None,
@@ -775,18 +778,27 @@ impl Ty {
775 } 778 }
776 } 779 }
777 780
778 pub fn as_fn_def(&self) -> Option<FunctionId> { 781 pub fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
779 match self.interned(&Interner) { 782 match self.interned(&Interner) {
780 &TyKind::FnDef(CallableDefId::FunctionId(func), ..) => Some(func), 783 &TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())),
781 _ => None, 784 _ => None,
782 } 785 }
783 } 786 }
784 787
788 pub fn as_fn_def(&self, db: &dyn HirDatabase) -> Option<FunctionId> {
789 if let Some(CallableDefId::FunctionId(func)) = self.callable_def(db) {
790 Some(func)
791 } else {
792 None
793 }
794 }
795
785 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> { 796 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> {
786 match self.interned(&Interner) { 797 match self.interned(&Interner) {
787 TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)), 798 TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)),
788 TyKind::FnDef(def, parameters) => { 799 TyKind::FnDef(def, parameters) => {
789 let sig = db.callable_item_signature(*def); 800 let callable_def = db.lookup_intern_callable_def((*def).into());
801 let sig = db.callable_item_signature(callable_def);
790 Some(sig.subst(&parameters)) 802 Some(sig.subst(&parameters))
791 } 803 }
792 TyKind::Closure(.., substs) => { 804 TyKind::Closure(.., substs) => {
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index a5ab1ff70..b8b1400eb 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1064,7 +1064,10 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
1064fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { 1064fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
1065 let generics = generics(db.upcast(), def.into()); 1065 let generics = generics(db.upcast(), def.into());
1066 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1066 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1067 Binders::new(substs.len(), TyKind::FnDef(def.into(), substs).intern(&Interner)) 1067 Binders::new(
1068 substs.len(),
1069 TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner),
1070 )
1068} 1071}
1069 1072
1070/// Build the declared type of a const. 1073/// Build the declared type of a const.
@@ -1107,7 +1110,10 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders<T
1107 } 1110 }
1108 let generics = generics(db.upcast(), def.into()); 1111 let generics = generics(db.upcast(), def.into());
1109 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1112 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1110 Binders::new(substs.len(), TyKind::FnDef(def.into(), substs).intern(&Interner)) 1113 Binders::new(
1114 substs.len(),
1115 TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner),
1116 )
1111} 1117}
1112 1118
1113fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig { 1119fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig {
@@ -1132,7 +1138,10 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
1132 } 1138 }
1133 let generics = generics(db.upcast(), def.parent.into()); 1139 let generics = generics(db.upcast(), def.parent.into());
1134 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1140 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1135 Binders::new(substs.len(), TyKind::FnDef(def.into(), substs).intern(&Interner)) 1141 Binders::new(
1142 substs.len(),
1143 TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner),
1144 )
1136} 1145}
1137 1146
1138fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { 1147fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 2d3cd6719..bb92d8e2a 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -21,8 +21,8 @@ use crate::{
21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, 21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
22 to_assoc_type_id, 22 to_assoc_type_id,
23 utils::generics, 23 utils::generics,
24 BoundVar, CallableDefId, CallableSig, DebruijnIndex, GenericPredicate, ProjectionPredicate, 24 BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, GenericPredicate,
25 ProjectionTy, Substs, TraitRef, Ty, TyKind, 25 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TyKind,
26}; 26};
27use mapping::{ 27use mapping::{
28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, 28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index e891efb7b..1dc3f497d 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -20,7 +20,6 @@ pub(crate) type ImplId = chalk_ir::ImplId<Interner>;
20pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; 20pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>;
21pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; 21pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>;
22pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; 22pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>;
23pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>;
24pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; 23pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
25pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; 24pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
26pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; 25pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 67ac95a0e..23ef07d77 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -66,8 +66,7 @@ impl ToChalk for Ty {
66 chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) 66 chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner)
67 } 67 }
68 TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner), 68 TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner),
69 TyKind::FnDef(callable_def, substs) => { 69 TyKind::FnDef(id, substs) => {
70 let id = callable_def.to_chalk(db);
71 let substitution = substs.to_chalk(db); 70 let substitution = substs.to_chalk(db);
72 chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) 71 chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner)
73 } 72 }
@@ -201,7 +200,7 @@ impl ToChalk for Ty {
201 chalk_ir::TyKind::Never => TyKind::Never, 200 chalk_ir::TyKind::Never => TyKind::Never,
202 201
203 chalk_ir::TyKind::FnDef(fn_def_id, subst) => { 202 chalk_ir::TyKind::FnDef(fn_def_id, subst) => {
204 TyKind::FnDef(from_chalk(db, fn_def_id), from_chalk(db, subst)) 203 TyKind::FnDef(fn_def_id, from_chalk(db, subst))
205 } 204 }
206 205
207 chalk_ir::TyKind::Closure(id, subst) => { 206 chalk_ir::TyKind::Closure(id, subst) => {