Skip to content

Commit 5b53e4d

Browse files
committed
Don't re-mono
1 parent 35e95a7 commit 5b53e4d

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_index::IndexVec;
44
use rustc_index::bit_set::BitSet;
55
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
66
use rustc_middle::mir::{UnwindTerminateReason, traversal};
7-
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, TyAndLayout};
7+
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout};
88
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
99
use rustc_middle::{bug, mir, span_bug};
1010
use rustc_target::callconv::{FnAbi, PassMode};
@@ -125,12 +125,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
125125
where
126126
T: Copy + TypeFoldable<TyCtxt<'tcx>>,
127127
{
128-
debug!("monomorphize: self.instance={:?}", self.instance);
129-
self.instance.instantiate_mir_and_normalize_erasing_regions(
130-
self.cx.tcx(),
131-
self.cx.typing_env(),
132-
ty::EarlyBinder::bind(value),
133-
)
128+
value
134129
}
135130
}
136131

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion};
224224
use rustc_middle::ty::layout::ValidityRequirement;
225225
use rustc_middle::ty::print::{shrunk_instance_name, with_no_trimmed_paths};
226226
use rustc_middle::ty::{
227-
self, GenericArgs, GenericParamDefKind, Instance, InstanceKind, Ty, TyCtxt, TypeFoldable,
228-
TypeVisitableExt, VtblEntry,
227+
self, GenericArgs, GenericParamDefKind, Instance, InstanceKind, Ty, TyCtxt, TypeVisitableExt,
228+
VtblEntry,
229229
};
230230
use rustc_middle::util::Providers;
231231
use rustc_middle::{bug, span_bug};
@@ -625,38 +625,24 @@ struct MirUsedCollector<'a, 'tcx> {
625625
/// See the comment in `collect_items_of_instance` for the purpose of this set.
626626
/// Note that this contains *not-monomorphized* items!
627627
used_mentioned_items: &'a mut UnordSet<MentionedItem<'tcx>>,
628-
instance: Instance<'tcx>,
629628
}
630629

631630
impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
632-
fn monomorphize<T>(&self, value: T) -> T
633-
where
634-
T: TypeFoldable<TyCtxt<'tcx>>,
635-
{
636-
trace!("monomorphize: self.instance={:?}", self.instance);
637-
self.instance.instantiate_mir_and_normalize_erasing_regions(
638-
self.tcx,
639-
ty::TypingEnv::fully_monomorphized(),
640-
ty::EarlyBinder::bind(value),
641-
)
642-
}
643-
644-
/// Evaluates a *not yet monomorphized* constant.
631+
/// Evaluates a monomorphized constant.
645632
fn eval_constant(
646633
&mut self,
647634
constant: &mir::ConstOperand<'tcx>,
648635
) -> Option<mir::ConstValue<'tcx>> {
649-
let const_ = self.monomorphize(constant.const_);
650636
// Evaluate the constant. This makes const eval failure a collection-time error (rather than
651637
// a codegen-time error). rustc stops after collection if there was an error, so this
652638
// ensures codegen never has to worry about failing consts.
653639
// (codegen relies on this and ICEs will happen if this is violated.)
654-
match const_.eval(self.tcx, ty::TypingEnv::fully_monomorphized(), constant.span) {
640+
match constant.const_.eval(self.tcx, ty::TypingEnv::fully_monomorphized(), constant.span) {
655641
Ok(v) => Some(v),
656642
Err(ErrorHandled::TooGeneric(..)) => span_bug!(
657643
constant.span,
658644
"collection encountered polymorphic constant: {:?}",
659-
const_
645+
constant.const_
660646
),
661647
Err(err @ ErrorHandled::Reported(..)) => {
662648
err.emit_note(self.tcx);
@@ -686,8 +672,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
686672
// *Before* monomorphizing, record that we already handled this mention.
687673
self.used_mentioned_items
688674
.insert(MentionedItem::UnsizeCast { source_ty, target_ty });
689-
let target_ty = self.monomorphize(target_ty);
690-
let source_ty = self.monomorphize(source_ty);
691675
let (source_ty, target_ty) =
692676
find_vtable_types_for_unsizing(self.tcx.at(span), source_ty, target_ty);
693677
// This could also be a different Unsize instruction, like
@@ -713,7 +697,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
713697
let fn_ty = operand.ty(self.body, self.tcx);
714698
// *Before* monomorphizing, record that we already handled this mention.
715699
self.used_mentioned_items.insert(MentionedItem::Fn(fn_ty));
716-
let fn_ty = self.monomorphize(fn_ty);
717700
visit_fn_use(self.tcx, fn_ty, false, span, self.used_items);
718701
}
719702
mir::Rvalue::Cast(
@@ -724,7 +707,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
724707
let source_ty = operand.ty(self.body, self.tcx);
725708
// *Before* monomorphizing, record that we already handled this mention.
726709
self.used_mentioned_items.insert(MentionedItem::Closure(source_ty));
727-
let source_ty = self.monomorphize(source_ty);
728710
if let ty::Closure(def_id, args) = *source_ty.kind() {
729711
let instance =
730712
Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce);
@@ -776,14 +758,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
776758
let callee_ty = func.ty(self.body, tcx);
777759
// *Before* monomorphizing, record that we already handled this mention.
778760
self.used_mentioned_items.insert(MentionedItem::Fn(callee_ty));
779-
let callee_ty = self.monomorphize(callee_ty);
780761
visit_fn_use(self.tcx, callee_ty, true, source, &mut self.used_items)
781762
}
782763
mir::TerminatorKind::Drop { ref place, .. } => {
783764
let ty = place.ty(self.body, self.tcx).ty;
784765
// *Before* monomorphizing, record that we already handled this mention.
785766
self.used_mentioned_items.insert(MentionedItem::Drop(ty));
786-
let ty = self.monomorphize(ty);
787767
visit_drop_use(self.tcx, ty, true, source, self.used_items);
788768
}
789769
mir::TerminatorKind::InlineAsm { ref operands, .. } => {
@@ -793,7 +773,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
793773
let fn_ty = value.const_.ty();
794774
// *Before* monomorphizing, record that we already handled this mention.
795775
self.used_mentioned_items.insert(MentionedItem::Fn(fn_ty));
796-
let fn_ty = self.monomorphize(fn_ty);
797776
visit_fn_use(self.tcx, fn_ty, false, source, self.used_items);
798777
}
799778
mir::InlineAsmOperand::SymStatic { def_id } => {
@@ -1228,7 +1207,6 @@ fn collect_items_of_instance<'tcx>(
12281207
body,
12291208
used_items: &mut used_items,
12301209
used_mentioned_items: &mut used_mentioned_items,
1231-
instance,
12321210
};
12331211

12341212
if mode == CollectionMode::UsedItems {
@@ -1249,8 +1227,7 @@ fn collect_items_of_instance<'tcx>(
12491227
// `used_items` above.
12501228
for item in body.mentioned_items() {
12511229
if !collector.used_mentioned_items.contains(&item.node) {
1252-
let item_mono = collector.monomorphize(item.node);
1253-
visit_mentioned_item(tcx, &item_mono, item.span, &mut mentioned_items);
1230+
visit_mentioned_item(tcx, &item.node, item.span, &mut mentioned_items);
12541231
}
12551232
}
12561233

0 commit comments

Comments
 (0)