Skip to content

Commit 51f1671

Browse files
committed
Auto merge of #152967 - JonathanBrouwer:rollup-rzkOS1F, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #149366 (GVN: consider constants of primitive types as deterministic) - #152779 (Clarify aspects of query macros) - #152958 (`rustc_queries` simplifications) - #149783 (stabilize `cfg_select!`) - #152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies)
2 parents 1500f0f + 807a5c8 commit 51f1671

57 files changed

Lines changed: 648 additions & 739 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_attr_parsing/src/attributes/cfg_select.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,14 @@ pub fn parse_cfg_select(
128128
}
129129
}
130130

131-
if let Some(features) = features
132-
&& features.enabled(sym::cfg_select)
133-
{
134-
let it = branches
135-
.reachable
136-
.iter()
137-
.map(|(entry, _, _)| CfgSelectPredicate::Cfg(entry.clone()))
138-
.chain(branches.wildcard.as_ref().map(|(t, _, _)| CfgSelectPredicate::Wildcard(*t)))
139-
.chain(
140-
branches.unreachable.iter().map(|(entry, _, _)| CfgSelectPredicate::clone(entry)),
141-
);
142-
143-
lint_unreachable(p, it, lint_node_id);
144-
}
131+
let it = branches
132+
.reachable
133+
.iter()
134+
.map(|(entry, _, _)| CfgSelectPredicate::Cfg(entry.clone()))
135+
.chain(branches.wildcard.as_ref().map(|(t, _, _)| CfgSelectPredicate::Wildcard(*t)))
136+
.chain(branches.unreachable.iter().map(|(entry, _, _)| CfgSelectPredicate::clone(entry)));
137+
138+
lint_unreachable(p, it, lint_node_id);
145139

146140
Ok(branches)
147141
}

