More moving stuff around

This commit is contained in:
Florian Diebold 2021-04-09 14:28:04 +02:00
parent 9fba7cf827
commit 2f02977e56
4 changed files with 74 additions and 78 deletions

View file

@ -17,7 +17,7 @@ use hir_expand::name::name;
use crate::{
db::HirDatabase,
display::HirDisplay,
from_assoc_type_id, make_only_type_binders,
from_assoc_type_id, from_chalk_trait_id, make_only_type_binders,
mapping::{from_chalk, ToChalk, TypeAliasAsValue},
method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
to_assoc_type_id, to_chalk_trait_id,
@ -79,7 +79,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
binders: &CanonicalVarKinds<Interner>,
) -> Vec<ImplId> {
debug!("impls_for_trait {:?}", trait_id);
let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
let trait_: hir_def::TraitId = from_chalk_trait_id(trait_id);
let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone();
@ -161,7 +161,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
Some(LangItemTarget::TraitId(trait_)) => trait_,
_ => return None,
};
Some(trait_.to_chalk(self.db))
Some(to_chalk_trait_id(trait_))
}
fn program_clauses_for_env(
@ -308,7 +308,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
}
fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
let id = from_chalk(self.db, trait_id);
let id = from_chalk_trait_id(trait_id);
self.db.trait_data(id).name.to_string()
}
fn adt_name(&self, chalk_ir::AdtId(adt_id): AdtId) -> String {
@ -413,7 +413,7 @@ pub(crate) fn trait_datum_query(
trait_id: TraitId,
) -> Arc<TraitDatum> {
debug!("trait_datum {:?}", trait_id);
let trait_: hir_def::TraitId = from_chalk(db, trait_id);
let trait_ = from_chalk_trait_id(trait_id);
let trait_data = db.trait_data(trait_);
debug!("trait {:?} = {:?}", trait_id, trait_data.name);
let generic_params = generics(db.upcast(), trait_.into());
@ -723,7 +723,10 @@ pub(super) fn generic_predicate_to_inline_bound(
.collect();
let alias_eq_bound = rust_ir::AliasEqBound {
value: ty.clone(),
trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
trait_bound: rust_ir::TraitBound {
trait_id: to_chalk_trait_id(trait_),
args_no_self,
},
associated_ty_id: projection_ty.associated_ty_id,
parameters: Vec::new(), // FIXME we don't support generic associated types yet
};

View file

@ -34,16 +34,12 @@ mod test_db;
use std::sync::Arc;
use base_db::salsa;
use chalk_ir::{
fold::{Fold, Shift},
interner::HasInterner,
UintTy,
};
use hir_def::{
expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
TypeParamId,
};
use hir_def::{expr::ExprId, type_ref::Rawness, TypeParamId};
use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
@ -56,6 +52,11 @@ pub use lower::{
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
TyDefId, TyLoweringContext, ValueTyDefId,
};
pub use mapping::{
const_from_placeholder_idx, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
from_placeholder_idx, lt_from_placeholder_idx, to_assoc_type_id, to_chalk_trait_id,
to_foreign_def_id, to_placeholder_idx,
};
pub use traits::TraitEnvironment;
pub use walk::TypeWalk;
@ -242,56 +243,6 @@ pub(crate) struct ReturnTypeImplTrait {
pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>,
}
pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId {
chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
}
pub fn from_foreign_def_id(id: ForeignDefId) -> TypeAliasId {
salsa::InternKey::from_intern_id(id.0)
}
pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId {
chalk_ir::AssocTypeId(salsa::InternKey::as_intern_id(&id))
}
pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId {
salsa::InternKey::from_intern_id(id.0)
}
pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
db.lookup_intern_type_param_id(interned_id)
}
pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex {
let interned_id = db.intern_type_param_id(id);
PlaceholderIndex {
ui: chalk_ir::UniverseIndex::ROOT,
idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(),
}
}
pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
db.lookup_intern_lifetime_param_id(interned_id)
}
pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
db.lookup_intern_const_param_id(interned_id)
}
pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
}
pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
salsa::InternKey::from_intern_id(id.0)
}
pub fn static_lifetime() -> Lifetime {
LifetimeData::Static.intern(&Interner)
}

View file

@ -5,10 +5,13 @@
use chalk_solve::rust_ir;
use base_db::salsa::InternKey;
use hir_def::TypeAliasId;
use base_db::salsa::{self, InternKey};
use hir_def::{ConstParamId, LifetimeParamId, TraitId, TypeAliasId, TypeParamId};
use crate::{chalk_db, db::HirDatabase, CallableDefId, FnDefId, Interner, OpaqueTyId};
use crate::{
chalk_db, db::HirDatabase, AssocTypeId, CallableDefId, ChalkTraitId, FnDefId, ForeignDefId,
Interner, OpaqueTyId, PlaceholderIndex,
};
pub(crate) trait ToChalk {
type Chalk;
@ -23,18 +26,6 @@ where
T::from_chalk(db, chalk)
}
impl ToChalk for hir_def::TraitId {
type Chalk = chalk_db::TraitId;
fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::TraitId {
chalk_ir::TraitId(self.as_intern_id())
}
fn from_chalk(_db: &dyn HirDatabase, trait_id: chalk_db::TraitId) -> hir_def::TraitId {
InternKey::from_intern_id(trait_id.0)
}
}
impl ToChalk for hir_def::ImplId {
type Chalk = chalk_db::ImplId;
@ -111,3 +102,53 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
chalk_ir::ClosureId(id.as_intern_id())
}
}
pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId {
chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
}
pub fn from_foreign_def_id(id: ForeignDefId) -> TypeAliasId {
salsa::InternKey::from_intern_id(id.0)
}
pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId {
chalk_ir::AssocTypeId(salsa::InternKey::as_intern_id(&id))
}
pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId {
salsa::InternKey::from_intern_id(id.0)
}
pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
db.lookup_intern_type_param_id(interned_id)
}
pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderIndex {
let interned_id = db.intern_type_param_id(id);
PlaceholderIndex {
ui: chalk_ir::UniverseIndex::ROOT,
idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(),
}
}
pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
db.lookup_intern_lifetime_param_id(interned_id)
}
pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
db.lookup_intern_const_param_id(interned_id)
}
pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
}
pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
salsa::InternKey::from_intern_id(id.0)
}

View file

@ -5,7 +5,8 @@ use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplicat
use itertools::Itertools;
use crate::{
chalk_db, db::HirDatabase, from_assoc_type_id, mapping::from_chalk, CallableDefId, Interner,
chalk_db, db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, mapping::from_chalk,
CallableDefId, Interner,
};
use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
@ -32,7 +33,7 @@ impl DebugContext<'_> {
id: chalk_db::TraitId,
fmt: &mut fmt::Formatter<'_>,
) -> Result<(), fmt::Error> {
let trait_: hir_def::TraitId = from_chalk(self.0, id);
let trait_: hir_def::TraitId = from_chalk_trait_id(id);
let trait_data = self.0.trait_data(trait_);
write!(fmt, "{}", trait_data.name)
}