Skip to content

Commit ab80f74

Browse files
collector-driven-trans: Take care of nits.
1 parent 00226fc commit ab80f74

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

src/librustc_trans/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2667,9 +2667,10 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26672667
{
26682668
let ccx = crate_context_list.get_ccx(0);
26692669

2670+
// FIXME: #34018
26702671
// At this point, we only walk the HIR for running
26712672
// enum_variant_size_lint(). This should arguably be moved somewhere
2672-
// else
2673+
// else.
26732674
{
26742675
intravisit::walk_mod(&mut TransItemsWithinModVisitor { ccx: &ccx }, &krate.module);
26752676
krate.visit_all_items(&mut TransModVisitor { ccx: &ccx });

src/librustc_trans/callee.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,20 +537,15 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
537537
// reference. It also occurs when testing libcore and in some
538538
// other weird situations. Annoying.
539539

540-
// Let's see if we can get the symbol name from the symbol_map, so we don't
541-
// have to recompute it.
542-
let mut sym_data = String::new();
543-
let sym = ccx.symbol_map().get(TransItem::Fn(instance)).unwrap_or_else(|| {
544-
sym_data = instance.symbol_name(ccx.shared());
545-
&sym_data[..]
546-
});
540+
let sym = ccx.symbol_map().get_or_compute(ccx.shared(),
541+
TransItem::Fn(instance));
547542

548543
let llptrty = type_of::type_of(ccx, fn_ptr_ty);
549-
let llfn = if let Some(llfn) = declare::get_declared_value(ccx, sym) {
544+
let llfn = if let Some(llfn) = declare::get_declared_value(ccx, &sym) {
550545
if let Some(span) = local_item {
551-
if declare::get_defined_value(ccx, sym).is_some() {
546+
if declare::get_defined_value(ccx, &sym).is_some() {
552547
ccx.sess().span_fatal(span,
553-
&format!("symbol `{}` is already defined", sym));
548+
&format!("symbol `{}` is already defined", &sym));
554549
}
555550
}
556551

@@ -566,7 +561,7 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
566561
llfn
567562
}
568563
} else {
569-
let llfn = declare::declare_fn(ccx, sym, ty);
564+
let llfn = declare::declare_fn(ccx, &sym, ty);
570565
assert_eq!(common::val_ty(llfn), llptrty);
571566
debug!("get_fn: not casting pointer!");
572567

src/librustc_trans/glue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
235235
let g = g.map_ty(|t| get_drop_glue_type(ccx.tcx(), t));
236236
match ccx.drop_glues().borrow().get(&g) {
237237
Some(&(glue, _)) => glue,
238-
None => { bug!("Could not find drop glue for {:?} -- {} -- {}",
238+
None => { bug!("Could not find drop glue for {:?} -- {} -- {}. \
239+
It should have be instantiated during the pre-definition phase",
239240
g,
240241
TransItem::DropGlue(g).to_raw_string(),
241242
ccx.codegen_unit().name) }

src/librustc_trans/monomorphize.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,14 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
8484
monomorphizing.insert(fn_id, depth + 1);
8585
}
8686

87-
// Let's see if we can get the symbol name from the symbol_map, so we don't
88-
// have to recompute it.
89-
let mut sym_data = String::new();
90-
let symbol = ccx.symbol_map().get(TransItem::Fn(instance)).unwrap_or_else(|| {
91-
sym_data = instance.symbol_name(ccx.shared());
92-
&sym_data[..]
93-
});
87+
let symbol = ccx.symbol_map().get_or_compute(ccx.shared(),
88+
TransItem::Fn(instance));
9489

95-
debug!("monomorphize_fn mangled to {}", symbol);
96-
assert!(declare::get_defined_value(ccx, symbol).is_none());
90+
debug!("monomorphize_fn mangled to {}", &symbol);
91+
assert!(declare::get_defined_value(ccx, &symbol).is_none());
9792

9893
// FIXME(nagisa): perhaps needs a more fine grained selection?
99-
let lldecl = declare::define_internal_fn(ccx, symbol, mono_ty);
94+
let lldecl = declare::define_internal_fn(ccx, &symbol, mono_ty);
10095
// FIXME(eddyb) Doubt all extern fn should allow unwinding.
10196
attributes::unwind(lldecl, true);
10297

src/librustc_trans/partitioning.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ impl<'tcx> CodegenUnit<'tcx> {
154154

155155
// The codegen tests rely on items being process in the same order as
156156
// they appear in the file, so for local items, we sort by node_id first
157-
items.as_mut_slice().sort_by(|&(trans_item1, _), &(trans_item2, _)| {
158-
157+
items.sort_by(|&(trans_item1, _), &(trans_item2, _)| {
159158
let node_id1 = local_node_id(tcx, trans_item1);
160159
let node_id2 = local_node_id(tcx, trans_item2);
161160

@@ -165,6 +164,7 @@ impl<'tcx> CodegenUnit<'tcx> {
165164
let symbol_name2 = symbol_map.get(trans_item2).unwrap();
166165
symbol_name1.cmp(symbol_name2)
167166
}
167+
// In the following two cases we can avoid looking up the symbol
168168
(None, Some(_)) => Ordering::Less,
169169
(Some(_), None) => Ordering::Greater,
170170
(Some(node_id1), Some(node_id2)) => {
@@ -241,7 +241,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
241241

242242
// Finally, sort by codegen unit name, so that we get deterministic results
243243
let mut result = post_inlining.0;
244-
result.as_mut_slice().sort_by(|cgu1, cgu2| {
244+
result.sort_by(|cgu1, cgu2| {
245245
(&cgu1.name[..]).cmp(&cgu2.name[..])
246246
});
247247

@@ -348,7 +348,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
348348
// translation items in a given unit. This could be improved on.
349349
while codegen_units.len() > target_cgu_count {
350350
// Sort small cgus to the back
351-
codegen_units.as_mut_slice().sort_by_key(|cgu| -(cgu.items.len() as i64));
351+
codegen_units.sort_by_key(|cgu| -(cgu.items.len() as i64));
352352
let smallest = codegen_units.pop().unwrap();
353353
let second_smallest = codegen_units.last_mut().unwrap();
354354

src/librustc_trans/symbol_map.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
use context::SharedCrateContext;
1212
use monomorphize::Instance;
1313
use rustc::ty::TyCtxt;
14+
use std::borrow::Cow;
1415
use syntax::codemap::Span;
1516
use trans_item::TransItem;
1617
use util::nodemap::FnvHashMap;
1718

18-
1919
// In the SymbolMap we collect the symbol names of all translation items of
20-
// the current crate.
20+
// the current crate. This map exists as a performance optimization. Symbol
21+
// names of translation items are deterministic and fully defined by the item.
22+
// Thus they could also always be recomputed if needed.
2123

2224
pub struct SymbolMap<'tcx> {
2325
index: FnvHashMap<TransItem<'tcx>, (usize, usize)>,
@@ -112,4 +114,15 @@ impl<'tcx> SymbolMap<'tcx> {
112114
&self.arena[start_index .. end_index]
113115
})
114116
}
117+
118+
pub fn get_or_compute<'map, 'scx>(&'map self,
119+
scx: &SharedCrateContext<'scx, 'tcx>,
120+
trans_item: TransItem<'tcx>)
121+
-> Cow<'map, str> {
122+
if let Some(sym) = self.get(trans_item) {
123+
Cow::from(sym)
124+
} else {
125+
Cow::from(trans_item.compute_symbol_name(scx))
126+
}
127+
}
115128
}

src/librustc_trans/trans_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
222222

223223
assert!(declare::get_defined_value(ccx, symbol_name).is_none());
224224
let llfn = declare::declare_cfn(ccx, symbol_name, llfnty);
225-
llvm::SetLinkage(llfn, linkage);
225+
llvm::SetLinkage(llfn, linkage);
226226
attributes::set_frame_pointer_elimination(ccx, llfn);
227227
ccx.drop_glues().borrow_mut().insert(dg, (llfn, fn_ty));
228228
}

0 commit comments

Comments
 (0)