Skip to content

Commit

Permalink
Auto merge of #58321 - csmoe:substs, r=oli-obk
Browse files Browse the repository at this point in the history
[Step 1] Implement "small substs optimization" for substs of length 1

addresses part of #58310
r?@arielb1
  • Loading branch information
bors committed Feb 27, 2019
2 parents 02c4c28 + cf11729 commit f0be457
Show file tree
Hide file tree
Showing 91 changed files with 385 additions and 379 deletions.
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use crate::traits::query::{
};
use crate::ty::{TyCtxt, FnSig, Instance, InstanceDef,
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;

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

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

[input] TargetFeaturesWhitelist,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::ty::{IntType, UintType};
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::error::TypeError;
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::traits::{Obligation, PredicateObligations};

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

fn relate_item_substs(&mut self,
item_def_id: DefId,
a_subst: &'tcx Substs<'tcx>,
b_subst: &'tcx Substs<'tcx>)
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>)
-> RelateResult<'tcx, SubstsRef<'tcx>>
{
if self.ambient_variance == ty::Variance::Invariant {
// Avoid fetching the variance if we are in an invariant
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::hir::def_id::DefId;

use crate::ty::{self, Ty, TyCtxt};
use crate::ty::TyVar;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};

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

fn relate_item_substs(&mut self,
_item_def_id: DefId,
a_subst: &'tcx Substs<'tcx>,
b_subst: &'tcx Substs<'tcx>)
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>)
-> RelateResult<'tcx, SubstsRef<'tcx>>
{
// N.B., once we are equating types, we don't care about
// variance, so don't try to lookup the variance here. This
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use crate::hir::Node;
use crate::middle::region;
use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty::error::TypeError;
use crate::ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable};
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TyKind, TypeFoldable};
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use std::{cmp, fmt};
use syntax_pos::{Pos, Span};
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
value: &mut DiagnosticStyledString,
other_value: &mut DiagnosticStyledString,
name: String,
sub: &ty::subst::Substs<'tcx>,
sub: ty::subst::SubstsRef<'tcx>,
pos: usize,
other_ty: &Ty<'tcx>,
) {
Expand Down Expand Up @@ -648,7 +648,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
mut t1_out: &mut DiagnosticStyledString,
mut t2_out: &mut DiagnosticStyledString,
path: String,
sub: &ty::subst::Substs<'tcx>,
sub: ty::subst::SubstsRef<'tcx>,
other_path: String,
other_ty: &Ty<'tcx>,
) -> Option<()> {
Expand Down Expand Up @@ -687,8 +687,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fn strip_generic_default_params(
&self,
def_id: DefId,
substs: &ty::subst::Substs<'tcx>,
) -> &'tcx ty::subst::Substs<'tcx> {
substs: ty::subst::SubstsRef<'tcx>,
) -> SubstsRef<'tcx> {
let generics = self.tcx.generics_of(def_id);
let mut num_supplied_defaults = 0;
let mut type_params = generics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::infer::{SubregionOrigin, TypeTrace};
use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty;
use crate::ty::error::ExpectedFound;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::util::ppaux::RegionHighlightMode;

impl NiceRegionError<'me, 'gcx, 'tcx> {
Expand Down Expand Up @@ -175,8 +175,8 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
sub_placeholder: Option<ty::Region<'tcx>>,
sup_placeholder: Option<ty::Region<'tcx>>,
trait_def_id: DefId,
expected_substs: &'tcx Substs<'tcx>,
actual_substs: &'tcx Substs<'tcx>,
expected_substs: SubstsRef<'tcx>,
actual_substs: SubstsRef<'tcx>,
) -> DiagnosticBuilder<'me> {
debug!(
"try_report_placeholders_trait(\
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use crate::ty::fold::TypeFoldable;
use crate::ty::relate::RelateResult;
use crate::ty::subst::{Kind, Substs};
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef};
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
use crate::ty::{FloatVid, IntVid, TyVid};
use crate::util::nodemap::FxHashMap;
Expand Down Expand Up @@ -1088,8 +1088,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

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

/// Returns `true` if errors have been reported since this infcx was
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::traits::{self, PredicateObligation};
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
use crate::ty::outlives::Component;
use crate::ty::subst::{Kind, Substs, UnpackedKind};
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, UnpackedKind};
use crate::util::nodemap::DefIdMap;

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

