aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/chalk_db.rs32
-rw-r--r--crates/hir_ty/src/db.rs16
-rw-r--r--crates/hir_ty/src/display.rs10
-rw-r--r--crates/hir_ty/src/infer/expr.rs2
-rw-r--r--crates/hir_ty/src/interner.rs17
-rw-r--r--crates/hir_ty/src/lib.rs2
-rw-r--r--crates/hir_ty/src/lower.rs8
-rw-r--r--crates/hir_ty/src/mapping.rs20
-rw-r--r--crates/hir_ty/src/tls.rs4
-rw-r--r--crates/hir_ty/src/traits.rs2
10 files changed, 76 insertions, 37 deletions
diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs
index 566e4f406..f5b2c5ff0 100644
--- a/crates/hir_ty/src/chalk_db.rs
+++ b/crates/hir_ty/src/chalk_db.rs
@@ -1,4 +1,5 @@
1//! Conversion code from/to Chalk. 1//! The implementation of `RustIrDatabase` for Chalk, which provides information
2//! about the code that Chalk needs.
2use std::sync::Arc; 3use std::sync::Arc;
3 4
4use log::debug; 5use log::debug;
@@ -13,7 +14,21 @@ use hir_def::{
13}; 14};
14use hir_expand::name::name; 15use hir_expand::name::name;
15 16
16use crate::{AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, Interner, ProjectionTy, Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause, traits::ChalkContext, db::HirDatabase, display::HirDisplay, from_assoc_type_id, make_only_type_binders, mapping::{convert_where_clauses, generic_predicate_to_inline_bound, TypeAliasAsValue}, method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, to_assoc_type_id, to_chalk_trait_id, utils::generics}; 17use crate::{
18 db::HirDatabase,
19 display::HirDisplay,
20 from_assoc_type_id, make_only_type_binders,
21 mapping::{
22 convert_where_clauses, from_chalk, generic_predicate_to_inline_bound, ToChalk,
23 TypeAliasAsValue,
24 },
25 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
26 to_assoc_type_id, to_chalk_trait_id,
27 traits::ChalkContext,
28 utils::generics,
29 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, Interner, ProjectionTy,
30 Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
31};
17 32
18pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; 33pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
19pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; 34pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
@@ -31,19 +46,6 @@ pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Inte
31pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; 46pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
32pub(crate) type Variances = chalk_ir::Variances<Interner>; 47pub(crate) type Variances = chalk_ir::Variances<Interner>;
33 48
34pub(crate) trait ToChalk {
35 type Chalk;
36 fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk;
37 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self;
38}
39
40pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T
41where
42 T: ToChalk<Chalk = ChalkT>,
43{
44 T::from_chalk(db, chalk)
45}
46
47impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { 49impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
48 fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> { 50 fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> {
49 self.db.associated_ty_data(id) 51 self.db.associated_ty_data(id)
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index ea0580df1..e11fc579e 100644
--- a/crates/hir_ty/src/db.rs
+++ b/crates/hir_ty/src/db.rs
@@ -9,7 +9,12 @@ use hir_def::{
9}; 9};
10use la_arena::ArenaMap; 10use la_arena::ArenaMap;
11 11
12use crate::{Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db, method_resolution::{InherentImpls, TraitImpls}}; 12use crate::{
13 chalk_db,
14 method_resolution::{InherentImpls, TraitImpls},
15 Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig,
16 QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
17};
13use hir_expand::name::Name; 18use hir_expand::name::Name;
14 19
15#[salsa::query_group(HirDatabaseStorage)] 20#[salsa::query_group(HirDatabaseStorage)]
@@ -93,10 +98,15 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
93 fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>; 98 fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
94 99
95 #[salsa::invoke(chalk_db::trait_datum_query)] 100 #[salsa::invoke(chalk_db::trait_datum_query)]
96 fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId) -> Arc<chalk_db::TraitDatum>; 101 fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId)
102 -> Arc<chalk_db::TraitDatum>;
97 103
98 #[salsa::invoke(chalk_db::struct_datum_query)] 104 #[salsa::invoke(chalk_db::struct_datum_query)]
99 fn struct_datum(&self, krate: CrateId, struct_id: chalk_db::AdtId) -> Arc<chalk_db::StructDatum>; 105 fn struct_datum(
106 &self,
107 krate: CrateId,
108 struct_id: chalk_db::AdtId,
109 ) -> Arc<chalk_db::StructDatum>;
100 110
101 #[salsa::invoke(chalk_db::impl_datum_query)] 111 #[salsa::invoke(chalk_db::impl_datum_query)]
102 fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>; 112 fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>;
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index a0746cd8f..ae3a82780 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -20,11 +20,11 @@ use hir_expand::name::Name;
20 20
21use crate::{ 21use crate::{
22 const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id, 22 const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
23 from_placeholder_idx, lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id, 23 from_placeholder_idx, lt_from_placeholder_idx, mapping::from_chalk, primitive, subst_prefix,
24 chalk_db::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, 24 to_assoc_type_id, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, Const,
25 CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, 25 ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData,
26 LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, 26 LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause,
27 QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause, 27 Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
28}; 28};
29 29
30pub struct HirFormatter<'a> { 30pub struct HirFormatter<'a> {
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index d42383012..50497eecb 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -17,11 +17,11 @@ use syntax::ast::RangeOp;
17use crate::{ 17use crate::{
18 autoderef, dummy_usize_const, 18 autoderef, dummy_usize_const,
19 lower::lower_to_chalk_mutability, 19 lower::lower_to_chalk_mutability,
20 mapping::from_chalk,
20 method_resolution, op, 21 method_resolution, op,
21 primitive::{self, UintTy}, 22 primitive::{self, UintTy},
22 static_lifetime, to_chalk_trait_id, 23 static_lifetime, to_chalk_trait_id,
23 traits::FnTrait, 24 traits::FnTrait,
24 chalk_db::from_chalk,
25 utils::{generics, Generics}, 25 utils::{generics, Generics},
26 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, 26 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
27 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind, 27 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,
diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs
index 0187767ce..02e26c04e 100644
--- a/crates/hir_ty/src/interner.rs
+++ b/crates/hir_ty/src/interner.rs
@@ -1,7 +1,7 @@
1//! Implementation of the Chalk `Interner` trait, which allows customizing the 1//! Implementation of the Chalk `Interner` trait, which allows customizing the
2//! representation of the various objects Chalk deals with (types, goals etc.). 2//! representation of the various objects Chalk deals with (types, goals etc.).
3 3
4use crate::{GenericArg, tls, chalk_db}; 4use crate::{chalk_db, tls, GenericArg};
5use base_db::salsa::InternId; 5use base_db::salsa::InternId;
6use chalk_ir::{Goal, GoalData}; 6use chalk_ir::{Goal, GoalData};
7use hir_def::{ 7use hir_def::{
@@ -60,15 +60,24 @@ impl chalk_ir::interner::Interner for Interner {
60 type Identifier = TypeAliasId; 60 type Identifier = TypeAliasId;
61 type FnAbi = (); 61 type FnAbi = ();
62 62
63 fn debug_adt_id(type_kind_id: chalk_db::AdtId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 63 fn debug_adt_id(
64 type_kind_id: chalk_db::AdtId,
65 fmt: &mut fmt::Formatter<'_>,
66 ) -> Option<fmt::Result> {
64 tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) 67 tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
65 } 68 }
66 69
67 fn debug_trait_id(type_kind_id: chalk_db::TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 70 fn debug_trait_id(
71 type_kind_id: chalk_db::TraitId,
72 fmt: &mut fmt::Formatter<'_>,
73 ) -> Option<fmt::Result> {
68 tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt))) 74 tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
69 } 75 }
70 76
71 fn debug_assoc_type_id(id: chalk_db::AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 77 fn debug_assoc_type_id(
78 id: chalk_db::AssocTypeId,
79 fmt: &mut fmt::Formatter<'_>,
80 ) -> Option<fmt::Result> {
72 tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt))) 81 tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
73 } 82 }
74 83
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 0743d3d30..434e2e533 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -51,13 +51,13 @@ pub use autoderef::autoderef;
51pub use builder::TyBuilder; 51pub use builder::TyBuilder;
52pub use chalk_ext::*; 52pub use chalk_ext::*;
53pub use infer::{could_unify, InferenceResult}; 53pub use infer::{could_unify, InferenceResult};
54pub use interner::Interner;
54pub use lower::{ 55pub use lower::{
55 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, 56 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
56 TyDefId, TyLoweringContext, ValueTyDefId, 57 TyDefId, TyLoweringContext, ValueTyDefId,
57}; 58};
58pub use traits::TraitEnvironment; 59pub use traits::TraitEnvironment;
59pub use walk::TypeWalk; 60pub use walk::TypeWalk;
60pub use interner::Interner;
61 61
62pub use chalk_ir::{ 62pub use chalk_ir::{
63 cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind, 63 cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 0cdded3e1..a035686bc 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -27,14 +27,14 @@ use stdx::impl_from;
27 27
28use crate::{ 28use crate::{
29 db::HirDatabase, 29 db::HirDatabase,
30 dummy_usize_const, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, 30 dummy_usize_const,
31 chalk_db::ToChalk, 31 mapping::ToChalk,
32 Interner, 32 static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
33 utils::{ 33 utils::{
34 all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics, 34 all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics,
35 }, 35 },
36 AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, 36 AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig,
37 FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, 37 FnSubst, ImplTraitId, Interner, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
38 QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, 38 QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution,
39 TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause, 39 TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause,
40}; 40};
diff --git a/crates/hir_ty/src/mapping.rs b/crates/hir_ty/src/mapping.rs
index 4d3c41b2c..f57115de6 100644
--- a/crates/hir_ty/src/mapping.rs
+++ b/crates/hir_ty/src/mapping.rs
@@ -3,13 +3,29 @@
3//! Chalk (in both directions); plus some helper functions for more specialized 3//! Chalk (in both directions); plus some helper functions for more specialized
4//! conversions. 4//! conversions.
5 5
6use chalk_ir::{DebruijnIndex, cast::Cast, fold::Shift}; 6use chalk_ir::{cast::Cast, fold::Shift, DebruijnIndex};
7use chalk_solve::rust_ir; 7use chalk_solve::rust_ir;
8 8
9use base_db::salsa::InternKey; 9use base_db::salsa::InternKey;
10use hir_def::{GenericDefId, TypeAliasId}; 10use hir_def::{GenericDefId, TypeAliasId};
11 11
12use crate::{AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt, QuantifiedWhereClause, Substitution, Ty, WhereClause, chalk_db::{self, ToChalk}, db::HirDatabase}; 12use crate::{
13 chalk_db, db::HirDatabase, AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt,
14 QuantifiedWhereClause, Substitution, Ty, WhereClause,
15};
16
17pub(crate) trait ToChalk {
18 type Chalk;
19 fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk;
20 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self;
21}
22
23pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T
24where
25 T: ToChalk<Chalk = ChalkT>,
26{
27 T::from_chalk(db, chalk)
28}
13 29
14impl ToChalk for hir_def::TraitId { 30impl ToChalk for hir_def::TraitId {
15 type Chalk = chalk_db::TraitId; 31 type Chalk = chalk_db::TraitId;
diff --git a/crates/hir_ty/src/tls.rs b/crates/hir_ty/src/tls.rs
index c319bcf70..92989f11f 100644
--- a/crates/hir_ty/src/tls.rs
+++ b/crates/hir_ty/src/tls.rs
@@ -4,7 +4,9 @@ use std::fmt;
4use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; 4use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication};
5use itertools::Itertools; 5use itertools::Itertools;
6 6
7use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId, chalk_db::{from_chalk, self}, Interner}; 7use crate::{
8 chalk_db, db::HirDatabase, from_assoc_type_id, mapping::from_chalk, CallableDefId, Interner,
9};
8use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; 10use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
9 11
10pub(crate) use unsafe_tls::{set_current_program, with_current_program}; 12pub(crate) use unsafe_tls::{set_current_program, with_current_program};
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index 5f8666d90..7f77e421d 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -9,7 +9,7 @@ use stdx::panic_context;
9 9
10use crate::{ 10use crate::{
11 db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment, 11 db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment,
12 Solution, TraitRefExt, Ty, TyKind, WhereClause, Interner, 12 Interner, Solution, TraitRefExt, Ty, TyKind, WhereClause,
13}; 13};
14 14
15/// This controls how much 'time' we give the Chalk solver before giving up. 15/// This controls how much 'time' we give the Chalk solver before giving up.