Skip to content

Commit 8b9f0f9

Browse files
committed
Auto merge of #132349 - matthiaskrgr:rollup-9g6s4p2, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #129394 (Don't lint `irrefutable_let_patterns` on leading patterns if `else if` let-chains) - #131856 (TypingMode: merge intercrate, reveal, and defining_opaque_types) - #132322 (powerpc64-ibm-aix: update maintainters) - #132327 (Point to Fuchsia team in platform support docs) - #132332 (Use `token_descr` more in error messages) - #132338 (Remove `Engine`) - #132340 (cg_llvm: Consistently use safe wrapper function `set_section`) - #132342 (cg_llvm: Clean up FFI calls for operand bundles) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 16422db + 879c4d5 commit 8b9f0f9

File tree

195 files changed

+1009
-1071
lines changed

Some content is hidden

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

195 files changed

+1009
-1071
lines changed

compiler/rustc_borrowck/src/lib.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_infer::infer::{
3434
use rustc_middle::mir::tcx::PlaceTy;
3535
use rustc_middle::mir::*;
3636
use rustc_middle::query::Providers;
37-
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt};
37+
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode};
3838
use rustc_middle::{bug, span_bug};
3939
use rustc_mir_dataflow::Analysis;
4040
use rustc_mir_dataflow::impls::{
@@ -193,9 +193,7 @@ fn do_mir_borrowck<'tcx>(
193193
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, |_| true)));
194194

195195
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
196-
.into_engine(tcx, body)
197-
.pass_name("borrowck")
198-
.iterate_to_fixpoint()
196+
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
199197
.into_results_cursor(body);
200198

201199
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
@@ -243,18 +241,21 @@ fn do_mir_borrowck<'tcx>(
243241
// usage significantly on some benchmarks.
244242
drop(flow_inits);
245243

246-
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
247-
.into_engine(tcx, body)
248-
.pass_name("borrowck")
249-
.iterate_to_fixpoint();
250-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
251-
.into_engine(tcx, body)
252-
.pass_name("borrowck")
253-
.iterate_to_fixpoint();
254-
let flow_ever_inits = EverInitializedPlaces::new(body, &move_data)
255-
.into_engine(tcx, body)
256-
.pass_name("borrowck")
257-
.iterate_to_fixpoint();
244+
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set).iterate_to_fixpoint(
245+
tcx,
246+
body,
247+
Some("borrowck"),
248+
);
249+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data).iterate_to_fixpoint(
250+
tcx,
251+
body,
252+
Some("borrowck"),
253+
);
254+
let flow_ever_inits = EverInitializedPlaces::new(body, &move_data).iterate_to_fixpoint(
255+
tcx,
256+
body,
257+
Some("borrowck"),
258+
);
258259

259260
let movable_coroutine =
260261
// The first argument is the coroutine type passed by value
@@ -440,7 +441,7 @@ pub struct BorrowckInferCtxt<'tcx> {
440441

441442
impl<'tcx> BorrowckInferCtxt<'tcx> {
442443
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
443-
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def_id).build();
444+
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, def_id));
444445
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
445446
}
446447

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_macros::extension;
99
use rustc_middle::ty::visit::TypeVisitableExt;
1010
use rustc_middle::ty::{
1111
self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable,
12+
TypingMode,
1213
};
1314
use rustc_span::Span;
1415
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
@@ -340,14 +341,13 @@ fn check_opaque_type_well_formed<'tcx>(
340341
parent_def_id = tcx.local_parent(parent_def_id);
341342
}
342343

343-
// FIXME(-Znext-solver): We probably should use `&[]` instead of
344-
// and prepopulate this `InferCtxt` with known opaque values, rather than
345-
// allowing opaque types to be defined and checking them after the fact.
344+
// FIXME(#132279): This should eventually use the already defined hidden types
345+
// instead. Alternatively we'll entirely remove this function given we also check
346+
// the opaque in `check_opaque_meets_bounds` later.
346347
let infcx = tcx
347348
.infer_ctxt()
348349
.with_next_trait_solver(next_trait_solver)
349-
.with_opaque_type_inference(parent_def_id)
350-
.build();
350+
.build(TypingMode::analysis_in_body(tcx, parent_def_id));
351351
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
352352
let identity_args = GenericArgs::identity_for_item(tcx, def_id);
353353

@@ -517,7 +517,9 @@ impl<'tcx> LazyOpaqueTyEnv<'tcx> {
517517
},
518518
);
519519

520-
let infcx = tcx.infer_ctxt().build();
520+
// FIXME(#132279): It feels wrong to use `non_body_analysis` here given that we're
521+
// in a body here.
522+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
521523
let ocx = ObligationCtxt::new(&infcx);
522524

