Skip to content

Commit e21d002

Browse files
committed
move codegenunitext to rustc::mir::mono
1 parent 621bf0d commit e21d002

File tree

4 files changed

+70
-92
lines changed

4 files changed

+70
-92
lines changed

src/librustc/mir/mono.rs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use crate::hir::HirId;
33
use syntax::symbol::InternedString;
44
use syntax::attr::InlineAttr;
55
use syntax::source_map::Span;
6-
use crate::ty::{Instance, TyCtxt, SymbolName, subst::InternalSubsts};
6+
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
77
use crate::util::nodemap::FxHashMap;
88
use crate::ty::print::obsolete::DefPathBasedNames;
9+
use crate::dep_graph::{WorkProductId, DepNode, WorkProduct, DepConstructor};
910
use rustc_data_structures::base_n;
1011
use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
1112
StableHasher};
@@ -350,6 +351,73 @@ impl<'tcx> CodegenUnit<'tcx> {
350351
self.size_estimate = Some(size_estimate + delta);
351352
}
352353
}
354+
355+
pub fn contains_item(&self, item: &MonoItem<'tcx>) -> bool {
356+
self.items().contains_key(item)
357+
}
358+
359+
pub fn work_product_id(&self) -> WorkProductId {
360+
WorkProductId::from_cgu_name(&self.name().as_str())
361+
}
362+
363+
pub fn work_product(&self, tcx: TyCtxt<'_, '_, '_>) -> WorkProduct {
364+
let work_product_id = self.work_product_id();
365+
tcx.dep_graph
366+
.previous_work_product(&work_product_id)
367+
.unwrap_or_else(|| {
368+
panic!("Could not find work-product for CGU `{}`", self.name())
369+
})
370+
}
371+
372+
pub fn items_in_deterministic_order<'a>(&self,
373+
tcx: TyCtxt<'a, 'tcx, 'tcx>)
374+
-> Vec<(MonoItem<'tcx>,
375+
(Linkage, Visibility))> {
376+
// The codegen tests rely on items being process in the same order as
377+
// they appear in the file, so for local items, we sort by node_id first
378+
#[derive(PartialEq, Eq, PartialOrd, Ord)]
379+
pub struct ItemSortKey(Option<HirId>, SymbolName);
380+
381+
fn item_sort_key<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
382+
item: MonoItem<'tcx>) -> ItemSortKey {
383+
ItemSortKey(match item {
384+
MonoItem::Fn(ref instance) => {
385+
match instance.def {
386+
// We only want to take HirIds of user-defined
387+
// instances into account. The others don't matter for
388+
// the codegen tests and can even make item order
389+
// unstable.
390+
InstanceDef::Item(def_id) => {
391+
tcx.hir().as_local_hir_id(def_id)
392+
}
393+
InstanceDef::VtableShim(..) |
394+
InstanceDef::Intrinsic(..) |
395+
InstanceDef::FnPtrShim(..) |
396+
InstanceDef::Virtual(..) |
397+
InstanceDef::ClosureOnceShim { .. } |
398+
InstanceDef::DropGlue(..) |
399+
InstanceDef::CloneShim(..) => {
400+
None
401+
}
402+
}
403+
}
404+
MonoItem::Static(def_id) => {
405+
tcx.hir().as_local_hir_id(def_id)
406+
}
407+
MonoItem::GlobalAsm(hir_id) => {
408+
Some(hir_id)
409+
}
410+
}, item.symbol_name(tcx))
411+
}
412+
413+
let mut items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect();
414+
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
415+
items
416+
}
417+
418+
pub fn codegen_dep_node(&self, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> DepNode {
419+
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name().clone()))
420+
}
353421
}
354422

355423
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for CodegenUnit<'tcx> {

src/librustc_codegen_llvm/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ extern crate flate2;
3232
#[macro_use] extern crate bitflags;
3333
extern crate libc;
3434
#[macro_use] extern crate rustc;
35-
extern crate rustc_mir;
3635
extern crate rustc_allocator;
3736
extern crate rustc_target;
3837
#[macro_use] extern crate rustc_data_structures;

