Skip to content

Commit 19dddf6

Browse files
committed
Use lang items rather than diagnostic items for profiling markers
1 parent e3bd1f0 commit 19dddf6

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use rustc_abi as abi;
55
use rustc_abi::{
66
Align, BackendRepr, FIRST_VARIANT, FieldIdx, Primitive, Size, TagEncoding, VariantIdx, Variants,
77
};
8+
use rustc_hir::LangItem;
89
use rustc_middle::mir::interpret::{Pointer, Scalar, alloc_range};
910
use rustc_middle::mir::{self, ConstValue};
1011
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1112
use rustc_middle::ty::{self, Ty};
1213
use rustc_middle::{bug, span_bug};
1314
use rustc_session::config::{AnnotateMoves, DebugInfo, OptLevel};
14-
use rustc_span::{Symbol, sym};
1515
use tracing::{debug, instrument};
1616

1717
use super::place::{PlaceRef, PlaceValue};
@@ -1039,8 +1039,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10391039
match *operand {
10401040
mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => {
10411041
let kind = match operand {
1042-
mir::Operand::Move(_) => sym::compiler_move,
1043-
mir::Operand::Copy(_) => sym::compiler_copy,
1042+
mir::Operand::Move(_) => LangItem::CompilerMove,
1043+
mir::Operand::Copy(_) => LangItem::CompilerCopy,
10441044
_ => unreachable!(),
10451045
};
10461046

@@ -1086,7 +1086,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10861086
&self,
10871087
bx: &Bx,
10881088
place: mir::PlaceRef<'tcx>,
1089-
kind: Symbol,
1089+
kind: LangItem,
10901090
) -> Option<ty::Instance<'tcx>> {
10911091
let tcx = bx.tcx();
10921092
let sess = tcx.sess;
@@ -1116,9 +1116,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11161116
return None;
11171117
}
11181118

1119-
// Look up the DefId for compiler_move or compiler_copy (skip if it's missing for some
1120-
// reason).
1121-
let def_id = tcx.get_diagnostic_item(kind)?;
1119+
// Look up the DefId for compiler_move or compiler_copy lang item
1120+
let def_id = tcx.lang_items().get(kind)?;
11221121

11231122
// Create generic args: compiler_move<T, SIZE> or compiler_copy<T, SIZE>
11241123
let size_const = ty::Const::from_target_usize(tcx, ty_size);

compiler/rustc_hir/src/lang_items.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ language_item_table! {
345345
EhPersonality, sym::eh_personality, eh_personality, Target::Fn, GenericRequirement::None;
346346
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None;
347347

348+
// Profiling markers for move/copy operations (used by -Z annotate-moves)
349+
CompilerMove, sym::compiler_move, compiler_move_fn, Target::Fn, GenericRequirement::Exact(2);
350+
CompilerCopy, sym::compiler_copy, compiler_copy_fn, Target::Fn, GenericRequirement::Exact(2);
351+
348352
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
349353
GlobalAlloc, sym::global_alloc_ty, global_alloc_ty, Target::Struct, GenericRequirement::None;
350354

library/core/src/profiling.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
///
99
/// The `SIZE` parameter encodes the size of the type being moved.
1010
#[unstable(feature = "profiling_marker_api", issue = "none")]
11-
#[rustc_diagnostic_item = "compiler_move"]
11+
#[lang = "compiler_move"]
1212
pub fn compiler_move<T, const SIZE: usize>(_src: *const T, _dst: *mut T) {
1313
unreachable!(
1414
"compiler_move marks where the compiler generated a copy; it is never actually called"
@@ -23,7 +23,7 @@ pub fn compiler_move<T, const SIZE: usize>(_src: *const T, _dst: *mut T) {
2323
///
2424
/// The `SIZE` parameter encodes the size of the type being copied.
2525
#[unstable(feature = "profiling_marker_api", issue = "none")]
26-
#[rustc_diagnostic_item = "compiler_copy"]
26+
#[lang = "compiler_copy"]
2727
pub fn compiler_copy<T, const SIZE: usize>(_src: *const T, _dst: *mut T) {
2828
unreachable!(
2929
"compiler_copy marks where the compiler generated a copy; it is never actually called"

0 commit comments

Comments
 (0)