Skip to content

Commit 1181f45

Browse files
MaikKleinarielb1
authored andcommitted
Rename TransItem to MonoItem
1 parent e579b06 commit 1181f45

File tree

9 files changed

+116
-111
lines changed

9 files changed

+116
-111
lines changed

src/librustc/middle/trans.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
1717
use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
1818

1919
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
20-
pub enum TransItem<'tcx> {
20+
pub enum MonoItem<'tcx> {
2121
Fn(Instance<'tcx>),
2222
Static(NodeId),
2323
GlobalAsm(NodeId),
2424
}
2525

26-
impl<'tcx> HashStable<StableHashingContext<'tcx>> for TransItem<'tcx> {
26+
impl<'tcx> HashStable<StableHashingContext<'tcx>> for MonoItem<'tcx> {
2727
fn hash_stable<W: StableHasherResult>(&self,
2828
hcx: &mut StableHashingContext<'tcx>,
2929
hasher: &mut StableHasher<W>) {
3030
::std::mem::discriminant(self).hash_stable(hcx, hasher);
3131

3232
match *self {
33-
TransItem::Fn(ref instance) => {
33+
MonoItem::Fn(ref instance) => {
3434
instance.hash_stable(hcx, hasher);
3535
}
36-
TransItem::Static(node_id) |
37-
TransItem::GlobalAsm(node_id) => {
36+
MonoItem::Static(node_id) |
37+
MonoItem::GlobalAsm(node_id) => {
3838
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
3939
node_id.hash_stable(hcx, hasher);
4040
})
@@ -49,7 +49,7 @@ pub struct CodegenUnit<'tcx> {
4949
/// contain something unique to this crate (e.g., a module path)
5050
/// as well as the crate name and disambiguator.
5151
name: InternedString,
52-
items: FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>,
52+
items: FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>,
5353
}
5454

5555
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
@@ -110,12 +110,12 @@ impl<'tcx> CodegenUnit<'tcx> {
110110
self.name = name;
111111
}
112112

113-
pub fn items(&self) -> &FxHashMap<TransItem<'tcx>, (Linkage, Visibility)> {
113+
pub fn items(&self) -> &FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
114114
&self.items
115115
}
116116

117117
pub fn items_mut(&mut self)
118-
-> &mut FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>
118+
-> &mut FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>
119119
{
120120
&mut self.items
121121
}

src/librustc/ty/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24712471
}
24722472
}
24732473

2474+
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
2475+
pub fn is_sized(self, ty: Ty<'tcx>) -> bool {
2476+
ty.is_sized(self, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
2477+
}
2478+
}
24742479
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24752480
pub fn with_freevars<T, F>(self, fid: NodeId, f: F) -> T where
24762481
F: FnOnce(&[hir::Freevar]) -> T,

src/librustc_mir/monomorphize/collector.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ use rustc::hir::map as hir_map;
195195
use rustc::hir::def_id::DefId;
196196
use rustc::middle::const_val::ConstVal;
197197
use rustc::middle::lang_items::{ExchangeMallocFnLangItem};
198-
use rustc::middle::trans::TransItem;
198+
use rustc::middle::trans::MonoItem;
199199
use rustc::traits;
200200
use rustc::ty::subst::Substs;
201201
use rustc::ty::{self, TypeFoldable, Ty, TyCtxt};
@@ -226,8 +226,8 @@ pub struct InliningMap<'tcx> {
226226
// accessed by it.
227227
// The two numbers in the tuple are the start (inclusive) and
228228
// end index (exclusive) within the `targets` vecs.
229-
index: FxHashMap<TransItem<'tcx>, (usize, usize)>,
230-
targets: Vec<TransItem<'tcx>>,
229+
index: FxHashMap<MonoItem<'tcx>, (usize, usize)>,
230+
targets: Vec<MonoItem<'tcx>>,
231231

232232
// Contains one bit per translation item in the `targets` field. That bit
233233
// is true if that translation item needs to be inlined into every CGU.
@@ -245,9 +245,9 @@ impl<'tcx> InliningMap<'tcx> {
245245
}
246246

