Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {

// Interned IDs for solver integration
#[salsa::interned]
fn intern_impl_trait_id(&self, id: ImplTraitId<'_>) -> InternedOpaqueTyId;
fn intern_impl_trait_id<'db>(&'db self, id: ImplTraitId<'db>) -> InternedOpaqueTyId<'db>;

#[salsa::interned]
fn intern_closure(&self, id: InternedClosure) -> InternedClosureId;
Expand Down Expand Up @@ -319,9 +319,9 @@ pub struct InternedConstParamId {
pub loc: ConstParamId,
}

#[salsa_macros::interned(no_lifetime, debug, revisions = usize::MAX)]
#[salsa_macros::interned(debug, revisions = usize::MAX)]
#[derive(PartialOrd, Ord)]
pub struct InternedOpaqueTyId {
pub struct InternedOpaqueTyId<'db> {
pub loc: ImplTraitId<'db>,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/dyn_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ fn contains_illegal_impl_trait_in_trait<'db>(
db: &'db dyn HirDatabase,
sig: &EarlyBinder<'db, Binder<'db, rustc_type_ir::FnSig<DbInterner<'db>>>>,
) -> Option<MethodViolationCode> {
struct OpaqueTypeCollector(FxHashSet<InternedOpaqueTyId>);
struct OpaqueTypeCollector<'x>(FxHashSet<InternedOpaqueTyId<'x>>);

impl<'db> rustc_type_ir::TypeVisitor<DbInterner<'db>> for OpaqueTypeCollector {
impl<'db> rustc_type_ir::TypeVisitor<DbInterner<'db>> for OpaqueTypeCollector<'db> {
type Result = ControlFlow<()>;

fn visit_ty(
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,8 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
struct TypeAliasImplTraitCollector<'a, 'db> {
db: &'a dyn HirDatabase,
table: &'a mut InferenceTable<'db>,
assocs: FxHashMap<InternedOpaqueTyId, (ImplId, Ty<'db>)>,
non_assocs: FxHashMap<InternedOpaqueTyId, Ty<'db>>,
assocs: FxHashMap<InternedOpaqueTyId<'db>, (ImplId, Ty<'db>)>,
non_assocs: FxHashMap<InternedOpaqueTyId<'db>, Ty<'db>>,
}

impl<'db> TypeVisitor<DbInterner<'db>> for TypeAliasImplTraitCollector<'_, 'db> {
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn could_unify_impl<'db>(
pub(crate) struct InferenceTable<'db> {
pub(crate) db: &'db dyn HirDatabase,
pub(crate) trait_env: Arc<TraitEnvironment<'db>>,
pub(crate) tait_coercion_table: Option<FxHashMap<InternedOpaqueTyId, Ty<'db>>>,
pub(crate) tait_coercion_table: Option<FxHashMap<InternedOpaqueTyId<'db>, Ty<'db>>>,
pub(crate) infer_ctxt: InferCtxt<'db>,
pub(super) fulfillment_cx: FulfillmentCtxt<'db>,
pub(super) diverging_type_vars: FxHashSet<Ty<'db>>,
Expand Down Expand Up @@ -478,14 +478,14 @@ impl<'db> InferenceTable<'db> {
}

/// Create a `GenericArgs` full of infer vars for `def`.
pub(crate) fn fresh_args_for_item(&self, def: SolverDefId) -> GenericArgs<'db> {
pub(crate) fn fresh_args_for_item(&self, def: SolverDefId<'db>) -> GenericArgs<'db> {
self.infer_ctxt.fresh_args_for_item(def)
}

/// Like `fresh_args_for_item()`, but first uses the args from `first`.
pub(crate) fn fill_rest_fresh_args(
&self,
def_id: SolverDefId,
def_id: SolverDefId<'db>,
first: impl IntoIterator<Item = GenericArg<'db>>,
) -> GenericArgs<'db> {
self.infer_ctxt.fill_rest_fresh_args(def_id, first)
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
|f| ImplTraitId::ReturnTypeImplTrait(f, Idx::from_raw(idx.into_raw())),
|a| ImplTraitId::TypeAliasImplTrait(a, Idx::from_raw(idx.into_raw())),
);
let opaque_ty_id: SolverDefId =
let opaque_ty_id: SolverDefId<'db> =
self.db.intern_impl_trait_id(impl_trait_id).into();

// We don't want to lower the bounds inside the binders
Expand Down Expand Up @@ -879,7 +879,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {

fn lower_impl_trait(
&mut self,
def_id: SolverDefId,
def_id: SolverDefId<'db>,
bounds: &[TypeBound],
krate: Crate,
) -> ImplTrait<'db> {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/next_solver/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<'db> rustc_type_ir::inherent::BoundVarLike<DbInterner<'db>> for BoundConst
self.var
}

fn assert_eq(self, var: BoundVarKind) {
fn assert_eq(self, var: BoundVarKind<'db>) {
var.expect_const()
}
}
Expand Down
135 changes: 97 additions & 38 deletions crates/hir-ty/src/next_solver/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use hir_def::{
GeneralConstId, GenericDefId, ImplId, StaticId, StructId, TraitId, TypeAliasId, UnionId,
};
use rustc_type_ir::inherent;
use stdx::impl_from;

use crate::db::{InternedClosureId, InternedCoroutineId, InternedOpaqueTyId};

Expand All @@ -18,7 +17,7 @@ pub enum Ctor {
}

#[derive(PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
pub enum SolverDefId {
pub enum SolverDefId<'db> {
AdtId(AdtId),
ConstId(ConstId),
FunctionId(FunctionId),
Expand All @@ -28,13 +27,13 @@ pub enum SolverDefId {
TypeAliasId(TypeAliasId),
InternedClosureId(InternedClosureId),
InternedCoroutineId(InternedCoroutineId),
InternedOpaqueTyId(InternedOpaqueTyId),
InternedOpaqueTyId(InternedOpaqueTyId<'db>),
EnumVariantId(EnumVariantId),
// FIXME(next-solver): Do we need the separation of `Ctor`? It duplicates some variants.
Ctor(Ctor),
}

impl std::fmt::Debug for SolverDefId {
impl<'db> std::fmt::Debug for SolverDefId<'db> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let interner = DbInterner::conjure();
let db = interner.db;
Expand Down Expand Up @@ -102,23 +101,83 @@ impl std::fmt::Debug for SolverDefId {
}
}

impl_from!(
AdtId(StructId, EnumId, UnionId),
ConstId,
FunctionId,
ImplId,
StaticId,
TraitId,
TypeAliasId,
InternedClosureId,
InternedCoroutineId,
InternedOpaqueTyId,
EnumVariantId,
Ctor
for SolverDefId
);
impl<'db> From<AdtId> for SolverDefId<'db> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl_from! doesn't work with generics unfortunately.

fn from(it: AdtId) -> SolverDefId<'db> {
SolverDefId::AdtId(it)
}
}
impl<'db> From<StructId> for SolverDefId<'db> {
fn from(it: StructId) -> SolverDefId<'db> {
SolverDefId::AdtId(AdtId::StructId(it))
}
}
impl<'db> From<EnumId> for SolverDefId<'db> {
fn from(it: EnumId) -> SolverDefId<'db> {
SolverDefId::AdtId(AdtId::EnumId(it))
}
}
impl<'db> From<UnionId> for SolverDefId<'db> {
fn from(it: UnionId) -> SolverDefId<'db> {
SolverDefId::AdtId(AdtId::UnionId(it))
}
}
impl<'db> From<ConstId> for SolverDefId<'db> {
fn from(it: ConstId) -> SolverDefId<'db> {
SolverDefId::ConstId(it)
}
}
impl<'db> From<FunctionId> for SolverDefId<'db> {
fn from(it: FunctionId) -> SolverDefId<'db> {
SolverDefId::FunctionId(it)
}
}
impl<'db> From<ImplId> for SolverDefId<'db> {
fn from(it: ImplId) -> SolverDefId<'db> {
SolverDefId::ImplId(it)
}
}
impl<'db> From<StaticId> for SolverDefId<'db> {
fn from(it: StaticId) -> SolverDefId<'db> {
SolverDefId::StaticId(it)
}
}
impl<'db> From<TraitId> for SolverDefId<'db> {
fn from(it: TraitId) -> SolverDefId<'db> {
SolverDefId::TraitId(it)
}
}
impl<'db> From<TypeAliasId> for SolverDefId<'db> {
fn from(it: TypeAliasId) -> SolverDefId<'db> {
SolverDefId::TypeAliasId(it)
}
}
impl<'db> From<InternedClosureId> for SolverDefId<'db> {
fn from(it: InternedClosureId) -> SolverDefId<'db> {
SolverDefId::InternedClosureId(it)
}
}
impl<'db> From<InternedCoroutineId> for SolverDefId<'db> {
fn from(it: InternedCoroutineId) -> SolverDefId<'db> {
SolverDefId::InternedCoroutineId(it)
}
}
impl<'db> From<InternedOpaqueTyId<'db>> for SolverDefId<'db> {
fn from(it: InternedOpaqueTyId<'db>) -> SolverDefId<'db> {
SolverDefId::InternedOpaqueTyId(it)
}
}
impl<'db> From<EnumVariantId> for SolverDefId<'db> {
fn from(it: EnumVariantId) -> SolverDefId<'db> {
SolverDefId::EnumVariantId(it)
}
}
impl<'db> From<Ctor> for SolverDefId<'db> {
fn from(it: Ctor) -> SolverDefId<'db> {
SolverDefId::Ctor(it)
}
}

