Skip to content

Commit fb33c2b

Browse files
authored
Rollup merge of #91931 - LegionMammal978:less-inband-codegen_llvm, r=davidtwco
Remove `in_band_lifetimes` from `rustc_codegen_llvm` See #91867 for more information. This one took a while. This crate has dozens of functions not associated with any type, and most of them were using in-band lifetimes for `'ll` and `'tcx`.
2 parents 4750924 + 462bb57 commit fb33c2b

28 files changed

+429
-392
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ impl ArgAttributesExt for ArgAttributes {
136136
}
137137

138138
pub trait LlvmType {
139-
fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type;
139+
fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type;
140140
}
141141

142142
impl LlvmType for Reg {
143-
fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
143+
fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
144144
match self.kind {
145145
RegKind::Integer => cx.type_ix(self.size.bits()),
146146
RegKind::Float => match self.size.bits() {
@@ -154,7 +154,7 @@ impl LlvmType for Reg {
154154
}
155155

156156
impl LlvmType for CastTarget {
157-
fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
157+
fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
158158
let rest_ll_unit = self.rest.unit.llvm_type(cx);
159159
let (rest_count, rem_bytes) = if self.rest.unit.size.bytes() == 0 {
160160
(0, 0)
@@ -212,7 +212,7 @@ pub trait ArgAbiExt<'ll, 'tcx> {
212212
);
213213
}
214214

215-
impl ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
215+
impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
216216
/// Gets the LLVM type for a place of the original Rust type of
217217
/// this argument/return, i.e., the result of `type_of::type_of`.
218218
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
@@ -287,7 +287,7 @@ impl ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
287287

288288
fn store_fn_arg(
289289
&self,
290-
bx: &mut Builder<'a, 'll, 'tcx>,
290+
bx: &mut Builder<'_, 'll, 'tcx>,
291291
idx: &mut usize,
292292
dst: PlaceRef<'tcx, &'ll Value>,
293293
) {
@@ -314,7 +314,7 @@ impl ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
314314
}
315315
}
316316

317-
impl ArgAbiMethods<'tcx> for Builder<'a, 'll, 'tcx> {
317+
impl<'ll, 'tcx> ArgAbiMethods<'tcx> for Builder<'_, 'll, 'tcx> {
318318
fn store_fn_arg(
319319
&mut self,
320320
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
@@ -336,15 +336,15 @@ impl ArgAbiMethods<'tcx> for Builder<'a, 'll, 'tcx> {
336336
}
337337
}
338338

339-
pub trait FnAbiLlvmExt<'tcx> {
339+
pub trait FnAbiLlvmExt<'ll, 'tcx> {
340340
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
341341
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
342342
fn llvm_cconv(&self) -> llvm::CallConv;
343343
fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value);
344-
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx>, callsite: &'ll Value);
344+
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value);
345345
}
346346

347-
impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
347+
impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
348348
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
349349
// Ignore "extra" args from the call site for C variadic functions.
350350
// Only the "fixed" args are part of the LLVM function signature.
@@ -505,7 +505,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
505505
}
506506
}
507507

508-
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx>, callsite: &'ll Value) {
508+
fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value) {
509509
if self.ret.layout.abi.is_uninhabited() {
510510
llvm::Attribute::NoReturn.apply_callsite(llvm::AttributePlace::Function, callsite);
511511
}
@@ -610,7 +610,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
610610
}
611611
}
612612

613-
impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
613+
impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
614614
fn apply_attrs_callsite(&mut self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, callsite: Self::Value) {
615615
fn_abi.apply_attrs_callsite(self, callsite)
616616
}

compiler/rustc_codegen_llvm/src/asm.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_target::asm::*;
2323
use libc::{c_char, c_uint};
2424
use tracing::debug;
2525

26-
impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
26+
impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
2727
fn codegen_llvm_inline_asm(
2828
&mut self,
2929
ia: &hir::LlvmInlineAsmInner,
@@ -399,7 +399,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
399399
}
400400
}
401401

