Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cbfdf0b

Browse files
committedMar 13, 2025
Auto merge of rust-lang#138459 - matthiaskrgr:rollup-hddfg18, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#138126 (Add an opt-out in pretty printing for RTN rendering) - rust-lang#138399 (Delegation: allow foreign fns `reuse`) - rust-lang#138406 (Update mdbook to 0.4.47) - rust-lang#138417 (minor interpreter cleanups) - rust-lang#138420 (Adapt to LLVM dropping CfiFunctionIndex::begin()/end()) - rust-lang#138423 (Don't emit error within cast function, propagate it as a `CastError`) - rust-lang#138425 (Remove `feature = "hash_raw_entry"`) - rust-lang#138427 (Fix RISC-V VxWorks LLVM target triples) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 52daa7d + 69b3ad1 commit cbfdf0b

File tree

27 files changed

+366
-717
lines changed

27 files changed

+366
-717
lines changed
 

‎compiler/rustc_ast_lowering/src/delegation.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
190190
) -> hir::FnSig<'hir> {
191191
let header = if let Some(local_sig_id) = sig_id.as_local() {
192192
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
193-
Some(sig) => self.lower_fn_header(
194-
sig.header,
193+
Some(sig) => {
194+
let parent = self.tcx.parent(sig_id);
195195
// HACK: we override the default safety instead of generating attributes from the ether.
196196
// We are not forwarding the attributes, as the delegation fn sigs are collected on the ast,
197197
// and here we need the hir attributes.
198-
if sig.target_feature { hir::Safety::Unsafe } else { hir::Safety::Safe },
199-
&[],
200-
),
198+
let default_safety =
199+
if sig.target_feature || self.tcx.def_kind(parent) == DefKind::ForeignMod {
200+
hir::Safety::Unsafe
201+
} else {
202+
hir::Safety::Safe
203+
};
204+
self.lower_fn_header(sig.header, default_safety, &[])
205+
}
201206
None => self.generate_header_error(),
202207
}
203208
} else {

‎compiler/rustc_const_eval/src/interpret/machine.rs

+19-35
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::hash::Hash;
88

99
use rustc_abi::{Align, Size};
1010
use rustc_apfloat::{Float, FloatConvert};
11-
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1211
use rustc_middle::query::TyCtxtAt;
1312
use rustc_middle::ty::Ty;
1413
use rustc_middle::ty::layout::TyAndLayout;
@@ -21,7 +20,6 @@ use super::{
2120
AllocBytes, AllocId, AllocKind, AllocRange, Allocation, CTFE_ALLOC_SALT, ConstAllocation,
2221
CtfeProvenance, FnArg, Frame, ImmTy, InterpCx, InterpResult, MPlaceTy, MemoryKind,
2322
Misalignment, OpTy, PlaceTy, Pointer, Provenance, RangeSet, interp_ok, throw_unsup,
24-
throw_unsup_format,
2523
};
2624

2725
/// Data returned by [`Machine::after_stack_pop`], and consumed by
@@ -361,6 +359,19 @@ pub trait Machine<'tcx>: Sized {
361359
size: i64,
362360
) -> Option<(AllocId, Size, Self::ProvenanceExtra)>;
363361