compiler/rustc_codegen_cranelift/patches/0027-sysroot_tests-128bit-atomic-operations.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ index 1e336bf..35e6f54 100644
1717
@@ -2,4 +2,3 @@
1818
// tidy-alphabetical-start
1919
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
20-
#![cfg_attr(test, feature(cfg_select))]
2120
#![feature(array_ptr_get)]
21+
#![feature(array_try_from_fn)]
2222
diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs
2323
index b735957..ea728b6 100644
2424
--- a/coretests/tests/atomic.rs

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
#![allow(rustc::default_hash_types)]
1212
#![allow(rustc::potential_query_instability)]
1313
#![cfg_attr(bootstrap, feature(assert_matches))]
14+
#![cfg_attr(bootstrap, feature(cfg_select))]
1415
#![cfg_attr(bootstrap, feature(cold_path))]
1516
#![cfg_attr(test, feature(test))]
1617
#![deny(unsafe_op_in_unsafe_fn)]
1718
#![feature(allocator_api)]
1819
#![feature(ascii_char)]
1920
#![feature(ascii_char_variants)]
2021
#![feature(auto_traits)]
21-
#![feature(cfg_select)]
2222
#![feature(const_default)]
2323
#![feature(const_trait_impl)]
2424
#![feature(dropck_eyepatch)]

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ declare_features! (
102102
(accepted, cfg_doctest, "1.40.0", Some(62210)),
103103
/// Enables `#[cfg(panic = "...")]` config key.
104104
(accepted, cfg_panic, "1.60.0", Some(77443)),
105+
/// Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
106+
(accepted, cfg_select, "CURRENT_RUSTC_VERSION", Some(115585)),
105107
/// Allows `cfg(target_abi = "...")`.
106108
(accepted, cfg_target_abi, "1.78.0", Some(80970)),
107109
/// Allows `cfg(target_feature = "...")`.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ declare_features! (
388388
(unstable, cfg_sanitize, "1.41.0", Some(39699)),
389389
/// Allows `cfg(sanitizer_cfi_generalize_pointers)` and `cfg(sanitizer_cfi_normalize_integers)`.
390390
(unstable, cfg_sanitizer_cfi, "1.77.0", Some(89653)),
391-
/// Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
392-
(unstable, cfg_select, "CURRENT_RUSTC_VERSION", Some(115585)),
393391
/// Allows `cfg(target(abi = "..."))`.
394392
(unstable, cfg_target_compact, "1.63.0", Some(96901)),
395393
/// Allows `cfg(target_has_atomic_load_store = "...")`.

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,6 @@ declare_lint! {
864864
/// ### Example
865865
///
866866
/// ```rust
867-
/// #![feature(cfg_select)]
868867
/// cfg_select! {
869868
/// _ => (),
870869
/// windows => (),
@@ -882,7 +881,6 @@ declare_lint! {
882881
pub UNREACHABLE_CFG_SELECT_PREDICATES,
883882
Warn,
884883
"detects unreachable configuration predicates in the cfg_select macro",
885-
@feature_gate = cfg_select;
886884
}
887885

888886
declare_lint! {

compiler/rustc_macros/src/query.rs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ impl<T: Parse> Parse for List<T> {
103103

104104
struct Desc {
105105
modifier: Ident,
106-
tcx_binding: Option<Ident>,
107106
expr_list: Punctuated<Expr, Token![,]>,
108107
}
109108

110109
struct CacheOnDiskIf {
111110
modifier: Ident,
112-
tcx_binding: Option<Pat>,
113111
block: Block,
114112
}
115113

@@ -192,35 +190,16 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
192190

193191
if modifier == "desc" {
194192
// Parse a description modifier like:
195-
// `desc { |tcx| "foo {}", tcx.item_path(key) }`
193+
// `desc { "foo {}", tcx.item_path(key) }`
196194
let attr_content;
197195
braced!(attr_content in input);
198-
let tcx_binding = if attr_content.peek(Token![|]) {
199-
attr_content.parse::<Token![|]>()?;
200-
let tcx = attr_content.parse()?;
201-
attr_content.parse::<Token![|]>()?;
202-
Some(tcx)
203-
} else {
204-
None
205-
};
206196
let expr_list = attr_content.parse_terminated(Expr::parse, Token![,])?;
207-
try_insert!(desc = Desc { modifier, tcx_binding, expr_list });
197+
try_insert!(desc = Desc { modifier, expr_list });
208198
} else if modifier == "cache_on_disk_if" {
209199
// Parse a cache-on-disk modifier like:
210-
//
211-
// `cache_on_disk_if { true }`
212-
// `cache_on_disk_if { key.is_local() }`
213-
// `cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }`
214-
let tcx_binding = if input.peek(token::Paren) {
215-
let args;
216-
parenthesized!(args in input);
217-
let tcx = Pat::parse_single(&args)?;
218-
Some(tcx)
219-
} else {
220-
None
221-
};
200+
// `cache_on_disk_if { tcx.is_typeck_child(key.to_def_id()) }`
222201
let block = input.parse()?;
223-
try_insert!(cache_on_disk_if = CacheOnDiskIf { modifier, tcx_binding, block });
202+
try_insert!(cache_on_disk_if = CacheOnDiskIf { modifier, block });
224203
} else if modifier == "arena_cache" {
225204
try_insert!(arena_cache = modifier);
226205
} else if modifier == "cycle_fatal" {
@@ -313,24 +292,24 @@ fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {
313292
erased_name.set_span(Span::call_site());
314293

315294
// Generate a function to check whether we should cache the query to disk, for some key.
316-
if let Some(CacheOnDiskIf { tcx_binding, block, .. }) = modifiers.cache_on_disk_if.as_ref() {
317-
let tcx = tcx_binding.as_ref().map(|t| quote! { #t }).unwrap_or_else(|| quote! { _ });
318-
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
295+
if let Some(CacheOnDiskIf { block, .. }) = modifiers.cache_on_disk_if.as_ref() {
296+
// `pass_by_value`: some keys are marked with `rustc_pass_by_value`, but we take keys by
297+
// reference here.
298+
// FIXME: `pass_by_value` is badly named; `allow(rustc::pass_by_value)` actually means
299+
// "allow pass by reference of `rustc_pass_by_value` types".
319300
streams.cache_on_disk_if_fns_stream.extend(quote! {
320301
#[allow(unused_variables, rustc::pass_by_value)]
321302
#[inline]
322-
pub fn #erased_name<'tcx>(#tcx: TyCtxt<'tcx>, #key_pat: &crate::queries::#name::Key<'tcx>) -> bool
303+
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: &#key_ty) -> bool
323304
#block
324305
});
325306
}
326307

327-
let Desc { tcx_binding, expr_list, .. } = &modifiers.desc;
328-
let tcx = tcx_binding.as_ref().map_or_else(|| quote! { _ }, |t| quote! { #t });
308+
let Desc { expr_list, .. } = &modifiers.desc;
329309

330310
let desc = quote! {
331311
#[allow(unused_variables)]
332-
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, key: #key_ty) -> String {
333-
let (#tcx, #key_pat) = (tcx, key);
312+
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: #key_ty) -> String {
334313
format!(#expr_list)
335314
}
336315
};

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ impl StableOrd for WorkProductId {
324324
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
325325
}
326326

327+
// Note: `$K` and `$V` are unused but present so this can be called by `rustc_with_all_queries`.
327328
macro_rules! define_dep_nodes {
328329
(
329330
$(
330331
$(#[$attr:meta])*
331-
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
332+
[$($modifiers:tt)*] fn $variant:ident($K:ty) -> $V:ty,
332333
)*
333334
) => {
334335

@@ -382,20 +383,20 @@ macro_rules! define_dep_nodes {
382383
}
383384

384385
// Create various data structures for each query, and also for a few things
385-
// that aren't queries.
386+
// that aren't queries. The key and return types aren't used, hence the use of `()`.
386387
rustc_with_all_queries!(define_dep_nodes![
387388
/// We use this for most things when incr. comp. is turned off.
388-
[] fn Null() -> (),
389+
[] fn Null(()) -> (),
389390
/// We use this to create a forever-red node.
390-
[] fn Red() -> (),
391+
[] fn Red(()) -> (),
391392
/// We use this to create a side effect node.
392-
[] fn SideEffect() -> (),
393+
[] fn SideEffect(()) -> (),
393394
/// We use this to create the anon node with zero dependencies.
394-
[] fn AnonZeroDeps() -> (),
395-
[] fn TraitSelect() -> (),
396-
[] fn CompileCodegenUnit() -> (),
397-
[] fn CompileMonoItem() -> (),
398-
[] fn Metadata() -> (),
395+
[] fn AnonZeroDeps(()) -> (),
396+
[] fn TraitSelect(()) -> (),
397+
[] fn CompileCodegenUnit(()) -> (),
398+
[] fn CompileMonoItem(()) -> (),
399+
[] fn Metadata(()) -> (),
399400
]);
400401

401402
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.

compiler/rustc_middle/src/mir/consts.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,6 @@ impl ConstValue {
181181
Some(data.inner().inspect_with_uninit_and_ptr_outside_interpreter(start..end))
182182
}
183183

184-
/// Check if a constant may contain provenance information. This is used by MIR opts.
185-
/// Can return `true` even if there is no provenance.
186-
pub fn may_have_provenance(&self, tcx: TyCtxt<'_>, size: Size) -> bool {
187-
match *self {
188-
ConstValue::ZeroSized | ConstValue::Scalar(Scalar::Int(_)) => return false,
189-
ConstValue::Scalar(Scalar::Ptr(..)) => return true,
190-
// It's hard to find out the part of the allocation we point to;
191-
// just conservatively check everything.
192-
ConstValue::Slice { alloc_id, meta: _ } => {
193-
!tcx.global_alloc(alloc_id).unwrap_memory().inner().provenance().ptrs().is_empty()
194-
}
195-
ConstValue::Indirect { alloc_id, offset } => !tcx
196-
.global_alloc(alloc_id)
197-
.unwrap_memory()
198-
.inner()
199-
.provenance()
200-
.range_empty(AllocRange::from(offset..offset + size), &tcx),
201-
}
202-
}
203-
204184
/// Check if a constant only contains uninitialized bytes.
205185
pub fn all_bytes_uninit(&self, tcx: TyCtxt<'_>) -> bool {
206186
let ConstValue::Indirect { alloc_id, .. } = self else {
@@ -474,39 +454,6 @@ impl<'tcx> Const<'tcx> {
474454
let val = ConstValue::Scalar(s);
475455
Self::Val(val, ty)
476456
}
477-
478-
/// Return true if any evaluation of this constant always returns the same value,
479-
/// taking into account even pointer identity tests.
480-
pub fn is_deterministic(&self) -> bool {
481-
// Some constants may generate fresh allocations for pointers they contain,
482-
// so using the same constant twice can yield two different results.
483-
// Notably, valtrees purposefully generate new allocations.
484-
match self {
485-
Const::Ty(_, c) => match c.kind() {
486-
ty::ConstKind::Param(..) => true,
487-
// A valtree may be a reference. Valtree references correspond to a
488-
// different allocation each time they are evaluated. Valtrees for primitive
489-
// types are fine though.
490-
ty::ConstKind::Value(cv) => cv.ty.is_primitive(),
491-
ty::ConstKind::Unevaluated(..) | ty::ConstKind::Expr(..) => false,
492-
// This can happen if evaluation of a constant failed. The result does not matter
493-
// much since compilation is doomed.
494-
ty::ConstKind::Error(..) => false,
495-
// Should not appear in runtime MIR.
496-
ty::ConstKind::Infer(..)
497-
| ty::ConstKind::Bound(..)
498-
| ty::ConstKind::Placeholder(..) => bug!(),
499-
},
500-
Const::Unevaluated(..) => false,
501-
Const::Val(
502-
ConstValue::Slice { .. }
503-
| ConstValue::ZeroSized
504-
| ConstValue::Scalar(_)
505-
| ConstValue::Indirect { .. },
506-
_,
507-
) => true,
508-
}
509-
}
510457
}
511458

512459
/// An unevaluated (potentially generic) constant used in MIR.

0 commit comments

Comments
 (0)