402-
impl AsmMethods for CodegenCx<'ll, 'tcx> {
402+
impl AsmMethods for CodegenCx<'_, '_> {
403403
fn codegen_global_asm(
404404
&self,
405405
template: &[InlineAsmTemplatePiece],
@@ -447,8 +447,8 @@ impl AsmMethods for CodegenCx<'ll, 'tcx> {
447447
}
448448
}
449449

450-
pub(crate) fn inline_asm_call(
451-
bx: &mut Builder<'a, 'll, 'tcx>,
450+
pub(crate) fn inline_asm_call<'ll>(
451+
bx: &mut Builder<'_, 'll, '_>,
452452
asm: &str,
453453
cons: &str,
454454
inputs: &[&'ll Value],
@@ -583,7 +583,7 @@ fn a64_vreg_index(reg: InlineAsmReg) -> Option<u32> {
583583
}
584584

585585
/// Converts a register class to an LLVM constraint code.
586-
fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>) -> String {
586+
fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) -> String {
587587
match reg {
588588
// For vector registers LLVM wants the register name to match the type size.
589589
InlineAsmRegOrRegClass::Reg(reg) => {
@@ -773,7 +773,7 @@ fn modifier_to_llvm(
773773

774774
/// Type to use for outputs that are discarded. It doesn't really matter what
775775
/// the type is, as long as it is valid for the constraint code.
776-
fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll Type {
776+
fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'ll Type {
777777
match reg {
778778
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => cx.type_i32(),
779779
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg)
@@ -841,7 +841,7 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
841841

842842
/// Helper function to get the LLVM type for a Scalar. Pointers are returned as
843843
/// the equivalent integer type.
844-
fn llvm_asm_scalar_type(cx: &CodegenCx<'ll, 'tcx>, scalar: Scalar) -> &'ll Type {
844+
fn llvm_asm_scalar_type<'ll>(cx: &CodegenCx<'ll, '_>, scalar: Scalar) -> &'ll Type {
845845
match scalar.value {
846846
Primitive::Int(Integer::I8, _) => cx.type_i8(),
847847
Primitive::Int(Integer::I16, _) => cx.type_i16(),
@@ -855,8 +855,8 @@ fn llvm_asm_scalar_type(cx: &CodegenCx<'ll, 'tcx>, scalar: Scalar) -> &'ll Type
855855
}
856856

857857
/// Fix up an input value to work around LLVM bugs.
858-
fn llvm_fixup_input(
859-
bx: &mut Builder<'a, 'll, 'tcx>,
858+
fn llvm_fixup_input<'ll, 'tcx>(
859+
bx: &mut Builder<'_, 'll, 'tcx>,
860860
mut value: &'ll Value,
861861
reg: InlineAsmRegClass,
862862
layout: &TyAndLayout<'tcx>,
@@ -933,8 +933,8 @@ fn llvm_fixup_input(
933933
}
934934

935935
/// Fix up an output value to work around LLVM bugs.
936-
fn llvm_fixup_output(
937-
bx: &mut Builder<'a, 'll, 'tcx>,
936+
fn llvm_fixup_output<'ll, 'tcx>(
937+
bx: &mut Builder<'_, 'll, 'tcx>,
938938
mut value: &'ll Value,
939939
reg: InlineAsmRegClass,
940940
layout: &TyAndLayout<'tcx>,
@@ -1009,7 +1009,7 @@ fn llvm_fixup_output(
10091009
}
10101010

10111011
/// Output type to use for llvm_fixup_output.
1012-
fn llvm_fixup_output_type(
1012+
fn llvm_fixup_output_type<'ll, 'tcx>(
10131013
cx: &CodegenCx<'ll, 'tcx>,
10141014
reg: InlineAsmRegClass,
10151015
layout: &TyAndLayout<'tcx>,

compiler/rustc_codegen_llvm/src/attributes.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::value::Value;
2525

2626
/// Mark LLVM function to use provided inline heuristic.
2727
#[inline]
28-
fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
28+
fn inline<'ll>(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
2929
use self::InlineAttr::*;
3030
match inline {
3131
Hint => Attribute::InlineHint.apply_llfn(Function, val),
@@ -41,7 +41,7 @@ fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
4141

4242
/// Apply LLVM sanitize attributes.
4343
#[inline]
44-
pub fn sanitize(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: &'ll Value) {
44+
pub fn sanitize<'ll>(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: &'ll Value) {
4545
let enabled = cx.tcx.sess.opts.debugging_opts.sanitizer - no_sanitize;
4646
if enabled.contains(SanitizerSet::ADDRESS) {
4747
llvm::Attribute::SanitizeAddress.apply_llfn(Function, llfn);
@@ -59,17 +59,17 @@ pub fn sanitize(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: &'ll V
5959

6060
/// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function.
6161
#[inline]
62-
pub fn emit_uwtable(val: &'ll Value, emit: bool) {
62+
pub fn emit_uwtable(val: &Value, emit: bool) {
6363
Attribute::UWTable.toggle_llfn(Function, val, emit);
6464
}
6565

6666
/// Tell LLVM if this function should be 'naked', i.e., skip the epilogue and prologue.
6767
#[inline]
68-
fn naked(val: &'ll Value, is_naked: bool) {
68+
fn naked(val: &Value, is_naked: bool) {
6969
Attribute::Naked.toggle_llfn(Function, val, is_naked);
7070
}
7171

72-
pub fn set_frame_pointer_type(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
72+
pub fn set_frame_pointer_type<'ll>(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
7373
let mut fp = cx.sess().target.frame_pointer;
7474
// "mcount" function relies on stack pointer.
7575
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
@@ -92,7 +92,7 @@ pub fn set_frame_pointer_type(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
9292

9393
/// Tell LLVM what instrument function to insert.
9494
#[inline]
95-
fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
95+
fn set_instrument_function<'ll>(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
9696
if cx.sess().instrument_mcount() {
9797
// Similar to `clang -pg` behavior. Handled by the
9898
// `post-inline-ee-instrument` LLVM pass.
@@ -110,7 +110,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
110110
}
111111
}
112112

113-
fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
113+
fn set_probestack<'ll>(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
114114
// Currently stack probes seem somewhat incompatible with the address
115115
// sanitizer and thread sanitizer. With asan we're already protected from
116116
// stack overflow anyway so we don't really need stack probes regardless.
@@ -161,7 +161,7 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
161161
}
162162
}
163163

164-
fn set_stackprotector(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
164+
fn set_stackprotector<'ll>(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
165165
let sspattr = match cx.sess().stack_protector() {
166166
StackProtector::None => return,
167167
StackProtector::All => Attribute::StackProtectReq,
@@ -172,7 +172,7 @@ fn set_stackprotector(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
172172
sspattr.apply_llfn(Function, llfn)
173173
}
174174

175-
pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
175+
pub fn apply_target_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
176176
let target_cpu = SmallCStr::new(llvm_util::target_cpu(cx.tcx.sess));
177177
llvm::AddFunctionAttrStringValue(
178178
llfn,
@@ -182,7 +182,7 @@ pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
182182
);
183183
}
184184

185-
pub fn apply_tune_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
185+
pub fn apply_tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
186186
if let Some(tune) = llvm_util::tune_cpu(cx.tcx.sess) {
187187
let tune_cpu = SmallCStr::new(tune);
188188
llvm::AddFunctionAttrStringValue(
@@ -196,14 +196,14 @@ pub fn apply_tune_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
196196

197197
/// Sets the `NonLazyBind` LLVM attribute on a given function,
198198
/// assuming the codegen options allow skipping the PLT.
199-
pub fn non_lazy_bind(sess: &Session, llfn: &'ll Value) {
199+
pub fn non_lazy_bind<'ll>(sess: &Session, llfn: &'ll Value) {
200200
// Don't generate calls through PLT if it's not necessary
201201
if !sess.needs_plt() {
202202
Attribute::NonLazyBind.apply_llfn(Function, llfn);
203203
}
204204
}
205205

206-
pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
206+
pub(crate) fn default_optimisation_attrs<'ll>(sess: &Session, llfn: &'ll Value) {
207207
match sess.opts.optimize {
208208
OptLevel::Size => {
209209
llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
@@ -226,7 +226,11 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
226226

227227
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
228228
/// attributes.
229-
pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::Instance<'tcx>) {
229+
pub fn from_fn_attrs<'ll, 'tcx>(
230+
cx: &CodegenCx<'ll, 'tcx>,
231+
llfn: &'ll Value,
232+
instance: ty::Instance<'tcx>,
233+
) {
230234
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
231235

232236
match codegen_fn_attrs.optimize {

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn fat_lto(
363363

364364
crate struct Linker<'a>(&'a mut llvm::Linker<'a>);
365365

366-
impl Linker<'a> {
366+
impl<'a> Linker<'a> {
367367
crate fn new(llmod: &'a llvm::Module) -> Self {
368368
unsafe { Linker(llvm::LLVMRustLinkerNew(llmod)) }
369369
}
@@ -383,7 +383,7 @@ impl Linker<'a> {
383383
}
384384
}
385385

386-
impl Drop for Linker<'a> {
386+
impl Drop for Linker<'_> {
387387
fn drop(&mut self) {
388388
unsafe {
389389
llvm::LLVMRustLinkerFree(&mut *(self.0 as *mut _));

compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn llvm_err(handler: &rustc_errors::Handler, msg: &str) -> FatalError {
4646
}
4747
}
4848

49-
pub fn write_output_file(
49+
pub fn write_output_file<'ll>(
5050
handler: &rustc_errors::Handler,
5151
target: &'ll llvm::TargetMachine,
5252
pm: &llvm::PassManager<'ll>,

compiler/rustc_codegen_llvm/src/base.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct ValueIter<'ll> {
3939
step: unsafe extern "C" fn(&'ll Value) -> Option<&'ll Value>,
4040
}
4141

42-
impl Iterator for ValueIter<'ll> {
42+
impl<'ll> Iterator for ValueIter<'ll> {
4343
type Item = &'ll Value;
4444

4545
fn next(&mut self) -> Option<&'ll Value> {
@@ -51,14 +51,11 @@ impl Iterator for ValueIter<'ll> {
5151
}
5252
}
5353

54-
pub fn iter_globals(llmod: &'ll llvm::Module) -> ValueIter<'ll> {
54+
pub fn iter_globals(llmod: &llvm::Module) -> ValueIter<'_> {
5555
unsafe { ValueIter { cur: llvm::LLVMGetFirstGlobal(llmod), step: llvm::LLVMGetNextGlobal } }
5656
}
5757

58-
pub fn compile_codegen_unit(
59-
tcx: TyCtxt<'tcx>,
60-
cgu_name: Symbol,
61-
) -> (ModuleCodegen<ModuleLlvm>, u64) {
58+
pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen<ModuleLlvm>, u64) {
6259
let start_time = Instant::now();
6360

6461
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);

0 commit comments

Comments
 (0)