src/librustc_codegen_ssa/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rustc::middle::cstore::{self, LinkagePreference};
2828
use rustc::util::common::{time, print_time_passes_entry};
2929
use rustc::session::config::{self, EntryFnType, Lto};
3030
use rustc::session::Session;
31-
use rustc_mir::monomorphize::partitioning::CodegenUnitExt;
3231
use rustc::util::nodemap::FxHashMap;
3332
use rustc_data_structures::indexed_vec::Idx;
3433
use rustc_codegen_utils::{symbol_names_test, check_for_rustc_errors_attr};

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ use std::cmp;
9797
use std::sync::Arc;
9898

9999
use syntax::symbol::InternedString;
100-
use rustc::dep_graph::{WorkProductId, WorkProduct, DepNode, DepConstructor};
101-
use rustc::hir::{CodegenFnAttrFlags, HirId};
100+
use rustc::hir::CodegenFnAttrFlags;
102101
use rustc::hir::def::DefKind;
103102
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
104103
use rustc::mir::mono::{Linkage, Visibility, CodegenUnitNameBuilder, CodegenUnit};
@@ -121,93 +120,6 @@ pub enum PartitioningStrategy {
121120
FixedUnitCount(usize)
122121
}
123122

124-
pub trait CodegenUnitExt<'tcx> {
125-
fn as_codegen_unit(&self) -> &CodegenUnit<'tcx>;
126-
127-
fn contains_item(&self, item: &MonoItem<'tcx>) -> bool {
128-
self.items().contains_key(item)
129-
}
130-
131-
fn name<'a>(&'a self) -> &'a InternedString
132-
where 'tcx: 'a,
133-
{
134-
&self.as_codegen_unit().name()
135-
}
136-
137-
fn items(&self) -> &FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
138-
&self.as_codegen_unit().items()
139-
}
140-
141-
fn work_product_id(&self) -> WorkProductId {
142-
WorkProductId::from_cgu_name(&self.name().as_str())
143-
}
144-
145-
fn work_product(&self, tcx: TyCtxt<'_, '_, '_>) -> WorkProduct {
146-
let work_product_id = self.work_product_id();
147-
tcx.dep_graph
148-
.previous_work_product(&work_product_id)
149-
.unwrap_or_else(|| {
150-
panic!("Could not find work-product for CGU `{}`", self.name())
151-
})
152-
}
153-
154-
fn items_in_deterministic_order<'a>(&self,
155-
tcx: TyCtxt<'a, 'tcx, 'tcx>)
156-
-> Vec<(MonoItem<'tcx>,
157-
(Linkage, Visibility))> {
158-
// The codegen tests rely on items being process in the same order as
159-
// they appear in the file, so for local items, we sort by node_id first
160-
#[derive(PartialEq, Eq, PartialOrd, Ord)]
161-
pub struct ItemSortKey(Option<HirId>, ty::SymbolName);
162-
163-
fn item_sort_key<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
164-
item: MonoItem<'tcx>) -> ItemSortKey {
165-
ItemSortKey(match item {
166-
MonoItem::Fn(ref instance) => {
167-
match instance.def {
168-
// We only want to take HirIds of user-defined
169-
// instances into account. The others don't matter for
170-
// the codegen tests and can even make item order
171-
// unstable.
172-
InstanceDef::Item(def_id) => {
173-
tcx.hir().as_local_hir_id(def_id)
174-
}
175-
InstanceDef::VtableShim(..) |
176-
InstanceDef::Intrinsic(..) |
177-
InstanceDef::FnPtrShim(..) |
178-
InstanceDef::Virtual(..) |
179-
InstanceDef::ClosureOnceShim { .. } |
180-
InstanceDef::DropGlue(..) |
181-
InstanceDef::CloneShim(..) => {
182-
None
183-
}
184-
}
185-
}
186-
MonoItem::Static(def_id) => {
187-
tcx.hir().as_local_hir_id(def_id)
188-
}
189-
MonoItem::GlobalAsm(hir_id) => {
190-
Some(hir_id)
191-
}
192-
}, item.symbol_name(tcx))
193-
}
194-
195-
let mut items: Vec<_> = self.items().iter().map(|(&i, &l)| (i, l)).collect();
196-
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
197-
items
198-
}
199-
200-
fn codegen_dep_node(&self, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> DepNode {
201-
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name().clone()))
202-
}
203-
}
204-
205-
impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
206-
fn as_codegen_unit(&self) -> &CodegenUnit<'tcx> {
207-
self
208-
}
209-
}
210-
211123
// Anything we can't find a proper codegen unit for goes into this.
212124
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_, '_, '_>) -> InternedString {
213125
name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu"))

0 commit comments

Comments
 (0)