Skip to content

Commit f0be457

Browse files
committed
Auto merge of #58321 - csmoe:substs, r=oli-obk
[Step 1] Implement "small substs optimization" for substs of length 1 addresses part of #58310 r?@arielb1
2 parents 02c4c28 + cf11729 commit f0be457

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+385
-379
lines changed

src/librustc/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use crate::traits::query::{
6767
};
6868
use crate::ty::{TyCtxt, FnSig, Instance, InstanceDef,
6969
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
70-
use crate::ty::subst::Substs;
70+
use crate::ty::subst::SubstsRef;
7171

7272
// erase!() just makes tokens go away. It's used to specify which macro argument
7373
// is repeated (i.e., which sub-expression of the macro we are in) but don't need
@@ -661,7 +661,7 @@ define_dep_nodes!( <'tcx>
661661
[] TypeOpNormalizePolyFnSig(CanonicalTypeOpNormalizeGoal<'tcx, PolyFnSig<'tcx>>),
662662
[] TypeOpNormalizeFnSig(CanonicalTypeOpNormalizeGoal<'tcx, FnSig<'tcx>>),
663663

664-
[] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) },
664+
[] SubstituteNormalizeAndTestPredicates { key: (DefId, SubstsRef<'tcx>) },
665665
[] MethodAutoderefSteps(CanonicalTyGoal<'tcx>),
666666

667667
[input] TargetFeaturesWhitelist,

src/librustc/infer/combine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::ty::{IntType, UintType};
3434
use crate::ty::{self, Ty, TyCtxt};
3535
use crate::ty::error::TypeError;
3636
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
37-
use crate::ty::subst::Substs;
37+
use crate::ty::subst::SubstsRef;
3838
use crate::traits::{Obligation, PredicateObligations};
3939

4040
use syntax::ast;
@@ -373,9 +373,9 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
373373

374374
fn relate_item_substs(&mut self,
375375
item_def_id: DefId,
376-
a_subst: &'tcx Substs<'tcx>,
377-
b_subst: &'tcx Substs<'tcx>)
378-
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
376+
a_subst: SubstsRef<'tcx>,
377+
b_subst: SubstsRef<'tcx>)
378+
-> RelateResult<'tcx, SubstsRef<'tcx>>
379379
{
380380
if self.ambient_variance == ty::Variance::Invariant {
381381
// Avoid fetching the variance if we are in an invariant

src/librustc/infer/equate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::hir::def_id::DefId;
55

66
use crate::ty::{self, Ty, TyCtxt};
77
use crate::ty::TyVar;
8-
use crate::ty::subst::Substs;
8+
use crate::ty::subst::SubstsRef;
99
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
1010

1111
/// Ensures `a` is made equal to `b`. Returns `a` on success.
@@ -33,9 +33,9 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
3333

3434
fn relate_item_substs(&mut self,
3535
_item_def_id: DefId,
36-
a_subst: &'tcx Substs<'tcx>,
37-
b_subst: &'tcx Substs<'tcx>)
38-
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
36+
a_subst: SubstsRef<'tcx>,
37+
b_subst: SubstsRef<'tcx>)
38+
-> RelateResult<'tcx, SubstsRef<'tcx>>
3939
{
4040
// N.B., once we are equating types, we don't care about
4141
// variance, so don't try to lookup the variance here. This

src/librustc/infer/error_reporting/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use crate::hir::Node;
5656
use crate::middle::region;
5757
use crate::traits::{ObligationCause, ObligationCauseCode};
5858
use crate::ty::error::TypeError;
59-
use crate::ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable};
59+
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TyKind, TypeFoldable};
6060
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6161
use std::{cmp, fmt};
6262
use syntax_pos::{Pos, Span};
@@ -570,7 +570,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
570570
value: &mut DiagnosticStyledString,
571571
other_value: &mut DiagnosticStyledString,
572572
name: String,
573-
sub: &ty::subst::Substs<'tcx>,
573+
sub: ty::subst::SubstsRef<'tcx>,
574574
pos: usize,
575575
other_ty: &Ty<'tcx>,
576576
) {
@@ -648,7 +648,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
648648
mut t1_out: &mut DiagnosticStyledString,
649649
mut t2_out: &mut DiagnosticStyledString,
650650
path: String,
651-
sub: &ty::subst::Substs<'tcx>,
651+
sub: ty::subst::SubstsRef<'tcx>,
652652
other_path: String,
653653
other_ty: &Ty<'tcx>,
654654
) -> Option<()> {
@@ -687,8 +687,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
687687
fn strip_generic_default_params(
688688
&self,
689689
def_id: DefId,
690-
substs: &ty::subst::Substs<'tcx>,
691-
) -> &'tcx ty::subst::Substs<'tcx> {
690+
substs: ty::subst::SubstsRef<'tcx>,
691+
) -> SubstsRef<'tcx> {
692692
let generics = self.tcx.generics_of(def_id);
693693
let mut num_supplied_defaults = 0;
694694
let mut type_params = generics

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::infer::{SubregionOrigin, TypeTrace};
77
use crate::traits::{ObligationCause, ObligationCauseCode};
88
use crate::ty;
99
use crate::ty::error::ExpectedFound;
10-
use crate::ty::subst::Substs;
10+
use crate::ty::subst::SubstsRef;
1111
use crate::util::ppaux::RegionHighlightMode;
1212

1313
impl NiceRegionError<'me, 'gcx, 'tcx> {
@@ -175,8 +175,8 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
175175
sub_placeholder: Option<ty::Region<'tcx>>,
176176
sup_placeholder: Option<ty::Region<'tcx>>,
177177
trait_def_id: DefId,
178-
expected_substs: &'tcx Substs<'tcx>,
179-
actual_substs: &'tcx Substs<'tcx>,
178+
expected_substs: SubstsRef<'tcx>,
179+
actual_substs: SubstsRef<'tcx>,
180180
) -> DiagnosticBuilder<'me> {
181181
debug!(
182182
"try_report_placeholders_trait(\

src/librustc/infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
1818
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
1919
use crate::ty::fold::TypeFoldable;
2020
use crate::ty::relate::RelateResult;
21-
use crate::ty::subst::{Kind, Substs};
21+
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef};
2222
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
2323
use crate::ty::{FloatVid, IntVid, TyVid};
2424
use crate::util::nodemap::FxHashMap;
@@ -1088,8 +1088,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10881088

10891089
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
10901090
/// type/region parameter to a fresh inference variable.
1091-
pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> &'tcx Substs<'tcx> {
1092-
Substs::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
1091+
pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> SubstsRef<'tcx> {
1092+
InternalSubsts::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
10931093
}
10941094

10951095
/// Returns `true` if errors have been reported since this infcx was

src/librustc/infer/opaque_types/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::traits::{self, PredicateObligation};
99
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
1010
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
1111
use crate::ty::outlives::Component;
12-
use crate::ty::subst::{Kind, Substs, UnpackedKind};
12+
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, UnpackedKind};
1313
use crate::util::nodemap::DefIdMap;
1414

1515
pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
@@ -30,7 +30,7 @@ pub struct OpaqueTypeDecl<'tcx> {
3030
/// fn foo<'a, 'b, T>() -> Foo<'a, T>
3131
///
3232
/// then `substs` would be `['a, T]`.
33-
pub substs: &'tcx Substs<'tcx>,
33+
pub substs: SubstsRef<'tcx>,
3434

3535
/// The type variable that represents the value of the abstract type
3636
/// that we require. In other words, after we compile this function,
@@ -437,7 +437,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
437437
// lifetimes with 'static and remapping only those used in the
438438
// `impl Trait` return type, resulting in the parameters
439439
// shifting.
440-
let id_substs = Substs::identity_for_item(gcx, def_id);
440+
let id_substs = InternalSubsts::identity_for_item(gcx, def_id);
441441
let map: FxHashMap<Kind<'tcx>, Kind<'gcx>> = opaque_defn
442442
.substs
443443
.iter()
@@ -740,7 +740,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
740740
&mut self,
741741
ty: Ty<'tcx>,
742742
def_id: DefId,
743-
substs: &'tcx Substs<'tcx>,
743+
substs: SubstsRef<'tcx>,
744744
) -> Ty<'tcx> {
745745
let infcx = self.infcx;
746746
let tcx = infcx.tcx;

src/librustc/infer/outlives/verify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::hir::def_id::DefId;
22
use crate::infer::outlives::env::RegionBoundPairs;
33
use crate::infer::{GenericKind, VerifyBound};
44
use crate::traits;
5-
use crate::ty::subst::{Subst, Substs};
5+
use crate::ty::subst::{Subst, InternalSubsts};
66
use crate::ty::{self, Ty, TyCtxt};
77
use crate::util::captures::Captures;
88

@@ -292,7 +292,7 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
292292
.iter()
293293
.map(|(p, _)| *p)
294294
.collect();
295-
let identity_substs = Substs::identity_for_item(tcx, assoc_item_def_id);
295+
let identity_substs = InternalSubsts::identity_for_item(tcx, assoc_item_def_id);
296296
let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs);
297297
self.collect_outlives_from_predicate_list(
298298
move |ty| ty == identity_proj,

src/librustc/middle/exported_symbols.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
55
use std::cmp;
66
use std::mem;
77
use crate::ty;
8-
use crate::ty::subst::Substs;
8+
use crate::ty::subst::SubstsRef;
99

1010
/// The SymbolExportLevel of a symbols specifies from which kinds of crates
1111
/// the symbol will be exported. `C` symbols will be exported from any
@@ -33,7 +33,7 @@ impl SymbolExportLevel {
3333
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
3434
pub enum ExportedSymbol<'tcx> {
3535
NonGeneric(DefId),
36-
Generic(DefId, &'tcx Substs<'tcx>),
36+
Generic(DefId, SubstsRef<'tcx>),
3737
NoDefId(ty::SymbolName),
3838
}
3939

src/librustc/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax::ast::{self, Name};
2727
use syntax::symbol::InternedString;
2828
use syntax_pos::{Span, DUMMY_SP};
2929
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
30-
use crate::ty::subst::{Subst, Substs};
30+
use crate::ty::subst::{Subst, SubstsRef};
3131
use crate::ty::layout::VariantIdx;
3232
use crate::ty::{
3333
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
@@ -2151,7 +2151,7 @@ impl<'tcx> Operand<'tcx> {
21512151
pub fn function_handle<'a>(
21522152
tcx: TyCtxt<'a, 'tcx, 'tcx>,
21532153
def_id: DefId,
2154-
substs: &'tcx Substs<'tcx>,
2154+
substs: SubstsRef<'tcx>,
21552155
span: Span,
21562156
) -> Self {
21572157
let ty = tcx.type_of(def_id).subst(tcx, substs);
@@ -2247,7 +2247,7 @@ pub enum AggregateKind<'tcx> {
22472247
Adt(
22482248
&'tcx AdtDef,
22492249
VariantIdx,
2250-
&'tcx Substs<'tcx>,
2250+
SubstsRef<'tcx>,
22512251
Option<UserTypeAnnotationIndex>,
22522252
Option<usize>,
22532253
),

src/librustc/mir/tcx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
use crate::mir::*;
7-
use crate::ty::subst::{Subst, Substs};
7+
use crate::ty::subst::{Subst, SubstsRef};
88
use crate::ty::{self, AdtDef, Ty, TyCtxt};
99
use crate::ty::layout::VariantIdx;
1010
use crate::hir;
@@ -17,7 +17,7 @@ pub enum PlaceTy<'tcx> {
1717

1818
/// Downcast to a particular variant of an enum.
1919
Downcast { adt_def: &'tcx AdtDef,
20-
substs: &'tcx Substs<'tcx>,
20+
substs: SubstsRef<'tcx>,
2121
variant_index: VariantIdx },
2222
}
2323

src/librustc/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::hir::def_id::DefId;
2-
use crate::ty::subst::Substs;
2+
use crate::ty::subst::SubstsRef;
33
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
44
use crate::mir::*;
55
use syntax_pos::Span;
@@ -238,7 +238,7 @@ macro_rules! make_mir_visitor {
238238
}
239239

240240
fn visit_substs(&mut self,
241-
substs: & $($mutability)? &'tcx Substs<'tcx>,
241+
substs: & $($mutability)? SubstsRef<'tcx>,
242242
_: Location) {
243243
self.super_substs(substs);
244244
}
@@ -889,7 +889,7 @@ macro_rules! make_mir_visitor {
889889
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::LazyConst<'tcx>) {
890890
}
891891

892-
fn super_substs(&mut self, _substs: & $($mutability)? &'tcx Substs<'tcx>) {
892+
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
893893
}
894894

895895
fn super_generator_substs(&mut self,

src/librustc/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
631631
finished_map
632632
}
633633

634-
fn is_param_no_infer(&self, substs: &Substs<'_>) -> bool {
634+
fn is_param_no_infer(&self, substs: SubstsRef<'_>) -> bool {
635635
return self.is_of_param(substs.type_at(0)) &&
636636
!substs.types().any(|t| t.has_infer_types());
637637
}

src/librustc/traits/codegen/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use syntax_pos::Span;
1111
use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
1212
TraitEngine, Vtable};
1313
use crate::ty::{self, Ty, TyCtxt};
14-
use crate::ty::subst::{Subst, Substs};
14+
use crate::ty::subst::{Subst, SubstsRef};
1515
use crate::ty::fold::TypeFoldable;
1616

1717
/// Attempts to resolve an obligation to a vtable. The result is
@@ -82,7 +82,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
8282
/// types.
8383
pub fn subst_and_normalize_erasing_regions<T>(
8484
self,
85-
param_substs: &Substs<'tcx>,
85+
param_substs: SubstsRef<'tcx>,
8686
param_env: ty::ParamEnv<'tcx>,
8787
value: &T
8888
) -> T

src/librustc/traits/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::mir::interpret::ErrorHandled;
2929
use rustc_data_structures::sync::Lrc;
3030
use syntax::ast;
3131
use syntax_pos::{Span, DUMMY_SP};
32-
use crate::ty::subst::Substs;
32+
use crate::ty::subst::{InternalSubsts, SubstsRef};
3333
use crate::ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
3434
use crate::ty::error::{ExpectedFound, TypeError};
3535
use crate::ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
@@ -565,7 +565,7 @@ pub enum Vtable<'tcx, N> {
565565
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
566566
pub struct VtableImplData<'tcx, N> {
567567
pub impl_def_id: DefId,
568-
pub substs: &'tcx Substs<'tcx>,
568+
pub substs: SubstsRef<'tcx>,
569569
pub nested: Vec<N>
570570
}
571571

@@ -622,7 +622,7 @@ pub struct VtableFnPointerData<'tcx, N> {
622622
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
623623
pub struct VtableTraitAliasData<'tcx, N> {
624624
pub alias_def_id: DefId,
625-
pub substs: &'tcx Substs<'tcx>,
625+
pub substs: SubstsRef<'tcx>,
626626
pub nested: Vec<N>,
627627
}
628628

@@ -963,7 +963,7 @@ fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
963963
}
964964

