Skip to content

Commit

Permalink
rustc: Make trans collect/partition a query
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Sep 17, 2017
1 parent dba3ddd commit 132bde7
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 248 deletions.
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ define_dep_nodes!( <'tcx>
[] StabilityIndex,
[] AllCrateNums,
[] ExportedSymbols,
[] CollectAndPartitionTranslationItems,
);

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub mod middle {
pub mod recursion_limit;
pub mod resolve_lifetime;
pub mod stability;
pub mod trans;
pub mod weak_lang_items;
}

Expand Down
69 changes: 69 additions & 0 deletions src/librustc/middle/trans.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use syntax::ast::NodeId;
use syntax::symbol::InternedString;
use ty::Instance;
use util::nodemap::FxHashMap;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
pub enum TransItem<'tcx> {
Fn(Instance<'tcx>),
Static(NodeId),
GlobalAsm(NodeId),
}

pub struct CodegenUnit<'tcx> {
/// A name for this CGU. Incremental compilation requires that
/// name be unique amongst **all** crates. Therefore, it should
/// contain something unique to this crate (e.g., a module path)
/// as well as the crate name and disambiguator.
name: InternedString,
items: FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Linkage {
External,
AvailableExternally,
LinkOnceAny,
LinkOnceODR,
WeakAny,
WeakODR,
Appending,
Internal,
Private,
ExternalWeak,
Common,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Visibility {
Default,
Hidden,
Protected,
}

impl<'tcx> CodegenUnit<'tcx> {
pub fn new(name: InternedString) -> CodegenUnit<'tcx> {
CodegenUnit {
name: name,
items: FxHashMap(),
}
}

pub fn name(&self) -> &InternedString {
&self.name
}

pub fn set_name(&mut self, name: InternedString) {
self.name = name;
}

pub fn items(&self) -> &FxHashMap<TransItem<'tcx>, (Linkage, Visibility)> {
&self.items
}

pub fn items_mut(&mut self)
-> &mut FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>
{
&mut self.items
}
}
14 changes: 14 additions & 0 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use middle::resolve_lifetime::{Region, ObjectLifetimeDefault};
use middle::stability::{self, DeprecationEntry};
use middle::lang_items::{LanguageItems, LangItem};
use middle::exported_symbols::ExportedSymbols;
use middle::trans::{TransItem, CodegenUnit};
use mir;
use mir::transform::{MirSuite, MirPassIndex};
use session::CompileResult;
Expand Down Expand Up @@ -753,6 +754,12 @@ impl<'tcx> QueryDescription for queries::exported_symbol_set<'tcx> {
}
}

impl<'tcx> QueryDescription for queries::collect_and_partition_translation_items<'tcx> {
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
format!("collect_and_partition_translation_items")
}
}

// If enabled, send a message to the profile-queries thread
macro_rules! profq_msg {
($tcx:expr, $msg:expr) => {
Expand Down Expand Up @@ -1382,6 +1389,9 @@ define_maps! { <'tcx>

[] fn exported_symbol_set: exported_symbol_set_node(CrateNum)
-> Arc<ExportedSymbols>,
[] fn collect_and_partition_translation_items:
collect_and_partition_translation_items_node(CrateNum)
-> (Arc<FxHashSet<TransItem<'tcx>>>, Vec<Arc<CodegenUnit<'tcx>>>),
}

fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
Expand Down Expand Up @@ -1499,3 +1509,7 @@ fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
fn exported_symbol_set_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
DepConstructor::ExportedSymbols
}

fn collect_and_partition_translation_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
DepConstructor::CollectAndPartitionTranslationItems
}
6 changes: 3 additions & 3 deletions src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub struct LinkerInfo {
}

impl<'a, 'tcx> LinkerInfo {
pub fn new(scx: &SharedCrateContext<'a, 'tcx>,
exports: &ExportedSymbols) -> LinkerInfo {
pub fn new(scx: &SharedCrateContext<'a, 'tcx>) -> LinkerInfo {
let exports = scx.tcx().exported_symbols();
LinkerInfo {
exports: scx.sess().crate_types.borrow().iter().map(|&c| {
(c, exported_symbols(scx, exports, c))
(c, exported_symbols(scx, &exports, c))
}).collect(),
}
}
Expand Down
Loading

0 comments on commit 132bde7

Please sign in to comment.