Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use rustc_abi::{CanonAbi, ExternAbi, X86Call};
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{ShimKind, TypeVisitableExt};
use rustc_session::Session;
use rustc_span::Spanned;
use rustc_target::callconv::{FnAbi, PassMode};
Expand Down Expand Up @@ -467,7 +467,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
}
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
// it is `func returning noop future`
InstanceKind::DropGlue(_, None) => {
InstanceKind::Shim(ShimKind::DropGlue(_, None)) => {
// empty drop glue - a nop.
let dest = target.expect("Non terminating drop_in_place_real???");
let ret_block = fx.get_block(dest);
Expand Down Expand Up @@ -725,7 +725,7 @@ pub(crate) fn codegen_drop<'tcx>(
let ret_block = fx.get_block(target);

// AsyncDropGlueCtorShim can't be here
if let ty::InstanceKind::DropGlue(_, None) = drop_instance.def {
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_instance.def {
// we don't actually need to drop anything
fx.bcx.ins().jump(ret_block, &[]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
) -> CValue<'tcx> {
let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) {
let instance = ty::Instance {
def: ty::InstanceKind::ThreadLocalShim(def_id),
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
args: ty::GenericArgs::empty(),
};
let func_ref = fx.get_function_ref(instance);
Expand Down
18 changes: 13 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use rustc_middle::middle::exported_symbols::{
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
};
use rustc_middle::query::LocalCrate;
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolName, Ty, TyCtxt};
use rustc_middle::ty::{
self, GenericArgKind, GenericArgsRef, Instance, ShimKind, SymbolName, Ty, TyCtxt,
};
use rustc_middle::util::Providers;
use rustc_session::config::CrateType;
use rustc_span::Span;
Expand Down Expand Up @@ -332,7 +334,10 @@ fn exported_generic_symbols_provider_local<'tcx>(
));
}
}
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => {
MonoItem::Fn(Instance {
def: InstanceKind::Shim(ShimKind::DropGlue(_, Some(ty))),
args,
}) => {
// A little sanity-check
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));