362+
/// Return a "root" pointer for the given allocation: the one that is used for direct
363+
/// accesses to this static/const/fn allocation, or the one returned from the heap allocator.
364+
///
365+
/// Not called on `extern` or thread-local statics (those use the methods above).
366+
///
367+
/// `kind` is the kind of the allocation the pointer points to; it can be `None` when
368+
/// it's a global and `GLOBAL_KIND` is `None`.
369+
fn adjust_alloc_root_pointer(
370+
ecx: &InterpCx<'tcx, Self>,
371+
ptr: Pointer,
372+
kind: Option<MemoryKind<Self::MemoryKind>>,
373+
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
374+
364375
/// Called to adjust global allocations to the Provenance and AllocExtra of this machine.
365376
///
366377
/// If `alloc` contains pointers, then they are all pointing to globals.
@@ -375,46 +386,19 @@ pub trait Machine<'tcx>: Sized {
375386
alloc: &'b Allocation,
376387
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>>;
377388

378-
/// Initialize the extra state of an allocation.
389+
/// Initialize the extra state of an allocation local to this machine.
379390
///
380-
/// This is guaranteed to be called exactly once on all allocations that are accessed by the
381-
/// program.
382-
fn init_alloc_extra(
391+
/// This is guaranteed to be called exactly once on all allocations local to this machine.
392+
/// It will not be called automatically for global allocations; `adjust_global_allocation`
393+
/// has to do that itself if that is desired.
394+
fn init_local_allocation(
383395
ecx: &InterpCx<'tcx, Self>,
384396
id: AllocId,
385397
kind: MemoryKind<Self::MemoryKind>,
386398
size: Size,
387399
align: Align,
388400
) -> InterpResult<'tcx, Self::AllocExtra>;
389401

390-
/// Return a "root" pointer for the given allocation: the one that is used for direct
391-
/// accesses to this static/const/fn allocation, or the one returned from the heap allocator.
392-
///
393-
/// Not called on `extern` or thread-local statics (those use the methods above).
394-
///
395-
/// `kind` is the kind of the allocation the pointer points to; it can be `None` when
396-
/// it's a global and `GLOBAL_KIND` is `None`.
397-
fn adjust_alloc_root_pointer(
398-
ecx: &InterpCx<'tcx, Self>,
399-
ptr: Pointer,
400-
kind: Option<MemoryKind<Self::MemoryKind>>,
401-
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
402-
403-
/// Evaluate the inline assembly.
404-
///
405-
/// This should take care of jumping to the next block (one of `targets`) when asm goto
406-
/// is triggered, `targets[0]` when the assembly falls through, or diverge in case of
407-
/// naked_asm! or `InlineAsmOptions::NORETURN` being set.
408-
fn eval_inline_asm(
409-
_ecx: &mut InterpCx<'tcx, Self>,
410-
_template: &'tcx [InlineAsmTemplatePiece],
411-
_operands: &[mir::InlineAsmOperand<'tcx>],
412-
_options: InlineAsmOptions,
413-
_targets: &[mir::BasicBlock],
414-
) -> InterpResult<'tcx> {
415-
throw_unsup_format!("inline assembly is not supported")
416-
}
417-
418402
/// Hook for performing extra checks on a memory read access.
419403
///
420404
/// This will *not* be called during validation!
@@ -699,7 +683,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
699683
interp_ok(Cow::Borrowed(alloc))
700684
}
701685

702-
fn init_alloc_extra(
686+
fn init_local_allocation(
703687
_ecx: &InterpCx<$tcx, Self>,
704688
_id: AllocId,
705689
_kind: MemoryKind<Self::MemoryKind>,

‎compiler/rustc_const_eval/src/interpret/memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
263263
M::GLOBAL_KIND.map(MemoryKind::Machine),
264264
"dynamically allocating global memory"
265265
);
266-
// We have set things up so we don't need to call `adjust_from_tcx` here,
267-
// so we avoid copying the entire allocation contents.
268-
let extra = M::init_alloc_extra(self, id, kind, alloc.size(), alloc.align)?;
266+
// This cannot be merged with the `adjust_global_allocation` code path
267+
// since here we have an allocation that already uses `M::Bytes`.
268+
let extra = M::init_local_allocation(self, id, kind, alloc.size(), alloc.align)?;
269269
let alloc = alloc.with_extra(extra);
270270
self.memory.alloc_map.insert(id, (kind, alloc));
271271
M::adjust_alloc_root_pointer(self, Pointer::from(id), Some(kind))

‎compiler/rustc_const_eval/src/interpret/step.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::{info, instrument, trace};
1414

1515
use super::{
1616
FnArg, FnVal, ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy,
17-
Projectable, Scalar, interp_ok, throw_ub,
17+
Projectable, Scalar, interp_ok, throw_ub, throw_unsup_format,
1818
};
1919
use crate::util;
2020

@@ -590,8 +590,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
590590
terminator.kind
591591
),
592592

593-
InlineAsm { template, ref operands, options, ref targets, .. } => {
594-
M::eval_inline_asm(self, template, operands, options, targets)?;
593+
InlineAsm { .. } => {
594+
throw_unsup_format!("inline assembly is not supported");
595595
}
596596
}
597597

‎compiler/rustc_hir_analysis/src/check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt as _};
8484
use rustc_infer::traits::ObligationCause;
8585
use rustc_middle::query::Providers;
8686
use rustc_middle::ty::error::{ExpectedFound, TypeError};
87+
use rustc_middle::ty::print::with_types_for_signature;
8788
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypingMode};
8889
use rustc_middle::{bug, span_bug};
8990
use rustc_session::parse::feature_err;
@@ -240,11 +241,11 @@ fn missing_items_err(
240241
(Vec::new(), Vec::new(), Vec::new());
241242

242243
for &trait_item in missing_items {
243-
let snippet = suggestion_signature(
244+
let snippet = with_types_for_signature!(suggestion_signature(
244245
tcx,
245246
trait_item,
246247
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
247-
);
248+
));
248249
let code = format!("{padding}{snippet}\n{padding}");
249250
if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
250251
missing_trait_item_label

‎compiler/rustc_hir_typeck/src/cast.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use rustc_ast::util::parser::ExprPrecedence;
3232
use rustc_data_structures::fx::FxHashSet;
3333
use rustc_errors::codes::*;
3434
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
35+
use rustc_hir::def_id::DefId;
3536
use rustc_hir::{self as hir, ExprKind};
3637
use rustc_infer::infer::DefineOpaqueTypes;
3738
use rustc_macros::{TypeFoldable, TypeVisitable};
@@ -155,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
155156
}
156157
}
157158

