Skip to content

Commit 865df22

Browse files
committed
Auto merge of #154240 - JonathanBrouwer:rollup-BsCGo2e, r=<try>
Rollup of 10 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents bbe8536 + ee4bcfe commit 865df22

104 files changed

Lines changed: 731 additions & 548 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::hash_map::Entry;
2-
use std::fmt::Write;
32

43
use rustc_ast::*;
54
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
@@ -124,13 +123,9 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
124123
self.dcx().emit_err(ClobberAbiNotSupported { abi_span: *abi_span });
125124
}
126125
Err(supported_abis) => {
127-
let mut abis = format!("`{}`", supported_abis[0]);
128-
for m in &supported_abis[1..] {
129-
let _ = write!(abis, ", `{m}`");
130-
}
131126
self.dcx().emit_err(InvalidAbiClobberAbi {
132127
abi_span: *abi_span,
133-
supported_abis: abis,
128+
supported_abis: supported_abis.to_vec().into(),
134129
});
135130
}
136131
}
@@ -164,15 +159,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
164159
asm::InlineAsmRegOrRegClass::RegClass(if let Some(asm_arch) = asm_arch {
165160
asm::InlineAsmRegClass::parse(asm_arch, reg_class).unwrap_or_else(
166161
|supported_register_classes| {
167-
let mut register_classes =
168-
format!("`{}`", supported_register_classes[0]);
169-
for m in &supported_register_classes[1..] {
170-
let _ = write!(register_classes, ", `{m}`");
171-
}
172162
self.dcx().emit_err(InvalidRegisterClass {
173163
op_span: *op_sp,
174164
reg_class,
175-
supported_register_classes: register_classes,
165+
supported_register_classes: supported_register_classes
166+
.to_vec()
167+
.into(),
176168
});
177169
asm::InlineAsmRegClass::Err
178170
},
@@ -272,23 +264,20 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
272264
}
273265
let valid_modifiers = class.valid_modifiers(asm_arch.unwrap());
274266
if !valid_modifiers.contains(&modifier) {
275-
let sub = if !valid_modifiers.is_empty() {
276-
let mut mods = format!("`{}`", valid_modifiers[0]);
277-
for m in &valid_modifiers[1..] {
278-
let _ = write!(mods, ", `{m}`");
279-
}
280-
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
267+
let sub = if valid_modifiers.is_empty() {
268+
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
281269
class_name: class.name(),
282-
modifiers: mods,
283270
}
284271
} else {
285-
InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier {
272+
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
286273
class_name: class.name(),
274+
modifiers: valid_modifiers.to_vec().into(),
287275
}
288276
};
289277
self.dcx().emit_err(InvalidAsmTemplateModifierRegClass {
290278
placeholder_span,
291279
op_span: op_sp,
280+
modifier: modifier.to_string(),
292281
sub,
293282
});
294283
}

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc_errors::DiagArgFromDisplay;
21
use rustc_errors::codes::*;
2+
use rustc_errors::{DiagArgFromDisplay, DiagSymbolList};
33
use rustc_macros::{Diagnostic, Subdiagnostic};
44
use rustc_span::{Ident, Span, Symbol};
55

@@ -191,10 +191,10 @@ pub(crate) struct ClobberAbiNotSupported {
191191
#[derive(Diagnostic)]
192192
#[note("the following ABIs are supported on this target: {$supported_abis}")]
193193
#[diag("invalid ABI for `clobber_abi`")]
194-
pub(crate) struct InvalidAbiClobberAbi {
194+
pub(crate) struct InvalidAbiClobberAbi<'a> {
195195
#[primary_span]
196196
pub abi_span: Span,
197-
pub supported_abis: String,
197+
pub supported_abis: DiagSymbolList<&'a str>,
198198
}
199199

200200
#[derive(Diagnostic)]
@@ -215,17 +215,18 @@ pub(crate) struct InvalidRegisterClass {
215215
#[primary_span]
216216
pub op_span: Span,
217217
pub reg_class: Symbol,
218-
pub supported_register_classes: String,
218+
pub supported_register_classes: DiagSymbolList<Symbol>,
219219
}
220220

221221
#[derive(Diagnostic)]
222-
#[diag("invalid asm template modifier for this register class")]
222+
#[diag("invalid asm template modifier `{$modifier}` for this register class")]
223223
pub(crate) struct InvalidAsmTemplateModifierRegClass {
224224
#[primary_span]
225225
#[label("template modifier")]
226226
pub placeholder_span: Span,
227227
#[label("argument")]
228228
pub op_span: Span,
229+
pub modifier: String,
229230
#[subdiagnostic]
230231
pub sub: InvalidAsmTemplateModifierRegClassSub,
231232
}
@@ -235,7 +236,7 @@ pub(crate) enum InvalidAsmTemplateModifierRegClassSub {
235236
#[note(
236237
"the `{$class_name}` register class supports the following template modifiers: {$modifiers}"
237238
)]
238-
SupportModifier { class_name: Symbol, modifiers: String },
239+
SupportModifier { class_name: Symbol, modifiers: DiagSymbolList<char> },
239240
#[note("the `{$class_name}` register class does not support template modifiers")]
240241
DoesNotSupportModifier { class_name: Symbol },
241242
}

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl AllocFnFactory<'_, '_> {
180180
}
181181

182182
fn ptr_alignment(&self) -> Box<Ty> {
183-
let path = self.cx.std_path(&[sym::ptr, sym::Alignment]);
183+
let path = self.cx.std_path(&[sym::mem, sym::Alignment]);
184184
let path = self.cx.path(self.span, path);
185185
self.cx.ty_path(path)
186186
}

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ enum ExpectedKind {
128128
Reference,
129129
Box,
130130
RawPtr,
131-
InitScalar,
132131
Bool,
133132
Char,
134133
Float,
@@ -143,7 +142,6 @@ impl fmt::Display for ExpectedKind {
143142
ExpectedKind::Reference => "expected a reference",
144143
ExpectedKind::Box => "expected a box",
145144
ExpectedKind::RawPtr => "expected a raw pointer",
146-
ExpectedKind::InitScalar => "expected initialized scalar value",
147145
ExpectedKind::Bool => "expected a boolean",
148146
ExpectedKind::Char => "expected a unicode scalar value",
149147
ExpectedKind::Float => "expected a floating point number",
@@ -1478,7 +1476,9 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
14781476
BackendRepr::Scalar(scalar_layout) => {
14791477
if !scalar_layout.is_uninit_valid() {
14801478
// There is something to check here.
1481-
let scalar = self.read_scalar(val, ExpectedKind::InitScalar)?;
1479+
// We read directly via `ecx` since the read cannot fail -- we already read
1480+
// this field above when recursing into the field.
1481+
let scalar = self.ecx.read_scalar(val)?;
14821482
self.visit_scalar(scalar, scalar_layout)?;
14831483
}
14841484
}
@@ -1487,8 +1487,9 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
14871487
// FIXME: find a way to also check ScalarPair when one side can be uninit but
14881488
// the other must be init.
14891489
if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() {
1490-
let (a, b) =
1491-
self.read_immediate(val, ExpectedKind::InitScalar)?.to_scalar_pair();
1490+
// We read directly via `ecx` since the read cannot fail -- we already read
1491+
// this field above when recursing into the field.
1492+
let (a, b) = self.ecx.read_immediate(val)?.to_scalar_pair();
14921493
self.visit_scalar(a, a_layout)?;
14931494
self.visit_scalar(b, b_layout)?;
14941495
}

compiler/rustc_data_structures/src/aligned.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use std::marker::PointeeSized;
2+
#[cfg(not(bootstrap))]
3+
use std::mem::Alignment;
4+
#[cfg(bootstrap)]
25
use std::ptr::Alignment;
36

47
/// Returns the ABI-required minimum alignment of a type in bytes.

compiler/rustc_data_structures/src/tagged_ptr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ pub unsafe trait Tag: Copy {
5555
/// Returns the number of bits available for use for tags in a pointer to `T`
5656
/// (this is based on `T`'s alignment).
5757
pub const fn bits_for<T: ?Sized + Aligned>() -> u32 {
58-
crate::aligned::align_of::<T>().as_nonzero().trailing_zeros()
58+
let alignment = crate::aligned::align_of::<T>();
59+
#[cfg(bootstrap)]
60+
let alignment = alignment.as_nonzero();
61+
#[cfg(not(bootstrap))]
62+
let alignment = alignment.as_nonzero_usize();
63+
alignment.trailing_zeros()
5964
}
6065

6166
/// Returns the correct [`Tag::BITS`] constant for a set of tag values.

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2291,8 +2291,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22912291
fn_sig,
22922292
);
22932293
let name = inherent_method.name();
2294+
let inputs = fn_sig.inputs();
2295+
let expected_inputs =
2296+
if inherent_method.is_method() { &inputs[1..] } else { inputs };
22942297
if let Some(ref args) = call_args
2295-
&& fn_sig.inputs()[1..]
2298+
&& expected_inputs
22962299
.iter()
22972300
.eq_by(args, |expected, found| self.may_coerce(*expected, *found))
22982301
{

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
104104
index: DepNodeIndex,
105105
) -> Option<C::Value>,
106106

107-
pub is_loadable_from_disk_fn:
108-
fn(tcx: TyCtxt<'tcx>, key: C::Key, index: SerializedDepNodeIndex) -> bool,
109-
110107
/// Function pointer that hashes this query's result values.
111108
///
112109
/// For `no_hash` queries, this function pointer is None.

compiler/rustc_middle/src/ty/list.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ unsafe impl<H: DynSync, T: DynSync> DynSync for RawList<H, T> {}
264264
// Layouts of `ListSkeleton<H, T>` and `RawList<H, T>` are the same, modulo opaque tail,
265265
// thus aligns of `ListSkeleton<H, T>` and `RawList<H, T>` must be the same.
266266
unsafe impl<H, T> Aligned for RawList<H, T> {
267+
#[cfg(bootstrap)]
267268
const ALIGN: ptr::Alignment = align_of::<ListSkeleton<H, T>>();
269+
#[cfg(not(bootstrap))]
270+
const ALIGN: mem::Alignment = align_of::<ListSkeleton<H, T>>();
268271
}
269272

270273
/// A [`List`] that additionally stores type information inline to speed up

compiler/rustc_query_impl/src/execution.rs

Lines changed: 50 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::warn;
1818

1919
use crate::dep_graph::{DepNode, DepNodeIndex};
2020
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
21-
use crate::plumbing::{current_query_job, next_job_id, start_query};
21+
use crate::plumbing::{current_query_job, loadable_from_disk, next_job_id, start_query};
2222
use crate::query_impl::for_each_query_vtable;
2323

2424
#[inline]
@@ -488,81 +488,59 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
488488

489489
debug_assert!(dep_graph_data.is_index_green(prev_index));
490490

491-
// First we try to load the result from the on-disk cache.
492-
// Some things are never cached on disk.
493-
if let Some(value) = (query.try_load_from_disk_fn)(tcx, key, prev_index, dep_node_index) {
494-
if std::intrinsics::unlikely(tcx.sess.opts.unstable_opts.query_dep_graph) {
495-
dep_graph_data.mark_debug_loaded_from_disk(*dep_node)
491+
// First try to load the result from the on-disk cache. Some things are never cached on disk.
492+
let value;
493+
let verify;
494+
match (query.try_load_from_disk_fn)(tcx, key, prev_index, dep_node_index) {
495+
Some(loaded_value) => {
496+
if std::intrinsics::unlikely(tcx.sess.opts.unstable_opts.query_dep_graph) {
497+
dep_graph_data.mark_debug_loaded_from_disk(*dep_node)
498+
}
499+
500+
value = loaded_value;
501+
502+
let prev_fingerprint = dep_graph_data.prev_value_fingerprint_of(prev_index);
503+
// If `-Zincremental-verify-ich` is specified, re-hash results from
504+
// the cache and make sure that they have the expected fingerprint.
505+
//
506+
// If not, we still seek to verify a subset of fingerprints loaded
507+
// from disk. Re-hashing results is fairly expensive, so we can't
508+
// currently afford to verify every hash. This subset should still
509+
// give us some coverage of potential bugs.
510+
verify = prev_fingerprint.split().1.as_u64().is_multiple_of(32)
511+
|| tcx.sess.opts.unstable_opts.incremental_verify_ich;
496512
}
513+
None => {
514+
// We could not load a result from the on-disk cache, so recompute. The dep-graph for
515+
// this computation is already in-place, so we can just call the query provider.
516+
let prof_timer = tcx.prof.query_provider();
517+
value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, key));
518+
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
497519

498-
let prev_fingerprint = dep_graph_data.prev_value_fingerprint_of(prev_index);
499-
// If `-Zincremental-verify-ich` is specified, re-hash results from
500-
// the cache and make sure that they have the expected fingerprint.
501-
//
502-
// If not, we still seek to verify a subset of fingerprints loaded
503-
// from disk. Re-hashing results is fairly expensive, so we can't
504-
// currently afford to verify every hash. This subset should still
505-
// give us some coverage of potential bugs though.
506-
let try_verify = prev_fingerprint.split().1.as_u64().is_multiple_of(32);
507-
if std::intrinsics::unlikely(
508-
try_verify || tcx.sess.opts.unstable_opts.incremental_verify_ich,
509-
) {
510-
incremental_verify_ich(
511-
tcx,
512-
dep_graph_data,
513-
&value,
514-
prev_index,
515-
query.hash_value_fn,
516-
query.format_value,
517-
);
520+
verify = true;
518521
}
522+
};
519523

520-
return value;
524+
if verify {
525+
// Verify that re-running the query produced a result with the expected hash.
526+
// This catches bugs in query implementations, turning them into ICEs.
527+
// For example, a query might sort its result by `DefId` - since `DefId`s are
528+
// not stable across compilation sessions, the result could get up getting sorted
529+
// in a different order when the query is re-run, even though all of the inputs
530+
// (e.g. `DefPathHash` values) were green.
531+
//
532+
// See issue #82920 for an example of a miscompilation that would get turned into
533+
// an ICE by this check
534+
incremental_verify_ich(
535+
tcx,
536+
dep_graph_data,
537+
&value,
538+
prev_index,
539+
query.hash_value_fn,
540+
query.format_value,
541+
);
521542
}
522543

523-
// We always expect to find a cached result for things that
524-
// can be forced from `DepNode`.
525-
debug_assert!(
526-
!(query.will_cache_on_disk_for_key_fn)(tcx, key)
527-
|| !tcx.key_fingerprint_style(dep_node.kind).is_maybe_recoverable(),
528-
"missing on-disk cache entry for {dep_node:?}"
529-
);
530-
531-
// Sanity check for the logic in `ensure`: if the node is green and the result loadable,
532-
// we should actually be able to load it.
533-
debug_assert!(
534-
!(query.is_loadable_from_disk_fn)(tcx, key, prev_index),
535-
"missing on-disk cache entry for loadable {dep_node:?}"
536-
);
537-
538-
// We could not load a result from the on-disk cache, so
539-
// recompute.
540-
let prof_timer = tcx.prof.query_provider();
541-
542-
// The dep-graph for this computation is already in-place.
543-
// Call the query provider.
544-
let value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, key));
545-
546-
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
547-
548-
// Verify that re-running the query produced a result with the expected hash
549-
// This catches bugs in query implementations, turning them into ICEs.
550-
// For example, a query might sort its result by `DefId` - since `DefId`s are
551-
// not stable across compilation sessions, the result could get up getting sorted
552-
// in a different order when the query is re-run, even though all of the inputs
553-
// (e.g. `DefPathHash` values) were green.
554-
//
555-
// See issue #82920 for an example of a miscompilation that would get turned into
556-
// an ICE by this check
557-
incremental_verify_ich(
558-
tcx,
559-
dep_graph_data,
560-
&value,
561-
prev_index,
562-
query.hash_value_fn,
563-
query.format_value,
564-
);
565-
566544
value
567545
}
568546

@@ -624,7 +602,8 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>(
624602
// In ensure-done mode, we can only skip execution for this key if
625603
// there's a disk-cached value available to load later if needed,
626604
// which guarantees the query provider will never run for this key.
627-
let is_loadable = (query.is_loadable_from_disk_fn)(tcx, key, serialized_dep_node_index);
605+
let is_loadable = (query.will_cache_on_disk_for_key_fn)(tcx, key)
606+
&& loadable_from_disk(tcx, serialized_dep_node_index);
628607
EnsureCanSkip { skip_execution: is_loadable, dep_node: Some(dep_node) }
629608
}
630609
}

0 commit comments

Comments
 (0)