247247
fn record_accesses<I>(&mut self,
248-
source: TransItem<'tcx>,
248+
source: MonoItem<'tcx>,
249249
new_targets: I)
250-
where I: Iterator<Item=(TransItem<'tcx>, bool)> + ExactSizeIterator
250+
where I: Iterator<Item=(MonoItem<'tcx>, bool)> + ExactSizeIterator
251251
{
252252
assert!(!self.index.contains_key(&source));
253253

@@ -271,8 +271,8 @@ impl<'tcx> InliningMap<'tcx> {
271271

272272
// Internally iterate over all items referenced by `source` which will be
273273
// made available for inlining.
274-
pub fn with_inlining_candidates<F>(&self, source: TransItem<'tcx>, mut f: F)
275-
where F: FnMut(TransItem<'tcx>)
274+
pub fn with_inlining_candidates<F>(&self, source: MonoItem<'tcx>, mut f: F)
275+
where F: FnMut(MonoItem<'tcx>)
276276
{
277277
if let Some(&(start_index, end_index)) = self.index.get(&source) {
278278
for (i, candidate) in self.targets[start_index .. end_index]
@@ -287,7 +287,7 @@ impl<'tcx> InliningMap<'tcx> {
287287

288288
// Internally iterate over all items and the things each accesses.
289289
pub fn iter_accesses<F>(&self, mut f: F)
290-
where F: FnMut(TransItem<'tcx>, &[TransItem<'tcx>])
290+
where F: FnMut(MonoItem<'tcx>, &[MonoItem<'tcx>])
291291
{
292292
for (&accessor, &(start_index, end_index)) in &self.index {
293293
f(accessor, &self.targets[start_index .. end_index])
@@ -297,7 +297,7 @@ impl<'tcx> InliningMap<'tcx> {
297297

298298
pub fn collect_crate_translation_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
299299
mode: TransItemCollectionMode)
300-
-> (FxHashSet<TransItem<'tcx>>,
300+
-> (FxHashSet<MonoItem<'tcx>>,
301301
InliningMap<'tcx>) {
302302
let roots = collect_roots(tcx, mode);
303303

@@ -321,7 +321,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
321321
// start monomorphizing from.
322322
fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
323323
mode: TransItemCollectionMode)
324-
-> Vec<TransItem<'tcx>> {
324+
-> Vec<MonoItem<'tcx>> {
325325
debug!("Collecting roots");
326326
let mut roots = Vec::new();
327327

@@ -350,8 +350,8 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
350350

351351
// Collect all monomorphized translation items reachable from `starting_point`
352352
fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
353-
starting_point: TransItem<'tcx>,
354-
visited: &mut FxHashSet<TransItem<'tcx>>,
353+
starting_point: MonoItem<'tcx>,
354+
visited: &mut FxHashSet<MonoItem<'tcx>>,
355355
recursion_depths: &mut DefIdMap<usize>,
356356
inlining_map: &mut InliningMap<'tcx>) {
357357
if !visited.insert(starting_point.clone()) {
@@ -364,7 +364,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
364364
let recursion_depth_reset;
365365

366366
match starting_point {
367-
TransItem::Static(node_id) => {
367+
MonoItem::Static(node_id) => {
368368
let def_id = tcx.hir.local_def_id(node_id);
369369
let instance = Instance::mono(tcx, def_id);
370370

@@ -378,7 +378,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
378378

379379
collect_neighbours(tcx, instance, true, &mut neighbors);
380380
}
381-
TransItem::Fn(instance) => {
381+
MonoItem::Fn(instance) => {
382382
// Sanity check whether this ended up being collected accidentally
383383
debug_assert!(should_trans_locally(tcx, &instance));
384384

@@ -390,7 +390,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
390390

391391
collect_neighbours(tcx, instance, false, &mut neighbors);
392392
}
393-
TransItem::GlobalAsm(..) => {
393+
MonoItem::GlobalAsm(..) => {
394394
recursion_depth_reset = None;
395395
}
396396
}
@@ -409,10 +409,10 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
409409
}
410410

411411
fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
412-
caller: TransItem<'tcx>,
413-
callees: &[TransItem<'tcx>],
412+
caller: MonoItem<'tcx>,
413+
callees: &[MonoItem<'tcx>],
414414
inlining_map: &mut InliningMap<'tcx>) {
415-
let is_inlining_candidate = |trans_item: &TransItem<'tcx>| {
415+
let is_inlining_candidate = |trans_item: &MonoItem<'tcx>| {
416416
trans_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
417417
};
418418

@@ -495,7 +495,7 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
495495
struct MirNeighborCollector<'a, 'tcx: 'a> {
496496
tcx: TyCtxt<'a, 'tcx, 'tcx>,
497497
mir: &'a mir::Mir<'tcx>,
498-
output: &'a mut Vec<TransItem<'tcx>>,
498+
output: &'a mut Vec<MonoItem<'tcx>>,
499499
param_substs: &'tcx Substs<'tcx>,
500500
const_context: bool,
501501
}
@@ -647,7 +647,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
647647
let instance = Instance::mono(tcx, static_.def_id);
648648
if should_trans_locally(tcx, &instance) {
649649
let node_id = tcx.hir.as_local_node_id(static_.def_id).unwrap();
650-
self.output.push(TransItem::Static(node_id));
650+
self.output.push(MonoItem::Static(node_id));
651651
}
652652

653653
self.super_static(static_, context, location);
@@ -657,7 +657,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
657657
fn visit_drop_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
658658
ty: Ty<'tcx>,
659659
is_direct_call: bool,
660-
output: &mut Vec<TransItem<'tcx>>)
660+
output: &mut Vec<MonoItem<'tcx>>)
661661
{
662662
let instance = monomorphize::resolve_drop_in_place(tcx, ty);
663663
visit_instance_use(tcx, instance, is_direct_call, output);
@@ -666,7 +666,7 @@ fn visit_drop_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
666666
fn visit_fn_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
667667
ty: Ty<'tcx>,
668668
is_direct_call: bool,
669-
output: &mut Vec<TransItem<'tcx>>)
669+
output: &mut Vec<MonoItem<'tcx>>)
670670
{
671671
if let ty::TyFnDef(def_id, substs) = ty.sty {
672672
let instance = ty::Instance::resolve(tcx,
@@ -680,7 +680,7 @@ fn visit_fn_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
680680
fn visit_instance_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
681681
instance: ty::Instance<'tcx>,
682682
is_direct_call: bool,
683-
output: &mut Vec<TransItem<'tcx>>)
683+
output: &mut Vec<MonoItem<'tcx>>)
684684
{
685685
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
686686
if !should_trans_locally(tcx, &instance) {
@@ -838,17 +838,17 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
838838
}
839839
}
840840

841-
fn create_fn_trans_item<'a, 'tcx>(instance: Instance<'tcx>) -> TransItem<'tcx> {
841+
fn create_fn_trans_item<'a, 'tcx>(instance: Instance<'tcx>) -> MonoItem<'tcx> {
842842
debug!("create_fn_trans_item(instance={})", instance);
843-
TransItem::Fn(instance)
843+
MonoItem::Fn(instance)
844844
}
845845

846846
/// Creates a `TransItem` for each method that is referenced by the vtable for
847847
/// the given trait/impl pair.
848848
fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
849849
trait_ty: Ty<'tcx>,
850850
impl_ty: Ty<'tcx>,
851-
output: &mut Vec<TransItem<'tcx>>) {
851+
output: &mut Vec<MonoItem<'tcx>>) {
852852
assert!(!trait_ty.needs_subst() && !trait_ty.has_escaping_regions() &&
853853
!impl_ty.needs_subst() && !impl_ty.has_escaping_regions());
854854

@@ -881,7 +881,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
881881
struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
882882
tcx: TyCtxt<'a, 'tcx, 'tcx>,
883883
mode: TransItemCollectionMode,
884-
output: &'b mut Vec<TransItem<'tcx>>,
884+
output: &'b mut Vec<MonoItem<'tcx>>,
885885
entry_fn: Option<DefId>,
886886
}
887887

@@ -925,13 +925,13 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
925925
debug!("RootCollector: ItemGlobalAsm({})",
926926
def_id_to_string(self.tcx,
927927
self.tcx.hir.local_def_id(item.id)));
928-
self.output.push(TransItem::GlobalAsm(item.id));
928+
self.output.push(MonoItem::GlobalAsm(item.id));
929929
}
930930
hir::ItemStatic(..) => {
931931
debug!("RootCollector: ItemStatic({})",
932932
def_id_to_string(self.tcx,
933933
self.tcx.hir.local_def_id(item.id)));
934-
self.output.push(TransItem::Static(item.id));
934+
self.output.push(MonoItem::Static(item.id));
935935
}
936936
hir::ItemConst(..) => {
937937
// const items only generate translation items if they are
@@ -946,7 +946,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
946946
def_id_to_string(tcx, def_id));
947947

948948
let instance = Instance::mono(tcx, def_id);
949-
self.output.push(TransItem::Fn(instance));
949+
self.output.push(MonoItem::Fn(instance));
950950
}
951951
}
952952
}
@@ -968,7 +968,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
968968
def_id_to_string(tcx, def_id));
969969

970970
let instance = Instance::mono(tcx, def_id);
971-
self.output.push(TransItem::Fn(instance));
971+
self.output.push(MonoItem::Fn(instance));
972972
}
973973
}
974974
_ => { /* Nothing to do here */ }
@@ -999,7 +999,7 @@ fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
999999

10001000
fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10011001
item: &'tcx hir::Item,
1002-
output: &mut Vec<TransItem<'tcx>>) {
1002+
output: &mut Vec<MonoItem<'tcx>>) {
10031003
match item.node {
10041004
hir::ItemImpl(_,
10051005
_,
@@ -1053,7 +1053,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10531053
fn collect_neighbours<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10541054
instance: Instance<'tcx>,
10551055
const_context: bool,
1056-
output: &mut Vec<TransItem<'tcx>>)
1056+
output: &mut Vec<MonoItem<'tcx>>)
10571057
{
10581058
let mir = tcx.instance_mir(instance.def);
10591059

0 commit comments

Comments
 (0)