Skip to content

Commit ae8a2ff

Browse files
committed
auto merge of #9538 : thestinger/rust/type_use, r=pcwalton
This is broken, and results in poor performance due to the undefined behaviour in the LLVM IR. LLVM's `mergefunc` is a *much* better way of doing this since it merges based on the equality of the bytecode. For example, consider `std::repr`. It generates different code per type, but is not included in the type bounds of generics. The `mergefunc` pass works for most of our code but currently hits an assert on libstd. It is receiving attention upstream so it will be ready soon, but I don't think removing this broken code should wait any longer. I've opened #9536 about enabling it by default. Closes #8651 Closes #3547 Closes #2537 Closes #6971 Closes #9222
2 parents afbc242 + c3e4e06 commit ae8a2ff

File tree

9 files changed

+21
-626
lines changed

9 files changed

+21
-626
lines changed

src/etc/monodebug.pl

-79
This file was deleted.

src/etc/zsh/_rust

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ _rustc_opts_debug=(
7171
'count-type-sizes:count the sizes of aggregate types'
7272
'meta-stats:gather metadata statistics'
7373
'no-opt:do not optimize, even if -O is passed'
74-
'no-monomorphic-collapse:do not collapse template instantiations'
7574
'print-link-args:Print the arguments passed to the linker'
7675
'gc:Garbage collect shared data (experimental)'
7776
'jit:Execute using JIT (experimental)'

src/librustc/driver/driver.rs

-7
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,6 @@ pub fn build_session_options(binary: @str,
748748
let debuginfo = debugging_opts & session::debug_info != 0 ||
749749
extra_debuginfo;
750750

751-
// If debugging info is generated, do not collapse monomorphized function instances.
752-
// Functions with equivalent llvm code still need separate debugging descriptions because names
753-
// might differ.
754-
if debuginfo {
755-
debugging_opts |= session::no_monomorphic_collapse;
756-
}
757-
758751
let statik = debugging_opts & session::statik != 0;
759752

760753
let addl_lib_search_paths = matches.opt_strs("L").map(|s| Path(*s));

src/librustc/driver/session.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,19 @@ pub static debug_llvm: uint = 1 << 13;
6767
pub static count_type_sizes: uint = 1 << 14;
6868
pub static meta_stats: uint = 1 << 15;
6969
pub static no_opt: uint = 1 << 16;
70-
pub static no_monomorphic_collapse: uint = 1 << 17;
71-
pub static gc: uint = 1 << 18;
72-
pub static jit: uint = 1 << 19;
73-
pub static debug_info: uint = 1 << 20;
74-
pub static extra_debug_info: uint = 1 << 21;
75-
pub static statik: uint = 1 << 22;
76-
pub static print_link_args: uint = 1 << 23;
77-
pub static no_debug_borrows: uint = 1 << 24;
78-
pub static lint_llvm: uint = 1 << 25;
79-
pub static once_fns: uint = 1 << 26;
80-
pub static print_llvm_passes: uint = 1 << 27;
81-
pub static no_vectorize_loops: uint = 1 << 28;
82-
pub static no_vectorize_slp: uint = 1 << 29;
83-
pub static no_prepopulate_passes: uint = 1 << 30;
70+
pub static gc: uint = 1 << 17;
71+
pub static jit: uint = 1 << 18;
72+
pub static debug_info: uint = 1 << 19;
73+
pub static extra_debug_info: uint = 1 << 20;
74+
pub static statik: uint = 1 << 21;
75+
pub static print_link_args: uint = 1 << 22;
76+
pub static no_debug_borrows: uint = 1 << 23;
77+
pub static lint_llvm: uint = 1 << 24;
78+
pub static once_fns: uint = 1 << 25;
79+
pub static print_llvm_passes: uint = 1 << 26;
80+
pub static no_vectorize_loops: uint = 1 << 27;
81+
pub static no_vectorize_slp: uint = 1 << 28;
82+
pub static no_prepopulate_passes: uint = 1 << 29;
8483

8584
pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
8685
~[(~"verbose", ~"in general, enable more debug printouts", verbose),
@@ -106,8 +105,6 @@ pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
106105
count_type_sizes),
107106
(~"meta-stats", ~"gather metadata statistics", meta_stats),
108107
(~"no-opt", ~"do not optimize, even if -O is passed", no_opt),
109-
(~"no-monomorphic-collapse", ~"do not collapse template instantiations",
110-
no_monomorphic_collapse),
111108
(~"print-link-args", ~"Print the arguments passed to the linker", print_link_args),
112109
(~"gc", ~"Garbage collect shared data (experimental)", gc),
113110
(~"jit", ~"Execute using JIT (experimental)", jit),
@@ -326,9 +323,6 @@ impl Session_ {
326323
pub fn borrowck_note_loan(&self) -> bool {
327324
self.debugging_opt(borrowck_note_loan)
328325
}
329-
pub fn no_monomorphic_collapse(&self) -> bool {
330-
self.debugging_opt(no_monomorphic_collapse)
331-
}
332326
pub fn debug_borrows(&self) -> bool {
333327
self.opts.optimize == No && !self.debugging_opt(no_debug_borrows)
334328
}

src/librustc/middle/trans/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use middle::trans::adt;
2222
use middle::trans::base;
2323
use middle::trans::builder::Builder;
2424
use middle::trans::debuginfo;
25-
use middle::trans::type_use;
2625
use middle::trans::common::{C_i32, C_null};
2726
use middle::ty;
2827

@@ -73,8 +72,6 @@ pub struct CrateContext {
7372
// Cache instances of monomorphized functions
7473
monomorphized: HashMap<mono_id, ValueRef>,
7574
monomorphizing: HashMap<ast::DefId, uint>,
76-
// Cache computed type parameter uses (see type_use.rs)
77-
type_use_cache: HashMap<ast::DefId, @~[type_use::type_uses]>,
7875
// Cache generated vtables
7976
vtables: HashMap<(ty::t, mono_id), ValueRef>,
8077
// Cache of constant strings,
@@ -204,7 +201,6 @@ impl CrateContext {
204201
non_inlineable_statics: HashSet::new(),
205202
monomorphized: HashMap::new(),
206203
monomorphizing: HashMap::new(),
207-
type_use_cache: HashMap::new(),
208204
vtables: HashMap::new(),
209205
const_cstr_cache: HashMap::new(),
210206
const_globals: HashMap::new(),

src/librustc/middle/trans/meth.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ pub fn vtable_id(ccx: @mut CrateContext,
520520
monomorphize::make_mono_id(
521521
ccx,
522522
impl_id,
523-
&psubsts,
524-
None)
523+
&psubsts)
525524
}
526525

527526
// can't this be checked at the callee?

src/librustc/middle/trans/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub mod foreign;
3838
pub mod intrinsic;
3939
pub mod reflect;
4040
pub mod debuginfo;
41-
pub mod type_use;
4241
pub mod machine;
4342
pub mod adt;
4443
pub mod asm;

src/librustc/middle/trans/monomorphize.rs

+7-64
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ use middle::trans::base::{trans_fn, decl_internal_rust_fn};
1818
use middle::trans::base::{get_item_val, no_self};
1919
use middle::trans::base;
2020
use middle::trans::common::*;
21-
use middle::trans::datum;
22-
use middle::trans::machine;
2321
use middle::trans::meth;
24-
use middle::trans::type_of;
25-
use middle::trans::type_use;
2622
use middle::trans::intrinsic;
2723
use middle::ty;
2824
use middle::typeck;
29-
use util::ppaux::{Repr,ty_to_str};
25+
use util::ppaux::Repr;
3026

3127
use syntax::ast;
3228
use syntax::ast_map;
@@ -65,10 +61,8 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
6561

6662
for s in real_substs.tps.iter() { assert!(!ty::type_has_params(*s)); }
6763
for s in psubsts.tys.iter() { assert!(!ty::type_has_params(*s)); }
68-
let param_uses = type_use::type_uses_for(ccx, fn_id, psubsts.tys.len());
6964

70-
71-
let hash_id = make_mono_id(ccx, fn_id, &*psubsts, Some(param_uses));
65+
let hash_id = make_mono_id(ccx, fn_id, &*psubsts);
7266
if hash_id.params.iter().any(
7367
|p| match *p { mono_precise(_, _) => false, _ => true }) {
7468
must_cast = true;
@@ -302,8 +296,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
302296

303297
pub fn make_mono_id(ccx: @mut CrateContext,
304298
item: ast::DefId,
305-
substs: &param_substs,
306-
param_uses: Option<@~[type_use::type_uses]>) -> mono_id {
299+
substs: &param_substs) -> mono_id {
307300
// FIXME (possibly #5801): Need a lot of type hints to get
308301
// .collect() to work.
309302
let substs_iter = substs.self_ty.iter().chain(substs.tys.iter());
@@ -321,59 +314,9 @@ pub fn make_mono_id(ccx: @mut CrateContext,
321314
};
322315

323316

324-
let param_ids = match param_uses {
325-
Some(ref uses) => {
326-
// param_uses doesn't include a use for the self type.
327-
// We just say it is fully used.
328-
let self_use =
329-
substs.self_ty.map(|_| type_use::use_repr|type_use::use_tydesc);
330-
let uses_iter = self_use.iter().chain(uses.iter());
331-
332-
precise_param_ids.iter().zip(uses_iter).map(|(id, uses)| {
333-
if ccx.sess.no_monomorphic_collapse() {
334-
match *id {
335-
(a, b) => mono_precise(a, b)
336-
}
337-
} else {
338-
match *id {
339-
(a, b@Some(_)) => mono_precise(a, b),
340-
(subst, None) => {
341-
if *uses == 0 {
342-
mono_any
343-
} else if *uses == type_use::use_repr &&
344-
!ty::type_needs_drop(ccx.tcx, subst)
345-
{
346-
let llty = type_of::type_of(ccx, subst);
347-
let size = machine::llbitsize_of_real(ccx, llty);
348-
let align = machine::llalign_of_min(ccx, llty);
349-
let mode = datum::appropriate_mode(ccx.tcx, subst);
350-
let data_class = mono_data_classify(subst);
351-
352-
debug!("make_mono_id: type %s -> size %u align %u mode %? class %?",
353-
ty_to_str(ccx.tcx, subst),
354-
size, align, mode, data_class);
355-
356-
// Special value for nil to prevent problems
357-
// with undef return pointers.
358-
if size <= 8u && ty::type_is_nil(subst) {
359-
mono_repr(0u, 0u, data_class, mode)
360-
} else {
361-
mono_repr(size, align, data_class, mode)
362-
}
363-
} else {
364-
mono_precise(subst, None)
365-
}
366-
}
367-
}
368-
}
369-
}).collect()
370-
}
371-
None => {
372-
precise_param_ids.iter().map(|x| {
373-
let (a, b) = *x;
374-
mono_precise(a, b)
375-
}).collect()
376-
}
377-
};
317+
let param_ids = precise_param_ids.iter().map(|x| {
318+
let (a, b) = *x;
319+
mono_precise(a, b)
320+
}).collect();
378321
@mono_id_ {def: item, params: param_ids}
379322
}

0 commit comments

Comments
 (0)