Skip to content

Commit 6c1d960

Browse files
committed
Auto merge of rust-lang#136318 - matthiaskrgr:rollup-a159mzo, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#135026 (Cast global variables to default address space) - rust-lang#135475 (uefi: Implement path) - rust-lang#135852 (Add `AsyncFn*` to `core` prelude) - rust-lang#136004 (tests: Skip const OOM tests on aarch64-unknown-linux-gnu) - rust-lang#136157 (override build profile for bootstrap tests) - rust-lang#136180 (Introduce a wrapper for "typed valtrees" and properly check the type before extracting the value) - rust-lang#136256 (Add release notes for 1.84.1) - rust-lang#136271 (Remove minor future footgun in `impl Debug for MaybeUninit`) - rust-lang#136288 (Improve documentation for file locking) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a730edc + 8673178 commit 6c1d960

File tree

69 files changed

+700
-293
lines changed

Some content is hidden

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

69 files changed

+700
-293
lines changed

Diff for: RELEASES.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
Version 1.84.1 (2025-01-30)
2+
==========================
3+
4+
<a id="1.84.1"></a>
5+
6+
- [Fix ICE 132920 in duplicate-crate diagnostics.](https://github.com/rust-lang/rust/pull/133304/)
7+
- [Fix errors for overlapping impls in incremental rebuilds.](https://github.com/rust-lang/rust/pull/133828/)
8+
- [Fix slow compilation related to the next-generation trait solver.](https://github.com/rust-lang/rust/pull/135618/)
9+
- [Fix debuginfo when LLVM's location discriminator value limit is exceeded.](https://github.com/rust-lang/rust/pull/135643/)
10+
- Fixes for building Rust from source:
11+
- [Only try to distribute `llvm-objcopy` if llvm tools are enabled.](https://github.com/rust-lang/rust/pull/134240/)
12+
- [Add Profile Override for Non-Git Sources.](https://github.com/rust-lang/rust/pull/135433/)
13+
- [Resolve symlinks of LLVM tool binaries before copying them.](https://github.com/rust-lang/rust/pull/135585/)
14+
- [Make it possible to use ci-rustc on tarball sources.](https://github.com/rust-lang/rust/pull/135722/)
15+
116
Version 1.84.0 (2025-01-09)
217
==========================
318

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
129129
return;
130130
}
131131

132-
let idx = generic_args[2]
133-
.expect_const()
134-
.try_to_valtree()
135-
.expect("expected monomorphic const in codegen")
136-
.0
137-
.unwrap_branch();
132+
let idx = generic_args[2].expect_const().to_value().valtree.unwrap_branch();
138133

139134
assert_eq!(x.layout(), y.layout());
140135
let layout = x.layout();

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13251325
impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> {
13261326
fn get_static(&mut self, def_id: DefId) -> &'ll Value {
13271327
// Forward to the `get_static` method of `CodegenCx`
1328-
self.cx().get_static(def_id)
1328+
let s = self.cx().get_static(def_id);
1329+
// Cast to default address space if globals are in a different addrspace
1330+
self.cx().const_pointercast(s, self.type_ptr())
13291331
}
13301332
}
13311333

Diff for: compiler/rustc_codegen_llvm/src/common.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
225225
llvm::LLVMSetUnnamedAddress(g, llvm::UnnamedAddr::Global);
226226
}
227227
llvm::set_linkage(g, llvm::Linkage::InternalLinkage);
228+
// Cast to default address space if globals are in a different addrspace
229+
let g = self.const_pointercast(g, self.type_ptr());
228230
(s.to_owned(), g)
229231
})
230232
.1;
@@ -289,7 +291,7 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
289291
let alloc = alloc.inner();
290292
let value = match alloc.mutability {
291293
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
292-
_ => self.static_addr_of(init, alloc.align, None),
294+
_ => self.static_addr_of_impl(init, alloc.align, None),
293295
};
294296
if !self.sess().fewer_names() && llvm::get_value_name(value).is_empty()
295297
{
@@ -315,7 +317,7 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
315317
.global_alloc(self.tcx.vtable_allocation((ty, dyn_ty.principal())))
316318
.unwrap_memory();
317319
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
318-
let value = self.static_addr_of(init, alloc.inner().align, None);
320+
let value = self.static_addr_of_impl(init, alloc.inner().align, None);
319321
(value, AddressSpace::DATA)
320322
}
321323
GlobalAlloc::Static(def_id) => {
@@ -327,7 +329,8 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
327329
let llval = unsafe {
328330
llvm::LLVMConstInBoundsGEP2(
329331
self.type_i8(),
330-
self.const_bitcast(base_addr, self.type_ptr_ext(base_addr_space)),
332+
// Cast to the required address space if necessary
333+
self.const_pointercast(base_addr, self.type_ptr_ext(base_addr_space)),
331334
&self.const_usize(offset.bytes()),
332335
1,
333336
)

Diff for: compiler/rustc_codegen_llvm/src/consts.rs

+44-17
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ impl<'ll> CodegenCx<'ll, '_> {
210210
unsafe { llvm::LLVMConstBitCast(val, ty) }
211211
}
212212

213+
pub(crate) fn const_pointercast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
214+
unsafe { llvm::LLVMConstPointerCast(val, ty) }
215+
}
216+
217+
/// Create a global variable.
218+
///
219+
/// The returned global variable is a pointer in the default address space for globals.
220+
/// Fails if a symbol with the given name already exists.
213221
pub(crate) fn static_addr_of_mut(
214222
&self,
215223
cv: &'ll Value,
@@ -233,6 +241,34 @@ impl<'ll> CodegenCx<'ll, '_> {
233241
gv
234242
}
235243

244+
/// Create a global constant.
245+
///
246+
/// The returned global variable is a pointer in the default address space for globals.
247+
pub(crate) fn static_addr_of_impl(
248+
&self,
249+
cv: &'ll Value,
250+
align: Align,
251+
kind: Option<&str>,
252+
) -> &'ll Value {
253+
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
254+
unsafe {
255+
// Upgrade the alignment in cases where the same constant is used with different
256+
// alignment requirements
257+
let llalign = align.bytes() as u32;
258+
if llalign > llvm::LLVMGetAlignment(gv) {
259+
llvm::LLVMSetAlignment(gv, llalign);
260+
}
261+
}
262+
return gv;
263+
}
264+
let gv = self.static_addr_of_mut(cv, align, kind);
265+
unsafe {
266+
llvm::LLVMSetGlobalConstant(gv, True);
267+
}
268+
self.const_globals.borrow_mut().insert(cv, gv);
269+
gv
270+
}
271+
236272
#[instrument(level = "debug", skip(self))]
237273
pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value {
238274
let instance = Instance::mono(self.tcx, def_id);
@@ -505,24 +541,15 @@ impl<'ll> CodegenCx<'ll, '_> {
505541
}
506542

507543
impl<'ll> StaticCodegenMethods for CodegenCx<'ll, '_> {
544+
/// Get a pointer to a global variable.
545+
///
546+
/// The pointer will always be in the default address space. If global variables default to a
547+
/// different address space, an addrspacecast is inserted.
508548
fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
509-
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
510-
unsafe {
511-
// Upgrade the alignment in cases where the same constant is used with different
512-
// alignment requirements
513-
let llalign = align.bytes() as u32;
514-
if llalign > llvm::LLVMGetAlignment(gv) {
515-
llvm::LLVMSetAlignment(gv, llalign);
516-
}
517-
}
518-
return gv;
519-
}
520-
let gv = self.static_addr_of_mut(cv, align, kind);
521-
unsafe {
522-
llvm::LLVMSetGlobalConstant(gv, True);
523-
}
524-
self.const_globals.borrow_mut().insert(cv, gv);
525-
gv
549+
let gv = self.static_addr_of_impl(cv, align, kind);
550+
// static_addr_of_impl returns the bare global variable, which might not be in the default
551+
// address space. Cast to the default address space if necessary.
552+
self.const_pointercast(gv, self.type_ptr())
526553
}
527554