965965
fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
966-
key: (DefId, &'tcx Substs<'tcx>))
966+
key: (DefId, SubstsRef<'tcx>))
967967
-> bool
968968
{
969969
debug!("substitute_normalize_and_test_predicates(key={:?})",
@@ -983,7 +983,7 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
983983
fn vtable_methods<'a, 'tcx>(
984984
tcx: TyCtxt<'a, 'tcx, 'tcx>,
985985
trait_ref: ty::PolyTraitRef<'tcx>)
986-
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
986+
-> Lrc<Vec<Option<(DefId, SubstsRef<'tcx>)>>>
987987
{
988988
debug!("vtable_methods({:?})", trait_ref);
989989

@@ -992,7 +992,7 @@ fn vtable_methods<'a, 'tcx>(
992992
let trait_methods = tcx.associated_items(trait_ref.def_id())
993993
.filter(|item| item.kind == ty::AssociatedKind::Method);
994994

995-
// Now list each method's DefId and Substs (for within its trait).
995+
// Now list each method's DefId and InternalSubsts (for within its trait).
996996
// If the method can never be called from this object, produce None.
997997
trait_methods.map(move |trait_method| {
998998
debug!("vtable_methods: trait_method={:?}", trait_method);
@@ -1007,7 +1007,7 @@ fn vtable_methods<'a, 'tcx>(
10071007
// the method may have some early-bound lifetimes, add
10081008
// regions for those
10091009
let substs = trait_ref.map_bound(|trait_ref|
1010-
Substs::for_item(tcx, def_id, |param, _|
1010+
InternalSubsts::for_item(tcx, def_id, |param, _|
10111011
match param.kind {
10121012
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
10131013
GenericParamDefKind::Type {..} => {

0 commit comments

Comments
 (0)