Skip to content

Commit 2065216

Browse files
committed
rustc: More interning for data used in Ty<'tcx>.
1 parent 8f72d81 commit 2065216

Some content is hidden

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

62 files changed

+402
-327
lines changed

src/librustc/infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ pub fn drain_fulfillment_cx<T>(&self,
10161016
pub fn fresh_substs_for_generics(&self,
10171017
span: Span,
10181018
generics: &ty::Generics<'tcx>)
1019-
-> subst::Substs<'tcx>
1019+
-> &'tcx subst::Substs<'tcx>
10201020
{
10211021
let type_params = subst::VecPerParamSpace::empty();
10221022

@@ -1034,7 +1034,7 @@ pub fn drain_fulfillment_cx<T>(&self,
10341034
generics.types.get_slice(*space));
10351035
}
10361036

1037-
return substs;
1037+
self.tcx.mk_substs(substs)
10381038
}
10391039

10401040
/// Given a set of generics defined on a trait, returns a substitution mapping each output
@@ -1533,7 +1533,7 @@ pub fn drain_fulfillment_cx<T>(&self,
15331533

15341534
pub fn closure_type(&self,
15351535
def_id: DefId,
1536-
substs: &ty::ClosureSubsts<'tcx>)
1536+
substs: ty::ClosureSubsts<'tcx>)
15371537
-> ty::ClosureTy<'tcx>
15381538
{
15391539
let closure_ty =

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14621462
fn fn_ret(&self, id: NodeId) -> ty::PolyFnOutput<'tcx> {
14631463
let fn_ty = self.ir.tcx.node_id_to_type(id);
14641464
match fn_ty.sty {
1465-
ty::TyClosure(closure_def_id, ref substs) =>
1465+
ty::TyClosure(closure_def_id, substs) =>
14661466
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
14671467
_ => fn_ty.fn_ret()
14681468
}

src/librustc/mir/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ pub enum AggregateKind<'tcx> {
816816
Vec,
817817
Tuple,
818818
Adt(AdtDef<'tcx>, usize, &'tcx Substs<'tcx>),
819-
Closure(DefId, &'tcx ClosureSubsts<'tcx>),
819+
Closure(DefId, ClosureSubsts<'tcx>),
820820
}
821821

822822
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
8282
match *self {
8383
LvalueTy::Ty { ty } => LvalueTy::Ty { ty: ty.fold_with(folder) },
8484
LvalueTy::Downcast { adt_def, substs, variant_index } => {
85-
let substs = substs.fold_with(folder);
8685
LvalueTy::Downcast {
8786
adt_def: adt_def,
88-
substs: folder.tcx().mk_substs(substs),
87+
substs: substs.fold_with(folder),
8988
variant_index: variant_index
9089
}
9190
}
@@ -209,8 +208,7 @@ impl<'a, 'tcx> Mir<'tcx> {
209208
Some(def.type_scheme(tcx).ty.subst(tcx, substs))
210209
}
211210
AggregateKind::Closure(did, substs) => {
212-
Some(tcx.mk_closure_from_closure_substs(
213-
did, Box::new(substs.clone())))
211+
Some(tcx.mk_closure_from_closure_substs(did, substs))
214212
}
215213
}
216214
}

src/librustc/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ macro_rules! make_mir_visitor {
197197
}
198198

199199
fn visit_closure_substs(&mut self,
200-
substs: & $($mutability)* &'tcx ClosureSubsts<'tcx>) {
200+
substs: & $($mutability)* ClosureSubsts<'tcx>) {
201201
self.super_closure_substs(substs);
202202
}
203203

@@ -681,7 +681,7 @@ macro_rules! make_mir_visitor {
681681
}
682682

683683
fn super_closure_substs(&mut self,
684-
_substs: & $($mutability)* &'tcx ClosureSubsts<'tcx>) {
684+
_substs: & $($mutability)* ClosureSubsts<'tcx>) {
685685
}
686686

687687
fn super_const_val(&mut self, _substs: & $($mutability)* ConstVal) {

src/librustc/traits/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fn consider_unification_despite_ambiguity<'cx, 'gcx, 'tcx>(
259259
debug!("consider_unification_despite_ambiguity: self_ty.sty={:?}",
260260
self_ty.sty);
261261
match self_ty.sty {
262-
ty::TyClosure(closure_def_id, ref substs) => {
262+
ty::TyClosure(closure_def_id, substs) => {
263263
let closure_typer = selcx.closure_typer();
264264
let closure_type = closure_typer.closure_type(closure_def_id, substs);
265265
let ty::Binder((_, ret_type)) =
@@ -1021,7 +1021,7 @@ fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
10211021
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
10221022
{
10231023
let closure_typer = selcx.closure_typer();
1024-
let closure_type = closure_typer.closure_type(vtable.closure_def_id, &vtable.substs);
1024+
let closure_type = closure_typer.closure_type(vtable.closure_def_id, vtable.substs);
10251025
let Normalized {
10261026
value: closure_type,
10271027
mut obligations

src/librustc/traits/select.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ enum SelectionCandidate<'tcx> {
197197
/// Implementation of a `Fn`-family trait by one of the anonymous types
198198
/// generated for a `||` expression. The ty::ClosureKind informs the
199199
/// confirmation step what ClosureKind obligation to emit.
200-
ClosureCandidate(/* closure */ DefId, &'tcx ty::ClosureSubsts<'tcx>, ty::ClosureKind),
200+
ClosureCandidate(/* closure */ DefId, ty::ClosureSubsts<'tcx>, ty::ClosureKind),
201201

202202
/// Implementation of a `Fn`-family trait by one of the anonymous
203203
/// types generated for a fn pointer type (e.g., `fn(int)->int`)
@@ -1270,7 +1270,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12701270
// type/region parameters
12711271
let self_ty = *obligation.self_ty().skip_binder();
12721272
let (closure_def_id, substs) = match self_ty.sty {
1273-
ty::TyClosure(id, ref substs) => (id, substs),
1273+
ty::TyClosure(id, substs) => (id, substs),
12741274
ty::TyInfer(ty::TyVar(_)) => {
12751275
debug!("assemble_unboxed_closure_candidates: ambiguous self-type");
12761276
candidates.ambiguous = true;
@@ -1707,16 +1707,16 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17071707

17081708
ty::TyStr | ty::TySlice(_) | ty::TyTrait(..) => Never,
17091709

1710-
ty::TyTuple(ref tys) => {
1710+
ty::TyTuple(tys) => {
17111711
// FIXME(#33242) we only need to constrain the last field
1712-
Where(ty::Binder(tys.clone()))
1712+
Where(ty::Binder(tys.to_vec()))
17131713
}
17141714

17151715
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
17161716
let sized_crit = def.sized_constraint(self.tcx());
17171717
// (*) binder moved here
17181718
Where(ty::Binder(match sized_crit.sty {
1719-
ty::TyTuple(ref tys) => tys.to_owned().subst(self.tcx(), substs),
1719+
ty::TyTuple(tys) => tys.to_vec().subst(self.tcx(), substs),
17201720
ty::TyBool => vec![],
17211721
_ => vec![sized_crit.subst(self.tcx(), substs)]
17221722
}))
@@ -1763,9 +1763,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17631763
Where(ty::Binder(vec![element_ty]))
17641764
}
17651765

1766-
ty::TyTuple(ref tys) => {
1766+
ty::TyTuple(tys) => {
17671767
// (*) binder moved here
1768-
Where(ty::Binder(tys.clone()))
1768+
Where(ty::Binder(tys.to_vec()))
17691769
}
17701770

17711771
ty::TyStruct(..) | ty::TyEnum(..) | ty::TyProjection(..) | ty::TyParam(..) => {
@@ -1842,7 +1842,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18421842

18431843
ty::TyTuple(ref tys) => {
18441844
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
1845-
tys.clone()
1845+
tys.to_vec()
18461846
}
18471847

18481848
ty::TyClosure(_, ref substs) => {
@@ -1854,7 +1854,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18541854
// OIBIT interact? That is, there is no way to say
18551855
// "make me invariant with respect to this TYPE, but
18561856
// do not act as though I can reach it"
1857-
substs.upvar_tys.clone()
1857+
substs.upvar_tys.to_vec()
18581858
}
18591859

18601860
// for `PhantomData<T>`, we pass `T`
@@ -2188,7 +2188,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21882188

21892189
fn vtable_impl(&mut self,
21902190
impl_def_id: DefId,
2191-
mut substs: Normalized<'tcx, Substs<'tcx>>,
2191+
mut substs: Normalized<'tcx, &'tcx Substs<'tcx>>,
21922192
cause: ObligationCause<'tcx>,
21932193
recursion_depth: usize,
21942194
skol_map: infer::SkolemizationMap,
@@ -2221,7 +2221,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
22212221
impl_obligations.append(&mut substs.obligations);
22222222

22232223
VtableImplData { impl_def_id: impl_def_id,
2224-
substs: self.tcx().mk_substs(substs.value),
2224+
substs: substs.value,
22252225
nested: impl_obligations }
22262226
}
22272227

@@ -2311,7 +2311,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23112311
fn confirm_closure_candidate(&mut self,
23122312
obligation: &TraitObligation<'tcx>,
23132313
closure_def_id: DefId,
2314-
substs: &ty::ClosureSubsts<'tcx>,
2314+
substs: ty::ClosureSubsts<'tcx>,
23152315
kind: ty::ClosureKind)
23162316
-> Result<VtableClosureData<'tcx, PredicateObligation<'tcx>>,
23172317
SelectionError<'tcx>>
@@ -2586,7 +2586,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25862586
impl_def_id: DefId,
25872587
obligation: &TraitObligation<'tcx>,
25882588
snapshot: &infer::CombinedSnapshot)
2589-
-> (Normalized<'tcx, Substs<'tcx>>, infer::SkolemizationMap)
2589+
-> (Normalized<'tcx, &'tcx Substs<'tcx>>, infer::SkolemizationMap)
25902590
{
25912591
match self.match_impl(impl_def_id, obligation, snapshot) {
25922592
Ok((substs, skol_map)) => (substs, skol_map),
@@ -2602,7 +2602,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26022602
impl_def_id: DefId,
26032603
obligation: &TraitObligation<'tcx>,
26042604
snapshot: &infer::CombinedSnapshot)
2605-
-> Result<(Normalized<'tcx, Substs<'tcx>>,
2605+
-> Result<(Normalized<'tcx, &'tcx Substs<'tcx>>,
26062606
infer::SkolemizationMap), ()>
26072607
{
26082608
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
@@ -2752,7 +2752,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27522752
fn closure_trait_ref_unnormalized(&mut self,
27532753
obligation: &TraitObligation<'tcx>,
27542754
closure_def_id: DefId,
2755-
substs: &ty::ClosureSubsts<'tcx>)
2755+
substs: ty::ClosureSubsts<'tcx>)
27562756
-> ty::PolyTraitRef<'tcx>
27572757
{
27582758
let closure_type = self.infcx.closure_type(closure_def_id, substs);
@@ -2773,7 +2773,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27732773
fn closure_trait_ref(&mut self,
27742774
obligation: &TraitObligation<'tcx>,
27752775
closure_def_id: DefId,
2776-
substs: &ty::ClosureSubsts<'tcx>)
2776+
substs: ty::ClosureSubsts<'tcx>)
27772777
-> Normalized<'tcx, ty::PolyTraitRef<'tcx>>
27782778
{
27792779
let trait_ref = self.closure_trait_ref_unnormalized(

src/librustc/traits/specialize/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
9696
specializaiton failed to hold")
9797
})
9898
}
99-
specialization_graph::Node::Trait(..) => source_trait_ref.substs.clone(),
99+
specialization_graph::Node::Trait(..) => source_trait_ref.substs,
100100
};
101101

102102
// directly inherent the method generics, since those do not vary across impls
@@ -171,7 +171,7 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
171171
fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
172172
source_trait_ref: ty::TraitRef<'tcx>,
173173
target_impl: DefId)
174-
-> Result<Substs<'tcx>, ()> {
174+
-> Result<&'tcx Substs<'tcx>, ()> {
175175
infcx.commit_if_ok(|_| {
176176
let selcx = &mut SelectionContext::new(&infcx);
177177
let target_substs = fresh_type_vars_for_impl(&infcx, DUMMY_SP, target_impl);

src/librustc/traits/structural_impls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx
173173

174174
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> {
175175
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
176-
let substs = self.substs.fold_with(folder);
177176
traits::VtableImplData {
178177
impl_def_id: self.impl_def_id,
179-
substs: folder.tcx().mk_substs(substs),
178+
substs: self.substs.fold_with(folder),
180179
nested: self.nested.fold_with(folder),
181180
}
182181
}

src/librustc/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
356356
pub fn fresh_type_vars_for_impl<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
357357
span: Span,
358358
impl_def_id: DefId)
359-
-> Substs<'tcx>
359+
-> &'tcx Substs<'tcx>
360360
{
361361
let tcx = infcx.tcx;
362362
let impl_generics = tcx.lookup_item_type(impl_def_id).generics;

src/librustc/ty/adjustment.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ impl<'a, 'gcx, 'tcx> ty::TyS<'tcx> {
156156
match *adjustment {
157157
AdjustReifyFnPointer => {
158158
match self.sty {
159-
ty::TyFnDef(_, _, b) => {
160-
tcx.mk_ty(ty::TyFnPtr(b))
161-
}
159+
ty::TyFnDef(_, _, f) => tcx.mk_fn_ptr(f),
162160
_ => {
163161
bug!("AdjustReifyFnPointer adjustment on non-fn-item: {:?}",
164162
self);

0 commit comments

Comments
 (0)