Skip to content

Commit 2f9dfd4

Browse files
tcx -> cx in rustc_type_ir
1 parent 23f26b1 commit 2f9dfd4

File tree

14 files changed

+149
-152
lines changed

14 files changed

+149
-152
lines changed

compiler/rustc_type_ir/src/binder.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ where
4949
{
5050
type Lifted = Binder<U, T::Lifted>;
5151

52-
fn lift_to_interner(self, tcx: U) -> Option<Self::Lifted> {
52+
fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
5353
Some(Binder {
54-
value: self.value.lift_to_interner(tcx)?,
55-
bound_vars: self.bound_vars.lift_to_interner(tcx)?,
54+
value: self.value.lift_to_interner(cx)?,
55+
bound_vars: self.bound_vars.lift_to_interner(cx)?,
5656
})
5757
}
5858
}
@@ -439,11 +439,11 @@ impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
439439
where
440440
Iter::Item: TypeFoldable<I>,
441441
{
442-
pub fn iter_instantiated<A>(self, tcx: I, args: A) -> IterInstantiated<I, Iter, A>
442+
pub fn iter_instantiated<A>(self, cx: I, args: A) -> IterInstantiated<I, Iter, A>
443443
where
444444
A: SliceLike<Item = I::GenericArg>,
445445
{
446-
IterInstantiated { it: self.value.into_iter(), tcx, args }
446+
IterInstantiated { it: self.value.into_iter(), cx, args }
447447
}
448448

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

456456
pub struct IterInstantiated<I: Interner, Iter: IntoIterator, A> {
457457
it: Iter::IntoIter,
458-
tcx: I,
458+
cx: I,
459459
args: A,
460460
}
461461

@@ -469,7 +469,7 @@ where
469469
fn next(&mut self) -> Option<Self::Item> {
470470
Some(
471471
EarlyBinder { value: self.it.next()?, _tcx: PhantomData }
472-
.instantiate(self.tcx, self.args),
472+
.instantiate(self.cx, self.args),
473473
)
474474
}
475475

@@ -487,7 +487,7 @@ where
487487
fn next_back(&mut self) -> Option<Self::Item> {
488488
Some(
489489
EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData }
490-
.instantiate(self.tcx, self.args),
490+
.instantiate(self.cx, self.args),
491491
)
492492
}
493493
}
@@ -507,10 +507,10 @@ where
507507
{
508508
pub fn iter_instantiated_copied(
509509
self,
510-
tcx: I,
510+
cx: I,
511511
args: &'s [I::GenericArg],
512512
) -> IterInstantiatedCopied<'s, I, Iter> {
513-
IterInstantiatedCopied { it: self.value.into_iter(), tcx, args }
513+
IterInstantiatedCopied { it: self.value.into_iter(), cx, args }
514514
}
515515

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

523523
pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
524524
it: Iter::IntoIter,
525-
tcx: I,
525+
cx: I,
526526
args: &'a [I::GenericArg],
527527
}
528528

@@ -535,7 +535,7 @@ where
535535

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

@@ -552,7 +552,7 @@ where
552552
{
553553
fn next_back(&mut self) -> Option<Self::Item> {
554554
self.it.next_back().map(|value| {
555-
EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.tcx, self.args)
555+
EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.cx, self.args)
556556
})
557557
}
558558
}
@@ -589,11 +589,11 @@ impl<I: Interner, T: Iterator> Iterator for EarlyBinderIter<I, T> {
589589
}
590590

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

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

621621
struct ArgFolder<'a, I: Interner> {
622-
tcx: I,
622+
cx: I,
623623
args: &'a [I::GenericArg],
624624

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

635635
fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
@@ -858,6 +858,6 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
858858
if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
859859
return region;
860860
}
861-
ty::fold::shift_region(self.tcx, region, self.binders_passed)
861+
ty::fold::shift_region(self.cx, region, self.binders_passed)
862862
}
863863
}

