Skip to content

Commit

Permalink
move single-use function
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Jun 3, 2019
1 parent 58bd0ea commit 5940689
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
44 changes: 0 additions & 44 deletions src/librustc_mir/monomorphize/mod.rs
Expand Up @@ -8,50 +8,6 @@ pub mod collector;
pub mod item;
pub mod partitioning;

#[inline(never)] // give this a place in the profiler
pub fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mono_items: I)
where I: Iterator<Item=&'a MonoItem<'tcx>>
{
let mut symbols: Vec<_> = mono_items.map(|mono_item| {
(mono_item, mono_item.symbol_name(tcx))
}).collect();

symbols.sort_by_key(|sym| sym.1);

for pair in symbols.windows(2) {
let sym1 = &pair[0].1;
let sym2 = &pair[1].1;

if sym1 == sym2 {
let mono_item1 = pair[0].0;
let mono_item2 = pair[1].0;

let span1 = mono_item1.local_span(tcx);
let span2 = mono_item2.local_span(tcx);

// Deterministically select one of the spans for error reporting
let span = match (span1, span2) {
(Some(span1), Some(span2)) => {
Some(if span1.lo().0 > span2.lo().0 {
span1
} else {
span2
})
}
(span1, span2) => span1.or(span2),
};

let error_message = format!("symbol `{}` is already defined", sym1);

if let Some(span) = span {
tcx.sess.span_fatal(span, &error_message)
} else {
tcx.sess.fatal(&error_message)
}
}
}
}

pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source_ty: Ty<'tcx>,
target_ty: Ty<'tcx>)
Expand Down
46 changes: 45 additions & 1 deletion src/librustc_mir/monomorphize/partitioning.rs
Expand Up @@ -882,6 +882,50 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}

#[inline(never)] // give this a place in the profiler
fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mono_items: I)
where I: Iterator<Item=&'a MonoItem<'tcx>>
{
let mut symbols: Vec<_> = mono_items.map(|mono_item| {
(mono_item, mono_item.symbol_name(tcx))
}).collect();

symbols.sort_by_key(|sym| sym.1);

for pair in symbols.windows(2) {
let sym1 = &pair[0].1;
let sym2 = &pair[1].1;

if sym1 == sym2 {
let mono_item1 = pair[0].0;
let mono_item2 = pair[1].0;

let span1 = mono_item1.local_span(tcx);
let span2 = mono_item2.local_span(tcx);

// Deterministically select one of the spans for error reporting
let span = match (span1, span2) {
(Some(span1), Some(span2)) => {
Some(if span1.lo().0 > span2.lo().0 {
span1
} else {
span2
})
}
(span1, span2) => span1.or(span2),
};

let error_message = format!("symbol `{}` is already defined", sym1);

if let Some(span) = span {
tcx.sess.span_fatal(span, &error_message)
} else {
tcx.sess.fatal(&error_message)
}
}
}
}

fn collect_and_partition_mono_items<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
cnum: CrateNum,
Expand Down Expand Up @@ -922,7 +966,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>(

tcx.sess.abort_if_errors();

crate::monomorphize::assert_symbols_are_distinct(tcx, items.iter());
assert_symbols_are_distinct(tcx, items.iter());

let strategy = if tcx.sess.opts.incremental.is_some() {
PartitioningStrategy::PerModule
Expand Down

0 comments on commit 5940689

Please sign in to comment.