Skip to content

Commit d33a048

Browse files
committed
Auto merge of #148496 - matthiaskrgr:rollup-8sl1xfa, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #145314 (Tweak output of missing lifetime on associated type) - #147803 (Add -Zannotate-moves for profiler visibility of move/copy operations (codegen)) - #147925 (Fix tests for big-endian) - #148341 (compiler: Fix a couple issues around cargo feature unification) - #148371 (Dogfood `trim_{suffix|prefix}` in compiler) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f15a7f3 + ba4e8e7 commit d33a048

File tree

68 files changed

+1184
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1184
-127
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10691069
OperandValue::Ref(place.val)
10701070
};
10711071

1072-
OperandRef { val, layout: place.layout }
1072+
OperandRef { val, layout: place.layout, move_annotation: None }
10731073
}
10741074

10751075
fn write_operand_repeatedly(

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::context::CodegenCx;
1919
pub(super) const UNKNOWN_LINE_NUMBER: u32 = 0;
2020
pub(super) const UNKNOWN_COLUMN_NUMBER: u32 = 0;
2121

22-
impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
22+
impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
2323
// FIXME(eddyb) find a common convention for all of the debuginfo-related
2424
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
2525
fn dbg_var_addr(

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
253253
);
254254
bx.lifetime_end(llscratch, scratch_size);
255255
}
256-
_ => {
256+
PassMode::Pair(..) | PassMode::Direct { .. } => {
257257
OperandRef::from_immediate_or_packed_pair(bx, val, self.layout).val.store(bx, dst);
258258
}
259259
}

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ fn report_inline_asm(
451451
llvm::DiagnosticLevel::Warning => Level::Warning,
452452
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
453453
};
454-
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
454+
let msg = msg.trim_prefix("error: ").to_string();
455455
cgcx.diag_emitter.inline_asm_error(span, msg, level, source);
456456
}
457457

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
751751
OperandValue::Ref(place.val)
752752
};
753753

754-
OperandRef { val, layout: place.layout }
754+
OperandRef { val, layout: place.layout, move_annotation: None }
755755
}
756756

757757
fn write_operand_repeatedly(

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'ll> Builder<'_, 'll, '_> {
146146
}
147147
}
148148

149-
impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
149+
impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
150150
// FIXME(eddyb) find a common convention for all of the debuginfo-related
151151
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
152152
fn dbg_var_addr(
@@ -284,6 +284,57 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
284284
llvm::set_value_name(value, name.as_bytes());
285285
}
286286
}
287+
288+
/// Annotate move/copy operations with debug info for profiling.
289+
///
290+
/// This creates a temporary debug scope that makes the move/copy appear as an inlined call to
291+
/// `compiler_move<T, SIZE>()` or `compiler_copy<T, SIZE>()`. The provided closure is executed
292+
/// with this temporary debug location active.
293+
///
294+
/// The `instance` parameter should be the monomorphized instance of the `compiler_move` or
295+
/// `compiler_copy` function with the actual type and size.
296+
fn with_move_annotation<R>(
297+
&mut self,
298+
instance: ty::Instance<'tcx>,
299+
f: impl FnOnce(&mut Self) -> R,
300+
) -> R {
301+
// Save the current debug location
302+
let saved_loc = self.get_dbg_loc();
303+
304+
// Create a DIScope for the compiler_move/compiler_copy function
305+
// We use the function's FnAbi for debug info generation
306+
let fn_abi = self
307+
.cx()
308+
.tcx
309+
.fn_abi_of_instance(
310+
self.cx().typing_env().as_query_input((instance, ty::List::empty())),
311+
)
312+
.unwrap();
313+
314+
let di_scope = self.cx().dbg_scope_fn(instance, fn_abi, None);
315+
316+
// Create an inlined debug location:
317+
// - scope: the compiler_move/compiler_copy function
318+
// - inlined_at: the current location (where the move/copy actually occurs)
319+
// - span: use the function's definition span
320+
let fn_span = self.cx().tcx.def_span(instance.def_id());
321+
let inlined_loc = self.cx().dbg_loc(di_scope, saved_loc, fn_span);
322+
323+
// Set the temporary debug location
324+
self.set_dbg_loc(inlined_loc);
325+
326+
// Execute the closure (which will generate the memcpy)
327+
let result = f(self);
328+
329+
// Restore the original debug location
330+
if let Some(loc) = saved_loc {
331+
self.set_dbg_loc(loc);
332+
} else {
333+
self.clear_dbg_loc();
334+
}
335+
336+
result
337+
}
287338
}
288339

289340
/// A source code location used to generate debug information.

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(macro_derive)]
1818
#![feature(rustdoc_internals)]
1919
#![feature(slice_as_array)]
20+
#![feature(trim_prefix_suffix)]
2021
#![feature(try_blocks)]
2122
// tidy-alphabetical-end
2223

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
557557
let op = match self.locals[mir::RETURN_PLACE] {
558558
LocalRef::Operand(op) => op,
559559
LocalRef::PendingOperand => bug!("use of return before def"),
560-
LocalRef::Place(cg_place) => {
561-
OperandRef { val: Ref(cg_place.val), layout: cg_place.layout }
562-
}
560+
LocalRef::Place(cg_place) => OperandRef {
561+
val: Ref(cg_place.val),
562+
layout: cg_place.layout,
563+
move_annotation: None,
564+
},
563565
LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
564566
};
565567
let llslot = match op.val {
@@ -1155,7 +1157,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11551157
| (&mir::Operand::Constant(_), Ref(PlaceValue { llextra: None, .. })) => {
11561158
let tmp = PlaceRef::alloca(bx, op.layout);
11571159
bx.lifetime_start(tmp.val.llval, tmp.layout.size);
1158-
op.val.store(bx, tmp);
1160+
op.store_with_annotation(bx, tmp);
11591161
op.val = Ref(tmp.val);
11601162
lifetime_ends_after_call.push((tmp.val.llval, tmp.layout.size));
11611163
}
@@ -1563,13 +1565,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
15631565
};
15641566
let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
15651567
bx.lifetime_start(scratch.llval, arg.layout.size);
1566-
op.val.store(bx, scratch.with_type(arg.layout));
1568+
op.store_with_annotation(bx, scratch.with_type(arg.layout));
15671569
lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
15681570
(scratch.llval, scratch.align, true)
15691571
}
15701572
PassMode::Cast { .. } => {
15711573
let scratch = PlaceRef::alloca(bx, arg.layout);
1572-
op.val.store(bx, scratch);
1574+
op.store_with_annotation(bx, scratch);
15731575
(scratch.val.llval, scratch.val.align, true)
15741576
}
15751577
_ => (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false),

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
480480
return local(OperandRef {
481481
val: OperandValue::Pair(a, b),
482482
layout: arg.layout,
483+
move_annotation: None,
483484
});
484485
}
485486
_ => {}
@@ -552,6 +553,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
552553
fx.caller_location = Some(OperandRef {
553554
val: OperandValue::Immediate(bx.get_param(llarg_idx)),
554555
layout: arg.layout,
556+
move_annotation: None,
555557
});
556558
}
557559

0 commit comments

Comments
 (0)