Skip to content

Commit d2cd59a

Browse files
committed
Add case for count_code_region() extern lang_item
As suggested in PR feedback: #73011 (comment) This allows count_code_region() to be handled like a normal intrinsic so the InstanceDef::InjectedCode variant is no longer needed.
1 parent 2c5c2a6 commit d2cd59a

File tree

13 files changed

+27
-54
lines changed

13 files changed

+27
-54
lines changed

src/libcore/intrinsics.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,22 +1941,13 @@ extern "rust-intrinsic" {
19411941
///
19421942
/// Perma-unstable: do not use.
19431943
pub fn miri_start_panic(payload: *mut u8) -> !;
1944-
}
19451944

1946-
/// Defines the `count_code_region` intrinsic as a `LangItem`. `LangItem`s require a function body
1947-
/// to register its DefId with the LangItem entry. The function body is never actually called (and
1948-
/// is therefore implemented as an aborting stub) because it is replaced with the LLVM intrinsic
1949-
/// `llvm.instrprof.increment` by
1950-
/// `rustc_codegen_llvm::intrinsic::IntrinsicCallMethods::codegen_intrinsic_call()`.
1951-
#[cfg(not(bootstrap))]
1952-
#[cfg_attr(not(bootstrap), lang = "count_code_region")]
1953-
fn count_code_region(_index: u32) {
1954-
// remove `unsafe` (and safety comment) on bootstrap bump
1955-
#[cfg_attr(not(bootstrap), allow(unused_unsafe))]
1956-
// SAFETY: the `abort` intrinsic has no requirements to be called.
1957-
unsafe {
1958-
abort()
1959-
}
1945+
/// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
1946+
/// option is enabled. The placeholder is replaced with `llvm.instrprof.increment` during code
1947+
/// generation.
1948+
#[cfg(not(bootstrap))]
1949+
#[cfg_attr(not(bootstrap), lang = "count_code_region")]
1950+
pub fn count_code_region(_index: u32);
19601951
}
19611952

19621953
// Some functions are defined here because they accidentally got made

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
566566

567567
// Handle intrinsics old codegen wants Expr's for, ourselves.
568568
let intrinsic = match def {
569-
Some(ty::InstanceDef::Intrinsic(def_id))
570-
| Some(ty::InstanceDef::InjectedCode(def_id)) => {
571-
Some(bx.tcx().item_name(def_id).as_str())
572-
}
569+
Some(ty::InstanceDef::Intrinsic(def_id)) => Some(bx.tcx().item_name(def_id).as_str()),
573570
_ => None,
574571
};
575572
let intrinsic = intrinsic.as_ref().map(|s| &s[..]);

