Skip to content

Commit 8ea1da7

Browse files
committed
Auto merge of rust-lang#135455 - matthiaskrgr:rollup-jbsibin, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#134498 (Fix cycle error only occurring with -Zdump-mir) - rust-lang#135440 (rm unnecessary `OpaqueTypeDecl` wrapper) - rust-lang#135441 (Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024) - rust-lang#135444 (Update books) - rust-lang#135451 (Remove code duplication when hashing query result and interning node) - rust-lang#135452 (bootstrap: fix outdated feature name in comment) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2ae9916 + 1c90d67 commit 8ea1da7

File tree

22 files changed

+123
-109
lines changed

22 files changed

+123
-109
lines changed

compiler/rustc_borrowck/src/type_check/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub(super) fn take_opaques_and_register_member_constraints<'tcx>(
2525
let opaque_types = infcx
2626
.take_opaque_types()
2727
.into_iter()
28-
.map(|(opaque_type_key, decl)| {
29-
let hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
28+
.map(|(opaque_type_key, hidden_type)| {
29+
let hidden_type = infcx.resolve_vars_if_possible(hidden_type);
3030
register_member_constraints(
3131
typeck,
3232
&mut member_constraints,

compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ fn check_opaque_meets_bounds<'tcx>(
436436
} else {
437437
// Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
438438
for (mut key, mut ty) in infcx.take_opaque_types() {
439-
ty.hidden_type.ty = infcx.resolve_vars_if_possible(ty.hidden_type.ty);
439+
ty.ty = infcx.resolve_vars_if_possible(ty.ty);
440440
key = infcx.resolve_vars_if_possible(key);
441-
sanity_check_found_hidden_type(tcx, key, ty.hidden_type)?;
441+
sanity_check_found_hidden_type(tcx, key, ty)?;
442442
}
443443
Ok(())
444444
}
@@ -1873,7 +1873,7 @@ pub(super) fn check_coroutine_obligations(
18731873
// Check that any hidden types found when checking these stalled coroutine obligations
18741874
// are valid.
18751875
for (key, ty) in infcx.take_opaque_types() {
1876-
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
1876+
let hidden_type = infcx.resolve_vars_if_possible(ty);
18771877
let key = infcx.resolve_vars_if_possible(key);
18781878
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
18791879
}

compiler/rustc_hir_typeck/src/writeback.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
562562
// types or by using this function at the end of writeback and running it as a
563563
// fixpoint.
564564
let opaque_types = self.fcx.infcx.clone_opaque_types();
565-
for (opaque_type_key, decl) in opaque_types {
566-
let hidden_type = self.resolve(decl.hidden_type, &decl.hidden_type.span);
567-
let opaque_type_key = self.resolve(opaque_type_key, &decl.hidden_type.span);
565+
for (opaque_type_key, hidden_type) in opaque_types {
566+
let hidden_type = self.resolve(hidden_type, &hidden_type.span);
567+
let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span);
568568

569569
if !self.fcx.next_trait_solver() {
570570
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()

compiler/rustc_infer/src/infer/canonical/query_response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ impl<'tcx> InferCtxt<'tcx> {
155155
.opaque_type_storage
156156
.opaque_types
157157
.iter()
158-
.map(|(k, v)| (*k, v.hidden_type.ty))
158+
.map(|(k, v)| (*k, v.ty))
159159
.collect()
160160
}
161161

162162
fn take_opaque_types_for_query_response(&self) -> Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
163-
self.take_opaque_types().into_iter().map(|(k, v)| (k, v.hidden_type.ty)).collect()
163+
self.take_opaque_types().into_iter().map(|(k, v)| (k, v.ty)).collect()
164164
}
165165

166166
/// Given the (canonicalized) result to a canonical query,

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
234234
pub fn iter_opaque_types(
235235
&self,
236236
) -> impl Iterator<Item = (ty::OpaqueTypeKey<'tcx>, ty::OpaqueHiddenType<'tcx>)> + '_ {
237-
self.opaque_type_storage.opaque_types.iter().map(|(&k, v)| (k, v.hidden_type))
237+
self.opaque_type_storage.opaque_types.iter().map(|(&k, &v)| (k, v))
238238
}
239239
}
240240

compiler/rustc_infer/src/infer/opaque_types/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,9 @@ use crate::traits::{self, Obligation, PredicateObligations};
1919

2020
mod table;
2121

22-
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
22+
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>;
2323
pub(crate) use table::{OpaqueTypeStorage, OpaqueTypeTable};
2424

25-
/// Information about the opaque types whose values we
26-
/// are inferring in this function (these are the `impl Trait` that
27-
/// appear in the return type).
28-
#[derive(Clone, Debug)]
29-
pub struct OpaqueTypeDecl<'tcx> {
30-
/// The hidden types that have been inferred for this opaque type.
31-
/// There can be multiple, but they are all `lub`ed together at the end
32-
/// to obtain the canonical hidden type.
33-
pub hidden_type: OpaqueHiddenType<'tcx>,
34-
}
35-
3625
impl<'tcx> InferCtxt<'tcx> {
3726
/// This is a backwards compatibility hack to prevent breaking changes from
3827
/// lazy TAIT around RPIT handling.

compiler/rustc_infer/src/infer/opaque_types/table.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ use rustc_middle::bug;
33
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
44
use tracing::instrument;
55

6-
use super::{OpaqueTypeDecl, OpaqueTypeMap};
6+
use super::OpaqueTypeMap;
77
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
88

99
#[derive(Default, Debug, Clone)]
1010
pub(crate) struct OpaqueTypeStorage<'tcx> {
1111
/// Opaque types found in explicit return types and their
1212
/// associated fresh inference variable. Writeback resolves these
1313
/// variables to get the concrete type, which can be used to
14-
/// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
14+
/// 'de-opaque' OpaqueHiddenType, after typeck is done with all functions.
1515
pub opaque_types: OpaqueTypeMap<'tcx>,
1616
}
1717

1818
impl<'tcx> OpaqueTypeStorage<'tcx> {
1919
#[instrument(level = "debug")]
20-
pub(crate) fn remove(&mut self, key: OpaqueTypeKey<'tcx>, idx: Option<OpaqueHiddenType<'tcx>>) {
21-
if let Some(idx) = idx {
22-
self.opaque_types.get_mut(&key).unwrap().hidden_type = idx;
20+
pub(crate) fn remove(
21+
&mut self,
22+
key: OpaqueTypeKey<'tcx>,
23+
prev: Option<OpaqueHiddenType<'tcx>>,
24+
) {
25+
if let Some(prev) = prev {
26+
*self.opaque_types.get_mut(&key).unwrap() = prev;
2327
} else {
2428
// FIXME(#120456) - is `swap_remove` correct?
2529
match self.opaque_types.swap_remove(&key) {
@@ -59,13 +63,12 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
5963
key: OpaqueTypeKey<'tcx>,
6064
hidden_type: OpaqueHiddenType<'tcx>,
6165
) -> Option<Ty<'tcx>> {
62-
if let Some(decl) = self.storage.opaque_types.get_mut(&key) {
63-
let prev = std::mem::replace(&mut decl.hidden_type, hidden_type);
66+
if let Some(entry) = self.storage.opaque_types.get_mut(&key) {
67+
let prev = std::mem::replace(entry, hidden_type);
6468
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
6569
return Some(prev.ty);
6670
}
67-
let decl = OpaqueTypeDecl { hidden_type };
68-
self.storage.opaque_types.insert(key, decl);
71+
self.storage.opaque_types.insert(key, hidden_type);
6972
self.undo_log.push(UndoLog::OpaqueTypes(key, None));
7073
None
7174
}

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ declare_lint! {
9999
/// To fix this, remove the `use<'a>`, since the lifetime is already captured
100100
/// since it is in scope.
101101
pub IMPL_TRAIT_REDUNDANT_CAPTURES,
102-
Warn,
102+
Allow,
103103
"redundant precise-capturing `use<...>` syntax on an `impl Trait`",
104104
}
105105

compiler/rustc_middle/src/mir/pretty.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1555,16 +1555,22 @@ pub fn write_allocations<'tcx>(
15551555
write!(w, " (vtable: impl {dyn_ty} for {ty})")?
15561556
}
15571557
Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => {
1558-
match tcx.eval_static_initializer(did) {
1559-
Ok(alloc) => {
1560-
write!(w, " (static: {}, ", tcx.def_path_str(did))?;
1561-
write_allocation_track_relocs(w, alloc)?;
1558+
write!(w, " (static: {}", tcx.def_path_str(did))?;
1559+
if body.phase <= MirPhase::Runtime(RuntimePhase::PostCleanup)
1560+
&& tcx.hir().body_const_context(body.source.def_id()).is_some()
1561+
{
1562+
// Statics may be cyclic and evaluating them too early
1563+
// in the MIR pipeline may cause cycle errors even though
1564+
// normal compilation is fine.
1565+
write!(w, ")")?;
1566+
} else {
1567+
match tcx.eval_static_initializer(did) {
1568+
Ok(alloc) => {
1569+
write!(w, ", ")?;
1570+
write_allocation_track_relocs(w, alloc)?;
1571+
}
1572+
Err(_) => write!(w, ", error during initializer evaluation)")?,
15621573
}
1563-
Err(_) => write!(
1564-
w,
1565-
" (static: {}, error during initializer evaluation)",
1566-
tcx.def_path_str(did)
1567-
)?,
15681574
}
15691575
}
15701576
Some(GlobalAlloc::Static(did)) => {

compiler/rustc_middle/src/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ macro_rules! define_feedable {
548548
let dep_node_index = tcx.dep_graph.with_feed_task(
549549
dep_node,
550550
tcx,
551-
key,
552551
&value,
553552
hash_result!([$($modifiers)*]),
554553
);

compiler/rustc_query_system/src/dep_graph/graph.rs

+36-42
Original file line numberDiff line numberDiff line change
@@ -376,25 +376,8 @@ impl<D: Deps> DepGraphData<D> {
376376
};
377377

378378
let dcx = cx.dep_context();
379-
let hashing_timer = dcx.profiler().incr_result_hashing();
380-
let current_fingerprint =
381-
hash_result.map(|f| dcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, &result)));
382-
383-
// Intern the new `DepNode`.
384-
let (dep_node_index, prev_and_color) =
385-
self.current.intern_node(&self.previous, key, edges, current_fingerprint);
386-
387-
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
388-
389-
if let Some((prev_index, color)) = prev_and_color {
390-
debug_assert!(
391-
self.colors.get(prev_index).is_none(),
392-
"DepGraph::with_task() - Duplicate DepNodeColor \
393-
insertion for {key:?}"
394-
);
395-
396-
self.colors.insert(prev_index, color);
397-
}
379+
let dep_node_index =
380+
self.hash_result_and_intern_node(dcx, key, edges, &result, hash_result);
398381

399382
(result, dep_node_index)
400383
}
@@ -462,6 +445,38 @@ impl<D: Deps> DepGraphData<D> {
462445

463446
(result, dep_node_index)
464447
}
448+
449+
/// Intern the new `DepNode` with the dependencies up-to-now.
450+
fn hash_result_and_intern_node<Ctxt: DepContext<Deps = D>, R>(
451+
&self,
452+
cx: &Ctxt,
453+
node: DepNode,
454+
edges: EdgesVec,
455+
result: &R,
456+
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
457+
) -> DepNodeIndex {
458+
let hashing_timer = cx.profiler().incr_result_hashing();
459+
let current_fingerprint = hash_result.map(|hash_result| {
460+
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
461+
});
462+
463+
// Intern the new `DepNode` with the dependencies up-to-now.
464+
let (dep_node_index, prev_and_color) =
465+
self.current.intern_node(&self.previous, node, edges, current_fingerprint);
466+
467+
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
468+
469+
if let Some((prev_index, color)) = prev_and_color {
470+
debug_assert!(
471+
self.colors.get(prev_index).is_none(),
472+
"DepGraph::with_task() - Duplicate DepNodeColor insertion for {node:?}",
473+
);
474+
475+
self.colors.insert(prev_index, color);
476+
}
477+
478+
dep_node_index
479+
}
465480
}
466481

467482
impl<D: Deps> DepGraph<D> {
@@ -536,11 +551,10 @@ impl<D: Deps> DepGraph<D> {
536551
/// FIXME: If the code is changed enough for this node to be marked before requiring the
537552
/// caller's node, we suppose that those changes will be enough to mark this node red and
538553
/// force a recomputation using the "normal" way.
539-
pub fn with_feed_task<Ctxt: DepContext<Deps = D>, A: Debug, R: Debug>(
554+
pub fn with_feed_task<Ctxt: DepContext<Deps = D>, R: Debug>(
540555
&self,
541556
node: DepNode,
542557
cx: Ctxt,
543-
key: A,
544558
result: &R,
545559
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
546560
) -> DepNodeIndex {
@@ -588,27 +602,7 @@ impl<D: Deps> DepGraph<D> {
588602
}
589603
});
590604

591-
let hashing_timer = cx.profiler().incr_result_hashing();
592-
let current_fingerprint = hash_result.map(|hash_result| {
593-
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
594-
});
595-
596-
// Intern the new `DepNode` with the dependencies up-to-now.
597-
let (dep_node_index, prev_and_color) =
598-
data.current.intern_node(&data.previous, node, edges, current_fingerprint);
599-
600-
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
601-
602-
if let Some((prev_index, color)) = prev_and_color {
603-
debug_assert!(
604-
data.colors.get(prev_index).is_none(),
605-
"DepGraph::with_task() - Duplicate DepNodeColor insertion for {key:?}",
606-
);
607-
608-
data.colors.insert(prev_index, color);
609-
}
610-
611-
dep_node_index
605+
data.hash_result_and_intern_node(&cx, node, edges, result, hash_result)
612606
} else {
613607
// Incremental compilation is turned off. We just execute the task
614608
// without tracking. We still provide a dep-node index that uniquely

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ xz2 = "0.1"
6565
# Dependencies needed by the build-metrics feature
6666
sysinfo = { version = "0.33.0", default-features = false, optional = true, features = ["system"] }
6767

68-
# Dependencies needed by the `logging` feature
68+
# Dependencies needed by the `tracing` feature
6969
tracing = { version = "0.1", optional = true, features = ["attributes"] }
7070
tracing-subscriber = { version = "0.3", optional = true, features = ["env-filter", "fmt", "registry", "std"] }
7171
tracing-tree = { version = "0.4.0", optional = true }

src/bootstrap/src/core/build_steps/tool.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ macro_rules! bootstrap_tool {
334334
}
335335

336336
bootstrap_tool!(
337-
Rustbook, "src/tools/rustbook", "rustbook", submodules = SUBMODULES_FOR_RUSTBOOK;
337+
// This is marked as an external tool because it includes dependencies
338+
// from submodules. Trying to keep the lints in sync between all the repos
339+
// is a bit of a pain. Unfortunately it means the rustbook source itself
340+
// doesn't deny warnings, but it is a relatively small piece of code.
341+
Rustbook, "src/tools/rustbook", "rustbook", is_external_tool = true, submodules = SUBMODULES_FOR_RUSTBOOK;
338342
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
339343
Tidy, "src/tools/tidy", "tidy";
340344
Linkchecker, "src/tools/linkchecker", "linkchecker";

src/doc/nomicon

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[derive(Debug)]
2+
pub struct Thing {
3+
pub next: &'static Thing,
4+
}
5+
6+
pub static THING: Thing = Thing { next: &THING };
7+
// CHECK: alloc{{.+}} (static: THING)
8+
9+
const fn thing() -> &'static Thing {
10+
&MUTUALLY_RECURSIVE
11+
}
12+
13+
pub static MUTUALLY_RECURSIVE: Thing = Thing { next: thing() };
14+
// CHECK: alloc{{.+}} (static: MUTUALLY_RECURSIVE)
15+
16+
fn main() {
17+
// Generate optimized MIR for the const fn, too.
18+
thing();
19+
}

tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ const BAR::promoted[0]: &[&i32; 1] = {
1515
}
1616
}
1717

18-
ALLOC0 (static: Y, size: 4, align: 4) {
19-
2a 00 00 00 │ *...
20-
}
18+
ALLOC0 (static: Y)

tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
bb2 (cleanup): {
3939
resume;
4040
}
41-
- }
42-
-
43-
- ALLOC0 (static: Y, size: 4, align: 4) {
44-
- 2a 00 00 00 │ *...
4541
}
42+
-
43+
- ALLOC0 (static: Y)
4644

0 commit comments

Comments
 (0)