Skip to content

Commit 2cf47e4

Browse files
committed
Auto merge of #130177 - workingjubilee:rollup-m4r01yn, r=workingjubilee
Rollup of 14 pull requests Successful merges: - #128316 (Stabilize most of `io_error_more`) - #129473 (use `download-ci-llvm=true` in the default compiler config) - #129529 (Add test to build crates used by r-a on stable) - #129778 (interpret: make typed copies lossy wrt provenance and padding) - #129981 (Remove `serialized_bitcode` from `LtoModuleCodegen`.) - #130025 (Also emit `missing_docs` lint with `--test` to fulfil expectations) - #130040 (unify `llvm-bitcode-linker`, `wasm-component-ld` and llvm-tools logics) - #130094 (Inform the solver if evaluation is concurrent) - #130132 ([illumos] enable SIGSEGV handler to detect stack overflows) - #130146 (bootstrap `naked_asm!` for `compiler-builtins`) - #130149 (Helper function for formatting with `LifetimeSuggestionPosition`) - #130152 (adapt a test for llvm 20) - #130162 (bump download-ci-llvm-stamp) - #130164 (move some const fn out of the const_ptr_as_ref feature) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 712463d + c1d1aef commit 2cf47e4

File tree

95 files changed

+1638
-468
lines changed

Some content is hidden

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

95 files changed

+1638
-468
lines changed

Diff for: compiler/rustc_builtin_macros/src/asm.rs

+38
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,44 @@ pub(super) fn expand_asm<'cx>(
812812
})
813813
}
814814

815+
pub(super) fn expand_naked_asm<'cx>(
816+
ecx: &'cx mut ExtCtxt<'_>,
817+
sp: Span,
818+
tts: TokenStream,
819+
) -> MacroExpanderResult<'cx> {
820+
ExpandResult::Ready(match parse_args(ecx, sp, tts, false) {
821+
Ok(args) => {
822+
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, args) else {
823+
return ExpandResult::Retry(());
824+
};
825+
let expr = match mac {
826+
Ok(mut inline_asm) => {
827+
// for future compatibility, we always set the NORETURN option.
828+
//
829+
// When we turn `asm!` into `naked_asm!` with this implementation, we can drop
830+
// the `options(noreturn)`, which makes the upgrade smooth when `naked_asm!`
831+
// starts disallowing the `noreturn` option in the future
832+
inline_asm.options |= ast::InlineAsmOptions::NORETURN;
833+
834+
P(ast::Expr {
835+
id: ast::DUMMY_NODE_ID,
836+
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
837+
span: sp,
838+
attrs: ast::AttrVec::new(),
839+
tokens: None,
840+
})
841+
}
842+
Err(guar) => DummyResult::raw_expr(sp, Some(guar)),
843+
};
844+
MacEager::expr(expr)
845+
}
846+
Err(err) => {
847+
let guar = err.emit();
848+
DummyResult::any(sp, guar)
849+
}
850+
})
851+
}
852+
815853
pub(super) fn expand_global_asm<'cx>(
816854
ecx: &'cx mut ExtCtxt<'_>,
817855
sp: Span,

Diff for: compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
9494
line: source_util::expand_line,
9595
log_syntax: log_syntax::expand_log_syntax,
9696
module_path: source_util::expand_mod,
97+
naked_asm: asm::expand_naked_asm,
9798
option_env: env::expand_option_env,
9899
pattern_type: pattern_type::expand,
99100
std_panic: edition_panic::expand_panic,

Diff for: compiler/rustc_builtin_macros/src/test_harness.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
326326
let main_attr = ecx.attr_word(sym::rustc_main, sp);
327327
// #[coverage(off)]
328328
let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp);
329+
// #[allow(missing_docs)]
330+
let missing_docs_attr = ecx.attr_nested_word(sym::allow, sym::missing_docs, sp);
329331

330332
// pub fn main() { ... }
331333
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
@@ -355,7 +357,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
355357

356358
let main = P(ast::Item {
357359
ident: main_id,
358-
attrs: thin_vec![main_attr, coverage_attr],
360+
attrs: thin_vec![main_attr, coverage_attr, missing_docs_attr],
359361
id: ast::DUMMY_NODE_ID,
360362
kind: main,
361363
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

Diff for: compiler/rustc_codegen_gcc/src/back/lto.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ fn fat_lto(
272272
}*/
273273
}
274274
};
275-
let mut serialized_bitcode = Vec::new();
276275
{
277276
info!("using {:?} as a base module", module.name);
278277

@@ -317,7 +316,6 @@ fn fat_lto(
317316
unimplemented!("from uncompressed file")
318317
}
319318
}
320-
serialized_bitcode.push(bc_decoded);
321319
}
322320
save_temp_bitcode(cgcx, &module, "lto.input");
323321

@@ -337,7 +335,7 @@ fn fat_lto(
337335
// of now.
338336
module.module_llvm.temp_dir = Some(tmp_path);
339337

340-
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: serialized_bitcode })
338+
Ok(LtoModuleCodegen::Fat(module))
341339
}
342340