Expand All @@ -356,7 +361,7 @@ fn exported_generic_symbols_provider_local<'tcx>(
}
}
MonoItem::Fn(Instance {
def: InstanceKind::AsyncDropGlueCtorShim(_, ty),
def: InstanceKind::Shim(ShimKind::AsyncDropGlueCtor(_, ty)),
args,
}) => {
// A little sanity-check
Expand All @@ -371,7 +376,10 @@ fn exported_generic_symbols_provider_local<'tcx>(
},
));
}
MonoItem::Fn(Instance { def: InstanceKind::AsyncDropGlue(def, ty), args: _ }) => {
MonoItem::Fn(Instance {
def: InstanceKind::Shim(ShimKind::AsyncDropGlue(def, ty)),
args: _,
}) => {
symbols.push((
ExportedSymbol::AsyncDropGlue(def, ty),
SymbolExportInfo {
Expand Down Expand Up @@ -578,7 +586,7 @@ pub(crate) fn symbol_name_for_instance_in_crate<'tcx>(
rustc_symbol_mangling::symbol_name_for_instance_in_crate(
tcx,
ty::Instance {
def: ty::InstanceKind::ThreadLocalShim(def_id),
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
args: ty::GenericArgs::empty(),
},
instantiating_crate,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let ty = self.monomorphize(ty);
let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);

if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_fn.def {
// we don't actually need to drop anything.
return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
}
Expand Down Expand Up @@ -934,7 +934,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
match instance.def {
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
// it is `func returning noop future`
ty::InstanceKind::DropGlue(_, None) => {
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) => {
// Empty drop glue; a no-op.
let target = target.unwrap();
return helper.funclet_br(self, bx, target, mergeable_succ, &[]);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let static_ = if !def_id.is_local() && bx.cx().tcx().needs_thread_local_shim(def_id)
{
let instance = ty::Instance {
def: ty::InstanceKind::ThreadLocalShim(def_id),
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
args: ty::GenericArgs::empty(),
};
let fn_ptr = bx.get_fn_addr(instance);
Expand Down
26 changes: 13 additions & 13 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// Determine whether this is a non-capturing closure. That's relevant as their first
// argument can be skipped (and that's the only kind of argument skipping we allow).
let is_non_capturing_closure =
(matches!(instance.def, ty::InstanceKind::ClosureOnceShim { .. })
(matches!(instance.def, ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. }))
|| self.tcx.is_closure_like(def_id))
&& {
let arg = &callee_fn_abi.args[0];
Expand Down Expand Up @@ -652,18 +652,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
interp_ok(())
}
}
ty::InstanceKind::VTableShim(..)
| ty::InstanceKind::ReifyShim(..)
| ty::InstanceKind::ClosureOnceShim { .. }
| ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
| ty::InstanceKind::FnPtrShim(..)
| ty::InstanceKind::DropGlue(..)
| ty::InstanceKind::CloneShim(..)
| ty::InstanceKind::FnPtrAddrShim(..)
| ty::InstanceKind::ThreadLocalShim(..)
| ty::InstanceKind::AsyncDropGlueCtorShim(..)
| ty::InstanceKind::AsyncDropGlue(..)
| ty::InstanceKind::FutureDropPollShim(..)
ty::InstanceKind::Shim(ty::ShimKind::VTable(..))
| ty::InstanceKind::Shim(ty::ShimKind::Reify(..))
| ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. })
| ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure { .. })
| ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..))
| ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..))
| ty::InstanceKind::Shim(ty::ShimKind::Clone(..))
| ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(..))
| ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..))
| ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(..))
| ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(..))
| ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(..))
| ty::InstanceKind::Item(_) => {
// We need MIR for this fn.
// Note that this can be an intrinsic, if we are executing its fallback body.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty);
Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
};
if let ty::InstanceKind::DropGlue(_, None) = instance.def {
if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = instance.def {
// This is the branch we enter if and only if the dropped type has no drop glue
// whatsoever. This can happen as a result of monomorphizing a drop of a
// generic. In order to make sure that generic and non-generic code behaves
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_span::Symbol;
use rustc_target::spec::SanitizerSet;

use crate::mono::Visibility;
use crate::ty::{InstanceKind, TyCtxt};
use crate::ty::{InstanceKind, ShimKind, TyCtxt};

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

// Ensure closure shims have the optimization properties of their closure applied to them.
if let InstanceKind::ClosureOnceShim { call_once: _, closure, track_caller: _ } =
instance_kind
if let InstanceKind::Shim(ShimKind::ClosureOnce {
call_once: _,
closure,
track_caller: _,
}) = instance_kind
{
let closure_attrs = self.codegen_fn_attrs(closure);
attrs.to_mut().optimize = closure_attrs.optimize;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/exported_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'tcx> ExportedSymbol<'tcx> {
tcx.symbol_name(ty::Instance::resolve_async_drop_in_place_poll(tcx, def_id, ty))
}
ExportedSymbol::ThreadLocalShim(def_id) => tcx.symbol_name(ty::Instance {
def: ty::InstanceKind::ThreadLocalShim(def_id),
def: ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(def_id)),
args: ty::GenericArgs::empty(),
}),
ExportedSymbol::NoDefId(symbol_name) => symbol_name,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use crate::mir::interpret::{AllocRange, Scalar};
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
use crate::ty::{
self, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt, TypeVisitableExt,
TypingEnv, UserTypeAnnotationIndex,
self, GenericArg, GenericArgsRef, Instance, InstanceKind, List, ShimKind, Ty, TyCtxt,
TypeVisitableExt, TypingEnv, UserTypeAnnotationIndex,
};

mod basic_blocks;
Expand Down Expand Up @@ -127,8 +127,8 @@ impl<'tcx> MirSource<'tcx> {
MirSource { instance: InstanceKind::Item(def_id), promoted: None }
}

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

#[inline]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> {
// All drop shims have the same DefId, so we have to add the type
// to get unique file names.
let shim_disambiguator = match source.instance {
ty::InstanceKind::DropGlue(_, Some(ty)) => {
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, Some(ty))) => {
// Unfortunately, pretty-printed types are not very filename-friendly.
// We do some filtering.
let mut s = ".".to_owned();
Expand All @@ -229,7 +229,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> {
}));
s
}
ty::InstanceKind::AsyncDropGlueCtorShim(_, ty) => {
ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_, ty)) => {
let mut s = ".".to_owned();
s.extend(ty.to_string().chars().filter_map(|c| match c {
' ' => None,
Expand All @@ -238,7 +238,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> {
}));
s
}
ty::InstanceKind::AsyncDropGlue(_, ty) => {
ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_, ty)) => {
let ty::Coroutine(_, args) = ty.kind() else {
bug!();
};
Expand All @@ -251,7 +251,7 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> {
}));
s
}
ty::InstanceKind::FutureDropPollShim(_, proxy_cor, impl_cor) => {
ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(_, proxy_cor, impl_cor)) => {
let mut s = ".".to_owned();
s.extend(proxy_cor.to_string().chars().filter_map(|c| match c {
' ' => None,
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,27 +347,27 @@ macro_rules! make_mir_visitor {
ty::InstanceKind::Item(_def_id) => {}

ty::InstanceKind::Intrinsic(_def_id)
| ty::InstanceKind::VTableShim(_def_id)
| ty::InstanceKind::ReifyShim(_def_id, _)
| ty::InstanceKind::Shim(ty::ShimKind::VTable(_def_id))
| ty::InstanceKind::Shim(ty::ShimKind::Reify(_def_id, _))
| ty::InstanceKind::Virtual(_def_id, _)
| ty::InstanceKind::ThreadLocalShim(_def_id)
| ty::InstanceKind::ClosureOnceShim { call_once: _def_id, closure: _, track_caller: _ }
| ty::InstanceKind::ConstructCoroutineInClosureShim {
| ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(_def_id))
| ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { call_once: _def_id, closure: _, track_caller: _ })
| ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: _def_id,
receiver_by_ref: _,
}
| ty::InstanceKind::DropGlue(_def_id, None) => {}

ty::InstanceKind::FnPtrShim(_def_id, ty)
| ty::InstanceKind::DropGlue(_def_id, Some(ty))
| ty::InstanceKind::CloneShim(_def_id, ty)
| ty::InstanceKind::FnPtrAddrShim(_def_id, ty)
| ty::InstanceKind::AsyncDropGlue(_def_id, ty)
| ty::InstanceKind::AsyncDropGlueCtorShim(_def_id, ty) => {
})
| ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id, None)) => {}

