Skip to content

Commit 132bde7

Browse files
committed
rustc: Make trans collect/partition a query
This commit moves the `collect_and_partition_translation_items` function into a query on `TyCtxt` instead of a free function in trans, allowing us to track dependencies and such of the function.
1 parent dba3ddd commit 132bde7

File tree

12 files changed

+352
-248
lines changed

12 files changed

+352
-248
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ define_dep_nodes!( <'tcx>
576576
[] StabilityIndex,
577577
[] AllCrateNums,
578578
[] ExportedSymbols,
579+
[] CollectAndPartitionTranslationItems,
579580
);
580581

581582
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub mod middle {
104104
pub mod recursion_limit;
105105
pub mod resolve_lifetime;
106106
pub mod stability;
107+
pub mod trans;
107108
pub mod weak_lang_items;
108109
}
109110

src/librustc/middle/trans.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use syntax::ast::NodeId;
2+
use syntax::symbol::InternedString;
3+
use ty::Instance;
4+
use util::nodemap::FxHashMap;
5+
6+
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
7+
pub enum TransItem<'tcx> {
8+
Fn(Instance<'tcx>),
9+
Static(NodeId),
10+
GlobalAsm(NodeId),
11+
}
12+
13+
pub struct CodegenUnit<'tcx> {
14+
/// A name for this CGU. Incremental compilation requires that
15+
/// name be unique amongst **all** crates. Therefore, it should
16+
/// contain something unique to this crate (e.g., a module path)
17+
/// as well as the crate name and disambiguator.
18+
name: InternedString,
19+
items: FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>,
20+
}
21+
22+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
23+
pub enum Linkage {
24+
External,
25+
AvailableExternally,
26+
LinkOnceAny,
27+
LinkOnceODR,
28+
WeakAny,
29+
WeakODR,
30+
Appending,
31+
Internal,
32+
Private,
33+
ExternalWeak,
34+
Common,
35+
}
36+
37+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
38+
pub enum Visibility {
39+
Default,
40+
Hidden,
41+
Protected,
42+
}
43+
44+
impl<'tcx> CodegenUnit<'tcx> {
45+
pub fn new(name: InternedString) -> CodegenUnit<'tcx> {
46+
CodegenUnit {
47+
name: name,
48+
items: FxHashMap(),
49+
}
50+
}
51+
52+
pub fn name(&self) -> &InternedString {
53+
&self.name
54+
}
55+
56+
pub fn set_name(&mut self, name: InternedString) {
57+
self.name = name;
58+
}
59+
60+
pub fn items(&self) -> &FxHashMap<TransItem<'tcx>, (Linkage, Visibility)> {
61+
&self.items
62+
}
63+
64+
pub fn items_mut(&mut self)
65+
-> &mut FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>
66+
{
67+
&mut self.items
68+
}
69+
}

src/librustc/ty/maps.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use middle::resolve_lifetime::{Region, ObjectLifetimeDefault};
2424
use middle::stability::{self, DeprecationEntry};
2525
use middle::lang_items::{LanguageItems, LangItem};
2626
use middle::exported_symbols::ExportedSymbols;
27+
use middle::trans::{TransItem, CodegenUnit};
2728
use mir;
2829
use mir::transform::{MirSuite, MirPassIndex};
2930
use session::CompileResult;
@@ -753,6 +754,12 @@ impl<'tcx> QueryDescription for queries::exported_symbol_set<'tcx> {
753754
}
754755
}
755756

757+
impl<'tcx> QueryDescription for queries::collect_and_partition_translation_items<'tcx> {
758+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
759+
format!("collect_and_partition_translation_items")
760+
}
761+
}
762+
756763
// If enabled, send a message to the profile-queries thread
757764
macro_rules! profq_msg {
758765
($tcx:expr, $msg:expr) => {
@@ -1382,6 +1389,9 @@ define_maps! { <'tcx>
13821389

13831390
[] fn exported_symbol_set: exported_symbol_set_node(CrateNum)
13841391
-> Arc<ExportedSymbols>,
1392+
[] fn collect_and_partition_translation_items:
1393+
collect_and_partition_translation_items_node(CrateNum)
1394+
-> (Arc<FxHashSet<TransItem<'tcx>>>, Vec<Arc<CodegenUnit<'tcx>>>),
13851395
}
13861396

13871397
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
@@ -1499,3 +1509,7 @@ fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
14991509
fn exported_symbol_set_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
15001510
DepConstructor::ExportedSymbols
15011511
}
1512+
1513+
fn collect_and_partition_translation_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1514+
DepConstructor::CollectAndPartitionTranslationItems
1515+
}

src/librustc_trans/back/linker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ pub struct LinkerInfo {
3434
}
3535

3636
impl<'a, 'tcx> LinkerInfo {
37-
pub fn new(scx: &SharedCrateContext<'a, 'tcx>,
38-
exports: &ExportedSymbols) -> LinkerInfo {
37+
pub fn new(scx: &SharedCrateContext<'a, 'tcx>) -> LinkerInfo {
38+
let exports = scx.tcx().exported_symbols();
3939
LinkerInfo {
4040
exports: scx.sess().crate_types.borrow().iter().map(|&c| {
41-
(c, exported_symbols(scx, exports, c))
41+
(c, exported_symbols(scx, &exports, c))
4242
}).collect(),
4343
}
4444
}

0 commit comments

Comments
 (0)