343341
pub struct ModuleBuffer(PathBuf);

Diff for: compiler/rustc_codegen_llvm/src/back/lto.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ fn fat_lto(
314314
}
315315
}
316316
};
317-
let mut serialized_bitcode = Vec::new();
318317
{
319318
let (llcx, llmod) = {
320319
let llvm = &module.module_llvm;
@@ -342,9 +341,7 @@ fn fat_lto(
342341
serialized_modules.sort_by(|module1, module2| module1.1.cmp(&module2.1));
343342

344343
// For all serialized bitcode files we parse them and link them in as we did
345-
// above, this is all mostly handled in C++. Like above, though, we don't
346-
// know much about the memory management here so we err on the side of being
347-
// save and persist everything with the original module.
344+
// above, this is all mostly handled in C++.
348345
let mut linker = Linker::new(llmod);
349346
for (bc_decoded, name) in serialized_modules {
350347
let _timer = cgcx
@@ -355,7 +352,6 @@ fn fat_lto(
355352
info!("linking {:?}", name);
356353
let data = bc_decoded.data();
357354
linker.add(data).map_err(|()| write::llvm_err(dcx, LlvmError::LoadBitcode { name }))?;
358-
serialized_bitcode.push(bc_decoded);
359355
}
360356
drop(linker);
361357
save_temp_bitcode(cgcx, &module, "lto.input");
@@ -372,7 +368,7 @@ fn fat_lto(
372368
}
373369
}
374370

375-
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: serialized_bitcode })
371+
Ok(LtoModuleCodegen::Fat(module))
376372
}
377373

378374
pub(crate) struct Linker<'a>(&'a mut llvm::Linker<'a>);

Diff for: compiler/rustc_codegen_ssa/src/back/lto.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ pub struct ThinShared<B: WriteBackendMethods> {
4141
}
4242

4343
pub enum LtoModuleCodegen<B: WriteBackendMethods> {
44-
Fat {
45-
module: ModuleCodegen<B::Module>,
46-
_serialized_bitcode: Vec<SerializedModule<B::ModuleBuffer>>,
47-
},
48-
44+
Fat(ModuleCodegen<B::Module>),
4945
Thin(ThinModule<B>),
5046
}
5147

5248
impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
5349
pub fn name(&self) -> &str {
5450
match *self {
55-
LtoModuleCodegen::Fat { .. } => "everything",
51+
LtoModuleCodegen::Fat(_) => "everything",
5652
LtoModuleCodegen::Thin(ref m) => m.name(),
5753
}
5854
}
@@ -68,7 +64,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
6864
cgcx: &CodegenContext<B>,
6965
) -> Result<ModuleCodegen<B::Module>, FatalError> {
7066
match self {
71-
LtoModuleCodegen::Fat { mut module, .. } => {
67+
LtoModuleCodegen::Fat(mut module) => {
7268
B::optimize_fat(cgcx, &mut module)?;
7369
Ok(module)
7470
}
@@ -81,7 +77,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
8177
pub fn cost(&self) -> u64 {
8278
match *self {
8379
// Only one module with fat LTO, so the cost doesn't matter.
84-
LtoModuleCodegen::Fat { .. } => 0,
80+
LtoModuleCodegen::Fat(_) => 0,
8581
LtoModuleCodegen::Thin(ref m) => m.cost(),
8682
}
8783
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
9494
let intern_result = intern_const_alloc_recursive(ecx, intern_kind, &ret);
9595

9696
// Since evaluation had no errors, validate the resulting constant.
97-
const_validate_mplace(&ecx, &ret, cid)?;
97+
const_validate_mplace(ecx, &ret, cid)?;
9898

9999
// Only report this after validation, as validaiton produces much better diagnostics.
100100
// FIXME: ensure validation always reports this and stop making interning care about it.
@@ -391,7 +391,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
391391

392392
#[inline(always)]
393393
fn const_validate_mplace<'tcx>(
394-
ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>,
394+
ecx: &mut InterpCx<'tcx, CompileTimeMachine<'tcx>>,
395395
mplace: &MPlaceTy<'tcx>,
396396
cid: GlobalId<'tcx>,
397397
) -> Result<(), ErrorHandled> {

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

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use std::borrow::Borrow;
1+
use std::borrow::{Borrow, Cow};
22
use std::fmt;
33
use std::hash::Hash;
44
use std::ops::ControlFlow;
55

66
use rustc_ast::Mutability;
7-
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
7+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::{self as hir, LangItem, CRATE_HIR_ID};
1010
use rustc_middle::mir::AssertMessage;
1111
use rustc_middle::query::TyCtxtAt;
1212
use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout};
13-
use rustc_middle::ty::{self, TyCtxt};
13+
use rustc_middle::ty::{self, Ty, TyCtxt};
1414
use rustc_middle::{bug, mir};
1515
use rustc_span::symbol::{sym, Symbol};
1616
use rustc_span::Span;
@@ -24,8 +24,8 @@ use crate::fluent_generated as fluent;
2424
use crate::interpret::{
2525
self, compile_time_machine, err_ub, throw_exhaust, throw_inval, throw_ub_custom, throw_unsup,
2626
throw_unsup_format, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame,
27-
GlobalAlloc, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, Scalar,
28-
StackPopCleanup,
27+
GlobalAlloc, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic,
28+
RangeSet, Scalar, StackPopCleanup,
2929
};
3030

3131
/// When hitting this many interpreted terminators we emit a deny by default lint
@@ -65,6 +65,9 @@ pub struct CompileTimeMachine<'tcx> {
6565
/// storing the result in the given `AllocId`.
6666
/// Used to prevent reads from a static's base allocation, as that may allow for self-initialization loops.
6767
pub(crate) static_root_ids: Option<(AllocId, LocalDefId)>,
68+
69+
/// A cache of "data range" computations for unions (i.e., the offsets of non-padding bytes).
70+
union_data_ranges: FxHashMap<Ty<'tcx>, RangeSet>,
6871
}
6972

7073
#[derive(Copy, Clone)]
@@ -99,6 +102,7 @@ impl<'tcx> CompileTimeMachine<'tcx> {
99102
can_access_mut_global,
100103
check_alignment,
101104
static_root_ids: None,
105+
union_data_ranges: FxHashMap::default(),
102106
}
103107
}
104108
}
@@ -766,6 +770,19 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
766770
}
767771
Ok(())
768772
}
773+
774+
fn cached_union_data_range<'e>(
775+
ecx: &'e mut InterpCx<'tcx, Self>,
776+
ty: Ty<'tcx>,
777+
compute_range: impl FnOnce() -> RangeSet,
778+
) -> Cow<'e, RangeSet> {
779+
if ecx.tcx.sess.opts.unstable_opts.extra_const_ub_checks {
780+
Cow::Borrowed(ecx.machine.union_data_ranges.entry(ty).or_insert_with(compute_range))
781+
} else {
782+
// Don't bother caching, we're only doing one validation at the end anyway.
783+
Cow::Owned(compute_range())
784+
}
785+
}
769786
}
770787

