aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs113
1 files changed, 34 insertions, 79 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 874c95411..0505fa4ae 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -7,21 +7,23 @@ macro_rules! eprintln {
7} 7}
8 8
9mod autoderef; 9mod autoderef;
10pub mod primitive;
11pub mod traits;
12pub mod method_resolution;
13mod op;
14mod lower;
15pub(crate) mod infer;
16pub(crate) mod utils;
17mod chalk_cast;
18mod chalk_ext;
19mod builder; 10mod builder;
11mod chalk_db;
12mod chalk_ext;
13mod infer;
14mod interner;
15mod lower;
16mod mapping;
17mod op;
18mod tls;
19mod utils;
20mod walk; 20mod walk;
21
22pub mod display;
23pub mod db; 21pub mod db;
24pub mod diagnostics; 22pub mod diagnostics;
23pub mod display;
24pub mod method_resolution;
25pub mod primitive;
26pub mod traits;
25 27
26#[cfg(test)] 28#[cfg(test)]
27mod tests; 29mod tests;
@@ -30,16 +32,12 @@ mod test_db;
30 32
31use std::sync::Arc; 33use std::sync::Arc;
32 34
33use base_db::salsa;
34use chalk_ir::{ 35use chalk_ir::{
35 fold::{Fold, Shift}, 36 fold::{Fold, Shift},
36 interner::HasInterner, 37 interner::HasInterner,
37 UintTy, 38 UintTy,
38}; 39};
39use hir_def::{ 40use hir_def::{expr::ExprId, type_ref::Rawness, TypeParamId};
40 expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
41 TypeParamId,
42};
43 41
44use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; 42use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
45 43
@@ -47,11 +45,18 @@ pub use autoderef::autoderef;
47pub use builder::TyBuilder; 45pub use builder::TyBuilder;
48pub use chalk_ext::*; 46pub use chalk_ext::*;
49pub use infer::{could_unify, InferenceResult}; 47pub use infer::{could_unify, InferenceResult};
48pub use interner::Interner;
50pub use lower::{ 49pub use lower::{
51 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, 50 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
52 TyDefId, TyLoweringContext, ValueTyDefId, 51 TyDefId, TyLoweringContext, ValueTyDefId,
53}; 52};
54pub use traits::{chalk::Interner, TraitEnvironment}; 53pub use mapping::{
54 const_from_placeholder_idx, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
55 from_placeholder_idx, lt_from_placeholder_idx, to_assoc_type_id, to_chalk_trait_id,
56 to_foreign_def_id, to_placeholder_idx,
57};
58pub use traits::TraitEnvironment;
59pub use utils::all_super_traits;
55pub use walk::TypeWalk; 60pub use walk::TypeWalk;
56 61
57pub use chalk_ir::{ 62pub use chalk_ir::{
@@ -94,6 +99,10 @@ pub type ConstValue = chalk_ir::ConstValue<Interner>;
94pub type ConcreteConst = chalk_ir::ConcreteConst<Interner>; 99pub type ConcreteConst = chalk_ir::ConcreteConst<Interner>;
95 100
96pub type ChalkTraitId = chalk_ir::TraitId<Interner>; 101pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
102pub type TraitRef = chalk_ir::TraitRef<Interner>;
103pub type QuantifiedWhereClause = Binders<WhereClause>;
104pub type QuantifiedWhereClauses = chalk_ir::QuantifiedWhereClauses<Interner>;
105pub type Canonical<T> = chalk_ir::Canonical<T>;
97 106
98pub type FnSig = chalk_ir::FnSig<Interner>; 107pub type FnSig = chalk_ir::FnSig<Interner>;
99 108
@@ -109,7 +118,7 @@ pub type WhereClause = chalk_ir::WhereClause<Interner>;
109pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution { 118pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution {
110 Substitution::from_iter( 119 Substitution::from_iter(
111 &Interner, 120 &Interner,
112 s.interned()[..std::cmp::min(s.len(&Interner), n)].iter().cloned(), 121 s.as_slice(&Interner)[..std::cmp::min(s.len(&Interner), n)].iter().cloned(),
113 ) 122 )
114} 123}
115 124
@@ -118,14 +127,14 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
118 generics(db.upcast(), id.parent).param_idx(id) 127 generics(db.upcast(), id.parent).param_idx(id)
119} 128}
120 129
121pub fn wrap_empty_binders<T>(value: T) -> Binders<T> 130pub(crate) fn wrap_empty_binders<T>(value: T) -> Binders<T>
122where 131where
123 T: Fold<Interner, Result = T> + HasInterner<Interner = Interner>, 132 T: Fold<Interner, Result = T> + HasInterner<Interner = Interner>,
124{ 133{
125 Binders::empty(&Interner, value.shifted_in_from(&Interner, DebruijnIndex::ONE)) 134 Binders::empty(&Interner, value.shifted_in_from(&Interner, DebruijnIndex::ONE))
126} 135}
127 136
128pub fn make_only_type_binders<T: HasInterner<Interner = Interner>>( 137pub(crate) fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
129 num_vars: usize, 138 num_vars: usize,
130 value: T, 139 value: T,
131) -> Binders<T> { 140) -> Binders<T> {
@@ -153,14 +162,6 @@ pub fn make_canonical<T: HasInterner<Interner = Interner>>(
153 Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) } 162 Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
154} 163}
155 164
156pub type TraitRef = chalk_ir::TraitRef<Interner>;
157
158pub type QuantifiedWhereClause = Binders<WhereClause>;
159
160pub type QuantifiedWhereClauses = chalk_ir::QuantifiedWhereClauses<Interner>;
161
162pub type Canonical<T> = chalk_ir::Canonical<T>;
163
164/// A function signature as seen by type inference: Several parameter types and 165/// A function signature as seen by type inference: Several parameter types and
165/// one return type. 166/// one return type.
166#[derive(Clone, PartialEq, Eq, Debug)] 167#[derive(Clone, PartialEq, Eq, Debug)]
@@ -169,6 +170,8 @@ pub struct CallableSig {
169 is_varargs: bool, 170 is_varargs: bool,
170} 171}
171 172
173has_interner!(CallableSig);
174
172/// A polymorphic function signature. 175/// A polymorphic function signature.
173pub type PolyFnSig = Binders<CallableSig>; 176pub type PolyFnSig = Binders<CallableSig>;
174 177
@@ -187,7 +190,7 @@ impl CallableSig {
187 .shifted_out_to(&Interner, DebruijnIndex::ONE) 190 .shifted_out_to(&Interner, DebruijnIndex::ONE)
188 .expect("unexpected lifetime vars in fn ptr") 191 .expect("unexpected lifetime vars in fn ptr")
189 .0 192 .0
190 .interned() 193 .as_slice(&Interner)
191 .iter() 194 .iter()
192 .map(|arg| arg.assert_ty_ref(&Interner).clone()) 195 .map(|arg| arg.assert_ty_ref(&Interner).clone())
193 .collect(), 196 .collect(),
@@ -232,61 +235,13 @@ pub struct ReturnTypeImplTraits {
232 pub(crate) impl_traits: Vec<ReturnTypeImplTrait>, 235 pub(crate) impl_traits: Vec<ReturnTypeImplTrait>,
233} 236}
234 237
238has_interner!(ReturnTypeImplTraits);
239
235#[derive(Clone, PartialEq, Eq, Debug, Hash)] 240#[derive(Clone, PartialEq, Eq, Debug, Hash)]
236pub(crate) struct ReturnTypeImplTrait { 241pub(crate) struct ReturnTypeImplTrait {
237 pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>, 242 pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>,
238} 243}
239 244
240pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId {
241 chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
242}
243
244pub fn from_foreign_def_id(id: ForeignDefId) -> TypeAliasId {
245 salsa::InternKey::from_intern_id(id.0)
246}
247
248pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId {
249 chalk_ir::AssocTypeId(salsa::InternKey::as_intern_id(&id))
250}
251
252pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId {
253 salsa::InternKey::from_intern_id(id.0)
254}
255
256pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId {
257 assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
258 let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
259 db.lookup_intern_type_param_id(interned_id)
260}
261
262pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex {
263 let interned_id = db.intern_type_param_id(id);
264 PlaceholderIndex {
265 ui: chalk_ir::UniverseIndex::ROOT,
266 idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(),
267 }
268}
269
270pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId {
271 assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
272 let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
273 db.lookup_intern_lifetime_param_id(interned_id)
274}
275
276pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId {
277 assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
278 let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
279 db.lookup_intern_const_param_id(interned_id)
280}
281
282pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
283 chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
284}
285
286pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
287 salsa::InternKey::from_intern_id(id.0)
288}
289
290pub fn static_lifetime() -> Lifetime { 245pub fn static_lifetime() -> Lifetime {
291 LifetimeData::Static.intern(&Interner) 246 LifetimeData::Static.intern(&Interner)
292} 247}