/// The type variable that represents the value of the abstract type
/// that we require. In other words, after we compile this function,
Expand Down Expand Up @@ -437,7 +437,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// lifetimes with 'static and remapping only those used in the
// `impl Trait` return type, resulting in the parameters
// shifting.
let id_substs = Substs::identity_for_item(gcx, def_id);
let id_substs = InternalSubsts::identity_for_item(gcx, def_id);
let map: FxHashMap<Kind<'tcx>, Kind<'gcx>> = opaque_defn
.substs
.iter()
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
&mut self,
ty: Ty<'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
) -> Ty<'tcx> {
let infcx = self.infcx;
let tcx = infcx.tcx;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::hir::def_id::DefId;
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::{GenericKind, VerifyBound};
use crate::traits;
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, InternalSubsts};
use crate::ty::{self, Ty, TyCtxt};
use crate::util::captures::Captures;

Expand Down Expand Up @@ -292,7 +292,7 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
.iter()
.map(|(p, _)| *p)
.collect();
let identity_substs = Substs::identity_for_item(tcx, assoc_item_def_id);
let identity_substs = InternalSubsts::identity_for_item(tcx, assoc_item_def_id);
let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs);
self.collect_outlives_from_predicate_list(
move |ty| ty == identity_proj,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/exported_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
use std::cmp;
use std::mem;
use crate::ty;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;

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

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use syntax::ast::{self, Name};
use syntax::symbol::InternedString;
use syntax_pos::{Span, DUMMY_SP};
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::layout::VariantIdx;
use crate::ty::{
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
Expand Down Expand Up @@ -2151,7 +2151,7 @@ impl<'tcx> Operand<'tcx> {
pub fn function_handle<'a>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
span: Span,
) -> Self {
let ty = tcx.type_of(def_id).subst(tcx, substs);
Expand Down Expand Up @@ -2247,7 +2247,7 @@ pub enum AggregateKind<'tcx> {
Adt(
&'tcx AdtDef,
VariantIdx,
&'tcx Substs<'tcx>,
SubstsRef<'tcx>,
Option<UserTypeAnnotationIndex>,
Option<usize>,
),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

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

/// Downcast to a particular variant of an enum.
Downcast { adt_def: &'tcx AdtDef,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
variant_index: VariantIdx },
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hir::def_id::DefId;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
use crate::mir::*;
use syntax_pos::Span;
Expand Down Expand Up @@ -238,7 +238,7 @@ macro_rules! make_mir_visitor {
}

fn visit_substs(&mut self,
substs: & $($mutability)? &'tcx Substs<'tcx>,
substs: & $($mutability)? SubstsRef<'tcx>,
_: Location) {
self.super_substs(substs);
}
Expand Down Expand Up @@ -889,7 +889,7 @@ macro_rules! make_mir_visitor {
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::LazyConst<'tcx>) {
}

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

fn super_generator_substs(&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
finished_map
}

fn is_param_no_infer(&self, substs: &Substs<'_>) -> bool {
fn is_param_no_infer(&self, substs: SubstsRef<'_>) -> bool {
return self.is_of_param(substs.type_at(0)) &&
!substs.types().any(|t| t.has_infer_types());
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use syntax_pos::Span;
use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
TraitEngine, Vtable};
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::fold::TypeFoldable;

/// Attempts to resolve an obligation to a vtable. The result is
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
/// types.
pub fn subst_and_normalize_erasing_regions<T>(
self,
param_substs: &Substs<'tcx>,
param_substs: SubstsRef<'tcx>,
param_env: ty::ParamEnv<'tcx>,
value: &T
) -> T
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::mir::interpret::ErrorHandled;
use rustc_data_structures::sync::Lrc;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
use crate::ty::subst::Substs;
use crate::ty::subst::{InternalSubsts, SubstsRef};
use crate::ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
use crate::ty::error::{ExpectedFound, TypeError};
use crate::ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
Expand Down Expand Up @@ -565,7 +565,7 @@ pub enum Vtable<'tcx, N> {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct VtableImplData<'tcx, N> {
pub impl_def_id: DefId,
pub substs: &'tcx Substs<'tcx>,
pub substs: SubstsRef<'tcx>,
pub nested: Vec<N>
}

Expand Down Expand Up @@ -622,7 +622,7 @@ pub struct VtableFnPointerData<'tcx, N> {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct VtableTraitAliasData<'tcx, N> {
pub alias_def_id: DefId,
pub substs: &'tcx Substs<'tcx>,
pub substs: SubstsRef<'tcx>,
pub nested: Vec<N>,
}

Expand Down Expand Up @@ -963,7 +963,7 @@ fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
key: (DefId, &'tcx Substs<'tcx>))
key: (DefId, SubstsRef<'tcx>))
-> bool
{
debug!("substitute_normalize_and_test_predicates(key={:?})",
Expand All @@ -983,7 +983,7 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
fn vtable_methods<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>)
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
-> Lrc<Vec<Option<(DefId, SubstsRef<'tcx>)>>>
{
debug!("vtable_methods({:?})", trait_ref);

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

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

0 comments on commit f0be457

Please sign in to comment.