Skip to content

Commit 5ca481b

Browse files
committed
Move ToChalk -> mapping
1 parent 743faa2 commit 5ca481b

File tree

10 files changed

+76
-37
lines changed

10 files changed

+76
-37
lines changed

crates/hir_ty/src/chalk_db.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
23
use std::sync::Arc;
34

45
use log::debug;
@@ -13,7 +14,21 @@ use hir_def::{
1314
};
1415
use hir_expand::name::name;
1516

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::{
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+
};
1732

1833
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
1934
pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
@@ -31,19 +46,6 @@ pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Inte
3146
pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
3247
pub(crate) type Variances = chalk_ir::Variances<Interner>;
3348

34-
pub(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-
40-
pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T
41-
where
42-
T: ToChalk<Chalk = ChalkT>,
43-
{
44-
T::from_chalk(db, chalk)
45-
}
46-
4749
impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
4850
fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> {
4951
self.db.associated_ty_data(id)

crates/hir_ty/src/db.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use hir_def::{
99
};
1010
use la_arena::ArenaMap;
1111

12-
use crate::{Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db, method_resolution::{InherentImpls, TraitImpls}};
12+
use 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+
};
1318
use hir_expand::name::Name;
1419

1520
#[salsa::query_group(HirDatabaseStorage)]
@@ -93,10 +98,15 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
9398
fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
9499

95100
#[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>;
97103

98104
#[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>;
100110

101111
#[salsa::invoke(chalk_db::impl_datum_query)]
102112
fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>;

crates/hir_ty/src/display.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use hir_expand::name::Name;
2020

2121
use crate::{
2222
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,
24-
chalk_db::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId,
25-
CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime,
26-
LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt,
27-
QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
23+
from_placeholder_idx, lt_from_placeholder_idx, mapping::from_chalk, primitive, subst_prefix,
24+
to_assoc_type_id, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, Const,
25+
ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData,
26+
LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause,
27+
Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
2828
};
2929

3030
pub struct HirFormatter<'a> {

crates/hir_ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use syntax::ast::RangeOp;
1717
use crate::{
1818
autoderef, dummy_usize_const,
1919
lower::lower_to_chalk_mutability,
20+
mapping::from_chalk,
2021
method_resolution, op,
2122
primitive::{self, UintTy},
2223
static_lifetime, to_chalk_trait_id,
2324
traits::FnTrait,
24-
chalk_db::from_chalk,
2525
utils::{generics, Generics},
2626
AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
2727
ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,

crates/hir_ty/src/interner.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementation of the Chalk `Interner` trait, which allows customizing the
22
//! representation of the various objects Chalk deals with (types, goals etc.).
33
4-
use crate::{GenericArg, tls, chalk_db};
4+
use crate::{chalk_db, tls, GenericArg};
55
use base_db::salsa::InternId;
66
use chalk_ir::{Goal, GoalData};
77
use hir_def::{
@@ -60,15 +60,24 @@ impl chalk_ir::interner::Interner for Interner {
6060
type Identifier = TypeAliasId;
6161
type FnAbi = ();
6262

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> {
6467
tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
6568
}
6669

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> {
6874
tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
6975
}
7076

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> {
7281
tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
7382
}
7483

crates/hir_ty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ pub use autoderef::autoderef;
5151
pub use builder::TyBuilder;
5252
pub use chalk_ext::*;
5353
pub use infer::{could_unify, InferenceResult};
54+
pub use interner::Interner;
5455
pub use lower::{
5556
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
5657
TyDefId, TyLoweringContext, ValueTyDefId,
5758
};
5859
pub use traits::TraitEnvironment;
5960
pub use walk::TypeWalk;
60-
pub use interner::Interner;
6161

6262
pub use chalk_ir::{
6363
cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,

crates/hir_ty/src/lower.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ use stdx::impl_from;
2727

2828
use crate::{
2929
db::HirDatabase,
30-
dummy_usize_const, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
31-
chalk_db::ToChalk,
32-
Interner,
30+
dummy_usize_const,
31+
mapping::ToChalk,
32+
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
3333
utils::{
3434
all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics,
3535
},
3636
AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig,
37-
FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
37+
FnSubst, ImplTraitId, Interner, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
3838
QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution,
3939
TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause,
4040
};

crates/hir_ty/src/mapping.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@
33
//! Chalk (in both directions); plus some helper functions for more specialized
44
//! conversions.
55
6-
use chalk_ir::{DebruijnIndex, cast::Cast, fold::Shift};
6+
use chalk_ir::{cast::Cast, fold::Shift, DebruijnIndex};
77
use chalk_solve::rust_ir;
88

99
use base_db::salsa::InternKey;
1010
use hir_def::{GenericDefId, TypeAliasId};
1111

12-
use crate::{AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt, QuantifiedWhereClause, Substitution, Ty, WhereClause, chalk_db::{self, ToChalk}, db::HirDatabase};
12+
use crate::{
13+
chalk_db, db::HirDatabase, AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt,
14+
QuantifiedWhereClause, Substitution, Ty, WhereClause,
15+
};
16+
17+
pub(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+
23+
pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T
24+
where
25+
T: ToChalk<Chalk = ChalkT>,
26+
{
27+
T::from_chalk(db, chalk)
28+
}
1329

1430
impl ToChalk for hir_def::TraitId {
1531
type Chalk = chalk_db::TraitId;

crates/hir_ty/src/tls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::fmt;
44
use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication};
55
use itertools::Itertools;
66

7-
use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId, chalk_db::{from_chalk, self}, Interner};
7+
use crate::{
8+
chalk_db, db::HirDatabase, from_assoc_type_id, mapping::from_chalk, CallableDefId, Interner,
9+
};
810
use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
911

1012
pub(crate) use unsafe_tls::{set_current_program, with_current_program};

crates/hir_ty/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use stdx::panic_context;
99

1010
use crate::{
1111
db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment,
12-
Solution, TraitRefExt, Ty, TyKind, WhereClause, Interner,
12+
Interner, Solution, TraitRefExt, Ty, TyKind, WhereClause,
1313
};
1414

1515
/// This controls how much 'time' we give the Chalk solver before giving up.

0 commit comments

Comments
 (0)