158-
#[derive(Copy, Clone, Debug)]
159+
#[derive(Debug)]
159160
enum CastError<'tcx> {
160161
ErrorGuaranteed(ErrorGuaranteed),
161162

@@ -182,6 +183,7 @@ enum CastError<'tcx> {
182183
/// when we're typechecking a type parameter with a ?Sized bound.
183184
IntToWideCast(Option<&'static str>),
184185
ForeignNonExhaustiveAdt,
186+
PtrPtrAddingAutoTrait(Vec<DefId>),
185187
}
186188

187189
impl From<ErrorGuaranteed> for CastError<'_> {
@@ -596,6 +598,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
596598
.with_note("cannot cast an enum with a non-exhaustive variant when it's defined in another crate")
597599
.emit();
598600
}
601+
CastError::PtrPtrAddingAutoTrait(added) => {
602+
fcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
603+
span: self.span,
604+
traits_len: added.len(),
605+
traits: {
606+
let mut traits: Vec<_> = added
607+
.into_iter()
608+
.map(|trait_did| fcx.tcx.def_path_str(trait_did))
609+
.collect();
610+
611+
traits.sort();
612+
traits.into()
613+
},
614+
});
615+
}
599616
}
600617
}
601618

@@ -940,19 +957,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
940957
.collect::<Vec<_>>();
941958

942959
if !added.is_empty() {
943-
tcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
944-
span: self.span,
945-
traits_len: added.len(),
946-
traits: {
947-
let mut traits: Vec<_> = added
948-
.into_iter()
949-
.map(|trait_did| tcx.def_path_str(trait_did))
950-
.collect();
951-
952-
traits.sort();
953-
traits.into()
954-
},
955-
});
960+
return Err(CastError::PtrPtrAddingAutoTrait(added));
956961
}
957962

958963
Ok(CastKind::PtrPtrCast)

‎compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1682,12 +1682,21 @@ extern "C" void LLVMRustComputeLTOCacheKey(RustStringRef KeyOut,
16821682
#endif
16831683

16841684
// Based on the 'InProcessThinBackend' constructor in LLVM
1685+
#if LLVM_VERSION_GE(21, 0)
1686+
for (auto &Name : Data->Index.cfiFunctionDefs().symbols())
1687+
CfiFunctionDefs.insert(
1688+
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
1689+
for (auto &Name : Data->Index.cfiFunctionDecls().symbols())
1690+
CfiFunctionDecls.insert(
1691+
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
1692+
#else
16851693
for (auto &Name : Data->Index.cfiFunctionDefs())
16861694
CfiFunctionDefs.insert(
16871695
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
16881696
for (auto &Name : Data->Index.cfiFunctionDecls())
16891697
CfiFunctionDecls.insert(
16901698
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
1699+
#endif
16911700

16921701
#if LLVM_VERSION_GE(20, 0)
16931702
Key = llvm::computeLTOCacheKey(conf, Data->Index, ModId, ImportList,
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.