Skip to content

Commit 4fc03ba

Browse files
committed
librustc: Implement "-Z no-monomorphic-collapse" as a debugging tool to diagnose mysterious crashes we're seeing. rs=debug-tool
1 parent aa3aa3b commit 4fc03ba

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

src/librustc/driver/session.rs

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const debug_llvm: uint = 1 << 13;
6565
const count_type_sizes: uint = 1 << 14;
6666
const meta_stats: uint = 1 << 15;
6767
const no_opt: uint = 1 << 16;
68+
const no_monomorphic_collapse: uint = 1 << 17;
6869

6970
fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
7071
~[(~"verbose", ~"in general, enable more debug printouts", verbose),
@@ -90,6 +91,8 @@ fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
9091
count_type_sizes),
9192
(~"meta-stats", ~"gather metadata statistics", meta_stats),
9293
(~"no-opt", ~"do not optimize, even if -O is passed", no_opt),
94+
(~"no-monomorphic-collapse", ~"do not collapse template instantiations",
95+
no_monomorphic_collapse),
9396
]
9497
}
9598

@@ -242,6 +245,9 @@ impl Session {
242245
fn borrowck_stats() -> bool { self.debugging_opt(borrowck_stats) }
243246
fn borrowck_note_pure() -> bool { self.debugging_opt(borrowck_note_pure) }
244247
fn borrowck_note_loan() -> bool { self.debugging_opt(borrowck_note_loan) }
248+
fn no_monomorphic_collapse() -> bool {
249+
self.debugging_opt(no_monomorphic_collapse)
250+
}
245251

246252
fn str_of(id: ast::ident) -> ~str {
247253
*self.parse_sess.interner.get(id)

src/librustc/middle/trans/monomorphize.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -320,37 +320,43 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
320320
let param_ids = match param_uses {
321321
Some(uses) => {
322322
vec::map2(precise_param_ids, uses, |id, uses| {
323-
match *id {
324-
(a, b@Some(_)) => mono_precise(a, b),
325-
(subst, None) => {
326-
if *uses == 0u {
327-
mono_any
328-
} else if *uses == type_use::use_repr &&
329-
!ty::type_needs_drop(ccx.tcx, subst)
330-
{
331-
let llty = type_of::type_of(ccx, subst);
332-
let size = machine::llbitsize_of_real(ccx, llty);
333-
let align = shape::llalign_of_pref(ccx, llty);
334-
let mode = datum::appropriate_mode(subst);
323+
if ccx.sess.no_monomorphic_collapse() {
324+
match *id {
325+
(a, b) => mono_precise(a, b)
326+
}
327+
} else {
328+
match *id {
329+
(a, b@Some(_)) => mono_precise(a, b),
330+
(subst, None) => {
331+
if *uses == 0u {
332+
mono_any
333+
} else if *uses == type_use::use_repr &&
334+
!ty::type_needs_drop(ccx.tcx, subst)
335+
{
336+
let llty = type_of::type_of(ccx, subst);
337+
let size = machine::llbitsize_of_real(ccx, llty);
338+
let align = shape::llalign_of_pref(ccx, llty);
339+
let mode = datum::appropriate_mode(subst);
335340

336-
// FIXME(#3547)---scalars and floats are
337-
// treated differently in most ABIs. But we
338-
// should be doing something more detailed
339-
// here.
340-
let is_float = match ty::get(subst).sty {
341-
ty::ty_float(_) => true,
342-
_ => false
343-
};
341+
// FIXME(#3547)---scalars and floats are
342+
// treated differently in most ABIs. But we
343+
// should be doing something more detailed
344+
// here.
345+
let is_float = match ty::get(subst).sty {
346+
ty::ty_float(_) => true,
347+
_ => false
348+
};
344349

345-
// Special value for nil to prevent problems
346-
// with undef return pointers.
347-
if size <= 8u && ty::type_is_nil(subst) {
348-
mono_repr(0u, 0u, is_float, mode)
350+
// Special value for nil to prevent problems
351+
// with undef return pointers.
352+
if size <= 8u && ty::type_is_nil(subst) {
353+
mono_repr(0u, 0u, is_float, mode)
354+
} else {
355+
mono_repr(size, align, is_float, mode)
356+
}
349357
} else {
350-
mono_repr(size, align, is_float, mode)
358+
mono_precise(subst, None)
351359
}
352-
} else {
353-
mono_precise(subst, None)
354360
}
355361
}
356362
}

0 commit comments

Comments
 (0)