Skip to content

Commit 93b6a78

Browse files
committed
Auto merge of #152982 - JonathanBrouwer:rollup-7T28A8b, r=JonathanBrouwer
Rollup of 8 pull requests Successful merges: - #149366 (GVN: consider constants of primitive types as deterministic) - #152779 (Clarify aspects of query macros) - #152958 (`rustc_queries` simplifications) - #152385 (Feature gate for defaulted associated type_consts with associated_type_defaults ) - #152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies) - #152921 (Add build.rustdoc option to bootstrap config) - #152926 (Fix ICE when an associated type is wrongly marked as `final`) - #152927 (Index expressions rendered the index: subexpression as the id, instea…)
2 parents 1500f0f + 63935ec commit 93b6a78

47 files changed

Lines changed: 1945 additions & 685 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.

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@
302302
# If you set this, you likely want to set `cargo` as well.
303303
#build.rustc = "/path/to/rustc"
304304

305+
# Use this rustdoc binary as the stage0 snapshot rustdoc.
306+
# If unspecified, then the binary "rustdoc" (with platform-specific extension, e.g. ".exe")
307+
# in the same directory as "rustc" will be used.
308+
#build.rustdoc = "/path/to/rustdoc"
309+
305310
# Instead of downloading the src/stage0 version of rustfmt specified,
306311
# use this rustfmt binary instead as the stage0 snapshot rustfmt.
307312
#build.rustfmt = "/path/to/rustfmt"

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
10851085
}
10861086
};
10871087

1088-
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value, || {
1089-
hir::Defaultness::Default { has_value }
1090-
});
1088+
let defaultness = match i.kind.defaultness() {
1089+
// We do not yet support `final` on trait associated items other than functions.
1090+
// Even though we reject `final` on non-functions during AST validation, we still
1091+
// need to stop propagating it here because later compiler passes do not expect
1092+
// and cannot handle such items.
1093+
Defaultness::Final(..) if !matches!(i.kind, AssocItemKind::Fn(..)) => {
1094+
Defaultness::Implicit
1095+
}
1096+
defaultness => defaultness,
1097+
};
1098+
let (defaultness, _) = self
1099+
.lower_defaultness(defaultness, has_value, || hir::Defaultness::Default { has_value });
10911100

10921101
let item = hir::TraitItem {
10931102
owner_id: trait_item_def_id,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
427427
false
428428
}
429429
ast::AssocItemKind::Const(box ast::ConstItem {
430-
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
430+
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
431431
..
432432
}) => {
433433
// Make sure this is only allowed if the feature gate is enabled.
@@ -438,6 +438,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
438438
i.span,
439439
"associated `type const` are unstable"
440440
);
441+
// Make sure associated `type const` defaults in traits are only allowed
442+
// if the feature gate is enabled.
443+
// #![feature(associated_type_defaults)]
444+
if ctxt == AssocCtxt::Trait && rhs.is_some() {
445+
gate!(
446+
&self,
447+
associated_type_defaults,
448+
i.span,
449+
"associated type defaults are unstable"
450+
);
451+
}
441452
false
442453
}
443454
_ => false,

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)