771788
// Please do not add any code below the above `Machine` trait impl. I (oli-obk) plan more cleanups

Diff for: compiler/rustc_const_eval/src/interpret/discriminant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_target::abi::{self, TagEncoding, VariantIdx, Variants};
77
use tracing::{instrument, trace};
88

99
use super::{
10-
err_ub, throw_ub, ImmTy, InterpCx, InterpResult, Machine, Readable, Scalar, Writeable,
10+
err_ub, throw_ub, ImmTy, InterpCx, InterpResult, Machine, Projectable, Scalar, Writeable,
1111
};
1212

1313
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
@@ -60,7 +60,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6060
#[instrument(skip(self), level = "trace")]
6161
pub fn read_discriminant(
6262
&self,
63-
op: &impl Readable<'tcx, M::Provenance>,
63+
op: &impl Projectable<'tcx, M::Provenance>,
6464
) -> InterpResult<'tcx, VariantIdx> {
6565
let ty = op.layout().ty;
6666
trace!("read_discriminant_value {:#?}", op.layout());

Diff for: compiler/rustc_const_eval/src/interpret/machine.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_apfloat::{Float, FloatConvert};
1010
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1111
use rustc_middle::query::TyCtxtAt;
1212
use rustc_middle::ty::layout::TyAndLayout;
13+
use rustc_middle::ty::Ty;
1314
use rustc_middle::{mir, ty};
1415
use rustc_span::def_id::DefId;
1516
use rustc_span::Span;
@@ -19,7 +20,7 @@ use rustc_target::spec::abi::Abi as CallAbi;
1920
use super::{
2021
throw_unsup, throw_unsup_format, AllocBytes, AllocId, AllocKind, AllocRange, Allocation,
2122
ConstAllocation, CtfeProvenance, FnArg, Frame, ImmTy, InterpCx, InterpResult, MPlaceTy,
22-
MemoryKind, Misalignment, OpTy, PlaceTy, Pointer, Provenance, CTFE_ALLOC_SALT,
23+
MemoryKind, Misalignment, OpTy, PlaceTy, Pointer, Provenance, RangeSet, CTFE_ALLOC_SALT,
2324
};
2425

2526
/// Data returned by [`Machine::after_stack_pop`], and consumed by
@@ -578,6 +579,15 @@ pub trait Machine<'tcx>: Sized {
578579
ecx: &InterpCx<'tcx, Self>,
579580
instance: Option<ty::Instance<'tcx>>,
580581
) -> usize;
582+
583+
fn cached_union_data_range<'e>(
584+
_ecx: &'e mut InterpCx<'tcx, Self>,
585+
_ty: Ty<'tcx>,
586+
compute_range: impl FnOnce() -> RangeSet,
587+
) -> Cow<'e, RangeSet> {
588+
// Default to no caching.
589+
Cow::Owned(compute_range())
590+
}
581591
}
582592

583593
/// A lot of the flexibility above is just needed for `Miri`, but all "compile-time" machines

0 commit comments

Comments
 (0)