Skip to content

Commit 42be0f9

Browse files
authored
Rollup merge of rust-lang#73055 - lcnr:skol-no-more, r=matthewjasper
remove leftover mentions of `skol` and `int` from the compiler This PR mostly changes `skol` -> `placeholder` and all cases where `int` is used as a type to `i32`.
2 parents 3e747da + 180334c commit 42be0f9

File tree

18 files changed

+79
-155
lines changed

18 files changed

+79
-155
lines changed

src/librustc_infer/infer/higher_ranked/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
6363
/// placeholder region. This is the first step of checking subtyping
6464
/// when higher-ranked things are involved.
6565
///
66-
/// **Important:** you must call this function from within a snapshot.
67-
/// Moreover, before committing the snapshot, you must eventually call
68-
/// either `plug_leaks` or `pop_placeholders` to remove the placeholder
69-
/// regions. If you rollback the snapshot (or are using a probe), then
70-
/// the pop occurs as part of the rollback, so an explicit call is not
71-
/// needed (but is also permitted).
72-
///
73-
/// For more information about how placeholders and HRTBs work, see
66+
/// **Important:** You have to be careful to not leak these placeholders,
67+
/// for more information about how placeholders and HRTBs work, see
7468
/// the [rustc dev guide].
7569
///
7670
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html

src/librustc_infer/infer/region_constraints/leak_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'tcx> TaintSet<'tcx> {
128128
verifys[i].origin.span(),
129129
"we never add verifications while doing higher-ranked things",
130130
),
131-
&Purged | &AddCombination(..) | &AddVar(..) => {}
131+
&AddCombination(..) | &AddVar(..) => {}
132132
}
133133
}
134134
}

src/librustc_infer/infer/region_constraints/mod.rs

-67
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,6 @@ pub(crate) enum UndoLog<'tcx> {
289289

290290
/// We added a GLB/LUB "combination variable".
291291
AddCombination(CombineMapType, TwoRegions<'tcx>),
292-
293-
/// During skolemization, we sometimes purge entries from the undo
294-
/// log in a kind of minisnapshot (unlike other snapshots, this
295-
/// purging actually takes place *on success*). In that case, we
296-
/// replace the corresponding entry with `Noop` so as to avoid the
297-
/// need to do a bunch of swapping. (We can't use `swap_remove` as
298-
/// the order of the vector is important.)
299-
Purged,
300292
}
301293

