Skip to content

Commit

Permalink
tcx -> cx in rustc_type_ir
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jul 17, 2024
1 parent a651050 commit 8d90f44
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 152 deletions.
36 changes: 18 additions & 18 deletions compiler/rustc_type_ir/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ where
{
type Lifted = Binder<U, T::Lifted>;

fn lift_to_interner(self, tcx: U) -> Option<Self::Lifted> {
fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
Some(Binder {
value: self.value.lift_to_interner(tcx)?,
bound_vars: self.bound_vars.lift_to_interner(tcx)?,
value: self.value.lift_to_interner(cx)?,
bound_vars: self.bound_vars.lift_to_interner(cx)?,
})
}
}
Expand Down Expand Up @@ -439,11 +439,11 @@ impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
where
Iter::Item: TypeFoldable<I>,
{
pub fn iter_instantiated<A>(self, tcx: I, args: A) -> IterInstantiated<I, Iter, A>
pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
where
A: SliceLike<Item = I::GenericArg>,
{
IterInstantiated { it: self.value.into_iter(), tcx, args }
IterInstantiated { it: self.value.into_iter(), cx, args }
}

/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
Expand All @@ -455,7 +455,7 @@ where

pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
it: Iter::IntoIter,
tcx: I,
cx: I,
args: A,
}

Expand All @@ -469,7 +469,7 @@ where
fn next(&mut self) -> Option<Self::Item> {
Some(
EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
.instantiate(self.tcx, self.args),
.instantiate(self.cx, self.args),
)
}

Expand All @@ -487,7 +487,7 @@ where
fn next_back(&mut self) -> Option<Self::Item> {
Some(
EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
.instantiate(self.tcx, self.args),
.instantiate(self.cx, self.args),
)
}
}
Expand All @@ -507,10 +507,10 @@ where
{
pub fn iter_instantiated_copied(
self,
tcx: I,
cx: I,
args: &'s [I::GenericArg],
) -> IterInstantiatedCopied<'s, I, Iter> {
IterInstantiatedCopied { it: self.value.into_iter(), tcx, args }
IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
}

/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
Expand All @@ -522,7 +522,7 @@ where

pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
it: Iter::IntoIter,
tcx: I,
cx: I,
args: &'a [I::GenericArg],
}

Expand All @@ -535,7 +535,7 @@ where

fn next(&mut self) -> Option<Self::Item> {
self.it.next().map(|value| {
EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.tcx, self.args)
EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
})
}

Expand All @@ -552,7 +552,7 @@ where
{
fn next_back(&mut self) -> Option<Self::Item> {
self.it.next_back().map(|value| {
EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.tcx, self.args)
EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
})
}
}
Expand Down Expand Up @@ -589,11 +589,11 @@ impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
}

impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
pub fn instantiate<A>(self, tcx: I, args: A) -> T
pub fn instantiate<A>(self, cx: I, args: A) -> T
where
A: SliceLike<Item = I::GenericArg>,
{
let mut folder = ArgFolder { tcx, args: args.as_slice(), binders_passed: 0 };
let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
self.value.fold_with(&mut folder)
}

Expand All @@ -619,7 +619,7 @@ impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
// The actual instantiation engine itself is a type folder.

struct ArgFolder<'a, I: Interner> {
tcx: I,
cx: I,
args: &'a [I::GenericArg],

/// Number of region binders we have passed through while doing the instantiation
Expand All @@ -629,7 +629,7 @@ struct ArgFolder<'a, I: Interner> {
impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
#[inline]
fn cx(&self) -> I {
self.tcx
self.cx
}

fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
Expand Down Expand Up @@ -858,6 +858,6 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
return region;
}
ty::fold::shift_region(self.tcx, region, self.binders_passed)
ty::fold::shift_region(self.cx, region, self.binders_passed)
}
}
12 changes: 6 additions & 6 deletions compiler/rustc_type_ir/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,25 @@ impl<I: Interner> CanonicalVarValues<I> {

// Given a list of canonical variables, construct a set of values which are
// the identity response.
pub fn make_identity(tcx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> {
pub fn make_identity(cx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> {
CanonicalVarValues {
var_values: tcx.mk_args_from_iter(infos.iter().enumerate().map(
var_values: cx.mk_args_from_iter(infos.iter().enumerate().map(
|(i, info)| -> I::GenericArg {
match info.kind {
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
Ty::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
Ty::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
.into()
}
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
Region::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
Region::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
.into()
}
CanonicalVarKind::Effect => {
Const::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
Const::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
.into()
}
CanonicalVarKind::Const(_) | CanonicalVarKind::PlaceholderConst(_) => {
Const::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
Const::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
.into()
}
}
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_type_ir/src/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@ pub enum EffectKind {
}

impl EffectKind {
pub fn try_from_def_id<I: Interner>(tcx: I, def_id: I::DefId) -> Option<EffectKind> {
if tcx.is_lang_item(def_id, EffectsMaybe) {
pub fn try_from_def_id<I: Interner>(cx: I, def_id: I::DefId) -> Option<EffectKind> {
if cx.is_lang_item(def_id, EffectsMaybe) {
Some(EffectKind::Maybe)
} else if tcx.is_lang_item(def_id, EffectsRuntime) {
} else if cx.is_lang_item(def_id, EffectsRuntime) {
Some(EffectKind::Runtime)
} else if tcx.is_lang_item(def_id, EffectsNoRuntime) {
} else if cx.is_lang_item(def_id, EffectsNoRuntime) {
Some(EffectKind::NoRuntime)
} else {
None
}
}

pub fn to_def_id<I: Interner>(self, tcx: I) -> I::DefId {
pub fn to_def_id<I: Interner>(self, cx: I) -> I::DefId {
let lang_item = match self {
EffectKind::Maybe => EffectsMaybe,
EffectKind::NoRuntime => EffectsNoRuntime,
EffectKind::Runtime => EffectsRuntime,
};

tcx.require_lang_item(lang_item)
cx.require_lang_item(lang_item)
}

pub fn try_from_ty<I: Interner>(tcx: I, ty: I::Ty) -> Option<EffectKind> {
pub fn try_from_ty<I: Interner>(cx: I, ty: I::Ty) -> Option<EffectKind> {
if let crate::Adt(def, _) = ty.kind() {
Self::try_from_def_id(tcx, def.def_id())
Self::try_from_def_id(cx, def.def_id())
} else {
None
}
}

pub fn to_ty<I: Interner>(self, tcx: I) -> I::Ty {
I::Ty::new_adt(tcx, tcx.adt_def(self.to_def_id(tcx)), Default::default())
pub fn to_ty<I: Interner>(self, cx: I) -> I::Ty {
I::Ty::new_adt(cx, cx.adt_def(self.to_def_id(cx)), Default::default())
}

/// Returns an intersection between two effect kinds. If one effect kind
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_type_ir/src/elaborate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ pub fn supertrait_def_ids<I: Interner>(
}

pub fn supertraits<I: Interner>(
tcx: I,
cx: I,
trait_ref: ty::Binder<I, ty::TraitRef<I>>,
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
elaborate(tcx, [trait_ref.upcast(tcx)]).filter_only_self().filter_to_traits()
elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits()
}

pub fn transitive_bounds<I: Interner>(
tcx: I,
cx: I,
trait_refs: impl Iterator<Item = ty::Binder<I, ty::TraitRef<I>>>,
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.upcast(tcx)))
elaborate(cx, trait_refs.map(|trait_ref| trait_ref.upcast(cx)))
.filter_only_self()
.filter_to_traits()
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_type_ir/src/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum TreatParams {
///
/// ¹ meaning that if the outermost layers are different, then the whole types are also different.
pub fn simplify_type<I: Interner>(
tcx: I,
cx: I,
ty: I::Ty,
treat_params: TreatParams,
) -> Option<SimplifiedType<I::DefId>> {
Expand All @@ -119,10 +119,10 @@ pub fn simplify_type<I: Interner>(
ty::Str => Some(SimplifiedType::Str),
ty::Array(..) => Some(SimplifiedType::Array),
ty::Slice(..) => Some(SimplifiedType::Slice),
ty::Pat(ty, ..) => simplify_type(tcx, ty, treat_params),
ty::Pat(ty, ..) => simplify_type(cx, ty, treat_params),
ty::RawPtr(_, mutbl) => Some(SimplifiedType::Ptr(mutbl)),
ty::Dynamic(trait_info, ..) => match trait_info.principal_def_id() {
Some(principal_def_id) if !tcx.trait_is_auto(principal_def_id) => {
Some(principal_def_id) if !cx.trait_is_auto(principal_def_id) => {
Some(SimplifiedType::Trait(principal_def_id))
}
_ => Some(SimplifiedType::MarkerTraitObject),
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_type_ir/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,20 @@ impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix,
// `rustc_middle/src/ty/generic_args.rs` for more details.

struct Shifter<I: Interner> {
tcx: I,
cx: I,
current_index: ty::DebruijnIndex,
amount: u32,
}

impl<I: Interner> Shifter<I> {
pub fn new(tcx: I, amount: u32) -> Self {
Shifter { tcx, current_index: ty::INNERMOST, amount }
pub fn new(cx: I, amount: u32) -> Self {
Shifter { cx, current_index: ty::INNERMOST, amount }
}
}

impl<I: Interner> TypeFolder<I> for Shifter<I> {
fn cx(&self) -> I {
self.tcx
self.cx
}

fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
Expand All @@ -372,7 +372,7 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
match r.kind() {
ty::ReBound(debruijn, br) if debruijn >= self.current_index => {
let debruijn = debruijn.shifted_in(self.amount);
Region::new_bound(self.tcx, debruijn, br)
Region::new_bound(self.cx, debruijn, br)
}
_ => r,
}
Expand All @@ -382,7 +382,7 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
match ty.kind() {
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
let debruijn = debruijn.shifted_in(self.amount);
Ty::new_bound(self.tcx, debruijn, bound_ty)
Ty::new_bound(self.cx, debruijn, bound_ty)
}

_ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self),
Expand All @@ -394,7 +394,7 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
match ct.kind() {
ty::ConstKind::Bound(debruijn, bound_ct) if debruijn >= self.current_index => {
let debruijn = debruijn.shifted_in(self.amount);
Const::new_bound(self.tcx, debruijn, bound_ct)
Const::new_bound(self.cx, debruijn, bound_ct)
}
_ => ct.super_fold_with(self),
}
Expand All @@ -405,16 +405,16 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
}
}

pub fn shift_region<I: Interner>(tcx: I, region: I::Region, amount: u32) -> I::Region {
pub fn shift_region<I: Interner>(cx: I, region: I::Region, amount: u32) -> I::Region {
match region.kind() {
ty::ReBound(debruijn, br) if amount > 0 => {
Region::new_bound(tcx, debruijn.shifted_in(amount), br)
Region::new_bound(cx, debruijn.shifted_in(amount), br)
}
_ => region,
}
}

pub fn shift_vars<I: Interner, T>(tcx: I, value: T, amount: u32) -> T
pub fn shift_vars<I: Interner, T>(cx: I, value: T, amount: u32) -> T
where
T: TypeFoldable<I>,
{
Expand All @@ -424,5 +424,5 @@ where
return value;
}

value.fold_with(&mut Shifter::new(tcx, amount))
value.fold_with(&mut Shifter::new(cx, amount))
}
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub trait Clause<I: Interner<Clause = Self>>:
/// poly-trait-ref to supertraits that must hold if that
/// poly-trait-ref holds. This is slightly different from a normal
/// instantiation in terms of what happens with bound regions.
fn instantiate_supertrait(self, tcx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
}

/// Common capabilities of placeholder kinds
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/lift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
/// e.g., `()` or `u8`, was interned in a different context.
pub trait Lift<I>: std::fmt::Debug {
type Lifted: std::fmt::Debug;
fn lift_to_interner(self, tcx: I) -> Option<Self::Lifted>;
fn lift_to_interner(self, cx: I) -> Option<Self::Lifted>;
}
10 changes: 5 additions & 5 deletions compiler/rustc_type_ir/src/opaque_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct OpaqueTypeKey<I: Interner> {
}

impl<I: Interner> OpaqueTypeKey<I> {
pub fn iter_captured_args(self, tcx: I) -> impl Iterator<Item = (usize, I::GenericArg)> {
let variances = tcx.variances_of(self.def_id.into());
pub fn iter_captured_args(self, cx: I) -> impl Iterator<Item = (usize, I::GenericArg)> {
let variances = cx.variances_of(self.def_id.into());
std::iter::zip(self.args.iter(), variances.iter()).enumerate().filter_map(
|(i, (arg, v))| match (arg.kind(), v) {
(_, ty::Invariant) => Some((i, arg)),
Expand All @@ -35,18 +35,18 @@ impl<I: Interner> OpaqueTypeKey<I> {

pub fn fold_captured_lifetime_args(
self,
tcx: I,
cx: I,
mut f: impl FnMut(I::Region) -> I::Region,
) -> Self {
let Self { def_id, args } = self;
let variances = tcx.variances_of(def_id.into());
let variances = cx.variances_of(def_id.into());
let args =
std::iter::zip(args.iter(), variances.iter()).map(|(arg, v)| match (arg.kind(), v) {
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => arg,
(ty::GenericArgKind::Lifetime(lt), _) => f(lt).into(),
_ => arg,
});
let args = tcx.mk_args_from_iter(args);
let args = cx.mk_args_from_iter(args);
Self { def_id, args }
}
}
Loading

0 comments on commit 8d90f44

Please sign in to comment.