diff options
author | Florian Diebold <[email protected]> | 2021-04-09 13:11:37 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-09 13:11:37 +0100 |
commit | 743faa21e74cc5b627935e2c4c3365807a5c722f (patch) | |
tree | 28504dbaaa7238c5d7d64d2371dc3b672cb21e16 /crates/hir_ty | |
parent | 99ed68a109c9f7e0dc6a82ccb5bf854d60943957 (diff) |
Reorganize hir_ty modules
Chalk isn't really a 'traits' thing anymore, so it doesn't make sense to
have all the Chalk-related stuff in submodules of `traits`.
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/chalk_db.rs (renamed from crates/hir_ty/src/traits/chalk.rs) | 36 | ||||
-rw-r--r-- | crates/hir_ty/src/db.rs | 47 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/interner.rs (renamed from crates/hir_ty/src/traits/chalk/interner.rs) | 24 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/mapping.rs (renamed from crates/hir_ty/src/traits/chalk/mapping.rs) | 28 | ||||
-rw-r--r-- | crates/hir_ty/src/tls.rs (renamed from crates/hir_ty/src/traits/chalk/tls.rs) | 9 | ||||
-rw-r--r-- | crates/hir_ty/src/traits.rs | 14 |
10 files changed, 73 insertions, 100 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/chalk_db.rs index cd511477b..566e4f406 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/chalk_db.rs | |||
@@ -13,25 +13,23 @@ use hir_def::{ | |||
13 | }; | 13 | }; |
14 | use hir_expand::name::name; | 14 | use hir_expand::name::name; |
15 | 15 | ||
16 | use super::ChalkContext; | 16 | use 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}; |
17 | use crate::{ | 17 | |
18 | db::HirDatabase, | 18 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; |
19 | display::HirDisplay, | 19 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; |
20 | from_assoc_type_id, make_only_type_binders, | 20 | pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>; |
21 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, | 21 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; |
22 | to_assoc_type_id, to_chalk_trait_id, | 22 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; |
23 | utils::generics, | 23 | |
24 | AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, | 24 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
25 | TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause, | 25 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; |
26 | }; | 26 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; |
27 | use mapping::{convert_where_clauses, generic_predicate_to_inline_bound, TypeAliasAsValue}; | 27 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; |
28 | 28 | pub(crate) type ImplId = chalk_ir::ImplId<Interner>; | |
29 | pub use self::interner::Interner; | 29 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; |
30 | pub(crate) use self::interner::*; | 30 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; |
31 | 31 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; | |
32 | pub(super) mod tls; | 32 | pub(crate) type Variances = chalk_ir::Variances<Interner>; |
33 | mod interner; | ||
34 | mod mapping; | ||
35 | 33 | ||
36 | pub(crate) trait ToChalk { | 34 | pub(crate) trait ToChalk { |
37 | type Chalk; | 35 | type Chalk; |
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index 326c20240..ea0580df1 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs | |||
@@ -9,12 +9,7 @@ use hir_def::{ | |||
9 | }; | 9 | }; |
10 | use la_arena::ArenaMap; | 10 | use la_arena::ArenaMap; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db, method_resolution::{InherentImpls, TraitImpls}}; |
13 | method_resolution::{InherentImpls, TraitImpls}, | ||
14 | traits::chalk, | ||
15 | Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig, | ||
16 | QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, | ||
17 | }; | ||
18 | use hir_expand::name::Name; | 13 | use hir_expand::name::Name; |
19 | 14 | ||
20 | #[salsa::query_group(HirDatabaseStorage)] | 15 | #[salsa::query_group(HirDatabaseStorage)] |
@@ -94,33 +89,33 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
94 | #[salsa::interned] | 89 | #[salsa::interned] |
95 | fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; | 90 | fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; |
96 | 91 | ||
97 | #[salsa::invoke(chalk::associated_ty_data_query)] | 92 | #[salsa::invoke(chalk_db::associated_ty_data_query)] |
98 | fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>; | 93 | fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>; |
99 | 94 | ||
100 | #[salsa::invoke(chalk::trait_datum_query)] | 95 | #[salsa::invoke(chalk_db::trait_datum_query)] |
101 | fn trait_datum(&self, krate: CrateId, trait_id: chalk::TraitId) -> Arc<chalk::TraitDatum>; | 96 | fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId) -> Arc<chalk_db::TraitDatum>; |
102 | 97 | ||
103 | #[salsa::invoke(chalk::struct_datum_query)] | 98 | #[salsa::invoke(chalk_db::struct_datum_query)] |
104 | fn struct_datum(&self, krate: CrateId, struct_id: chalk::AdtId) -> Arc<chalk::StructDatum>; | 99 | fn struct_datum(&self, krate: CrateId, struct_id: chalk_db::AdtId) -> Arc<chalk_db::StructDatum>; |
105 | 100 | ||
106 | #[salsa::invoke(crate::traits::chalk::impl_datum_query)] | 101 | #[salsa::invoke(chalk_db::impl_datum_query)] |
107 | fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>; | 102 | fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>; |
108 | 103 | ||
109 | #[salsa::invoke(crate::traits::chalk::fn_def_datum_query)] | 104 | #[salsa::invoke(chalk_db::fn_def_datum_query)] |
110 | fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk::FnDefDatum>; | 105 | fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk_db::FnDefDatum>; |
111 | 106 | ||
112 | #[salsa::invoke(crate::traits::chalk::fn_def_variance_query)] | 107 | #[salsa::invoke(chalk_db::fn_def_variance_query)] |
113 | fn fn_def_variance(&self, krate: CrateId, fn_def_id: FnDefId) -> chalk::Variances; | 108 | fn fn_def_variance(&self, krate: CrateId, fn_def_id: FnDefId) -> chalk_db::Variances; |
114 | 109 | ||
115 | #[salsa::invoke(crate::traits::chalk::adt_variance_query)] | 110 | #[salsa::invoke(chalk_db::adt_variance_query)] |
116 | fn adt_variance(&self, krate: CrateId, adt_id: chalk::AdtId) -> chalk::Variances; | 111 | fn adt_variance(&self, krate: CrateId, adt_id: chalk_db::AdtId) -> chalk_db::Variances; |
117 | 112 | ||
118 | #[salsa::invoke(crate::traits::chalk::associated_ty_value_query)] | 113 | #[salsa::invoke(chalk_db::associated_ty_value_query)] |
119 | fn associated_ty_value( | 114 | fn associated_ty_value( |
120 | &self, | 115 | &self, |
121 | krate: CrateId, | 116 | krate: CrateId, |
122 | id: chalk::AssociatedTyValueId, | 117 | id: chalk_db::AssociatedTyValueId, |
123 | ) -> Arc<chalk::AssociatedTyValue>; | 118 | ) -> Arc<chalk_db::AssociatedTyValue>; |
124 | 119 | ||
125 | #[salsa::invoke(crate::traits::trait_solve_query)] | 120 | #[salsa::invoke(crate::traits::trait_solve_query)] |
126 | fn trait_solve( | 121 | fn trait_solve( |
@@ -129,12 +124,12 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
129 | goal: crate::Canonical<crate::InEnvironment<crate::DomainGoal>>, | 124 | goal: crate::Canonical<crate::InEnvironment<crate::DomainGoal>>, |
130 | ) -> Option<crate::Solution>; | 125 | ) -> Option<crate::Solution>; |
131 | 126 | ||
132 | #[salsa::invoke(crate::traits::chalk::program_clauses_for_chalk_env_query)] | 127 | #[salsa::invoke(chalk_db::program_clauses_for_chalk_env_query)] |
133 | fn program_clauses_for_chalk_env( | 128 | fn program_clauses_for_chalk_env( |
134 | &self, | 129 | &self, |
135 | krate: CrateId, | 130 | krate: CrateId, |
136 | env: chalk_ir::Environment<chalk::Interner>, | 131 | env: chalk_ir::Environment<Interner>, |
137 | ) -> chalk_ir::ProgramClauses<chalk::Interner>; | 132 | ) -> chalk_ir::ProgramClauses<Interner>; |
138 | } | 133 | } |
139 | 134 | ||
140 | fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { | 135 | fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 92224b46b..a0746cd8f 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -21,7 +21,7 @@ use hir_expand::name::Name; | |||
21 | use crate::{ | 21 | use 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, primitive, subst_prefix, to_assoc_type_id, |
24 | traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, | 24 | chalk_db::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, |
25 | CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, | 25 | CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, |
26 | LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, | 26 | LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, |
27 | QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause, | 27 | QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause, |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 7961f4a52..d42383012 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -20,7 +20,8 @@ use crate::{ | |||
20 | method_resolution, op, | 20 | method_resolution, op, |
21 | primitive::{self, UintTy}, | 21 | primitive::{self, UintTy}, |
22 | static_lifetime, to_chalk_trait_id, | 22 | static_lifetime, to_chalk_trait_id, |
23 | traits::{chalk::from_chalk, FnTrait}, | 23 | traits::FnTrait, |
24 | chalk_db::from_chalk, | ||
24 | utils::{generics, Generics}, | 25 | utils::{generics, Generics}, |
25 | AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, | 26 | AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, |
26 | 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/traits/chalk/interner.rs b/crates/hir_ty/src/interner.rs index b6a3cec6d..0187767ce 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/interner.rs | |||
@@ -1,8 +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 | ||
4 | use super::tls; | 4 | use crate::{GenericArg, tls, chalk_db}; |
5 | use crate::GenericArg; | ||
6 | use base_db::salsa::InternId; | 5 | use base_db::salsa::InternId; |
7 | use chalk_ir::{Goal, GoalData}; | 6 | use chalk_ir::{Goal, GoalData}; |
8 | use hir_def::{ | 7 | use hir_def::{ |
@@ -15,21 +14,6 @@ use std::{fmt, sync::Arc}; | |||
15 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] | 14 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] |
16 | pub struct Interner; | 15 | pub struct Interner; |
17 | 16 | ||
18 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | ||
19 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; | ||
20 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; | ||
21 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; | ||
22 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; | ||
23 | pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>; | ||
24 | pub(crate) type ImplId = chalk_ir::ImplId<Interner>; | ||
25 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; | ||
26 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; | ||
27 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; | ||
28 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; | ||
29 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | ||
30 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; | ||
31 | pub(crate) type Variances = chalk_ir::Variances<Interner>; | ||
32 | |||
33 | #[derive(PartialEq, Eq, Hash, Debug)] | 17 | #[derive(PartialEq, Eq, Hash, Debug)] |
34 | pub struct InternedWrapper<T>(T); | 18 | pub struct InternedWrapper<T>(T); |
35 | 19 | ||
@@ -76,15 +60,15 @@ impl chalk_ir::interner::Interner for Interner { | |||
76 | type Identifier = TypeAliasId; | 60 | type Identifier = TypeAliasId; |
77 | type FnAbi = (); | 61 | type FnAbi = (); |
78 | 62 | ||
79 | fn debug_adt_id(type_kind_id: AdtId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { | 63 | fn debug_adt_id(type_kind_id: chalk_db::AdtId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { |
80 | tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) | 64 | tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) |
81 | } | 65 | } |
82 | 66 | ||
83 | fn debug_trait_id(type_kind_id: TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { | 67 | fn debug_trait_id(type_kind_id: chalk_db::TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { |
84 | tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt))) | 68 | tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt))) |
85 | } | 69 | } |
86 | 70 | ||
87 | fn debug_assoc_type_id(id: AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { | 71 | fn debug_assoc_type_id(id: chalk_db::AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { |
88 | tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt))) | 72 | tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt))) |
89 | } | 73 | } |
90 | 74 | ||
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index beb58d711..0743d3d30 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -18,6 +18,10 @@ mod chalk_cast; | |||
18 | mod chalk_ext; | 18 | mod chalk_ext; |
19 | mod builder; | 19 | mod builder; |
20 | mod walk; | 20 | mod walk; |
21 | mod tls; | ||
22 | mod interner; | ||
23 | mod mapping; | ||
24 | mod chalk_db; | ||
21 | 25 | ||
22 | pub mod display; | 26 | pub mod display; |
23 | pub mod db; | 27 | pub mod db; |
@@ -51,8 +55,9 @@ pub use lower::{ | |||
51 | associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, | 55 | associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, |
52 | TyDefId, TyLoweringContext, ValueTyDefId, | 56 | TyDefId, TyLoweringContext, ValueTyDefId, |
53 | }; | 57 | }; |
54 | pub use traits::{chalk::Interner, TraitEnvironment}; | 58 | pub use traits::TraitEnvironment; |
55 | pub use walk::TypeWalk; | 59 | pub use walk::TypeWalk; |
60 | pub use interner::Interner; | ||
56 | 61 | ||
57 | pub use chalk_ir::{ | 62 | pub use chalk_ir::{ |
58 | 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 8a22d9ea3..0cdded3e1 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -28,7 +28,8 @@ use stdx::impl_from; | |||
28 | use crate::{ | 28 | use 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, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, |
31 | traits::chalk::{Interner, ToChalk}, | 31 | chalk_db::ToChalk, |
32 | Interner, | ||
32 | utils::{ | 33 | utils::{ |
33 | 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, |
34 | }, | 35 | }, |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/mapping.rs index e78581ea5..4d3c41b2c 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/mapping.rs | |||
@@ -3,40 +3,34 @@ | |||
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 | ||
6 | use chalk_ir::cast::Cast; | 6 | use chalk_ir::{DebruijnIndex, cast::Cast, fold::Shift}; |
7 | use chalk_solve::rust_ir; | 7 | use chalk_solve::rust_ir; |
8 | 8 | ||
9 | use base_db::salsa::InternKey; | 9 | use base_db::salsa::InternKey; |
10 | use hir_def::{GenericDefId, TypeAliasId}; | 10 | use hir_def::{GenericDefId, TypeAliasId}; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt, QuantifiedWhereClause, Substitution, Ty, WhereClause, chalk_db::{self, ToChalk}, db::HirDatabase}; |
13 | db::HirDatabase, AliasTy, CallableDefId, ProjectionTyExt, QuantifiedWhereClause, Substitution, | ||
14 | Ty, WhereClause, | ||
15 | }; | ||
16 | |||
17 | use super::interner::*; | ||
18 | use super::*; | ||
19 | 13 | ||
20 | impl ToChalk for hir_def::TraitId { | 14 | impl ToChalk for hir_def::TraitId { |
21 | type Chalk = TraitId; | 15 | type Chalk = chalk_db::TraitId; |
22 | 16 | ||
23 | fn to_chalk(self, _db: &dyn HirDatabase) -> TraitId { | 17 | fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::TraitId { |
24 | chalk_ir::TraitId(self.as_intern_id()) | 18 | chalk_ir::TraitId(self.as_intern_id()) |
25 | } | 19 | } |
26 | 20 | ||
27 | fn from_chalk(_db: &dyn HirDatabase, trait_id: TraitId) -> hir_def::TraitId { | 21 | fn from_chalk(_db: &dyn HirDatabase, trait_id: chalk_db::TraitId) -> hir_def::TraitId { |
28 | InternKey::from_intern_id(trait_id.0) | 22 | InternKey::from_intern_id(trait_id.0) |
29 | } | 23 | } |
30 | } | 24 | } |
31 | 25 | ||
32 | impl ToChalk for hir_def::ImplId { | 26 | impl ToChalk for hir_def::ImplId { |
33 | type Chalk = ImplId; | 27 | type Chalk = chalk_db::ImplId; |
34 | 28 | ||
35 | fn to_chalk(self, _db: &dyn HirDatabase) -> ImplId { | 29 | fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::ImplId { |
36 | chalk_ir::ImplId(self.as_intern_id()) | 30 | chalk_ir::ImplId(self.as_intern_id()) |
37 | } | 31 | } |
38 | 32 | ||
39 | fn from_chalk(_db: &dyn HirDatabase, impl_id: ImplId) -> hir_def::ImplId { | 33 | fn from_chalk(_db: &dyn HirDatabase, impl_id: chalk_db::ImplId) -> hir_def::ImplId { |
40 | InternKey::from_intern_id(impl_id.0) | 34 | InternKey::from_intern_id(impl_id.0) |
41 | } | 35 | } |
42 | } | 36 | } |
@@ -56,15 +50,15 @@ impl ToChalk for CallableDefId { | |||
56 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); | 50 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); |
57 | 51 | ||
58 | impl ToChalk for TypeAliasAsValue { | 52 | impl ToChalk for TypeAliasAsValue { |
59 | type Chalk = AssociatedTyValueId; | 53 | type Chalk = chalk_db::AssociatedTyValueId; |
60 | 54 | ||
61 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssociatedTyValueId { | 55 | fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::AssociatedTyValueId { |
62 | rust_ir::AssociatedTyValueId(self.0.as_intern_id()) | 56 | rust_ir::AssociatedTyValueId(self.0.as_intern_id()) |
63 | } | 57 | } |
64 | 58 | ||
65 | fn from_chalk( | 59 | fn from_chalk( |
66 | _db: &dyn HirDatabase, | 60 | _db: &dyn HirDatabase, |
67 | assoc_ty_value_id: AssociatedTyValueId, | 61 | assoc_ty_value_id: chalk_db::AssociatedTyValueId, |
68 | ) -> TypeAliasAsValue { | 62 | ) -> TypeAliasAsValue { |
69 | TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0)) | 63 | TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0)) |
70 | } | 64 | } |
diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/tls.rs index 8892a63a9..c319bcf70 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/tls.rs | |||
@@ -4,8 +4,7 @@ use std::fmt; | |||
4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; | 4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use super::{from_chalk, Interner}; | 7 | use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId, chalk_db::{from_chalk, self}, Interner}; |
8 | use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId}; | ||
9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; | 8 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; |
10 | 9 | ||
11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; | 10 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; |
@@ -15,7 +14,7 @@ pub(crate) struct DebugContext<'a>(&'a dyn HirDatabase); | |||
15 | impl DebugContext<'_> { | 14 | impl DebugContext<'_> { |
16 | pub(crate) fn debug_struct_id( | 15 | pub(crate) fn debug_struct_id( |
17 | &self, | 16 | &self, |
18 | id: super::AdtId, | 17 | id: chalk_db::AdtId, |
19 | f: &mut fmt::Formatter<'_>, | 18 | f: &mut fmt::Formatter<'_>, |
20 | ) -> Result<(), fmt::Error> { | 19 | ) -> Result<(), fmt::Error> { |
21 | let name = match id.0 { | 20 | let name = match id.0 { |
@@ -28,7 +27,7 @@ impl DebugContext<'_> { | |||
28 | 27 | ||
29 | pub(crate) fn debug_trait_id( | 28 | pub(crate) fn debug_trait_id( |
30 | &self, | 29 | &self, |
31 | id: super::TraitId, | 30 | id: chalk_db::TraitId, |
32 | fmt: &mut fmt::Formatter<'_>, | 31 | fmt: &mut fmt::Formatter<'_>, |
33 | ) -> Result<(), fmt::Error> { | 32 | ) -> Result<(), fmt::Error> { |
34 | let trait_: hir_def::TraitId = from_chalk(self.0, id); | 33 | let trait_: hir_def::TraitId = from_chalk(self.0, id); |
@@ -38,7 +37,7 @@ impl DebugContext<'_> { | |||
38 | 37 | ||
39 | pub(crate) fn debug_assoc_type_id( | 38 | pub(crate) fn debug_assoc_type_id( |
40 | &self, | 39 | &self, |
41 | id: super::AssocTypeId, | 40 | id: chalk_db::AssocTypeId, |
42 | fmt: &mut fmt::Formatter<'_>, | 41 | fmt: &mut fmt::Formatter<'_>, |
43 | ) -> Result<(), fmt::Error> { | 42 | ) -> Result<(), fmt::Error> { |
44 | let type_alias: TypeAliasId = from_assoc_type_id(id); | 43 | let type_alias: TypeAliasId = from_assoc_type_id(id); |
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 1cda72d22..5f8666d90 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs | |||
@@ -9,20 +9,16 @@ use stdx::panic_context; | |||
9 | 9 | ||
10 | use crate::{ | 10 | use 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, | 12 | Solution, TraitRefExt, Ty, TyKind, WhereClause, Interner, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | use self::chalk::Interner; | ||
16 | |||
17 | pub(crate) mod chalk; | ||
18 | |||
19 | /// 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. |
20 | const CHALK_SOLVER_FUEL: i32 = 100; | 16 | const CHALK_SOLVER_FUEL: i32 = 100; |
21 | 17 | ||
22 | #[derive(Debug, Copy, Clone)] | 18 | #[derive(Debug, Copy, Clone)] |
23 | struct ChalkContext<'a> { | 19 | pub(crate) struct ChalkContext<'a> { |
24 | db: &'a dyn HirDatabase, | 20 | pub(crate) db: &'a dyn HirDatabase, |
25 | krate: CrateId, | 21 | pub(crate) krate: CrateId, |
26 | } | 22 | } |
27 | 23 | ||
28 | fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> { | 24 | fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> { |
@@ -148,7 +144,7 @@ fn solve( | |||
148 | // don't set the TLS for Chalk unless Chalk debugging is active, to make | 144 | // don't set the TLS for Chalk unless Chalk debugging is active, to make |
149 | // extra sure we only use it for debugging | 145 | // extra sure we only use it for debugging |
150 | let solution = | 146 | let solution = |
151 | if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() }; | 147 | if is_chalk_debug() { crate::tls::set_current_program(db, solve) } else { solve() }; |
152 | 148 | ||
153 | solution | 149 | solution |
154 | } | 150 | } |