impl From<GenericDefId> for SolverDefId {
impl<'db> From<GenericDefId> for SolverDefId<'db> {
fn from(value: GenericDefId) -> Self {
match value {
GenericDefId::AdtId(adt_id) => SolverDefId::AdtId(adt_id),
Expand All @@ -132,7 +191,7 @@ impl From<GenericDefId> for SolverDefId {
}
}

impl From<GeneralConstId> for SolverDefId {
impl<'db> From<GeneralConstId> for SolverDefId<'db> {
#[inline]
fn from(value: GeneralConstId) -> Self {
match value {
Expand All @@ -142,7 +201,7 @@ impl From<GeneralConstId> for SolverDefId {
}
}

impl From<DefWithBodyId> for SolverDefId {
impl<'db> From<DefWithBodyId> for SolverDefId<'db> {
#[inline]
fn from(value: DefWithBodyId) -> Self {
match value {
Expand All @@ -154,10 +213,10 @@ impl From<DefWithBodyId> for SolverDefId {
}
}

impl TryFrom<SolverDefId> for GenericDefId {
impl<'db> TryFrom<SolverDefId<'db>> for GenericDefId {
type Error = ();

fn try_from(value: SolverDefId) -> Result<Self, Self::Error> {
fn try_from(value: SolverDefId<'db>) -> Result<Self, Self::Error> {
Ok(match value {
SolverDefId::AdtId(adt_id) => GenericDefId::AdtId(adt_id),
SolverDefId::ConstId(const_id) => GenericDefId::ConstId(const_id),
Expand All @@ -175,10 +234,10 @@ impl TryFrom<SolverDefId> for GenericDefId {
}
}

impl SolverDefId {
impl<'db> SolverDefId<'db> {
#[inline]
#[track_caller]
pub fn expect_opaque_ty(self) -> InternedOpaqueTyId {
pub fn expect_opaque_ty(self) -> InternedOpaqueTyId<'db> {
match self {
SolverDefId::InternedOpaqueTyId(it) => it,
_ => panic!("expected opaque type, found {self:?}"),
Expand All @@ -195,8 +254,8 @@ impl SolverDefId {
}
}

impl<'db> inherent::DefId<DbInterner<'db>> for SolverDefId {
fn as_local(self) -> Option<SolverDefId> {
impl<'db> inherent::DefId<DbInterner<'db>> for SolverDefId<'db> {
fn as_local(self) -> Option<SolverDefId<'db>> {
Some(self)
}
fn is_local(self) -> bool {
Expand Down Expand Up @@ -229,18 +288,18 @@ macro_rules! declare_id_wrapper {
}
}

impl From<$name> for SolverDefId {
impl<'db> From<$name> for SolverDefId<'db> {
#[inline]
fn from(value: $name) -> SolverDefId {
fn from(value: $name) -> SolverDefId<'db> {
value.0.into()
}
}

impl TryFrom<SolverDefId> for $name {
impl<'db> TryFrom<SolverDefId<'db>> for $name {
type Error = ();

#[inline]
fn try_from(value: SolverDefId) -> Result<Self, Self::Error> {
fn try_from(value: SolverDefId<'db>) -> Result<Self, Self::Error> {
match value {
SolverDefId::$wraps(it) => Ok(Self(it)),
_ => Err(()),
Expand All @@ -249,7 +308,7 @@ macro_rules! declare_id_wrapper {
}

impl<'db> inherent::DefId<DbInterner<'db>> for $name {
fn as_local(self) -> Option<SolverDefId> {
fn as_local(self) -> Option<SolverDefId<'db>> {
Some(self.into())
}
fn is_local(self) -> bool {
Expand Down Expand Up @@ -286,20 +345,20 @@ impl From<CallableDefId> for CallableIdWrapper {
Self(value)
}
}
impl From<CallableIdWrapper> for SolverDefId {
impl<'db> From<CallableIdWrapper> for SolverDefId<'db> {
#[inline]
fn from(value: CallableIdWrapper) -> SolverDefId {
fn from(value: CallableIdWrapper) -> SolverDefId<'db> {
match value.0 {
CallableDefId::FunctionId(it) => it.into(),
CallableDefId::StructId(it) => Ctor::Struct(it).into(),
CallableDefId::EnumVariantId(it) => Ctor::Enum(it).into(),
}
}
}
impl TryFrom<SolverDefId> for CallableIdWrapper {
impl<'db> TryFrom<SolverDefId<'db>> for CallableIdWrapper {
type Error = ();
#[inline]
fn try_from(value: SolverDefId) -> Result<Self, Self::Error> {
fn try_from(value: SolverDefId<'db>) -> Result<Self, Self::Error> {
match value {
SolverDefId::FunctionId(it) => Ok(Self(it.into())),
SolverDefId::Ctor(Ctor::Struct(it)) => Ok(Self(it.into())),
Expand All @@ -309,7 +368,7 @@ impl TryFrom<SolverDefId> for CallableIdWrapper {
}
}
impl<'db> inherent::DefId<DbInterner<'db>> for CallableIdWrapper {
fn as_local(self) -> Option<SolverDefId> {
fn as_local(self) -> Option<SolverDefId<'db>> {
Some(self.into())
}
fn is_local(self) -> bool {
Expand Down
12 changes: 6 additions & 6 deletions crates/hir-ty/src/next_solver/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ use super::{
/// gets mapped to the same result. `BoundVarReplacer` caches by using
/// a `DelayedMap` which does not cache the first few types it encounters.
pub trait BoundVarReplacerDelegate<'db> {
fn replace_region(&mut self, br: BoundRegion) -> Region<'db>;
fn replace_ty(&mut self, bt: BoundTy) -> Ty<'db>;
fn replace_region(&mut self, br: BoundRegion<'db>) -> Region<'db>;
fn replace_ty(&mut self, bt: BoundTy<'db>) -> Ty<'db>;
fn replace_const(&mut self, bv: BoundConst) -> Const<'db>;
}

/// A simple delegate taking 3 mutable functions. The used functions must
/// always return the same result for each bound variable, no matter how
/// frequently they are called.
pub struct FnMutDelegate<'db, 'a> {
pub regions: &'a mut (dyn FnMut(BoundRegion) -> Region<'db> + 'a),
pub types: &'a mut (dyn FnMut(BoundTy) -> Ty<'db> + 'a),
pub regions: &'a mut (dyn FnMut(BoundRegion<'db>) -> Region<'db> + 'a),
pub types: &'a mut (dyn FnMut(BoundTy<'db>) -> Ty<'db> + 'a),
pub consts: &'a mut (dyn FnMut(BoundConst) -> Const<'db> + 'a),
}

impl<'db, 'a> BoundVarReplacerDelegate<'db> for FnMutDelegate<'db, 'a> {
fn replace_region(&mut self, br: BoundRegion) -> Region<'db> {
fn replace_region(&mut self, br: BoundRegion<'db>) -> Region<'db> {
(self.regions)(br)
}
fn replace_ty(&mut self, bt: BoundTy) -> Ty<'db> {
fn replace_ty(&mut self, bt: BoundTy<'db>) -> Ty<'db> {
(self.types)(bt)
}
fn replace_const(&mut self, bv: BoundConst) -> Const<'db> {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/next_solver/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl<'db> FulfillmentCtxt<'db> {
/// This function can be also return false positives, which will lead to poor diagnostics
/// so we want to keep this visitor *precise* too.
pub struct StalledOnCoroutines<'a, 'db> {
pub stalled_coroutines: &'a [SolverDefId],
pub stalled_coroutines: &'a [SolverDefId<'db>],
pub cache: FxHashSet<Ty<'db>>,
}

Expand Down
Loading