Skip to content

Commit d347081

Browse files
committed
Auto merge of #158105 - camelid:group-shims, r=<try>
Extract all instance shim variants into new `ShimKind` enum
2 parents cddcbec + c0e7481 commit d347081

35 files changed

Lines changed: 508 additions & 436 deletions

File tree

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use rustc_abi::{CanonAbi, ExternAbi, X86Call};
1616
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
1717
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
1818
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
19-
use rustc_middle::ty::TypeVisitableExt;
2019
use rustc_middle::ty::layout::FnAbiOf;
2120
use rustc_middle::ty::print::with_no_trimmed_paths;
21+
use rustc_middle::ty::{ShimKind, TypeVisitableExt};
2222
use rustc_session::Session;
2323
use rustc_span::Spanned;
2424
use rustc_target::callconv::{FnAbi, PassMode};
@@ -467,7 +467,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
467467
}
468468
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
469469
// it is `func returning noop future`
470-
InstanceKind::DropGlue(_, None) => {
470+
InstanceKind::Shim(ShimKind::DropGlue(_, None)) => {
471471
// empty drop glue - a nop.
472472
let dest = target.expect("Non terminating drop_in_place_real???");
473473
let ret_block = fx.get_block(dest);
@@ -725,7 +725,7 @@ pub(crate) fn codegen_drop<'tcx>(
725725
let ret_block = fx.get_block(target);
726726

727727
// AsyncDropGlueCtorShim can't be here
728-
if let ty::InstanceKind::DropGlue(_, None) = drop_instance.def {
728+
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_instance.def {
729729
// we don't actually need to drop anything
730730
fx.bcx.ins().jump(ret_block, &[]);
731731
} else {

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
5353
) -> CValue<'tcx> {
5454
let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) {
5555
let instance = ty::Instance {
56-
def: ty::InstanceKind::ThreadLocalShim(def_id),
56+
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
5757
args: ty::GenericArgs::empty(),
5858
};
5959
let func_ref = fx.get_function_ref(instance);

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use rustc_middle::middle::exported_symbols::{
1111
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
1212
};
1313
use rustc_middle::query::LocalCrate;
14-
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolName, Ty, TyCtxt};
14+
use rustc_middle::ty::{
15+
self, GenericArgKind, GenericArgsRef, Instance, ShimKind, SymbolName, Ty, TyCtxt,
16+
};
1517
use rustc_middle::util::Providers;
1618
use rustc_session::config::CrateType;
1719
use rustc_span::Span;
@@ -332,7 +334,10 @@ fn exported_generic_symbols_provider_local<'tcx>(
332334
));
333335
}
334336
}
335-
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => {
337+
MonoItem::Fn(Instance {
338+
def: InstanceKind::Shim(ShimKind::DropGlue(_, Some(ty))),
339+
args,
340+
}) => {
336341
// A little sanity-check
337342
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
338343

@@ -356,7 +361,7 @@ fn exported_generic_symbols_provider_local<'tcx>(
356361
}
357362
}
358363
MonoItem::Fn(Instance {
359-
def: InstanceKind::AsyncDropGlueCtorShim(_, ty),
364+
def: InstanceKind::Shim(ShimKind::AsyncDropGlueCtor(_, ty)),
360365
args,
361366
}) => {
362367
// A little sanity-check
@@ -371,7 +376,10 @@ fn exported_generic_symbols_provider_local<'tcx>(
371376
},
372377
));
373378
}
374-
MonoItem::Fn(Instance { def: InstanceKind::AsyncDropGlue(def, ty), args: _ }) => {
379+
MonoItem::Fn(Instance {
380+
def: InstanceKind::Shim(ShimKind::AsyncDropGlue(def, ty)),
381+
args: _,
382+
}) => {
375383
symbols.push((
376384
ExportedSymbol::AsyncDropGlue(def, ty),
377385
SymbolExportInfo {
@@ -578,7 +586,7 @@ pub(crate) fn symbol_name_for_instance_in_crate<'tcx>(
578586
rustc_symbol_mangling::symbol_name_for_instance_in_crate(
579587
tcx,
580588
ty::Instance {
581-
def: ty::InstanceKind::ThreadLocalShim(def_id),
589+
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
582590
args: ty::GenericArgs::empty(),
583591
},
584592
instantiating_crate,

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
618618
let ty = self.monomorphize(ty);
619619
let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
620620

621-
if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
621+
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_fn.def {
622622
// we don't actually need to drop anything.
623623
return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
624624
}
@@ -934,7 +934,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
934934
match instance.def {
935935
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
936936
// it is `func returning noop future`
937-
ty::InstanceKind::DropGlue(_, None) => {
937+
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) => {
938938
// Empty drop glue; a no-op.
939939
let target = target.unwrap();
940940
return helper.funclet_br(self, bx, target, mergeable_succ, &[]);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
665665
let static_ = if !def_id.is_local() && bx.cx().tcx().needs_thread_local_shim(def_id)
666666
{
667667
let instance = ty::Instance {
668-
def: ty::InstanceKind::ThreadLocalShim(def_id),
668+
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
669669
args: ty::GenericArgs::empty(),
670670
};
671671
let fn_ptr = bx.get_fn_addr(instance);

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
428428
// Determine whether this is a non-capturing closure. That's relevant as their first
429429
// argument can be skipped (and that's the only kind of argument skipping we allow).
430430
let is_non_capturing_closure =
431-
(matches!(instance.def, ty::InstanceKind::ClosureOnceShim { .. })
431+
(matches!(instance.def, ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. }))
432432
|| self.tcx.is_closure_like(def_id))
433433
&& {
434434
let arg = &callee_fn_abi.args[0];
@@ -652,18 +652,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
652652
interp_ok(())
653653
}
654654
}
655-
ty::InstanceKind::VTableShim(..)
656-
| ty::InstanceKind::ReifyShim(..)
657-
| ty::InstanceKind::ClosureOnceShim { .. }
658-
| ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
659-
| ty::InstanceKind::FnPtrShim(..)
660-
| ty::InstanceKind::DropGlue(..)
661-
| ty::InstanceKind::CloneShim(..)
662-
| ty::InstanceKind::FnPtrAddrShim(..)
663-
| ty::InstanceKind::ThreadLocalShim(..)
664-
| ty::InstanceKind::AsyncDropGlueCtorShim(..)
665-
| ty::InstanceKind::AsyncDropGlue(..)
666-
| ty::InstanceKind::FutureDropPollShim(..)
655+
ty::InstanceKind::Shim(ty::ShimKind::VTable(..))
656+
| ty::InstanceKind::Shim(ty::ShimKind::Reify(..))
657+
| ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. })
658+
| ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure { .. })
659+
| ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..))
660+
| ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..))
661+
| ty::InstanceKind::Shim(ty::ShimKind::Clone(..))
662+
| ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(..))
663+
| ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..))
664+
| ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(..))
665+
| ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(..))
666+
| ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(..))
667667
| ty::InstanceKind::Item(_) => {
668668
// We need MIR for this fn.
669669
// Note that this can be an intrinsic, if we are executing its fallback body.

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
607607
enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty);
608608
Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
609609
};
610-
if let ty::InstanceKind::DropGlue(_, None) = instance.def {
610+
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = instance.def {
611611
// This is the branch we enter if and only if the dropped type has no drop glue
612612
// whatsoever. This can happen as a result of monomorphizing a drop of a
613613
// generic. In order to make sure that generic and non-generic code behaves

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Symbol;
88
use rustc_target::spec::SanitizerSet;
99

1010
use crate::mono::Visibility;
11-
use crate::ty::{InstanceKind, TyCtxt};
11+
use crate::ty::{InstanceKind, ShimKind, TyCtxt};
1212

1313
impl<'tcx> TyCtxt<'tcx> {
1414
pub fn codegen_instance_attrs(
@@ -33,7 +33,7 @@ impl<'tcx> TyCtxt<'tcx> {
3333
//
3434
// A `ClosureOnceShim` with the track_caller attribute does not have a symbol,
3535
// and therefore can be skipped here.
36-
if let InstanceKind::ReifyShim(_, _) = instance_kind
36+
if let InstanceKind::Shim(ShimKind::Reify(_, _)) = instance_kind
3737
&& attrs.flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
3838
{
3939
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
@@ -54,8 +54,11 @@ impl<'tcx> TyCtxt<'tcx> {
5454
}
5555

5656
// Ensure closure shims have the optimization properties of their closure applied to them.
57-
if let InstanceKind::ClosureOnceShim { call_once: _, closure, track_caller: _ } =
58-
instance_kind
57+
if let InstanceKind::Shim(ShimKind::ClosureOnce {
58+
call_once: _,
59+
closure,
60+
track_caller: _,
61+
}) = instance_kind
5962
{
6063
let closure_attrs = self.codegen_fn_attrs(closure);
6164
attrs.to_mut().optimize = closure_attrs.optimize;

compiler/rustc_middle/src/middle/exported_symbols.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'tcx> ExportedSymbol<'tcx> {
7575
tcx.symbol_name(ty::Instance::resolve_async_drop_in_place_poll(tcx, def_id, ty))
7676
}
7777
ExportedSymbol::ThreadLocalShim(def_id) => tcx.symbol_name(ty::Instance {
78-
def: ty::InstanceKind::ThreadLocalShim(def_id),
78+
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
7979
args: ty::GenericArgs::empty(),
8080
}),
8181
ExportedSymbol::NoDefId(symbol_name) => symbol_name,

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use crate::mir::interpret::{AllocRange, Scalar};
3232
use crate::ty::codec::{TyDecoder, TyEncoder};
3333
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
3434
use crate::ty::{
35-
self, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt, TypeVisitableExt,
36-
TypingEnv, UserTypeAnnotationIndex,
35+
self, GenericArg, GenericArgsRef, Instance, InstanceKind, List, ShimKind, Ty, TyCtxt,
36+
TypeVisitableExt, TypingEnv, UserTypeAnnotationIndex,
3737
};
3838

3939
mod basic_blocks;
@@ -127,8 +127,8 @@ impl<'tcx> MirSource<'tcx> {
127127
MirSource { instance: InstanceKind::Item(def_id), promoted: None }
128128
}
129129

130-
pub fn from_instance(instance: InstanceKind<'tcx>) -> Self {
131-
MirSource { instance, promoted: None }
130+
pub fn from_shim(shim: ShimKind<'tcx>) -> Self {
131+
MirSource { instance: InstanceKind::Shim(shim), promoted: None }
132132
}
133133

134134
#[inline]

0 commit comments

Comments
 (0)