Skip to content

Commit 7b4a357

Browse files
Fix codegen tests by make sure items are translated in AST order.
1 parent c61f356 commit 7b4a357

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

src/librustc_trans/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26332633
// Instantiate translation items without filling out definitions yet...
26342634
for ccx in crate_context_list.iter() {
26352635
let trans_items = ccx.codegen_unit()
2636-
.items_in_deterministic_order(&symbol_map);
2636+
.items_in_deterministic_order(tcx, &symbol_map);
26372637

26382638
for (trans_item, linkage) in trans_items {
26392639
trans_item.predefine(&ccx, linkage);
@@ -2643,7 +2643,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26432643
// ... and now that we have everything pre-defined, fill out those definitions.
26442644
for ccx in crate_context_list.iter() {
26452645
let trans_items = ccx.codegen_unit()
2646-
.items_in_deterministic_order(&symbol_map);
2646+
.items_in_deterministic_order(tcx, &symbol_map);
26472647

26482648
for (trans_item, _) in trans_items {
26492649
trans_item.define(&ccx);

src/librustc_trans/partitioning.rs

+40-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ use rustc::hir::map::DefPathData;
124124
use rustc::session::config::NUMBERED_CODEGEN_UNIT_MARKER;
125125
use rustc::ty::TyCtxt;
126126
use rustc::ty::item_path::characteristic_def_id_of_type;
127+
use std::cmp::Ordering;
127128
use symbol_map::SymbolMap;
129+
use syntax::ast::NodeId;
128130
use syntax::parse::token::{self, InternedString};
129131
use trans_item::TransItem;
130132
use util::nodemap::{FnvHashMap, FnvHashSet, NodeSet};
@@ -144,18 +146,52 @@ pub struct CodegenUnit<'tcx> {
144146

145147
impl<'tcx> CodegenUnit<'tcx> {
146148
pub fn items_in_deterministic_order(&self,
149+
tcx: TyCtxt,
147150
symbol_map: &SymbolMap)
148151
-> Vec<(TransItem<'tcx>, llvm::Linkage)> {
149152
let mut items: Vec<(TransItem<'tcx>, llvm::Linkage)> =
150153
self.items.iter().map(|(item, linkage)| (*item, *linkage)).collect();
151154

155+
// The codegen tests rely on items being process in the same order as
156+
// they appear in the file, so for local items, we sort by node_id first
152157
items.as_mut_slice().sort_by(|&(trans_item1, _), &(trans_item2, _)| {
153-
let symbol_name1 = symbol_map.get(trans_item1).unwrap();
154-
let symbol_name2 = symbol_map.get(trans_item2).unwrap();
155-
symbol_name1.cmp(symbol_name2)
158+
159+
let node_id1 = local_node_id(tcx, trans_item1);
160+
let node_id2 = local_node_id(tcx, trans_item2);
161+
162+
match (node_id1, node_id2) {
163+
(None, None) => {
164+
let symbol_name1 = symbol_map.get(trans_item1).unwrap();
165+
let symbol_name2 = symbol_map.get(trans_item2).unwrap();
166+
symbol_name1.cmp(symbol_name2)
167+
}
168+
(None, Some(_)) => Ordering::Less,
169+
(Some(_), None) => Ordering::Greater,
170+
(Some(node_id1), Some(node_id2)) => {
171+
let ordering = node_id1.cmp(&node_id2);
172+
173+
if ordering != Ordering::Equal {
174+
return ordering;
175+
}
176+
177+
let symbol_name1 = symbol_map.get(trans_item1).unwrap();
178+
let symbol_name2 = symbol_map.get(trans_item2).unwrap();
179+
symbol_name1.cmp(symbol_name2)
180+
}
181+
}
156182
});
157183

158-
items
184+
return items;
185+
186+
fn local_node_id(tcx: TyCtxt, trans_item: TransItem) -> Option<NodeId> {
187+
match trans_item {
188+
TransItem::Fn(instance) => {
189+
tcx.map.as_local_node_id(instance.def)
190+
}
191+
TransItem::Static(node_id) => Some(node_id),
192+
TransItem::DropGlue(_) => None,
193+
}
194+
}
159195
}
160196
}
161197

src/test/codegen/drop.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ pub fn droppy() {
3131
// that's one new drop call per call to possibly_unwinding(), and finally 3 drop calls for the
3232
// regular function exit. We used to have problems with quadratic growths of drop calls in such
3333
// functions.
34-
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
35-
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
36-
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
37-
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
38-
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
39-
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
40-
// CHECK-NOT: call{{.*}}SomeUniqueName{{.*}}drop
34+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
35+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
36+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
37+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
38+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
39+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
40+
// CHECK-NOT: call{{.*}}drop{{.*}}SomeUniqueName
4141
// The next line checks for the } that ends the function definition
4242
// CHECK-LABEL: {{^[}]}}
4343
let _s = SomeUniqueName;

0 commit comments

Comments
 (0)