mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Instance is Copy
This commit is contained in:
parent
cb7c63606e
commit
99fbc6f8ef
@ -1630,7 +1630,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
|
||||
}
|
||||
|
||||
let typeid = if let Some(instance) = instance {
|
||||
typeid_for_instance(self.tcx, &instance, options)
|
||||
typeid_for_instance(self.tcx, instance, options)
|
||||
} else {
|
||||
typeid_for_fnabi(self.tcx, fn_abi, options)
|
||||
};
|
||||
@ -1678,7 +1678,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
|
||||
}
|
||||
|
||||
let kcfi_typeid = if let Some(instance) = instance {
|
||||
kcfi_typeid_for_instance(self.tcx, &instance, options)
|
||||
kcfi_typeid_for_instance(self.tcx, instance, options)
|
||||
} else {
|
||||
kcfi_typeid_for_fnabi(self.tcx, fn_abi, options)
|
||||
};
|
||||
|
@ -141,17 +141,17 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
|
||||
|
||||
if self.tcx.sess.is_sanitizer_cfi_enabled() {
|
||||
if let Some(instance) = instance {
|
||||
let typeid = typeid_for_instance(self.tcx, &instance, TypeIdOptions::empty());
|
||||
let typeid = typeid_for_instance(self.tcx, instance, TypeIdOptions::empty());
|
||||
self.set_type_metadata(llfn, typeid);
|
||||
let typeid =
|
||||
typeid_for_instance(self.tcx, &instance, TypeIdOptions::GENERALIZE_POINTERS);
|
||||
typeid_for_instance(self.tcx, instance, TypeIdOptions::GENERALIZE_POINTERS);
|
||||
self.add_type_metadata(llfn, typeid);
|
||||
let typeid =
|
||||
typeid_for_instance(self.tcx, &instance, TypeIdOptions::NORMALIZE_INTEGERS);
|
||||
typeid_for_instance(self.tcx, instance, TypeIdOptions::NORMALIZE_INTEGERS);
|
||||
self.add_type_metadata(llfn, typeid);
|
||||
let typeid = typeid_for_instance(
|
||||
self.tcx,
|
||||
&instance,
|
||||
instance,
|
||||
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
|
||||
);
|
||||
self.add_type_metadata(llfn, typeid);
|
||||
@ -182,7 +182,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
|
||||
}
|
||||
|
||||
if let Some(instance) = instance {
|
||||
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, &instance, options);
|
||||
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, instance, options);
|
||||
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
|
||||
} else {
|
||||
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
|
||||
|
@ -335,7 +335,7 @@ impl<'tcx> InstanceDef<'tcx> {
|
||||
|
||||
fn fmt_instance(
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
instance: &Instance<'_>,
|
||||
instance: Instance<'_>,
|
||||
type_length: Option<rustc_session::Limit>,
|
||||
) -> fmt::Result {
|
||||
ty::tls::with(|tcx| {
|
||||
@ -369,9 +369,9 @@ fn fmt_instance(
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);
|
||||
pub struct ShortInstance<'tcx>(pub Instance<'tcx>, pub usize);
|
||||
|
||||
impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
|
||||
impl<'tcx> fmt::Display for ShortInstance<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_instance(f, self.0, Some(rustc_session::Limit(self.1)))
|
||||
}
|
||||
@ -379,7 +379,7 @@ impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
|
||||
|
||||
impl<'tcx> fmt::Display for Instance<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_instance(f, self, None)
|
||||
fmt_instance(f, *self, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ impl<'tcx> Inliner<'tcx> {
|
||||
caller_body: &mut Body<'tcx>,
|
||||
callsite: &CallSite<'tcx>,
|
||||
) -> Result<std::ops::Range<BasicBlock>, &'static str> {
|
||||
self.check_mir_is_available(caller_body, &callsite.callee)?;
|
||||
self.check_mir_is_available(caller_body, callsite.callee)?;
|
||||
|
||||
let callee_attrs = self.tcx.codegen_fn_attrs(callsite.callee.def_id());
|
||||
let cross_crate_inlinable = self.tcx.cross_crate_inlinable(callsite.callee.def_id());
|
||||
@ -298,7 +298,7 @@ impl<'tcx> Inliner<'tcx> {
|
||||
fn check_mir_is_available(
|
||||
&self,
|
||||
caller_body: &Body<'tcx>,
|
||||
callee: &Instance<'tcx>,
|
||||
callee: Instance<'tcx>,
|
||||
) -> Result<(), &'static str> {
|
||||
let caller_def_id = caller_body.source.def_id();
|
||||
let callee_def_id = callee.def_id();
|
||||
@ -354,7 +354,7 @@ impl<'tcx> Inliner<'tcx> {
|
||||
|
||||
// If we know for sure that the function we're calling will itself try to
|
||||
// call us, then we avoid inlining that function.
|
||||
if self.tcx.mir_callgraph_reachable((*callee, caller_def_id.expect_local())) {
|
||||
if self.tcx.mir_callgraph_reachable((callee, caller_def_id.expect_local())) {
|
||||
return Err("caller might be reachable from callee (query cycle avoidance)");
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ fn collect_items_rec<'tcx>(
|
||||
let instance = Instance::mono(tcx, def_id);
|
||||
|
||||
// Sanity check whether this ended up being collected accidentally
|
||||
debug_assert!(should_codegen_locally(tcx, &instance));
|
||||
debug_assert!(should_codegen_locally(tcx, instance));
|
||||
|
||||
let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
|
||||
// Nested statics have no type.
|
||||
@ -429,7 +429,7 @@ fn collect_items_rec<'tcx>(
|
||||
}
|
||||
MonoItem::Fn(instance) => {
|
||||
// Sanity check whether this ended up being collected accidentally
|
||||
debug_assert!(should_codegen_locally(tcx, &instance));
|
||||
debug_assert!(should_codegen_locally(tcx, instance));
|
||||
|
||||
// Keep track of the monomorphization recursion depth
|
||||
recursion_depth_reset = Some(check_recursion_limit(
|
||||
@ -474,7 +474,7 @@ fn collect_items_rec<'tcx>(
|
||||
}
|
||||
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
|
||||
let instance = Instance::mono(tcx, *def_id);
|
||||
if should_codegen_locally(tcx, &instance) {
|
||||
if should_codegen_locally(tcx, instance) {
|
||||
trace!("collecting static {:?}", def_id);
|
||||
used_items.push(dummy_spanned(MonoItem::Static(*def_id)));
|
||||
}
|
||||
@ -557,7 +557,7 @@ fn collect_items_rec<'tcx>(
|
||||
/// If the type name is longer than before+after, it will be written to a file.
|
||||
fn shrunk_instance_name<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance: &Instance<'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
) -> (String, Option<PathBuf>) {
|
||||
let s = instance.to_string();
|
||||
|
||||
@ -603,7 +603,7 @@ fn check_recursion_limit<'tcx>(
|
||||
if !recursion_limit.value_within_limit(adjusted_recursion_depth) {
|
||||
let def_span = tcx.def_span(def_id);
|
||||
let def_path_str = tcx.def_path_str(def_id);
|
||||
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
|
||||
let (shrunk, written_to_path) = shrunk_instance_name(tcx, instance);
|
||||
let mut path = PathBuf::new();
|
||||
let was_written = if let Some(written_to_path) = written_to_path {
|
||||
path = written_to_path;
|
||||
@ -645,7 +645,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
|
||||
//
|
||||
// Bail out in these cases to avoid that bad user experience.
|
||||
if !tcx.type_length_limit().value_within_limit(type_length) {
|
||||
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
|
||||
let (shrunk, written_to_path) = shrunk_instance_name(tcx, instance);
|
||||
let span = tcx.def_span(instance.def_id());
|
||||
let mut path = PathBuf::new();
|
||||
let was_written = if let Some(path2) = written_to_path {
|
||||
@ -892,7 +892,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
||||
if let ty::Closure(def_id, args) = *source_ty.kind() {
|
||||
let instance =
|
||||
Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce);
|
||||
if should_codegen_locally(self.tcx, &instance) {
|
||||
if should_codegen_locally(self.tcx, instance) {
|
||||
self.used_items.push(create_fn_mono_item(self.tcx, instance, span));
|
||||
}
|
||||
} else {
|
||||
@ -902,7 +902,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
||||
mir::Rvalue::ThreadLocalRef(def_id) => {
|
||||
assert!(self.tcx.is_thread_local_static(def_id));
|
||||
let instance = Instance::mono(self.tcx, def_id);
|
||||
if should_codegen_locally(self.tcx, &instance) {
|
||||
if should_codegen_locally(self.tcx, instance) {
|
||||
trace!("collecting thread-local static {:?}", def_id);
|
||||
self.used_items.push(respan(span, MonoItem::Static(def_id)));
|
||||
}
|
||||
@ -929,7 +929,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| {
|
||||
let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source)));
|
||||
if should_codegen_locally(tcx, &instance) {
|
||||
if should_codegen_locally(tcx, instance) {
|
||||
this.used_items.push(create_fn_mono_item(tcx, instance, source));
|
||||
}
|
||||
};
|
||||
@ -962,7 +962,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
||||
}
|
||||
mir::InlineAsmOperand::SymStatic { def_id } => {
|
||||
let instance = Instance::mono(self.tcx, def_id);
|
||||
if should_codegen_locally(self.tcx, &instance) {
|
||||
if should_codegen_locally(self.tcx, instance) {
|
||||
trace!("collecting asm sym static {:?}", def_id);
|
||||
self.used_items.push(respan(source, MonoItem::Static(def_id)));
|
||||
}
|
||||
@ -1051,7 +1051,7 @@ fn visit_instance_use<'tcx>(
|
||||
output: &mut MonoItems<'tcx>,
|
||||
) {
|
||||
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
|
||||
if !should_codegen_locally(tcx, &instance) {
|
||||
if !should_codegen_locally(tcx, instance) {
|
||||
return;
|
||||
}
|
||||
if let ty::InstanceDef::Intrinsic(def_id) = instance.def {
|
||||
@ -1063,13 +1063,13 @@ fn visit_instance_use<'tcx>(
|
||||
// codegen a call to that function without generating code for the function itself.
|
||||
let def_id = tcx.lang_items().get(LangItem::PanicNounwind).unwrap();
|
||||
let panic_instance = Instance::mono(tcx, def_id);
|
||||
if should_codegen_locally(tcx, &panic_instance) {
|
||||
if should_codegen_locally(tcx, panic_instance) {
|
||||
output.push(create_fn_mono_item(tcx, panic_instance, source));
|
||||
}
|
||||
} else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
|
||||
// Codegen the fallback body of intrinsics with fallback bodies
|
||||
let instance = ty::Instance::new(def_id, instance.args);
|
||||
if should_codegen_locally(tcx, &instance) {
|
||||
if should_codegen_locally(tcx, instance) {
|
||||
output.push(create_fn_mono_item(tcx, instance, source));
|
||||
}
|
||||
}
|
||||
@ -1107,7 +1107,7 @@ fn visit_instance_use<'tcx>(
|
||||
|
||||
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
|
||||
/// can just link to the upstream crate and therefore don't need a mono item.
|
||||
pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) -> bool {
|
||||
pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
|
||||
let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else {
|
||||
return true;
|
||||
};
|
||||
@ -1304,7 +1304,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
|
||||
None
|
||||
}
|
||||
VtblEntry::Method(instance) => {
|
||||
Some(*instance).filter(|instance| should_codegen_locally(tcx, instance))
|
||||
Some(*instance).filter(|instance| should_codegen_locally(tcx, *instance))
|
||||
}
|
||||
})
|
||||
.map(|item| create_fn_mono_item(tcx, item, source));
|
||||
@ -1321,7 +1321,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
|
||||
GlobalAlloc::Static(def_id) => {
|
||||
assert!(!tcx.is_thread_local_static(def_id));
|
||||
let instance = Instance::mono(tcx, def_id);
|
||||
if should_codegen_locally(tcx, &instance) {
|
||||
if should_codegen_locally(tcx, instance) {
|
||||
trace!("collecting static {:?}", def_id);
|
||||
output.push(dummy_spanned(MonoItem::Static(def_id)));
|
||||
}
|
||||
@ -1339,7 +1339,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
|
||||
}
|
||||
}
|
||||
GlobalAlloc::Function(fn_instance) => {
|
||||
if should_codegen_locally(tcx, &fn_instance) {
|
||||
if should_codegen_locally(tcx, fn_instance) {
|
||||
trace!("collecting {:?} with {:#?}", alloc_id, fn_instance);
|
||||
output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP));
|
||||
}
|
||||
@ -1474,7 +1474,7 @@ fn visit_mentioned_item<'tcx>(
|
||||
if let ty::Closure(def_id, args) = *source_ty.kind() {
|
||||
let instance =
|
||||
Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce);
|
||||
if should_codegen_locally(tcx, &instance) {
|
||||
if should_codegen_locally(tcx, instance) {
|
||||
output.push(create_fn_mono_item(tcx, instance, span));
|
||||
}
|
||||
} else {
|
||||
@ -1736,7 +1736,7 @@ fn create_mono_items_for_default_impls<'tcx>(
|
||||
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args);
|
||||
|
||||
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
|
||||
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, &instance) {
|
||||
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {
|
||||
output.push(mono_item);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
|
||||
!instance.def_id().is_local()
|
||||
&& tcx.is_compiler_builtins(LOCAL_CRATE)
|
||||
&& tcx.codegen_fn_attrs(instance.def_id()).link_name.is_none()
|
||||
&& !should_codegen_locally(tcx, &instance)
|
||||
&& !should_codegen_locally(tcx, instance)
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
@ -33,10 +33,10 @@ pub fn typeid_for_fnabi<'tcx>(
|
||||
/// Returns a type metadata identifier for the specified Instance.
|
||||
pub fn typeid_for_instance<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance: &Instance<'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
options: TypeIdOptions,
|
||||
) -> String {
|
||||
typeid_itanium_cxx_abi::typeid_for_instance(tcx, *instance, options)
|
||||
typeid_itanium_cxx_abi::typeid_for_instance(tcx, instance, options)
|
||||
}
|
||||
|
||||
/// Returns a KCFI type metadata identifier for the specified FnAbi.
|
||||
@ -55,12 +55,12 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
|
||||
/// Returns a KCFI type metadata identifier for the specified Instance.
|
||||
pub fn kcfi_typeid_for_instance<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance: &Instance<'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
options: TypeIdOptions,
|
||||
) -> u32 {
|
||||
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
|
||||
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
|
||||
let mut hash: XxHash64 = Default::default();
|
||||
hash.write(typeid_itanium_cxx_abi::typeid_for_instance(tcx, *instance, options).as_bytes());
|
||||
hash.write(typeid_itanium_cxx_abi::typeid_for_instance(tcx, instance, options).as_bytes());
|
||||
hash.finish() as u32
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user