Skip to content

Commit 83b1982

Browse files
Use TypedArena::alloc_slice in rustc.
1 parent a714c2a commit 83b1982

File tree

18 files changed

+54
-50
lines changed

18 files changed

+54
-50
lines changed

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'tcx> Rvalue<'tcx> {
163163
let lhs_ty = lhs.ty(mir, tcx);
164164
let rhs_ty = rhs.ty(mir, tcx);
165165
let ty = op.ty(tcx, lhs_ty, rhs_ty);
166-
let ty = tcx.mk_tup(vec![ty, tcx.types.bool]);
166+
let ty = tcx.mk_tup(&[ty, tcx.types.bool]);
167167
Some(ty)
168168
}
169169
&Rvalue::UnaryOp(_, ref operand) => {
@@ -184,7 +184,7 @@ impl<'tcx> Rvalue<'tcx> {
184184
}
185185
AggregateKind::Tuple => {
186186
Some(tcx.mk_tup(
187-
ops.iter().map(|op| op.ty(mir, tcx)).collect()
187+
&ops.iter().map(|op| op.ty(mir, tcx)).collect::<Vec<_>>()
188188
))
189189
}
190190
AggregateKind::Adt(def, _, substs, _) => {

src/librustc/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
486486
{
487487
let arguments_tuple = match tuple_arguments {
488488
TupleArgumentsFlag::No => sig.0.inputs[0],
489-
TupleArgumentsFlag::Yes => self.mk_tup(sig.0.inputs.to_vec()),
489+
TupleArgumentsFlag::Yes => self.mk_tup(&sig.0.inputs),
490490
};
491491
let trait_ref = ty::TraitRef {
492492
def_id: fn_trait_def_id,

src/librustc/ty/context.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ use hir;
5454
pub struct CtxtArenas<'tcx> {
5555
// internings
5656
type_: TypedArena<TyS<'tcx>>,
57-
type_list: TypedArena<Vec<Ty<'tcx>>>,
58-
substs: TypedArena<Vec<Kind<'tcx>>>,
57+
type_list: TypedArena<Ty<'tcx>>,
58+
substs: TypedArena<Kind<'tcx>>,
5959
bare_fn: TypedArena<BareFnTy<'tcx>>,
6060
region: TypedArena<Region>,
6161
stability: TypedArena<attr::Stability>,
@@ -1117,6 +1117,7 @@ impl<'tcx> Borrow<Region> for Interned<'tcx, Region> {
11171117

11181118
macro_rules! intern_method {
11191119
($lt_tcx:tt, $name:ident: $method:ident($alloc:ty,
1120+
$alloc_method:ident,
11201121
$alloc_to_key:expr,
11211122
$alloc_to_ret:expr,
11221123
$needs_infer:expr) -> $ty:ty) => {
@@ -1142,7 +1143,8 @@ macro_rules! intern_method {
11421143
let v = unsafe {
11431144
mem::transmute(v)
11441145
};
1145-
let i = ($alloc_to_ret)(self.global_interners.arenas.$name.alloc(v));
1146+
let i = ($alloc_to_ret)(self.global_interners.arenas.$name
1147+
.$alloc_method(v));
11461148
self.global_interners.$name.borrow_mut().insert(Interned(i));
11471149
return i;
11481150
}
@@ -1156,7 +1158,7 @@ macro_rules! intern_method {
11561158
}
11571159
}
11581160

1159-
let i = ($alloc_to_ret)(self.interners.arenas.$name.alloc(v));
1161+
let i = ($alloc_to_ret)(self.interners.arenas.$name.$alloc_method(v));
11601162
self.interners.$name.borrow_mut().insert(Interned(i));
11611163
i
11621164
}
@@ -1180,7 +1182,7 @@ macro_rules! direct_interners {
11801182
}
11811183
}
11821184

1183-
intern_method!($lt_tcx, $name: $method($ty, |x| x, |x| x, $needs_infer) -> $ty);)+
1185+
intern_method!($lt_tcx, $name: $method($ty, alloc, |x| x, |x| x, $needs_infer) -> $ty);)+
11841186
}
11851187
}
11861188

@@ -1200,16 +1202,18 @@ direct_interners!('tcx,
12001202
}) -> Region
12011203
);
12021204

