Skip to content

Commit 9e5c162

Browse files
committed
Move the implementation to codegen, to use monomorphized types
1 parent dedc3b3 commit 9e5c162

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
153153

154154
let llfn = cx.get_fn(instance);
155155

156-
let mir = cx.tcx().instance_mir(instance.def);
156+
let mut mir = cx.tcx().instance_mir(instance.def);
157157

158158
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
159159
debug!("fn_abi: {:?}", fn_abi);
@@ -260,6 +260,31 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
260260
// Apply debuginfo to the newly allocated locals.
261261
fx.debug_introduce_locals(&mut start_bx);
262262

263+
if mir.args_iter().any(|arg| {
264+
// Find the monomorphized type of our argument
265+
let arg_decl = &mir.local_decls[arg];
266+
let arg_ty = fx.monomorphize(arg_decl.ty);
267+
268+
// And check if it is a reference to an uninhabited type
269+
let ty = arg_ty.peel_refs();
270+
start_bx.layout_of(ty).abi.is_uninhabited()
271+
}) {
272+
// We're probably not supposed to mutate MIR here.
273+
// But since we have an arena, we can just create a clone and replace all references to
274+
// the old MIR with the new.
275+
let mut body = mir.clone();
276+
let blocks = body.basic_blocks.as_mut();
277+
blocks.truncate(1);
278+
let block = &mut blocks[rustc_middle::mir::START_BLOCK];
279+
block.statements.clear();
280+
block.terminator.as_mut().unwrap().kind = rustc_middle::mir::TerminatorKind::Unreachable;
281+
block.is_cleanup = false;
282+
283+
// Now we have new MIR, stash it in the TyCtxt arena and swap it in
284+
mir = fx.cx.tcx().arena.alloc(body);
285+
fx.mir = mir;
286+
}
287+
263288
// The builders will be created separately for each basic block at `codegen_block`.
264289
// So drop the builder of `start_llbb` to avoid having two at the same time.
265290
drop(start_bx);

compiler/rustc_mir_transform/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ mod multiple_return_terminators;
8686
mod normalize_array_len;
8787
mod nrvo;
8888
mod prettify;
89-
mod ralf_refs;
9089
mod ref_prop;
9190
mod remove_noop_landing_pads;
9291
mod remove_storage_markers;
@@ -546,7 +545,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
546545
&check_alignment::CheckAlignment,
547546
&reveal_all::RevealAll, // has to be done before inlining, since inlined code is in RevealAll mode.
548547
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
549-
&ralf_refs::RalfRefs,
550548
&unreachable_prop::UnreachablePropagation,
551549
&uninhabited_enum_branching::UninhabitedEnumBranching,
552550
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),

compiler/rustc_mir_transform/src/ralf_refs.rs

-38
This file was deleted.

0 commit comments

Comments
 (0)