compiler/rustc_type_ir/src/canonical.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -330,25 +330,25 @@ impl<I: Interner> CanonicalVarValues<I> {
330330

331331
// Given a list of canonical variables, construct a set of values which are
332332
// the identity response.
333-
pub fn make_identity(tcx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> {
333+
pub fn make_identity(cx: I, infos: I::CanonicalVars) -> CanonicalVarValues<I> {
334334
CanonicalVarValues {
335-
var_values: tcx.mk_args_from_iter(infos.iter().enumerate().map(
335+
var_values: cx.mk_args_from_iter(infos.iter().enumerate().map(
336336
|(i, info)| -> I::GenericArg {
337337
match info.kind {
338338
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
339-
Ty::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
339+
Ty::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
340340
.into()
341341
}
342342
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
343-
Region::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
343+
Region::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
344344
.into()
345345
}
346346
CanonicalVarKind::Effect => {
347-
Const::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
347+
Const::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
348348
.into()
349349
}
350350
CanonicalVarKind::Const(_) | CanonicalVarKind::PlaceholderConst(_) => {
351-
Const::new_anon_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i))
351+
Const::new_anon_bound(cx, ty::INNERMOST, ty::BoundVar::from_usize(i))
352352
.into()
353353
}
354354
}

compiler/rustc_type_ir/src/effects.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ pub enum EffectKind {
1010
}
1111

1212
impl EffectKind {
13-
pub fn try_from_def_id<I: Interner>(tcx: I, def_id: I::DefId) -> Option<EffectKind> {
14-
if tcx.is_lang_item(def_id, EffectsMaybe) {
13+
pub fn try_from_def_id<I: Interner>(cx: I, def_id: I::DefId) -> Option<EffectKind> {
14+
if cx.is_lang_item(def_id, EffectsMaybe) {
1515
Some(EffectKind::Maybe)
16-
} else if tcx.is_lang_item(def_id, EffectsRuntime) {
16+
} else if cx.is_lang_item(def_id, EffectsRuntime) {
1717
Some(EffectKind::Runtime)
18-
} else if tcx.is_lang_item(def_id, EffectsNoRuntime) {
18+
} else if cx.is_lang_item(def_id, EffectsNoRuntime) {
1919
Some(EffectKind::NoRuntime)
2020
} else {
2121
None
2222
}
2323
}
2424

25-
pub fn to_def_id<I: Interner>(self, tcx: I) -> I::DefId {
25+
pub fn to_def_id<I: Interner>(self, cx: I) -> I::DefId {
2626
let lang_item = match self {
2727
EffectKind::Maybe => EffectsMaybe,
2828
EffectKind::NoRuntime => EffectsNoRuntime,
2929
EffectKind::Runtime => EffectsRuntime,
3030
};
3131

32-
tcx.require_lang_item(lang_item)
32+
cx.require_lang_item(lang_item)
3333
}
3434

35-
pub fn try_from_ty<I: Interner>(tcx: I, ty: I::Ty) -> Option<EffectKind> {
35+
pub fn try_from_ty<I: Interner>(cx: I, ty: I::Ty) -> Option<EffectKind> {
3636
if let crate::Adt(def, _) = ty.kind() {
37-
Self::try_from_def_id(tcx, def.def_id())
37+
Self::try_from_def_id(cx, def.def_id())
3838
} else {
3939
None
4040
}
4141
}
4242

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

4747
/// Returns an intersection between two effect kinds. If one effect kind

compiler/rustc_type_ir/src/elaborate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ pub fn supertrait_def_ids<I: Interner>(
258258
}
259259

260260
pub fn supertraits<I: Interner>(
261-
tcx: I,
261+
cx: I,
262262
trait_ref: ty::Binder<I, ty::TraitRef<I>>,
263263
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
264-
elaborate(tcx, [trait_ref.upcast(tcx)]).filter_only_self().filter_to_traits()
264+
elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits()
265265
}
266266

267267
pub fn transitive_bounds<I: Interner>(
268-
tcx: I,
268+
cx: I,
269269
trait_refs: impl Iterator<Item = ty::Binder<I, ty::TraitRef<I>>>,
270270
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
271-
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.upcast(tcx)))
271+
elaborate(cx, trait_refs.map(|trait_ref| trait_ref.upcast(cx)))
272272
.filter_only_self()
273273
.filter_to_traits()
274274
}

compiler/rustc_type_ir/src/fast_reject.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub enum TreatParams {
105105
///
106106
/// ¹ meaning that if the outermost layers are different, then the whole types are also different.
107107
pub fn simplify_type<I: Interner>(
108-
tcx: I,
108+
cx: I,
109109
ty: I::Ty,
110110
treat_params: TreatParams,
111111
) -> Option<SimplifiedType<I::DefId>> {
@@ -119,10 +119,10 @@ pub fn simplify_type<I: Interner>(
119119
ty::Str => Some(SimplifiedType::Str),
120120
ty::Array(..) => Some(SimplifiedType::Array),
121121
ty::Slice(..) => Some(SimplifiedType::Slice),
122-
ty::Pat(ty, ..) => simplify_type(tcx, ty, treat_params),
122+
ty::Pat(ty, ..) => simplify_type(cx, ty, treat_params),
123123
ty::RawPtr(_, mutbl) => Some(SimplifiedType::Ptr(mutbl)),
124124
ty::Dynamic(trait_info, ..) => match trait_info.principal_def_id() {
125-
Some(principal_def_id) if !tcx.trait_is_auto(principal_def_id) => {
125+
Some(principal_def_id) if !cx.trait_is_auto(principal_def_id) => {
126126
Some(SimplifiedType::Trait(principal_def_id))
127127
}
128128
_ => Some(SimplifiedType::MarkerTraitObject),

compiler/rustc_type_ir/src/fold.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,20 @@ impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix,
345345
// `rustc_middle/src/ty/generic_args.rs` for more details.
346346

347347
struct Shifter<I: Interner> {
348-
tcx: I,
348+
cx: I,
349349
current_index: ty::DebruijnIndex,
350350
amount: u32,
351351
}
352352

353353
impl<I: Interner> Shifter<I> {
354-
pub fn new(tcx: I, amount: u32) -> Self {
355-
Shifter { tcx, current_index: ty::INNERMOST, amount }
354+
pub fn new(cx: I, amount: u32) -> Self {
355+
Shifter { cx, current_index: ty::INNERMOST, amount }
356356
}
357357
}
358358

359359
impl<I: Interner> TypeFolder<I> for Shifter<I> {
360360
fn cx(&self) -> I {
361-
self.tcx
361+
self.cx
362362
}
363363

364364
fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> {
@@ -372,7 +372,7 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
372372
match r.kind() {
373373
ty::ReBound(debruijn, br) if debruijn >= self.current_index => {
374374
let debruijn = debruijn.shifted_in(self.amount);
375-
Region::new_bound(self.tcx, debruijn, br)
375+
Region::new_bound(self.cx, debruijn, br)
376376
}
377377
_ => r,
378378
}
@@ -382,7 +382,7 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
382382
match ty.kind() {
383383
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
384384
let debruijn = debruijn.shifted_in(self.amount);
385-
Ty::new_bound(self.tcx, debruijn, bound_ty)
385+
Ty::new_bound(self.cx, debruijn, bound_ty)
386386
}
387387

388388
_ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self),
@@ -394,7 +394,7 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
394394
match ct.kind() {
395395
ty::ConstKind::Bound(debruijn, bound_ct) if debruijn >= self.current_index => {
396396
let debruijn = debruijn.shifted_in(self.amount);
397-
Const::new_bound(self.tcx, debruijn, bound_ct)
397+
Const::new_bound(self.cx, debruijn, bound_ct)
398398
}
399399
_ => ct.super_fold_with(self),
400400
}
@@ -405,16 +405,16 @@ impl<I: Interner> TypeFolder<I> for Shifter<I> {
405405
}
406406
}
407407

408-
pub fn shift_region<I: Interner>(tcx: I, region: I::Region, amount: u32) -> I::Region {
408+
pub fn shift_region<I: Interner>(cx: I, region: I::Region, amount: u32) -> I::Region {
409409
match region.kind() {
410410
ty::ReBound(debruijn, br) if amount > 0 => {
411-
Region::new_bound(tcx, debruijn.shifted_in(amount), br)
411+
Region::new_bound(cx, debruijn.shifted_in(amount), br)
412412
}
413413
_ => region,
414414
}
415415
}
416416

417-
pub fn shift_vars<I: Interner, T>(tcx: I, value: T, amount: u32) -> T
417+
pub fn shift_vars<I: Interner, T>(cx: I, value: T, amount: u32) -> T
418418
where
419419
T: TypeFoldable<I>,
420420
{
@@ -424,5 +424,5 @@ where
424424
return value;
425425
}
426426

427-
value.fold_with(&mut Shifter::new(tcx, amount))
427+
value.fold_with(&mut Shifter::new(cx, amount))
428428
}

compiler/rustc_type_ir/src/inherent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub trait Clause<I: Interner<Clause = Self>>:
475475
/// poly-trait-ref to supertraits that must hold if that
476476
/// poly-trait-ref holds. This is slightly different from a normal
477477
/// instantiation in terms of what happens with bound regions.
478-
fn instantiate_supertrait(self, tcx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
478+
fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
479479
}
480480

481481
/// Common capabilities of placeholder kinds

compiler/rustc_type_ir/src/lift.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
/// e.g., `()` or `u8`, was interned in a different context.
1818
pub trait Lift<I>: std::fmt::Debug {
1919
type Lifted: std::fmt::Debug;
20-
fn lift_to_interner(self, tcx: I) -> Option<Self::Lifted>;
20+
fn lift_to_interner(self, cx: I) -> Option<Self::Lifted>;
2121
}

compiler/rustc_type_ir/src/opaque_ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub struct OpaqueTypeKey<I: Interner> {
2222
}
2323

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

3636
pub fn fold_captured_lifetime_args(
3737
self,
38-
tcx: I,
38+
cx: I,
3939
mut f: impl FnMut(I::Region) -> I::Region,
4040
) -> Self {
4141
let Self { def_id, args } = self;
42-
let variances = tcx.variances_of(def_id.into());
42+
let variances = cx.variances_of(def_id.into());
4343
let args =
4444
std::iter::zip(args.iter(), variances.iter()).map(|(arg, v)| match (arg.kind(), v) {
4545
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => arg,
4646
(ty::GenericArgKind::Lifetime(lt), _) => f(lt).into(),
4747
_ => arg,
4848
});
49-
let args = tcx.mk_args_from_iter(args);
49+
let args = cx.mk_args_from_iter(args);
5050
Self { def_id, args }
5151
}
5252
}

0 commit comments

Comments
 (0)