1203-
intern_method!('tcx,
1204-
type_list: mk_type_list(Vec<Ty<'tcx>>, Deref::deref, |xs: &[Ty]| -> &Slice<Ty> {
1205-
unsafe { mem::transmute(xs) }
1206-
}, keep_local) -> Slice<Ty<'tcx>>
1207-
);
1205+
macro_rules! slice_interners {
1206+
($($field:ident: $method:ident($ty:ident)),+) => (
1207+
$(intern_method!('tcx, $field: $method(&[$ty<'tcx>], alloc_slice, Deref::deref,
1208+
|xs: &[$ty]| -> &Slice<$ty> {
1209+
unsafe { mem::transmute(xs) }
1210+
}, |xs: &[$ty]| xs.iter().any(keep_local)) -> Slice<$ty<'tcx>>);)+
1211+
)
1212+
}
12081213

1209-
intern_method!('tcx,
1210-
substs: mk_substs(Vec<Kind<'tcx>>, Deref::deref, |xs: &[Kind]| -> &Slice<Kind> {
1211-
unsafe { mem::transmute(xs) }
1212-
}, keep_local) -> Slice<Kind<'tcx>>
1214+
slice_interners!(
1215+
type_list: mk_type_list(Ty),
1216+
substs: mk_substs(Kind)
12131217
);
12141218

12151219
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
@@ -1314,12 +1318,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13141318
self.mk_ty(TySlice(ty))
13151319
}
13161320

1317-
pub fn mk_tup(self, ts: Vec<Ty<'tcx>>) -> Ty<'tcx> {
1321+
pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
13181322
self.mk_ty(TyTuple(self.mk_type_list(ts)))
13191323
}
13201324

13211325
pub fn mk_nil(self) -> Ty<'tcx> {
1322-
self.mk_tup(Vec::new())
1326+
self.mk_tup(&[])
13231327
}
13241328

