Skip to content

Commit 74fe27f

Browse files
committed
box large variants in MIR
Operand: 72 -> 24 B Statement: 192 -> 96 B Terminator: 256 -> 112 B librustc translation memory usage: 1795 -> 1669 MB next step would be interning lvalues, I suppose?
1 parent 2df18ed commit 74fe27f

File tree

22 files changed

+42
-40
lines changed

22 files changed

+42
-40
lines changed

src/librustc/mir/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ pub enum StatementKind<'tcx> {
797797
StorageDead(Lvalue<'tcx>),
798798

799799
InlineAsm {
800-
asm: InlineAsm,
800+
asm: Box<InlineAsm>,
801801
outputs: Vec<Lvalue<'tcx>>,
802802
inputs: Vec<Operand<'tcx>>
803803
},
@@ -993,7 +993,7 @@ pub struct VisibilityScopeData {
993993
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
994994
pub enum Operand<'tcx> {
995995
Consume(Lvalue<'tcx>),
996-
Constant(Constant<'tcx>),
996+
Constant(Box<Constant<'tcx>>),
997997
}
998998

999999
impl<'tcx> Debug for Operand<'tcx> {
@@ -1013,7 +1013,7 @@ impl<'tcx> Operand<'tcx> {
10131013
substs: &'tcx Substs<'tcx>,
10141014
span: Span,
10151015
) -> Self {
1016-
Operand::Constant(Constant {
1016+
Operand::Constant(box Constant {
10171017
span: span,
10181018
ty: tcx.item_type(def_id).subst(tcx, substs),
10191019
literal: Literal::Value { value: ConstVal::Function(def_id, substs) },
@@ -1060,7 +1060,7 @@ pub enum Rvalue<'tcx> {
10601060
/// ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case
10611061
/// that `Foo` has a destructor. These rvalues can be optimized
10621062
/// away after type-checking and before lowering.
1063-
Aggregate(AggregateKind<'tcx>, Vec<Operand<'tcx>>),
1063+
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
10641064
}
10651065

10661066
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
@@ -1183,7 +1183,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11831183
tuple_fmt.finish()
11841184
}
11851185

1186-
match *kind {
1186+
match **kind {
11871187
AggregateKind::Array(_) => write!(fmt, "{:?}", lvs),
11881188

11891189
AggregateKind::Tuple => {
@@ -1601,7 +1601,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
16011601
Discriminant(ref lval) => Discriminant(lval.fold_with(folder)),
16021602
Box(ty) => Box(ty.fold_with(folder)),
16031603
Aggregate(ref kind, ref fields) => {
1604-
let kind = match *kind {
1604+
let kind = box match **kind {
16051605
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
16061606
AggregateKind::Tuple => AggregateKind::Tuple,
16071607
AggregateKind::Adt(def, v, substs, n) =>
@@ -1629,7 +1629,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
16291629
Discriminant(ref lval) => lval.visit_with(visitor),
16301630
Box(ty) => ty.visit_with(visitor),
16311631
Aggregate(ref kind, ref fields) => {
1632-
(match *kind {
1632+
(match **kind {
16331633
AggregateKind::Array(ty) => ty.visit_with(visitor),
16341634
AggregateKind::Tuple => false,
16351635
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> Rvalue<'tcx> {
183183
tcx.mk_box(t)
184184
}
185185
Rvalue::Aggregate(ref ak, ref ops) => {
186-
match *ak {
186+
match **ak {
187187
AggregateKind::Array(ty) => {
188188
tcx.mk_array(ty, ops.len())
189189
}

src/librustc/mir/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ macro_rules! make_mir_visitor {
515515

516516
Rvalue::Aggregate(ref $($mutability)* kind,
517517
ref $($mutability)* operands) => {
518+
let kind = &$($mutability)* **kind;
518519
match *kind {
519520
AggregateKind::Array(ref $($mutability)* ty) => {
520521
self.visit_ty(ty);

src/librustc_borrowck/borrowck/mir/elaborate_drops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
517517
}
518518

519519
fn constant_bool(&self, span: Span, val: bool) -> Rvalue<'tcx> {
520-
Rvalue::Use(Operand::Constant(Constant {
520+
Rvalue::Use(Operand::Constant(Box::new(Constant {
521521
span: span,
522522
ty: self.tcx.types.bool,
523523
literal: Literal::Value { value: ConstVal::Bool(val) }
524-
}))
524+
})))
525525
}
526526

527527
fn set_drop_flag(&mut self, loc: Location, path: MovePathIndex, val: DropFlagState) {

src/librustc_mir/build/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ impl<'tcx> CFG<'tcx> {
6060
temp: &Lvalue<'tcx>,
6161
constant: Constant<'tcx>) {
6262
self.push_assign(block, source_info, temp,
63-
Rvalue::Use(Operand::Constant(constant)));
63+
Rvalue::Use(Operand::Constant(box constant)));
6464
}
6565

6666
pub fn push_assign_unit(&mut self,
6767
block: BasicBlock,
6868
source_info: SourceInfo,
6969
lvalue: &Lvalue<'tcx>) {
7070
self.push_assign(block, source_info, lvalue, Rvalue::Aggregate(
71-
AggregateKind::Tuple, vec![]
71+
box AggregateKind::Tuple, vec![]
7272
));
7373
}
7474

src/librustc_mir/build/expr/as_operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
6666
match category {
6767
Category::Constant => {
6868
let constant = this.as_constant(expr);
69-
block.and(Operand::Constant(constant))
69+
block.and(Operand::Constant(box constant))
7070
}
7171
Category::Lvalue |
7272
Category::Rvalue(..) => {

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
166166
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
167167
.collect();
168168

169-
block.and(Rvalue::Aggregate(AggregateKind::Array(el_ty), fields))
169+
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
170170
}
171171
ExprKind::Tuple { fields } => { // see (*) above
172172
// first process the set of fields
@@ -175,14 +175,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
175175
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
176176
.collect();
177177

178-
block.and(Rvalue::Aggregate(AggregateKind::Tuple, fields))
178+
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
179179
}
180180
ExprKind::Closure { closure_id, substs, upvars } => { // see (*) above
181181
let upvars =
182182
upvars.into_iter()
183183
.map(|upvar| unpack!(block = this.as_operand(block, scope, upvar)))
184184
.collect();
185-
block.and(Rvalue::Aggregate(AggregateKind::Closure(closure_id, substs), upvars))
185+
block.and(Rvalue::Aggregate(box AggregateKind::Closure(closure_id, substs), upvars))
186186
}
187187
ExprKind::Adt {
188188
adt_def, variant_index, substs, fields, base
@@ -215,7 +215,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
215215
field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect()
216216
};
217217

218-
let adt = AggregateKind::Adt(adt_def, variant_index, substs, active_field_index);
218+
let adt =
219+
box AggregateKind::Adt(adt_def, variant_index, substs, active_field_index);
219220
block.and(Rvalue::Aggregate(adt, fields))
220221
}
221222
ExprKind::Assign { .. } |

src/librustc_mir/build/expr/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
129129
this.cfg.push(block, Statement {
130130
source_info: source_info,
131131
kind: StatementKind::InlineAsm {
132-
asm: asm.clone(),
132+
asm: box asm.clone(),
133133
outputs: outputs,
134134
inputs: inputs
135135
},

src/librustc_mir/build/matches/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
308308
let eq_block = self.cfg.start_new_block();
309309
let cleanup = self.diverge_cleanup();
310310
self.cfg.terminate(block, source_info, TerminatorKind::Call {
311-
func: Operand::Constant(Constant {
311+
func: Operand::Constant(box Constant {
312312
span: test.span,
313313
ty: mty,
314314
literal: method

src/librustc_mir/build/misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4040
ty: Ty<'tcx>,
4141
literal: Literal<'tcx>)
4242
-> Operand<'tcx> {
43-
let constant = Constant {
43+
let constant = box Constant {
4444
span: span,
4545
ty: ty,
4646
literal: literal,
@@ -49,7 +49,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4949
}
5050

5151
pub fn unit_rvalue(&mut self) -> Rvalue<'tcx> {
52-
Rvalue::Aggregate(AggregateKind::Tuple, vec![])
52+
Rvalue::Aggregate(box AggregateKind::Tuple, vec![])
5353
}
5454

5555
// Returns a zero literal operand for the appropriate type, works for

0 commit comments

Comments
 (0)