523525
let wf_tys = ocx.assumed_wf_types(param_env, parent).unwrap_or_else(|_| {

compiler/rustc_codegen_llvm/src/allocator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ fn create_wrapper_function(
154154
.enumerate()
155155
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
156156
.collect::<Vec<_>>();
157-
let ret = llvm::LLVMRustBuildCall(
157+
let ret = llvm::LLVMBuildCallWithOperandBundles(
158158
llbuilder,
159159
ty,
160160
callee,
161161
args.as_ptr(),
162162
args.len() as c_uint,
163163
[].as_ptr(),
164164
0 as c_uint,
165+
c"".as_ptr(),
165166
);
166167
llvm::LLVMSetTailCall(ret, True);
167168
if output.is_some() {

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,14 @@ fn get_bitcode_slice_from_object_data<'a>(
165165
// We drop the "__LLVM," prefix here because on Apple platforms there's a notion of "segment
166166
// name" which in the public API for sections gets treated as part of the section name, but
167167
// internally in MachOObjectFile.cpp gets treated separately.
168-
let section_name = bitcode_section_name(cgcx).trim_start_matches("__LLVM,");
168+
let section_name = bitcode_section_name(cgcx).to_str().unwrap().trim_start_matches("__LLVM,");
169169
let mut len = 0;
170170
let data = unsafe {
171171
llvm::LLVMRustGetSliceFromObjectDataByName(
172172
obj.as_ptr(),
173173
obj.len(),
174174
section_name.as_ptr(),
175+
section_name.len(),
175176
&mut len,
176177
)
177178
};

compiler/rustc_codegen_llvm/src/back/write.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ffi::CString;
1+
use std::ffi::{CStr, CString};
22
use std::io::{self, Write};
33
use std::path::{Path, PathBuf};
44
use std::sync::Arc;
@@ -958,14 +958,13 @@ fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
958958
cgcx.opts.target_triple.triple().contains("-aix")
959959
}
960960

961-
//FIXME use c string literals here too
962-
pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static str {
961+
pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static CStr {
963962
if target_is_apple(cgcx) {
964-
"__LLVM,__bitcode\0"
963+
c"__LLVM,__bitcode"
965964
} else if target_is_aix(cgcx) {
966-
".ipa\0"
965+
c".ipa"
967966
} else {
968-
".llvmbc\0"
967+
c".llvmbc"
969968
}
970969
}
971970

@@ -1042,8 +1041,7 @@ unsafe fn embed_bitcode(
10421041
);
10431042
llvm::LLVMSetInitializer(llglobal, llconst);
10441043

1045-
let section = bitcode_section_name(cgcx);
1046-
llvm::LLVMSetSection(llglobal, section.as_c_char_ptr());
1044+
llvm::set_section(llglobal, bitcode_section_name(cgcx));
10471045
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
10481046
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
10491047

@@ -1061,7 +1059,7 @@ unsafe fn embed_bitcode(
10611059
} else {
10621060
c".llvmcmd"
10631061
};
1064-
llvm::LLVMSetSection(llglobal, section.as_ptr());
1062+
llvm::set_section(llglobal, section);
10651063
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
10661064
} else {
10671065
// We need custom section flags, so emit module-level inline assembly.

compiler/rustc_codegen_llvm/src/base.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ pub(crate) fn compile_codegen_unit(
145145

146146
pub(crate) fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
147147
let Some(sect) = attrs.link_section else { return };
148-
unsafe {
149-
let buf = SmallCStr::new(sect.as_str());
150-
llvm::LLVMSetSection(llval, buf.as_ptr());
151-
}
148+
let buf = SmallCStr::new(sect.as_str());
149+
llvm::set_section(llval, &buf);
152150
}
153151

154152
pub(crate) fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {

compiler/rustc_codegen_llvm/src/builder.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
239239

240240
let args = self.check_call("invoke", llty, llfn, args);
241241
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
242-
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
243242
let mut bundles: SmallVec<[_; 2]> = SmallVec::new();
244243
if let Some(funclet_bundle) = funclet_bundle {
245244
bundles.push(funclet_bundle);
@@ -250,13 +249,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
250249

251250
// Emit KCFI operand bundle
252251
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
253-
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
254-
if let Some(kcfi_bundle) = kcfi_bundle {
252+
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
255253
bundles.push(kcfi_bundle);
256254
}
257255

258256
let invoke = unsafe {
259-
llvm::LLVMRustBuildInvoke(
257+
llvm::LLVMBuildInvokeWithOperandBundles(
260258
self.llbuilder,
261259
llty,
262260
llfn,
@@ -1179,7 +1177,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11791177

11801178
let args = self.check_call("call", llty, llfn, args);
11811179
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
1182-
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
11831180
let mut bundles: SmallVec<[_; 2]> = SmallVec::new();
11841181
if let Some(funclet_bundle) = funclet_bundle {
11851182
bundles.push(funclet_bundle);
@@ -1190,20 +1187,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11901187

11911188
// Emit KCFI operand bundle
11921189
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1193-
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
1194-
if let Some(kcfi_bundle) = kcfi_bundle {
1190+
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
11951191
bundles.push(kcfi_bundle);
11961192
}
11971193

11981194
let call = unsafe {
1199-
llvm::LLVMRustBuildCall(
1195+
llvm::LLVMBuildCallWithOperandBundles(
12001196
self.llbuilder,
12011197
llty,
12021198
llfn,
12031199
args.as_ptr() as *const &llvm::Value,
12041200
args.len() as c_uint,
12051201
bundles.as_ptr(),
12061202
bundles.len() as c_uint,
1203+
c"".as_ptr(),
12071204
)
12081205
};
12091206
if let Some(fn_abi) = fn_abi {
@@ -1509,7 +1506,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15091506

15101507
let args = self.check_call("callbr", llty, llfn, args);
15111508
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
1512-
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
15131509
let mut bundles: SmallVec<[_; 2]> = SmallVec::new();
15141510
if let Some(funclet_bundle) = funclet_bundle {
15151511
bundles.push(funclet_bundle);
@@ -1520,13 +1516,12 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15201516

15211517
// Emit KCFI operand bundle
15221518
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1523-
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
1524-
if let Some(kcfi_bundle) = kcfi_bundle {
1519+
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
15251520
bundles.push(kcfi_bundle);
15261521
}
15271522

15281523
let callbr = unsafe {
1529-
llvm::LLVMRustBuildCallBr(
1524+
llvm::LLVMBuildCallBr(
15301525
self.llbuilder,
15311526
llty,
15321527
llfn,
@@ -1601,7 +1596,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16011596
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
16021597
instance: Option<Instance<'tcx>>,
16031598
llfn: &'ll Value,
1604-
) -> Option<llvm::OperandBundleDef<'ll>> {
1599+
) -> Option<llvm::OperandBundleOwned<'ll>> {
16051600
let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) };
16061601
let kcfi_bundle = if self.tcx.sess.is_sanitizer_kcfi_enabled()
16071602
&& let Some(fn_abi) = fn_abi
@@ -1627,7 +1622,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16271622
kcfi::typeid_for_fnabi(self.tcx, fn_abi, options)
16281623
};
16291624

1630-
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
1625+
Some(llvm::OperandBundleOwned::new("kcfi", &[self.const_u32(kcfi_typeid)]))
16311626
} else {
16321627
None
16331628
};

compiler/rustc_codegen_llvm/src/common.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tracing::debug;
1717

1818
use crate::consts::const_alloc_to_llvm;
1919
pub(crate) use crate::context::CodegenCx;
20-
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, OperandBundleDef, True};
20+
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, True};
2121
use crate::type_::Type;
2222
use crate::value::Value;
2323

@@ -63,19 +63,19 @@ use crate::value::Value;
6363
/// the `OperandBundleDef` value created for MSVC landing pads.
6464
pub(crate) struct Funclet<'ll> {
6565
cleanuppad: &'ll Value,
66-
operand: OperandBundleDef<'ll>,
66+
operand: llvm::OperandBundleOwned<'ll>,
6767
}
6868

6969
impl<'ll> Funclet<'ll> {
7070
pub(crate) fn new(cleanuppad: &'ll Value) -> Self {
71-
Funclet { cleanuppad, operand: OperandBundleDef::new("funclet", &[cleanuppad]) }
71+
Funclet { cleanuppad, operand: llvm::OperandBundleOwned::new("funclet", &[cleanuppad]) }
7272
}
7373

7474
pub(crate) fn cleanuppad(&self) -> &'ll Value {
7575
self.cleanuppad
7676
}
7777

78-
pub(crate) fn bundle(&self) -> &OperandBundleDef<'ll> {
78+
pub(crate) fn bundle(&self) -> &llvm::OperandBundle<'ll> {
7979
&self.operand
8080
}
8181
}

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
565565
let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
566566
llvm::LLVMSetInitializer(g, array);
567567
llvm::set_linkage(g, llvm::Linkage::AppendingLinkage);
568-
llvm::LLVMSetSection(g, c"llvm.metadata".as_ptr());
568+
llvm::set_section(g, c"llvm.metadata");
569569
}
570570
}
571571
}

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
7272
let section_var = cx
7373
.define_global(section_var_name, llvm_type)
7474
.unwrap_or_else(|| bug!("symbol `{}` is already defined", section_var_name));
75-
llvm::LLVMSetSection(section_var, c".debug_gdb_scripts".as_ptr());
75+
llvm::set_section(section_var, c".debug_gdb_scripts");
7676
llvm::LLVMSetInitializer(section_var, cx.const_bytes(section_contents));
7777
llvm::LLVMSetGlobalConstant(section_var, llvm::True);
7878
llvm::LLVMSetUnnamedAddress(section_var, llvm::UnnamedAddr::Global);

0 commit comments

Comments
 (0)