Skip to content

Commit fdd0301

Browse files
committed
Auto merge of rust-lang#111721 - Dylan-DPC:rollup-9jw6b7k, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#110986 (Delay a bug when overwriting fed value.) - rust-lang#111054 (Do not recover when parsing stmt in cfg-eval.) - rust-lang#111685 (Fix typo in bootstrap command description) - rust-lang#111686 (Retire is_foreign_item query.) - rust-lang#111695 (Exclude inherent projections from some alias type `match`es) - rust-lang#111703 (Merge query property modules into one) - rust-lang#111707 (Remove unused `impl<T> WorkerLocal<Vec<T>>`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ba6f5e3 + ad214ac commit fdd0301

File tree

26 files changed

+219
-177
lines changed

26 files changed

+219
-177
lines changed

compiler/rustc_builtin_macros/src/cfg_eval.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ impl CfgEval<'_, '_> {
166166
))
167167
},
168168
Annotatable::Stmt(_) => |parser| {
169-
Ok(Annotatable::Stmt(P(parser.parse_stmt(ForceCollect::Yes)?.unwrap())))
169+
Ok(Annotatable::Stmt(P(parser
170+
.parse_stmt_without_recovery(false, ForceCollect::Yes)?
171+
.unwrap())))
170172
},
171173
Annotatable::Expr(_) => {
172174
|parser| Ok(Annotatable::Expr(parser.parse_expr_force_collect()?))

compiler/rustc_data_structures/src/sync/worker_local.rs

-7
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ impl<T> WorkerLocal<T> {
154154
}
155155
}
156156