ty::InstanceKind::Shim(ty::ShimKind::FnPtr(_def_id, ty))
| ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id, Some(ty)))
| ty::InstanceKind::Shim(ty::ShimKind::Clone(_def_id, ty))
| ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(_def_id, ty))
| ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_def_id, ty))
| ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_def_id, ty)) => {
// FIXME(eddyb) use a better `TyContext` here.
self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
}
ty::InstanceKind::FutureDropPollShim(_def_id, proxy_ty, impl_ty) => {
ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(_def_id, proxy_ty, impl_ty)) => {
self.visit_ty($(& $mutability)? *proxy_ty, TyContext::Location(location));
self.visit_ty($(& $mutability)? *impl_ty, TyContext::Location(location));
}
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_middle/src/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tracing::debug;
use crate::dep_graph::dep_node::{make_compile_codegen_unit, make_compile_mono_item};
use crate::dep_graph::{DepNode, WorkProduct, WorkProductId};
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::{self, GenericArgs, Instance, InstanceKind, SymbolName, Ty, TyCtxt};
use crate::ty::{self, GenericArgs, Instance, InstanceKind, ShimKind, SymbolName, Ty, TyCtxt};

/// Describes how a monomorphization will be instantiated in object files.
#[derive(PartialEq)]
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'tcx> MonoItem<'tcx> {
// incrementality (which wants small CGUs with as many things GloballyShared as possible).
// The heuristics implemented here do better than a completely naive approach in the
// compiler benchmark suite, but there is no reason to believe they are optimal.
if let InstanceKind::DropGlue(_, Some(ty)) = instance.def {
if let InstanceKind::Shim(ShimKind::DropGlue(_, Some(ty))) = instance.def {
if tcx.sess.opts.optimize == OptLevel::No {
return InstantiationMode::GloballyShared { may_conflict: false };
}
Expand Down Expand Up @@ -523,20 +523,20 @@ impl<'tcx> CodegenUnit<'tcx> {
match item {
MonoItem::Fn(ref instance) => match instance.def {
InstanceKind::Item(def) => def.as_local().map(|_| def),
InstanceKind::VTableShim(..)
| InstanceKind::ReifyShim(..)
| InstanceKind::Intrinsic(..)
| InstanceKind::FnPtrShim(..)
InstanceKind::Intrinsic(..)
| InstanceKind::Virtual(..)
| InstanceKind::ClosureOnceShim { .. }
| InstanceKind::ConstructCoroutineInClosureShim { .. }
| InstanceKind::DropGlue(..)
| InstanceKind::CloneShim(..)
| InstanceKind::ThreadLocalShim(..)
| InstanceKind::FnPtrAddrShim(..)
| InstanceKind::AsyncDropGlue(..)
| InstanceKind::FutureDropPollShim(..)
| InstanceKind::AsyncDropGlueCtorShim(..) => None,
| InstanceKind::Shim(ShimKind::VTable(..))
| InstanceKind::Shim(ShimKind::Reify(..))
| InstanceKind::Shim(ShimKind::FnPtr(..))
| InstanceKind::Shim(ShimKind::ClosureOnce { .. })
| InstanceKind::Shim(ShimKind::ConstructCoroutineInClosure { .. })
| InstanceKind::Shim(ShimKind::DropGlue(..))
| InstanceKind::Shim(ShimKind::Clone(..))
| InstanceKind::Shim(ShimKind::ThreadLocal(..))
| InstanceKind::Shim(ShimKind::FnPtrAddr(..))
| InstanceKind::Shim(ShimKind::AsyncDropGlue(..))
| InstanceKind::Shim(ShimKind::FutureDropPoll(..))
| InstanceKind::Shim(ShimKind::AsyncDropGlueCtor(..)) => None,
},
MonoItem::Static(def_id) => def_id.as_local().map(|_| def_id),
MonoItem::GlobalAsm(item_id) => Some(item_id.owner_id.def_id.to_def_id()),
Expand Down
Loading
Loading