528555
fn codegen_static(&self, def_id: DefId) {

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,26 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14871487
.di_node
14881488
}
14891489

1490+
/// Get the global variable for the vtable.
1491+
///
1492+
/// When using global variables, we may have created an addrspacecast to get a pointer to the
1493+
/// default address space if global variables are created in a different address space.
1494+
/// For modifying the vtable, we need the real global variable. This function accepts either a
1495+
/// global variable (which is simply returned), or an addrspacecast constant expression.
1496+
/// If the given value is an addrspacecast, the cast is removed and the global variable behind
1497+
/// the cast is returned.
1498+
fn find_vtable_behind_cast<'ll>(vtable: &'ll Value) -> &'ll Value {
1499+
// The vtable is a global variable, which may be behind an addrspacecast.
1500+
unsafe {
1501+
if let Some(c) = llvm::LLVMIsAConstantExpr(vtable) {
1502+
if llvm::LLVMGetConstOpcode(c) == llvm::Opcode::AddrSpaceCast {
1503+
return llvm::LLVMGetOperand(c, 0).unwrap();
1504+
}
1505+
}
1506+
}
1507+
vtable
1508+
}
1509+
14901510
pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
14911511
cx: &CodegenCx<'ll, 'tcx>,
14921512
ty: Ty<'tcx>,
@@ -1507,6 +1527,8 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
15071527