13251329
pub fn mk_diverging_default(self) -> Ty<'tcx> {
@@ -1361,7 +1365,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13611365
pub fn mk_closure(self,
13621366
closure_id: DefId,
13631367
substs: &'tcx Substs<'tcx>,
1364-
tys: Vec<Ty<'tcx>>)
1368+
tys: &[Ty<'tcx>])
13651369
-> Ty<'tcx> {
13661370
self.mk_closure_from_closure_substs(closure_id, ClosureSubsts {
13671371
func_substs: substs,

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ impl<'a, 'tcx> AdtDefData<'tcx, 'tcx> {
17971797
_ if tys.references_error() => tcx.types.err,
17981798
0 => tcx.types.bool,
17991799
1 => tys[0],
1800-
_ => tcx.mk_tup(tys)
1800+
_ => tcx.mk_tup(&tys)
18011801
};
18021802

18031803
match self.sized_constraint.get(dep_node()) {

src/librustc/ty/relate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
491491
if as_.len() == bs.len() {
492492
let ts = as_.iter().zip(bs)
493493
.map(|(a, b)| relation.relate(a, b))
494-
.collect::<Result<_, _>>()?;
495-
Ok(tcx.mk_tup(ts))
494+
.collect::<Result<Vec<_>, _>>()?;
495+
Ok(tcx.mk_tup(&ts))
496496
} else if !(as_.is_empty() || bs.is_empty()) {
497497
Err(TypeError::TupleSize(
498498
expected_found(relation, &as_.len(), &bs.len())))
@@ -547,7 +547,7 @@ impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
547547
let upvar_tys = relation.relate_zip(&a.upvar_tys, &b.upvar_tys)?;
548548
Ok(ty::ClosureSubsts {
549549
func_substs: substs,
550-
upvar_tys: relation.tcx().mk_type_list(upvar_tys)
550+
upvar_tys: relation.tcx().mk_type_list(&upvar_tys)
551551
})
552552
}
553553
}

src/librustc/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitObject<'tcx> {
448448

449449
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<Ty<'tcx>> {
450450
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
451-
let tys = self.iter().map(|t| t.fold_with(folder)).collect();
452-
folder.tcx().mk_type_list(tys)
451+
let tys = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
452+
folder.tcx().mk_type_list(&tys)
453453
}
454454

455455
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {

src/librustc/ty/subst.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
167167
pub fn new<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>, params: I)
168168
-> &'tcx Substs<'tcx>
169169
where I: IntoIterator<Item=Kind<'tcx>> {
170-
tcx.mk_substs(params.into_iter().collect())
170+
tcx.mk_substs(&params.into_iter().collect::<Vec<_>>())
171171
}
172172

173173
pub fn maybe_new<I, E>(tcx: TyCtxt<'a, 'gcx, 'tcx>, params: I)
@@ -311,7 +311,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> {
311311
if params[..] == self[..] {
312312
self
313313
} else {
314-
folder.tcx().mk_substs(params)
314+
folder.tcx().mk_substs(&params)
315315
}
316316
}
317317

src/librustc_driver/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
275275
}
276276

277277
pub fn t_pair(&self, ty1: Ty<'tcx>, ty2: Ty<'tcx>) -> Ty<'tcx> {
278-
self.infcx.tcx.mk_tup(vec![ty1, ty2])
278+
self.infcx.tcx.mk_tup(&[ty1, ty2])
279279
}
280280

281281
pub fn t_param(&self, index: u32) -> Ty<'tcx> {
@@ -803,8 +803,8 @@ fn walk_ty() {
803803
let tcx = env.infcx.tcx;
804804
let int_ty = tcx.types.isize;
805805
let uint_ty = tcx.types.usize;
806-
let tup1_ty = tcx.mk_tup(vec![int_ty, uint_ty, int_ty, uint_ty]);
807-
let tup2_ty = tcx.mk_tup(vec![tup1_ty, tup1_ty, uint_ty]);
806+
let tup1_ty = tcx.mk_tup(&[int_ty, uint_ty, int_ty, uint_ty]);
807+
let tup2_ty = tcx.mk_tup(&[tup1_ty, tup1_ty, uint_ty]);
808808
let uniq_ty = tcx.mk_box(tup2_ty);
809809
let walked: Vec<_> = uniq_ty.walk().collect();
810810
assert_eq!(walked,
@@ -819,8 +819,8 @@ fn walk_ty_skip_subtree() {
819819
let tcx = env.infcx.tcx;
820820
let int_ty = tcx.types.isize;
821821
let uint_ty = tcx.types.usize;
822-
let tup1_ty = tcx.mk_tup(vec![int_ty, uint_ty, int_ty, uint_ty]);
823-
let tup2_ty = tcx.mk_tup(vec![tup1_ty, tup1_ty, uint_ty]);
822+
let tup1_ty = tcx.mk_tup(&[int_ty, uint_ty, int_ty, uint_ty]);
823+
let tup2_ty = tcx.mk_tup(&[tup1_ty, tup1_ty, uint_ty]);
824824
let uniq_ty = tcx.mk_box(tup2_ty);
825825

826826
// types we expect to see (in order), plus a boolean saying

src/librustc_metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<'a, 'tcx> SpecializedDecoder<ty::GenericPredicates<'tcx>> for DecodeContext
374374

375375
impl<'a, 'tcx> SpecializedDecoder<&'tcx Substs<'tcx>> for DecodeContext<'a, 'tcx> {
376376
fn specialized_decode(&mut self) -> Result<&'tcx Substs<'tcx>, Self::Error> {
377-
Ok(self.tcx().mk_substs(Decodable::decode(self)?))
377+
Ok(self.tcx().mk_substs(&Vec::decode(self)?))
378378
}
379379
}
380380

@@ -386,7 +386,7 @@ impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::Region> for DecodeContext<'a, 'tcx>
386386

387387
impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::Slice<Ty<'tcx>>> for DecodeContext<'a, 'tcx> {
388388
fn specialized_decode(&mut self) -> Result<&'tcx ty::Slice<Ty<'tcx>>, Self::Error> {
389-
Ok(self.tcx().mk_type_list(Decodable::decode(self)?))
389+
Ok(self.tcx().mk_type_list(&Vec::decode(self)?))
390390
}
391391
}
392392

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
257257
let source_info = self.source_info(span);
258258
let bool_ty = self.hir.bool_ty();
259259
if self.hir.check_overflow() && op.is_checkable() && ty.is_integral() {
260-
let result_tup = self.hir.tcx().mk_tup(vec![ty, bool_ty]);
260+
let result_tup = self.hir.tcx().mk_tup(&[ty, bool_ty]);
261261
let result_value = self.temp(result_tup);
262262

263263
self.cfg.push_assign(block, source_info,

0 commit comments

Comments
 (0)