src/librustc_middle/mir/mono.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ impl<'tcx> CodegenUnit<'tcx> {
352352
InstanceDef::VtableShim(..)
353353
| InstanceDef::ReifyShim(..)
354354
| InstanceDef::Intrinsic(..)
355-
| InstanceDef::InjectedCode(..)
356355
| InstanceDef::FnPtrShim(..)
357356
| InstanceDef::Virtual(..)
358357
| InstanceDef::ClosureOnceShim { .. }

src/librustc_middle/ty/instance.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ pub enum InstanceDef<'tcx> {
2121
Item(DefId),
2222
Intrinsic(DefId),
2323

24-
/// Injected call to a placeholder function that is replaced with
25-
/// For example: `core::intrinsic::count_code_region()` for code coverage.
26-
InjectedCode(DefId),
27-
2824
/// `<T as Trait>::method` where `method` receives unsizeable `self: Self`.
2925
VtableShim(DefId),
3026

@@ -153,7 +149,6 @@ impl<'tcx> InstanceDef<'tcx> {
153149
| InstanceDef::FnPtrShim(def_id, _)
154150
| InstanceDef::Virtual(def_id, _)
155151
| InstanceDef::Intrinsic(def_id)
156-
| InstanceDef::InjectedCode(def_id)
157152
| InstanceDef::ClosureOnceShim { call_once: def_id }
158153
| InstanceDef::DropGlue(def_id, _)
159154
| InstanceDef::CloneShim(def_id, _) => def_id,
@@ -241,7 +236,6 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
241236
InstanceDef::VtableShim(_) => write!(f, " - shim(vtable)"),
242237
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
243238
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
244-
InstanceDef::InjectedCode(_) => write!(f, " - injected-code"),
245239
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
246240
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({:?})", ty),
247241
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
@@ -421,7 +415,6 @@ impl<'tcx> Instance<'tcx> {
421415
| InstanceDef::FnPtrShim(..)
422416
| InstanceDef::Item(_)
423417
| InstanceDef::Intrinsic(..)
424-
| InstanceDef::InjectedCode(..)
425418
| InstanceDef::ReifyShim(..)
426419
| InstanceDef::Virtual(..)
427420
| InstanceDef::VtableShim(..) => Some(self.substs),

src/librustc_middle/ty/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,6 @@ impl<'tcx> TyCtxt<'tcx> {
27172717
ty::InstanceDef::VtableShim(..)
27182718
| ty::InstanceDef::ReifyShim(..)
27192719
| ty::InstanceDef::Intrinsic(..)
2720-
| ty::InstanceDef::InjectedCode(..)
27212720
| ty::InstanceDef::FnPtrShim(..)
27222721
| ty::InstanceDef::Virtual(..)
27232722
| ty::InstanceDef::ClosureOnceShim { .. }

src/librustc_middle/ty/structural_impls.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
674674
ty::InstanceDef::VtableShim(def_id) => Some(ty::InstanceDef::VtableShim(def_id)),
675675
ty::InstanceDef::ReifyShim(def_id) => Some(ty::InstanceDef::ReifyShim(def_id)),
676676
ty::InstanceDef::Intrinsic(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)),
677-
ty::InstanceDef::InjectedCode(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)),
678677
ty::InstanceDef::FnPtrShim(def_id, ref ty) => {
679678
Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?))
680679
}
@@ -847,7 +846,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
847846
VtableShim(did) => VtableShim(did.fold_with(folder)),
848847
ReifyShim(did) => ReifyShim(did.fold_with(folder)),
849848
Intrinsic(did) => Intrinsic(did.fold_with(folder)),
850-
InjectedCode(did) => InjectedCode(did.fold_with(folder)),
851849
FnPtrShim(did, ty) => FnPtrShim(did.fold_with(folder), ty.fold_with(folder)),
852850
Virtual(did, i) => Virtual(did.fold_with(folder), i),
853851
ClosureOnceShim { call_once } => {
@@ -863,12 +861,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
863861
use crate::ty::InstanceDef::*;
864862
self.substs.visit_with(visitor)
865863
|| match self.def {
866-
Item(did)
867-
| VtableShim(did)
868-
| ReifyShim(did)
869-
| Intrinsic(did)
870-
| InjectedCode(did)
871-
| Virtual(did, _) => did.visit_with(visitor),
864+
Item(did) | VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => {
865+
did.visit_with(visitor)
866+
}
872867
FnPtrShim(did, ty) | CloneShim(did, ty) => {
873868
did.visit_with(visitor) || ty.visit_with(visitor)
874869
}

src/librustc_mir/interpret/terminator.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
257257
assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic);
258258
M::call_intrinsic(self, instance, args, ret, unwind)
259259
}
260-
ty::InstanceDef::InjectedCode(..) => {
261-
M::call_intrinsic(self, instance, args, ret, unwind)
262-
}
263260
ty::InstanceDef::VtableShim(..)
264261
| ty::InstanceDef::ReifyShim(..)
265262
| ty::InstanceDef::ClosureOnceShim { .. }

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,7 @@ fn visit_instance_use<'tcx>(
714714
}
715715

716716
match instance.def {
717-
ty::InstanceDef::Virtual(..)
718-
| ty::InstanceDef::Intrinsic(_)
719-
| ty::InstanceDef::InjectedCode(_) => {
717+
ty::InstanceDef::Virtual(..) | ty::InstanceDef::Intrinsic(_) => {
720718
if !is_direct_call {
721719
bug!("{:?} being reified", instance);
722720
}
@@ -753,7 +751,6 @@ fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx
753751
| ty::InstanceDef::FnPtrShim(..)
754752
| ty::InstanceDef::DropGlue(..)
755753
| ty::InstanceDef::Intrinsic(_)
756-
| ty::InstanceDef::InjectedCode(_)
757754
| ty::InstanceDef::CloneShim(..) => return true,
758755
};
759756

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ fn mono_item_visibility(
322322
| InstanceDef::FnPtrShim(..)
323323
| InstanceDef::Virtual(..)
324324
| InstanceDef::Intrinsic(..)
325-
| InstanceDef::InjectedCode(..)
326325
| InstanceDef::ClosureOnceShim { .. }
327326
| InstanceDef::DropGlue(..)
328327
| InstanceDef::CloneShim(..) => return Visibility::Hidden,
@@ -718,7 +717,6 @@ fn characteristic_def_id_of_mono_item<'tcx>(
718717
| ty::InstanceDef::FnPtrShim(..)
719718
| ty::InstanceDef::ClosureOnceShim { .. }
720719
| ty::InstanceDef::Intrinsic(..)
721-
| ty::InstanceDef::InjectedCode(..)
722720
| ty::InstanceDef::DropGlue(..)
723721
| ty::InstanceDef::Virtual(..)
724722
| ty::InstanceDef::CloneShim(..) => return None,

src/librustc_mir/shim.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
109109
ty::InstanceDef::Intrinsic(_) => {
110110
bug!("creating shims from intrinsics ({:?}) is unsupported", instance)
111111
}
112-
ty::InstanceDef::InjectedCode(_) => {
113-
bug!("creating shims from injected code ({:?}) is unsupported", instance)
114-
}
115112
};
116113
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
117114

0 commit comments

Comments
 (0)