Replace unused hir_ty::Lifetime with chalk equivalents

This commit is contained in:
Lukas Wirth 2021-04-05 20:46:15 +02:00
parent 87e56eb94c
commit d587ca2991
4 changed files with 50 additions and 18 deletions

View File

@ -5,7 +5,7 @@
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
use hir_def::{
db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId,
LocalFieldId, TypeParamId, VariantId,
LifetimeParamId, LocalFieldId, TypeParamId, VariantId,
};
use la_arena::ArenaMap;
@ -86,6 +86,8 @@ fn generic_predicates_for_param(
#[salsa::interned]
fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId;
#[salsa::interned]
fn intern_lifetime_param_id(&self, param_id: LifetimeParamId) -> InternedLifetimeParamId;
#[salsa::interned]
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
#[salsa::interned]
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
@ -155,6 +157,10 @@ fn _assert_object_safe(_: &dyn HirDatabase) {}
pub struct InternedTypeParamId(salsa::InternId);
impl_intern_key!(InternedTypeParamId);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InternedLifetimeParamId(salsa::InternId);
impl_intern_key!(InternedLifetimeParamId);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InternedOpaqueTyId(salsa::InternId);
impl_intern_key!(InternedOpaqueTyId);

View File

@ -1,8 +1,10 @@
//! FIXME: write short doc here
use std::{array, fmt};
use std::{
array,
fmt::{self, Debug},
};
use chalk_ir::Mutability;
use hir_def::{
db::DefDatabase,
find_path,
@ -16,9 +18,10 @@
use hir_expand::name::Name;
use crate::{
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive,
to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy,
CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy,
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
lt_from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk,
utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg,
ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy,
ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause,
};
@ -827,15 +830,35 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
}
}
impl HirDisplay for LifetimeOutlives {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
self.a.hir_fmt(f)?;
write!(f, ": ")?;
self.b.hir_fmt(f)
}
}
impl HirDisplay for Lifetime {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
self.interned().hir_fmt(f)
}
}
impl HirDisplay for LifetimeData {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
match self {
Lifetime::Parameter(id) => {
LifetimeData::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index),
LifetimeData::InferenceVar(_) => write!(f, "_"),
LifetimeData::Placeholder(idx) => {
let id = lt_from_placeholder_idx(f.db, *idx);
let generics = generics(f.db.upcast(), id.parent);
let param_data = &generics.params.lifetimes[id.local_id];
write!(f, "{}", &param_data.name)
write!(f, "{}", param_data.name)
}
Lifetime::Static => write!(f, "'static"),
LifetimeData::Static => write!(f, "'static"),
LifetimeData::Empty(_) => Ok(()),
LifetimeData::Erased => Ok(()),
LifetimeData::Phantom(_, _) => Ok(()),
}
}
}

View File

@ -35,8 +35,8 @@ macro_rules! eprintln {
use base_db::salsa;
use hir_def::{
expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule, Lookup,
TraitId, TypeAliasId, TypeParamId,
expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule,
LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
};
use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
@ -70,6 +70,10 @@ macro_rules! eprintln {
pub type VariableKinds = chalk_ir::VariableKinds<Interner>;
pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
pub type Lifetime = chalk_ir::Lifetime<Interner>;
pub type LifetimeData = chalk_ir::LifetimeData<Interner>;
pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
impl ProjectionTy {
@ -546,6 +550,12 @@ pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderI
}
}
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 to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
}

View File

@ -7,7 +7,6 @@
cast::{CastTo, Caster},
BoundVar, Mutability, Scalar, TyVariableKind,
};
use hir_def::LifetimeParamId;
use smallvec::SmallVec;
use crate::{
@ -15,12 +14,6 @@
InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKinds,
};
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub enum Lifetime {
Parameter(LifetimeParamId),
Static,
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct OpaqueTy {
pub opaque_ty_id: OpaqueTyId,