302294
#[derive(Copy, Clone, PartialEq)]
@@ -357,9 +349,6 @@ impl<'tcx> RegionConstraintStorage<'tcx> {
357349

358350
fn rollback_undo_entry(&mut self, undo_entry: UndoLog<'tcx>) {
359351
match undo_entry {
360-
Purged => {
361-
// nothing to do here
362-
}
363352
AddVar(vid) => {
364353
self.var_infos.pop().unwrap();
365354
assert_eq!(self.var_infos.len(), vid.index() as usize);
@@ -488,62 +477,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
488477
self.var_infos[vid].origin
489478
}
490479

491-
/// Removes all the edges to/from the placeholder regions that are
492-
/// in `skols`. This is used after a higher-ranked operation
493-
/// completes to remove all trace of the placeholder regions
494-
/// created in that time.
495-
pub fn pop_placeholders(&mut self, placeholders: &FxHashSet<ty::Region<'tcx>>) {
496-
debug!("pop_placeholders(placeholders={:?})", placeholders);
497-
498-
assert!(UndoLogs::<super::UndoLog<'_>>::in_snapshot(&self.undo_log));
499-
500-
let constraints_to_kill: Vec<usize> = self
501-
.undo_log
502-
.iter()
503-
.enumerate()
504-
.rev()
505-
.filter(|&(_, undo_entry)| match undo_entry {
506-
super::UndoLog::RegionConstraintCollector(undo_entry) => {
507-
kill_constraint(placeholders, undo_entry)
508-
}
509-
_ => false,
510-
})
511-
.map(|(index, _)| index)
512-
.collect();
513-
514-
for index in constraints_to_kill {
515-
let undo_entry = match &mut self.undo_log[index] {
516-
super::UndoLog::RegionConstraintCollector(undo_entry) => {
517-
mem::replace(undo_entry, Purged)
518-
}
519-
_ => unreachable!(),
520-
};
521-
self.rollback_undo_entry(undo_entry);
522-
}
523-
524-
return;
525-
526-
fn kill_constraint<'tcx>(
527-
placeholders: &FxHashSet<ty::Region<'tcx>>,
528-
undo_entry: &UndoLog<'tcx>,
529-
) -> bool {
530-
match undo_entry {
531-
&AddConstraint(Constraint::VarSubVar(..)) => false,
532-
&AddConstraint(Constraint::RegSubVar(a, _)) => placeholders.contains(&a),
533-
&AddConstraint(Constraint::VarSubReg(_, b)) => placeholders.contains(&b),
534-
&AddConstraint(Constraint::RegSubReg(a, b)) => {
535-
placeholders.contains(&a) || placeholders.contains(&b)
536-
}
537-
&AddGiven(..) => false,
538-
&AddVerify(_) => false,
539-
&AddCombination(_, ref two_regions) => {
540-
placeholders.contains(&two_regions.a) || placeholders.contains(&two_regions.b)
541-
}
542-
&AddVar(..) | &Purged => false,
543-
}
544-
}
545-
}
546-
547480
fn add_constraint(&mut self, constraint: Constraint<'tcx>, origin: SubregionOrigin<'tcx>) {
548481
// cannot add constraints once regions are resolved
549482
debug!("RegionConstraintCollector: add_constraint({:?})", constraint);

src/librustc_infer/infer/undo_log.rs

-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ impl<'tcx> InferCtxtUndoLogs<'tcx> {
198198
assert!(self.logs.len() >= snapshot.undo_len);
199199
assert!(self.num_open_snapshots > 0);
200200
}
201-
202-
pub(crate) fn iter(&self) -> std::slice::Iter<'_, UndoLog<'tcx>> {
203-
self.logs.iter()
204-
}
205201
}
206202

207203
impl<'tcx> std::ops::Index<usize> for InferCtxtUndoLogs<'tcx> {

src/librustc_infer/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ pub use self::project::{
2727
};
2828
pub use rustc_middle::traits::*;
2929

30-
/// An `Obligation` represents some trait reference (e.g., `int: Eq`) for
30+
/// An `Obligation` represents some trait reference (e.g., `i32: Eq`) for
3131
/// which the "impl_source" must be found. The process of finding a "impl_source" is
3232
/// called "resolving" the `Obligation`. This process consists of
33-
/// either identifying an `impl` (e.g., `impl Eq for int`) that
33+
/// either identifying an `impl` (e.g., `impl Eq for i32`) that
3434
/// satisfies the obligation, or else finding a bound that is in
3535
/// scope. The eventual result is usually a `Selection` (defined below).
3636
#[derive(Clone, PartialEq, Eq, Hash)]

src/librustc_infer/traits/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ impl PredicateSet<'tcx> {
6363
fn insert(&mut self, pred: ty::Predicate<'tcx>) -> bool {
6464
// We have to be careful here because we want
6565
//
66-
// for<'a> Foo<&'a int>
66+
// for<'a> Foo<&'a i32>
6767
//
6868
// and
6969
//
70-
// for<'b> Foo<&'b int>
70+
// for<'b> Foo<&'b i32>
7171
//
7272
// to be considered equivalent. So normalize all late-bound
7373
// regions before we throw things into the underlying set.

src/librustc_middle/traits/mod.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -393,23 +393,25 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
393393
/// ```
394394
/// impl<T:Clone> Clone<T> for Option<T> { ... } // Impl_1
395395
/// impl<T:Clone> Clone<T> for Box<T> { ... } // Impl_2
396-
/// impl Clone for int { ... } // Impl_3
396+
/// impl Clone for i32 { ... } // Impl_3
397397
///
398-
/// fn foo<T:Clone>(concrete: Option<Box<int>>,
399-
/// param: T,
400-
/// mixed: Option<T>) {
398+
/// fn foo<T: Clone>(concrete: Option<Box<i32>>, param: T, mixed: Option<T>) {
399+
/// // Case A: Vtable points at a specific impl. Only possible when
400+
/// // type is concretely known. If the impl itself has bounded
401+
/// // type parameters, Vtable will carry resolutions for those as well:
402+
/// concrete.clone(); // Vtable(Impl_1, [Vtable(Impl_2, [Vtable(Impl_3)])])
401403
///
402-
/// // Case A: ImplSource points at a specific impl. Only possible when
403-
/// // type is concretely known. If the impl itself has bounded
404-
/// // type parameters, ImplSource will carry resolutions for those as well:
405-
/// concrete.clone(); // ImplSource(Impl_1, [ImplSource(Impl_2, [ImplSource(Impl_3)])])
404+
/// // Case A: ImplSource points at a specific impl. Only possible when
405+
/// // type is concretely known. If the impl itself has bounded
406+
/// // type parameters, ImplSource will carry resolutions for those as well:
407+
/// concrete.clone(); // ImplSource(Impl_1, [ImplSource(Impl_2, [ImplSource(Impl_3)])])
406408
///
407-
/// // Case B: ImplSource must be provided by caller. This applies when
408-
/// // type is a type parameter.
409-
/// param.clone(); // ImplSourceParam
409+
/// // Case B: ImplSource must be provided by caller. This applies when
410+
/// // type is a type parameter.
411+
/// param.clone(); // ImplSourceParam
410412
///
411-
/// // Case C: A mix of cases A and B.
412-
/// mixed.clone(); // ImplSource(Impl_1, [ImplSourceParam])
413+
/// // Case C: A mix of cases A and B.
414+
/// mixed.clone(); // ImplSource(Impl_1, [ImplSourceParam])
413415
/// }
414416
/// ```
415417
///

src/librustc_middle/ty/subst.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
610610
///
611611
/// ```
612612
/// type Func<A> = fn(A);
613-
/// type MetaFunc = for<'a> fn(Func<&'a int>)
613+
/// type MetaFunc = for<'a> fn(Func<&'a i32>)
614614
/// ```
615615
///
616616
/// The type `MetaFunc`, when fully expanded, will be
617617
///
618-
/// for<'a> fn(fn(&'a int))
618+
/// for<'a> fn(fn(&'a i32))
619619
/// ^~ ^~ ^~~
620620
/// | | |
621621
/// | | DebruijnIndex of 2
@@ -624,26 +624,26 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
624624
/// Here the `'a` lifetime is bound in the outer function, but appears as an argument of the
625625
/// inner one. Therefore, that appearance will have a DebruijnIndex of 2, because we must skip
626626
/// over the inner binder (remember that we count De Bruijn indices from 1). However, in the
627-
/// definition of `MetaFunc`, the binder is not visible, so the type `&'a int` will have a
627+
/// definition of `MetaFunc`, the binder is not visible, so the type `&'a i32` will have a
628628
/// De Bruijn index of 1. It's only during the substitution that we can see we must increase the
629629
/// depth by 1 to account for the binder that we passed through.
630630
///
631631
/// As a second example, consider this twist:
632632
///
633633
/// ```
634634
/// type FuncTuple<A> = (A,fn(A));
635-
/// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a int>)
635+
/// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>)
636636
/// ```
637637
///
638638
/// Here the final type will be:
639639
///
640-
/// for<'a> fn((&'a int, fn(&'a int)))
640+
/// for<'a> fn((&'a i32, fn(&'a i32)))
641641
/// ^~~ ^~~
642642
/// | |
643643
/// DebruijnIndex of 1 |
644644
/// DebruijnIndex of 2
645645
///
646-
/// As indicated in the diagram, here the same type `&'a int` is substituted once, but in the
646+
/// As indicated in the diagram, here the same type `&'a i32` is substituted once, but in the
647647
/// first case we do not increase the De Bruijn index and in the second case we do. The reason
648648
/// is that only in the second case have we passed through a fn binder.
649649
fn shift_vars_through_binders<T: TypeFoldable<'tcx>>(&self, val: T) -> T {

src/librustc_middle/ty/walk.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ impl<'tcx> TypeWalker<'tcx> {
2222
/// Skips the subtree corresponding to the last type
2323
/// returned by `next()`.
2424
///
25-
/// Example: Imagine you are walking `Foo<Bar<int>, usize>`.
25+
/// Example: Imagine you are walking `Foo<Bar<i32>, usize>`.
2626
///
2727
/// ```
2828
/// let mut iter: TypeWalker = ...;
2929
/// iter.next(); // yields Foo
30-
/// iter.next(); // yields Bar<int>
31-
/// iter.skip_current_subtree(); // skips int
30+
/// iter.next(); // yields Bar<i32>
31+
/// iter.skip_current_subtree(); // skips i32
3232
/// iter.next(); // yields usize
3333
/// ```
3434
pub fn skip_current_subtree(&mut self) {

src/librustc_trait_selection/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
361361
// handle normalization within binders because
362362
// otherwise we wind up a need to normalize when doing
363363
// trait matching (since you can have a trait
364-
// obligation like `for<'a> T::B : Fn(&'a int)`), but
364+
// obligation like `for<'a> T::B: Fn(&'a i32)`), but
365365
// we can't normalize with bound regions in scope. So
366366
// far now we just ignore binders but only normalize
367367
// if all bound regions are gone (and then we still

src/librustc_trait_selection/traits/query/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
145145
// handle normalization within binders because
146146
// otherwise we wind up a need to normalize when doing
147147
// trait matching (since you can have a trait
148-
// obligation like `for<'a> T::B : Fn(&'a int)`), but
148+
// obligation like `for<'a> T::B: Fn(&'a i32)`), but
149149
// we can't normalize with bound regions in scope. So
150150
// far now we just ignore binders but only normalize
151151
// if all bound regions are gone (and then we still

src/librustc_trait_selection/traits/select/confirmation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
553553
///
554554
/// Here is an example. Imagine we have a closure expression
555555
/// and we desugared it so that the type of the expression is
556-
/// `Closure`, and `Closure` expects an int as argument. Then it
556+
/// `Closure`, and `Closure` expects `i32` as argument. Then it
557557
/// is "as if" the compiler generated this impl:
558558
///
559-
/// impl Fn(int) for Closure { ... }
559+
/// impl Fn(i32) for Closure { ... }
560560
///
561-
/// Now imagine our obligation is `Fn(usize) for Closure`. So far
561+
/// Now imagine our obligation is `Closure: Fn(usize)`. So far
562562
/// we have matched the self type `Closure`. At this point we'll
563-
/// compare the `int` to `usize` and generate an error.
563+
/// compare the `i32` to `usize` and generate an error.
564564
///
565565
/// Note that this checking occurs *after* the impl has selected,
566566
/// because these output type parameters should not affect the

src/librustc_trait_selection/traits/select/mod.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -1748,38 +1748,37 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17481748
) -> Vec<PredicateObligation<'tcx>> {
17491749
// Because the types were potentially derived from
17501750
// higher-ranked obligations they may reference late-bound
1751-
// regions. For example, `for<'a> Foo<&'a int> : Copy` would
1752-
// yield a type like `for<'a> &'a int`. In general, we
1751+
// regions. For example, `for<'a> Foo<&'a i32> : Copy` would
1752+
// yield a type like `for<'a> &'a i32`. In general, we
17531753
// maintain the invariant that we never manipulate bound
17541754
// regions, so we have to process these bound regions somehow.
17551755
//
17561756
// The strategy is to:
17571757
//
17581758
// 1. Instantiate those regions to placeholder regions (e.g.,
1759-
// `for<'a> &'a int` becomes `&0 int`.
1760-
// 2. Produce something like `&'0 int : Copy`
1761-
// 3. Re-bind the regions back to `for<'a> &'a int : Copy`
1759+
// `for<'a> &'a i32` becomes `&0 i32`.
1760+
// 2. Produce something like `&'0 i32 : Copy`
1761+
// 3. Re-bind the regions back to `for<'a> &'a i32 : Copy`
17621762

17631763
types
1764-
.skip_binder()
1764+
.skip_binder() // binder moved -\
17651765
.iter()
17661766
.flat_map(|ty| {
1767-
// binder moved -\
17681767
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
17691768

17701769
self.infcx.commit_unconditionally(|_| {
1771-
let (skol_ty, _) = self.infcx.replace_bound_vars_with_placeholders(&ty);
1770+
let (placeholder_ty, _) = self.infcx.replace_bound_vars_with_placeholders(&ty);
17721771
let Normalized { value: normalized_ty, mut obligations } =
17731772
ensure_sufficient_stack(|| {
17741773
project::normalize_with_depth(
17751774
self,
17761775
param_env,
17771776
cause.clone(),
17781777
recursion_depth,
1779-
&skol_ty,
1778+
&placeholder_ty,
17801779
)
17811780
});
1782-
let skol_obligation = predicate_for_trait_def(
1781+
let placeholder_obligation = predicate_for_trait_def(
17831782
self.tcx(),
17841783
param_env,
17851784
cause.clone(),
@@ -1788,7 +1787,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17881787
normalized_ty,
17891788
&[],
17901789
);
1791-
obligations.push(skol_obligation);
1790+
obligations.push(placeholder_obligation);
17921791
obligations
17931792
})
17941793
})
@@ -1838,9 +1837,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18381837
return Err(());
18391838
}
18401839

1841-
let (skol_obligation, placeholder_map) =
1840+
let (placeholder_obligation, placeholder_map) =
18421841
self.infcx().replace_bound_vars_with_placeholders(&obligation.predicate);
1843-
let skol_obligation_trait_ref = skol_obligation.trait_ref;
1842+
let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
18441843

18451844
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
18461845

@@ -1859,14 +1858,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18591858

18601859
debug!(
18611860
"match_impl(impl_def_id={:?}, obligation={:?}, \
1862-
impl_trait_ref={:?}, skol_obligation_trait_ref={:?})",
1863-
impl_def_id, obligation, impl_trait_ref, skol_obligation_trait_ref
1861+
impl_trait_ref={:?}, placeholder_obligation_trait_ref={:?})",
1862+
impl_def_id, obligation, impl_trait_ref, placeholder_obligation_trait_ref
18641863
);
18651864

18661865
let InferOk { obligations, .. } = self
18671866
.infcx
18681867
.at(&obligation.cause, obligation.param_env)
1869-
.eq(skol_obligation_trait_ref, impl_trait_ref)
1868+
.eq(placeholder_obligation_trait_ref, impl_trait_ref)
18701869
.map_err(|e| debug!("match_impl: failed eq_trait_refs due to `{}`", e))?;
18711870
nested_obligations.extend(obligations);
18721871

src/librustc_trait_selection/traits/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
130130

131131
// We determine whether there's a subset relationship by:
132132
//
133-
// - skolemizing impl1,
133+
// - replacing bound vars with placeholders in impl1,
134134
// - assuming the where clauses for impl1,
135135
// - instantiating impl2 with fresh inference variables,
136136
// - unifying,

0 commit comments

Comments
 (0)