Skip to content

Commit c85501b

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 2b97174 commit c85501b

File tree

22 files changed

+41
-40
lines changed

22 files changed

+41
-40
lines changed

src/librustc/mir/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ pub enum StatementKind<'tcx> {
799799
StorageDead(Lvalue<'tcx>),
800800

801801
InlineAsm {
802-
asm: InlineAsm,
802+
asm: Box<InlineAsm>,
803803
outputs: Vec<Lvalue<'tcx>>,
804804
inputs: Vec<Operand<'tcx>>
805805
},
@@ -995,7 +995,7 @@ pub struct VisibilityScopeData {
995995
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
996996
pub enum Operand<'tcx> {
997997
Consume(Lvalue<'tcx>),
998-
Constant(Constant<'tcx>),
998+
Constant(Box<Constant<'tcx>>),
999999
}
10001000

10011001
impl<'tcx> Debug for Operand<'tcx> {
@@ -1015,7 +1015,7 @@ impl<'tcx> Operand<'tcx> {
10151015
substs: &'tcx Substs<'tcx>,
10161016
span: Span,
10171017
) -> Self {
1018-
Operand::Constant(Constant {
1018+
Operand::Constant(box Constant {
10191019
span: span,
10201020
ty: tcx.type_of(def_id).subst(tcx, substs),
10211021
literal: Literal::Value { value: ConstVal::Function(def_id, substs) },
@@ -1062,7 +1062,7 @@ pub enum Rvalue<'tcx> {
10621062
/// ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case
10631063
/// that `Foo` has a destructor. These rvalues can be optimized
10641064
/// away after type-checking and before lowering.
1065-
Aggregate(AggregateKind<'tcx>, Vec<Operand<'tcx>>),
1065+
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
10661066
}
10671067

10681068
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
@@ -1185,7 +1185,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11851185
tuple_fmt.finish()
11861186
}
11871187

1188-
match *kind {
1188+
match **kind {
11891189
AggregateKind::Array(_) => write!(fmt, "{:?}", lvs),
11901190

11911191
AggregateKind::Tuple => {
@@ -1603,7 +1603,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
16031603
Discriminant(ref lval) => Discriminant(lval.fold_with(folder)),
16041604
Box(ty) => Box(ty.fold_with(folder)),
16051605
Aggregate(ref kind, ref fields) => {
1606-
let kind = match *kind {
1606+
let kind = box match **kind {
16071607
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
16081608
AggregateKind::Tuple => AggregateKind::Tuple,
16091609
AggregateKind::Adt(def, v, substs, n) =>
@@ -1631,7 +1631,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
16311631
Discriminant(ref lval) => lval.visit_with(visitor),
16321632
Box(ty) => ty.visit_with(visitor),
16331633
Aggregate(ref kind, ref fields) => {
1634-
(match *kind {
1634+
(match **kind {
16351635
AggregateKind::Array(ty) => ty.visit_with(visitor),
16361636
AggregateKind::Tuple => false,
16371637
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),

src/librustc/mir/tcx.rs

+1-1
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

+1
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

+2-2
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

+2-2
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

+1-1
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

+5-4
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

+1-1
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

+1-1
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

+2-2
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

src/librustc_mir/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
786786
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem);
787787
let substs = tcx.intern_substs(&[Kind::from(data.item_ty)]);
788788
TerminatorKind::Call {
789-
func: Operand::Constant(Constant {
789+
func: Operand::Constant(box Constant {
790790
span: data.span,
791791
ty: tcx.type_of(free_func).subst(tcx, substs),
792792
literal: Literal::Value {

src/librustc_mir/shim.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
323323
let (callee, mut args) = match call_kind {
324324
CallKind::Indirect => (rcvr, vec![]),
325325
CallKind::Direct(def_id) => (
326-
Operand::Constant(Constant {
326+
Operand::Constant(box Constant {
327327
span: span,
328328
ty: tcx.type_of(def_id).subst(tcx, param_env.free_substs),
329329
literal: Literal::Value {
@@ -449,7 +449,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
449449
kind: StatementKind::Assign(
450450
Lvalue::Local(RETURN_POINTER),
451451
Rvalue::Aggregate(
452-
AggregateKind::Adt(adt_def, variant_no, substs, None),
452+
box AggregateKind::Adt(adt_def, variant_no, substs, None),
453453
(1..sig.inputs().len()+1).map(|i| {
454454
Operand::Consume(Lvalue::Local(Local::new(i)))
455455
}).collect()

src/librustc_mir/transform/copy_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstantPropagationVisitor<'tcx> {
316316
_ => return,
317317
}
318318

319-
*operand = Operand::Constant(self.constant.clone());
319+
*operand = Operand::Constant(box self.constant.clone());
320320
self.uses_replaced += 1
321321
}
322322
}

src/librustc_mir/transform/deaggregator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ impl MirPass for Deaggregator {
4949
&Rvalue::Aggregate(ref agg_kind, ref operands) => (agg_kind, operands),
5050
_ => span_bug!(src_info.span, "expected aggregate, not {:?}", rhs),
5151
};
52-
let (adt_def, variant, substs) = match agg_kind {
53-
&AggregateKind::Adt(adt_def, variant, substs, None)
52+
let (adt_def, variant, substs) = match **agg_kind {
53+
AggregateKind::Adt(adt_def, variant, substs, None)
5454
=> (adt_def, variant, substs),
5555
_ => span_bug!(src_info.span, "expected struct, not {:?}", rhs),
5656
};
@@ -114,8 +114,8 @@ fn get_aggregate_statement_index<'a, 'tcx, 'b>(start: usize,
114114
&Rvalue::Aggregate(ref kind, ref operands) => (kind, operands),
115115
_ => continue,
116116
};
117-
let (adt_def, variant) = match kind {
118-
&AggregateKind::Adt(adt_def, variant, _, None) => (adt_def, variant),
117+
let (adt_def, variant) = match **kind {
118+
AggregateKind::Adt(adt_def, variant, _, None) => (adt_def, variant),
119119
_ => continue,
120120
};
121121
if operands.len() == 0 {

src/librustc_mir/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
230230
(if self.keep_original {
231231
rhs.clone()
232232
} else {
233-
let unit = Rvalue::Aggregate(AggregateKind::Tuple, vec![]);
233+
let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
234234
mem::replace(rhs, unit)
235235
}, statement.source_info)
236236
};
@@ -288,7 +288,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
288288

289289
fn promote_candidate(mut self, candidate: Candidate) {
290290
let span = self.promoted.span;
291-
let new_operand = Operand::Constant(Constant {
291+
let new_operand = Operand::Constant(box Constant {
292292
span: span,
293293
ty: self.promoted.return_ty,
294294
literal: Literal::Promoted {

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
730730
}
731731

732732
Rvalue::Aggregate(ref kind, _) => {
733-
if let AggregateKind::Adt(def, ..) = *kind {
733+
if let AggregateKind::Adt(def, ..) = **kind {
734734
if def.has_dtor(self.tcx) {
735735
self.add(Qualif::NEEDS_DROP);
736736
self.deny_drop();

src/librustc_mir/transform/simplify_branches.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl MirPass for SimplifyBranches {
3737
for block in mir.basic_blocks_mut() {
3838
let terminator = block.terminator_mut();
3939
terminator.kind = match terminator.kind {
40-
TerminatorKind::SwitchInt { discr: Operand::Constant(Constant {
40+
TerminatorKind::SwitchInt { discr: Operand::Constant(box Constant {
4141
literal: Literal::Value { ref value }, ..
4242
}), ref values, ref targets, .. } => {
4343
if let Some(ref constint) = value.to_const_int() {
@@ -54,7 +54,7 @@ impl MirPass for SimplifyBranches {
5454
continue
5555
}
5656
},
57-
TerminatorKind::Assert { target, cond: Operand::Constant(Constant {
57+
TerminatorKind::Assert { target, cond: Operand::Constant(box Constant {
5858
literal: Literal::Value {
5959
value: ConstVal::Bool(cond)
6060
}, ..
@@ -66,4 +66,3 @@ impl MirPass for SimplifyBranches {
6666
}
6767
}
6868
}
69-

src/librustc_mir/transform/type_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
534534

535535
fn is_box_free(&self, operand: &Operand<'tcx>) -> bool {
536536
match operand {
537-
&Operand::Constant(Constant {
537+
&Operand::Constant(box Constant {
538538
literal: Literal::Value {
539539
value: ConstVal::Function(def_id, _), ..
540540
}, ..

src/librustc_passes/mir_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
190190
Rvalue::Aggregate(ref kind, ref _operands) => {
191191
// AggregateKind is not distinguished by visit API, so
192192
// record it. (`super_rvalue` handles `_operands`.)
193-
self.record(match *kind {
193+
self.record(match **kind {
194194
AggregateKind::Array(_) => "AggregateKind::Array",
195195
AggregateKind::Tuple => "AggregateKind::Tuple",
196196
AggregateKind::Adt(..) => "AggregateKind::Adt",

src/librustc_trans/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
108108
location: Location) {
109109
match *kind {
110110
mir::TerminatorKind::Call {
111-
func: mir::Operand::Constant(mir::Constant {
111+
func: mir::Operand::Constant(box mir::Constant {
112112
literal: Literal::Value {
113113
value: ConstVal::Function(def_id, _), ..
114114
}, ..

src/librustc_trans/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
537537
}
538538
failure?;
539539

540-
match *kind {
540+
match **kind {
541541
mir::AggregateKind::Array(_) => {
542542
self.const_array(dest_ty, &fields)
543543
}

src/librustc_trans/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
104104
}
105105

106106
mir::Rvalue::Aggregate(ref kind, ref operands) => {
107-
match *kind {
107+
match **kind {
108108
mir::AggregateKind::Adt(adt_def, variant_index, substs, active_field_index) => {
109109
let discr = adt_def.discriminant_for_variant(bcx.tcx(), variant_index)
110110
.to_u128_unchecked() as u64;

0 commit comments

Comments
 (0)