157-
impl<T> WorkerLocal<Vec<T>> {
158-
/// Joins the elements of all the worker locals into one Vec
159-
pub fn join(self) -> Vec<T> {
160-
self.into_inner().into_iter().flat_map(|v| v).collect()
161-
}
162-
}
163-
164157
impl<T> Deref for WorkerLocal<T> {
165158
type Target = T;
166159

compiler/rustc_hir_analysis/src/collect.rs

-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ pub fn provide(providers: &mut Providers) {
7373
fn_sig,
7474
impl_trait_ref,
7575
impl_polarity,
76-
is_foreign_item,
7776
generator_kind,
7877
collect_mod_item_types,
7978
is_type_alias_impl_trait,
@@ -1466,10 +1465,6 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
14661465
fty
14671466
}
14681467

1469-
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1470-
matches!(tcx.hir().get_by_def_id(def_id), Node::ForeignItem(..))
1471-
}
1472-
14731468
fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {
14741469
match tcx.hir().get_by_def_id(def_id) {
14751470
Node::Expr(&rustc_hir::Expr {

compiler/rustc_macros/src/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn add_query_desc_cached_impl(
253253
quote! {
254254
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
255255
#[inline]
256-
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::query_keys::#name<'tcx>) -> bool {
256+
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
257257
#expr
258258
}
259259
}
@@ -262,7 +262,7 @@ fn add_query_desc_cached_impl(
262262
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
263263
#[allow(rustc::pass_by_value)]
264264
#[inline]
265-
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::query_keys::#name<'tcx>) -> bool {
265+
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
266266
false
267267
}
268268
}
@@ -273,7 +273,7 @@ fn add_query_desc_cached_impl(
273273

274274
let desc = quote! {
275275
#[allow(unused_variables)]
276-
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::query_keys::#name<'tcx>) -> String {
276+
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::queries::#name::Key<'tcx>) -> String {
277277
let (#tcx, #key) = (tcx, key);
278278
::rustc_middle::ty::print::with_no_trimmed_paths!(
279279
format!(#desc)

compiler/rustc_metadata/src/rmeta/decoder.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1251,14 +1251,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12511251
}
12521252
}
12531253

1254-
fn is_foreign_item(self, id: DefIndex) -> bool {
1255-
if let Some(parent) = self.def_key(id).parent {
1256-
matches!(self.def_kind(parent), DefKind::ForeignMod)
1257-
} else {
1258-
false
1259-
}
1260-
}
1261-
12621254
#[inline]
12631255
fn def_key(self, index: DefIndex) -> DefKey {
12641256
*self

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ macro_rules! provide_one {
114114
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
115115
fn $name<'tcx>(
116116
$tcx: TyCtxt<'tcx>,
117-
def_id_arg: rustc_middle::query::query_keys::$name<'tcx>,
118-
) -> rustc_middle::query::query_provided::$name<'tcx> {
117+
def_id_arg: rustc_middle::query::queries::$name::Key<'tcx>,
118+
) -> rustc_middle::query::queries::$name::ProvidedValue<'tcx> {
119119
let _prof_timer =
120120
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
121121

@@ -280,7 +280,6 @@ provide! { tcx, def_id, other, cdata,
280280
}
281281
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
282282
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
283-
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
284283
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
285284
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
286285
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }

compiler/rustc_middle/src/hir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::query::Providers;
1010
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_data_structures::sync::{par_for_each_in, DynSend, DynSync};
13+
use rustc_hir::def::DefKind;
1314
use rustc_hir::def_id::{DefId, LocalDefId};
1415
use rustc_hir::*;
1516
use rustc_query_system::ich::StableHashingContext;
@@ -110,6 +111,12 @@ impl<'tcx> TyCtxt<'tcx> {
110111
None => self.type_of(def_id).map_bound(ImplSubject::Inherent),
111112
}
112113
}
114+
115+
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
116+
pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
117+
self.opt_parent(def_id.into())
118+
.map_or(false, |parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
119+
}
113120
}
114121

115122
pub fn provide(providers: &mut Providers) {

compiler/rustc_middle/src/query/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,6 @@ rustc_queries! {
726726
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
727727
}
728728

729-
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
730-
query is_foreign_item(key: DefId) -> bool {
731-
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
732-
separate_provide_extern
733-
}
734-
735729
/// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
736730
query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
737731
desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }

compiler/rustc_middle/src/query/plumbing.rs

+77-98
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ macro_rules! separate_provide_extern_decl {
221221
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
222222
for<'tcx> fn(
223223
TyCtxt<'tcx>,
224-
query_keys::$name<'tcx>,
225-
) -> query_provided::$name<'tcx>
224+
queries::$name::Key<'tcx>,
225+
) -> queries::$name::ProvidedValue<'tcx>
226226
};
227227
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
228228
separate_provide_extern_decl!([$($modifiers)*][$($args)*])
@@ -252,60 +252,37 @@ macro_rules! define_callbacks {
252252
$($(#[$attr:meta])*
253253
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
254254

255-
// HACK(eddyb) this is like the `impl QueryConfig for queries::$name`
256-
// below, but using type aliases instead of associated types, to bypass
257-
// the limitations around normalizing under HRTB - for example, this:
258-
// `for<'tcx> fn(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::Value`
259-
// doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`.
260-
// This is primarily used by the `provide!` macro in `rustc_metadata`.
261-
#[allow(nonstandard_style, unused_lifetimes)]
262-
pub mod query_keys {
263-
use super::*;
264-
265-
$(pub type $name<'tcx> = $($K)*;)*
266-
}
267-
#[allow(nonstandard_style, unused_lifetimes)]
268-
pub mod query_keys_local {
269-
use super::*;
270-
271-
$(pub type $name<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);)*
272-
}
273-
#[allow(nonstandard_style, unused_lifetimes)]
274-
pub mod query_values {
275-
use super::*;
255+
#[allow(unused_lifetimes)]
256+
pub mod queries {
257+
$(pub mod $name {
258+
use super::super::*;
276259

277-
$(pub type $name<'tcx> = $V;)*
278-
}
260+
pub type Key<'tcx> = $($K)*;
261+
pub type Value<'tcx> = $V;
279262

280-
/// This module specifies the type returned from query providers and the type used for
281-
/// decoding. For regular queries this is the declared returned type `V`, but
282-
/// `arena_cache` will use `<V as Deref>::Target` instead.
283-
#[allow(nonstandard_style, unused_lifetimes)]
284-
pub mod query_provided {
285-
use super::*;
263+
pub type LocalKey<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);
286264

287-
$(
288-
pub type $name<'tcx> = query_if_arena!([$($modifiers)*] (<$V as Deref>::Target) ($V));
289-
)*
290-
}
291-
292-
/// This module has a function per query which takes a `query_provided` value and coverts
293-
/// it to a regular `V` value by allocating it on an arena if the query has the
294-
/// `arena_cache` modifier. This will happen when computing the query using a provider or
295-
/// decoding a stored result.
296-
#[allow(nonstandard_style, unused_lifetimes)]
297-
pub mod query_provided_to_value {
298-
use super::*;
265+
/// This type alias specifies the type returned from query providers and the type
266+
/// used for decoding. For regular queries this is the declared returned type `V`,
267+
/// but `arena_cache` will use `<V as Deref>::Target` instead.
268+
pub type ProvidedValue<'tcx> = query_if_arena!(
269+
[$($modifiers)*]
270+
(<$V as Deref>::Target)
271+
($V)
272+
);
299273

300-
$(
274+
/// This function takes `ProvidedValue` and coverts it to an erased `Value` by
275+
/// allocating it on an arena if the query has the `arena_cache` modifier. The
276+
/// value is then erased and returned. This will happen when computing the query
277+
/// using a provider or decoding a stored result.
301278
#[inline(always)]
302-
pub fn $name<'tcx>(
279+
pub fn provided_to_erased<'tcx>(
303280
_tcx: TyCtxt<'tcx>,
304-
value: query_provided::$name<'tcx>,
305-
) -> Erase<query_values::$name<'tcx>> {
281+
value: ProvidedValue<'tcx>,
282+
) -> Erase<Value<'tcx>> {
306283
erase(query_if_arena!([$($modifiers)*]
307284
{
308-
if mem::needs_drop::<query_provided::$name<'tcx>>() {
285+
if mem::needs_drop::<ProvidedValue<'tcx>>() {
309286
&*_tcx.query_system.arenas.$name.alloc(value)
310287
} else {
311288
&*_tcx.arena.dropless.alloc(value)
@@ -314,47 +291,41 @@ macro_rules! define_callbacks {
314291
(value)
315292
))
316293
}
317-
)*
318-
}
319-
#[allow(nonstandard_style, unused_lifetimes)]
320-
pub mod query_storage {
321-
use super::*;
322294

323-
$(
324-
pub type $name<'tcx> = <<$($K)* as Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>>::Cache;
325-
)*
295+
pub type Storage<'tcx> = <
296+
<$($K)* as keys::Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>
297+
>::Cache;
298+
299+
// Ensure that keys grow no larger than 64 bytes
300+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
301+
const _: () = {
302+
if mem::size_of::<Key<'static>>() > 64 {
303+
panic!("{}", concat!(
304+
"the query `",
305+
stringify!($name),
306+
"` has a key type `",
307+
stringify!($($K)*),
308+
"` that is too large"
309+
));
310+
}
311+
};
312+
313+
// Ensure that values grow no larger than 64 bytes
314+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
315+
const _: () = {
316+
if mem::size_of::<Value<'static>>() > 64 {
317+
panic!("{}", concat!(
318+
"the query `",
319+
stringify!($name),
320+
"` has a value type `",
321+
stringify!($V),
322+
"` that is too large"
323+
));
324+
}
325+
};
326+
})*
326327
}
327328

328-
$(
329-
// Ensure that keys grow no larger than 64 bytes
330-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
331-
const _: () = {
332-
if mem::size_of::<query_keys::$name<'static>>() > 64 {
333-
panic!("{}", concat!(
334-
"the query `",
335-
stringify!($name),
336-
"` has a key type `",
337-
stringify!($($K)*),
338-
"` that is too large"
339-
));
340-
}
341-
};
342-
343-
// Ensure that values grow no larger than 64 bytes
344-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
345-
const _: () = {
346-
if mem::size_of::<query_values::$name<'static>>() > 64 {
347-
panic!("{}", concat!(
348-
"the query `",
349-
stringify!($name),
350-
"` has a value type `",
351-
stringify!($V),
352-
"` that is too large"
353-
));
354-
}
355-
};
356-
)*
357-
358329
pub struct QueryArenas<'tcx> {
359330
$($(#[$attr])* pub $name: query_if_arena!([$($modifiers)*]
360331
(WorkerLocal<TypedArena<<$V as Deref>::Target>>)
@@ -375,7 +346,7 @@ macro_rules! define_callbacks {
375346

376347
#[derive(Default)]
377348
pub struct QueryCaches<'tcx> {
378-
$($(#[$attr])* pub $name: query_storage::$name<'tcx>,)*
349+
$($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)*
379350
}
380351

381352
impl<'tcx> TyCtxtEnsure<'tcx> {
@@ -433,7 +404,7 @@ macro_rules! define_callbacks {
433404

434405
pub struct DynamicQueries<'tcx> {
435406
$(
436-
pub $name: DynamicQuery<'tcx, query_storage::$name<'tcx>>,
407+
pub $name: DynamicQuery<'tcx, queries::$name::Storage<'tcx>>,
437408
)*
438409
}
439410

@@ -447,8 +418,8 @@ macro_rules! define_callbacks {
447418
pub struct Providers {
448419
$(pub $name: for<'tcx> fn(
449420
TyCtxt<'tcx>,
450-
query_keys_local::$name<'tcx>,
451-
) -> query_provided::$name<'tcx>,)*
421+
queries::$name::LocalKey<'tcx>,
422+
) -> queries::$name::ProvidedValue<'tcx>,)*
452423
}
453424

454425
pub struct ExternProviders {
@@ -493,7 +464,7 @@ macro_rules! define_callbacks {
493464
$(pub $name: for<'tcx> fn(
494465
TyCtxt<'tcx>,
495466
Span,
496-
query_keys::$name<'tcx>,
467+
queries::$name::Key<'tcx>,
497468
QueryMode,
498469
) -> Option<Erase<$V>>,)*
499470
}
@@ -517,11 +488,11 @@ macro_rules! define_feedable {
517488
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
518489
$(#[$attr])*
519490
#[inline(always)]
520-
pub fn $name(self, value: query_provided::$name<'tcx>) {
491+
pub fn $name(self, value: queries::$name::ProvidedValue<'tcx>) {
521492
let key = self.key().into_query_param();
522493

523494
let tcx = self.tcx;
524-
let erased = query_provided_to_value::$name(tcx, value);
495+
let erased = queries::$name::provided_to_erased(tcx, value);
525496
let value = restore::<$V>(erased);
526497
let cache = &tcx.query_system.caches.$name;
527498

@@ -533,12 +504,20 @@ macro_rules! define_feedable {
533504
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx.with_stable_hashing_context(|mut hcx|
534505
(hasher(&mut hcx, &value), hasher(&mut hcx, &old))
535506
);
536-
assert_eq!(
537-
old_hash, value_hash,
538-
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
539-
stringify!($name),
540-
)
507+
if old_hash != value_hash {
508+
// We have an inconsistency. This can happen if one of the two
509+
// results is tainted by errors. In this case, delay a bug to
510+
// ensure compilation is doomed, and keep the `old` value.
511+
tcx.sess.delay_span_bug(DUMMY_SP, format!(
512+
"Trying to feed an already recorded value for query {} key={key:?}:\n\
513+
old value: {old:?}\nnew value: {value:?}",
514+
stringify!($name),
515+
));
516+
}
541517
} else {
518+
// The query is `no_hash`, so we have no way to perform a sanity check.
519+
// If feeding the same value multiple times needs to be supported,
520+
// the query should not be marked `no_hash`.
542521
bug!(
543522
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
544523
stringify!($name),

0 commit comments

Comments
 (0)