15081528
let Some(trait_ref) = trait_ref else { return };
15091529

1530+
// Unwrap potential addrspacecast
1531+
let vtable = find_vtable_behind_cast(vtable);
15101532
let trait_ref_self = trait_ref.with_self_ty(cx.tcx, ty);
15111533
let trait_ref_self = cx.tcx.erase_regions(trait_ref_self);
15121534
let trait_def_id = trait_ref_self.def_id();
@@ -1580,6 +1602,9 @@ pub(crate) fn create_vtable_di_node<'ll, 'tcx>(
15801602
return;
15811603
}
15821604

1605+
// Unwrap potential addrspacecast
1606+
let vtable = find_vtable_behind_cast(vtable);
1607+
15831608
// When full debuginfo is enabled, we want to try and prevent vtables from being
15841609
// merged. Otherwise debuggers will have a hard time mapping from dyn pointer
15851610
// to concrete type.

Diff for: compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
13291329
}
13301330

13311331
if name == sym::simd_shuffle_generic {
1332-
let idx = fn_args[2].expect_const().try_to_valtree().unwrap().0.unwrap_branch();
1332+
let idx = fn_args[2].expect_const().to_value().valtree.unwrap_branch();
13331333
let n = idx.len() as u64;
13341334

13351335
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+77
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,79 @@ pub enum MemoryEffects {
661661
InaccessibleMemOnly,
662662
}
663663

664+
/// LLVMOpcode
665+
#[derive(Copy, Clone, PartialEq, Eq)]
666+
#[repr(C)]
667+
pub enum Opcode {
668+
Ret = 1,
669+
Br = 2,
670+
Switch = 3,
671+
IndirectBr = 4,
672+
Invoke = 5,
673+
Unreachable = 7,
674+
CallBr = 67,
675+
FNeg = 66,
676+
Add = 8,
677+
FAdd = 9,
678+
Sub = 10,
679+
FSub = 11,
680+
Mul = 12,
681+
FMul = 13,
682+
UDiv = 14,
683+
SDiv = 15,
684+
FDiv = 16,
685+
URem = 17,
686+
SRem = 18,
687+
FRem = 19,
688+
Shl = 20,
689+
LShr = 21,
690+
AShr = 22,
691+
And = 23,
692+
Or = 24,
693+
Xor = 25,
694+
Alloca = 26,
695+
Load = 27,
696+
Store = 28,
697+
GetElementPtr = 29,
698+
Trunc = 30,
699+
ZExt = 31,
700+
SExt = 32,
701+
FPToUI = 33,
702+
FPToSI = 34,
703+
UIToFP = 35,
704+
SIToFP = 36,
705+
FPTrunc = 37,
706+
FPExt = 38,
707+
PtrToInt = 39,
708+
IntToPtr = 40,
709+
BitCast = 41,
710+
AddrSpaceCast = 60,
711+
ICmp = 42,
712+
FCmp = 43,
713+
PHI = 44,
714+
Call = 45,
715+
Select = 46,
716+
UserOp1 = 47,
717+
UserOp2 = 48,
718+
VAArg = 49,
719+
ExtractElement = 50,
720+
InsertElement = 51,
721+
ShuffleVector = 52,
722+
ExtractValue = 53,
723+
InsertValue = 54,
724+
Freeze = 68,
725+
Fence = 55,
726+
AtomicCmpXchg = 56,
727+
AtomicRMW = 57,
728+
Resume = 58,
729+
LandingPad = 59,
730+
CleanupRet = 61,
731+
CatchRet = 62,
732+
CatchPad = 63,
733+
CleanupPad = 64,
734+
CatchSwitch = 65,
735+
}
736+
664737
unsafe extern "C" {
665738
type Opaque;
666739
}
@@ -991,7 +1064,10 @@ unsafe extern "C" {
9911064
pub fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
9921065
pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
9931066
pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1067+
pub fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
9941068
pub fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;
1069+
pub fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode;
1070+
pub fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>;
9951071

9961072
// Operations on global variables, functions, and aliases (globals)
9971073
pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
@@ -1048,6 +1124,7 @@ unsafe extern "C" {
10481124
// Operations on instructions
10491125
pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
10501126
pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
1127+
pub fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>;
10511128

10521129
// Operations on call sites
10531130
pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);

Diff for: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -673,25 +673,23 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
673673
ty::ConstKind::Param(param) => {
674674
write!(output, "{}", param.name)
675675
}
676-
ty::ConstKind::Value(ty, valtree) => {
677-
match ty.kind() {
676+
ty::ConstKind::Value(cv) => {
677+
match cv.ty.kind() {
678678
ty::Int(ity) => {
679-
// FIXME: directly extract the bits from a valtree instead of evaluating an
680-
// already evaluated `Const` in order to get the bits.
681-
let bits = ct
679+
let bits = cv
682680
.try_to_bits(tcx, ty::TypingEnv::fully_monomorphized())
683681
.expect("expected monomorphic const in codegen");
684682
let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128;
685683
write!(output, "{val}")
686684
}
687685
ty::Uint(_) => {
688-
let val = ct
686+
let val = cv
689687
.try_to_bits(tcx, ty::TypingEnv::fully_monomorphized())
690688
.expect("expected monomorphic const in codegen");
691689
write!(output, "{val}")
692690
}
693691
ty::Bool => {
694-
let val = ct.try_to_bool().expect("expected monomorphic const in codegen");
692+
let val = cv.try_to_bool().expect("expected monomorphic const in codegen");
695693
write!(output, "{val}")
696694
}
697695
_ => {
@@ -703,9 +701,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
703701
// avoiding collisions and will make the emitted type names shorter.
704702
let hash_short = tcx.with_stable_hashing_context(|mut hcx| {
705703
let mut hasher = StableHasher::new();
706-
hcx.while_hashing_spans(false, |hcx| {
707-
(ty, valtree).hash_stable(hcx, &mut hasher)
708-
});
704+
hcx.while_hashing_spans(false, |hcx| cv.hash_stable(hcx, &mut hasher));
709705
hasher.finish::<Hash64>()
710706
});
711707

Diff for: compiler/rustc_codegen_ssa/src/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4343
mir::Const::Ty(_, c) => match c.kind() {
4444
// A constant that came from a const generic but was then used as an argument to
4545
// old-style simd_shuffle (passing as argument instead of as a generic param).
46-
rustc_type_ir::ConstKind::Value(_, valtree) => return Ok(Ok(valtree)),
46+
rustc_type_ir::ConstKind::Value(cv) => return Ok(Ok(cv.valtree)),
4747
other => span_bug!(constant.span, "{other:#?}"),
4848
},
4949
// We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate

Diff for: compiler/rustc_const_eval/src/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ where
345345
Const::Ty(_, ct)
346346
if matches!(
347347
ct.kind(),
348-
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_, _)
348+
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_)
349349
) =>
350350
{
351351
None

Diff for: compiler/rustc_const_eval/src/const_eval/valtrees.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ pub(crate) fn eval_to_valtree<'tcx>(
272272

273273
/// Converts a `ValTree` to a `ConstValue`, which is needed after mir
274274
/// construction has finished.
275-
// FIXME Merge `valtree_to_const_value` and `valtree_into_mplace` into one function
275+
// FIXME(valtrees): Merge `valtree_to_const_value` and `valtree_into_mplace` into one function
276+
// FIXME(valtrees): Accept `ty::Value` instead of `Ty` and `ty::ValTree` separately.
276277
#[instrument(skip(tcx), level = "debug", ret)]
277278
pub fn valtree_to_const_value<'tcx>(
278279
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)