Skip to content

Commit 2194af9

Browse files
authored
Rollup merge of rust-lang#152419 - nnethercote:mv-more-query-system-code, r=Zalathar
Move more query system code Towards the goal of eliminating `rustc_query_system`, this commit moves some code from `rustc_query_system` to `rustc_middle` and `rustc_query_impl`, and from `rustc_middle` to `rustc_query_impl`. r? @Zalathar
2 parents d34f1f9 + a34317e commit 2194af9

15 files changed

Lines changed: 619 additions & 615 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,6 +4492,7 @@ name = "rustc_query_impl"
44924492
version = "0.0.0"
44934493
dependencies = [
44944494
"measureme",
4495+
"rustc_abi",
44954496
"rustc_data_structures",
44964497
"rustc_errors",
44974498
"rustc_hashes",
@@ -4501,7 +4502,9 @@ dependencies = [
45014502
"rustc_middle",
45024503
"rustc_query_system",
45034504
"rustc_serialize",
4505+
"rustc_session",
45044506
"rustc_span",
4507+
"rustc_thread_pool",
45054508
"tracing",
45064509
]
45074510

compiler/rustc_interface/src/interface.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use rustc_parse::lexer::StripTokens;
1616
use rustc_parse::new_parser_from_source_str;
1717
use rustc_parse::parser::Recovery;
1818
use rustc_parse::parser::attr::AllowLeadingUnsafe;
19-
use rustc_query_impl::QueryCtxt;
20-
use rustc_query_system::query::print_query_stack;
19+
use rustc_query_impl::{QueryCtxt, print_query_stack};
2120
use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileName};
2221
use rustc_session::parse::ParseSess;
2322
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, lint};

compiler/rustc_interface/src/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
184184
use rustc_data_structures::defer;
185185
use rustc_data_structures::sync::FromDyn;
186186
use rustc_middle::ty::tls;
187-
use rustc_query_impl::QueryCtxt;
188-
use rustc_query_system::query::{QueryContext, break_query_cycles};
187+
use rustc_query_impl::{QueryCtxt, break_query_cycles};
189188

190189
let thread_stack_size = init_stack_size(thread_builder_diag);
191190

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ mod keys;
1313
pub mod on_disk_cache;
1414
#[macro_use]
1515
pub mod plumbing;
16-
pub mod values;
1716

1817
pub fn describe_as_module(def_id: impl Into<LocalDefId>, tcx: TyCtxt<'_>) -> String {
1918
let def_id = def_id.into();

compiler/rustc_query_impl/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
measureme = "12.0.1"
9+
rustc_abi = { path = "../rustc_abi" }
910
rustc_data_structures = { path = "../rustc_data_structures" }
1011
rustc_errors = { path = "../rustc_errors" }
1112
rustc_hashes = { path = "../rustc_hashes" }
@@ -15,6 +16,8 @@ rustc_macros = { path = "../rustc_macros" }
1516
rustc_middle = { path = "../rustc_middle" }
1617
rustc_query_system = { path = "../rustc_query_system" }
1718
rustc_serialize = { path = "../rustc_serialize" }
19+
rustc_session = { path = "../rustc_session" }
1820
rustc_span = { path = "../rustc_span" }
21+
rustc_thread_pool = { path = "../rustc_thread_pool" }
1922
tracing = "0.1"
2023
# tidy-alphabetical-end

compiler/rustc_query_impl/src/error.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_errors::codes::*;
12
use rustc_hir::limit::Limit;
23
use rustc_macros::{Diagnostic, Subdiagnostic};
34
use rustc_span::{Span, Symbol};
@@ -22,3 +23,59 @@ pub(crate) struct QueryOverflowNote {
2223
pub desc: String,
2324
pub depth: usize,
2425
}
26+
27+
#[derive(Subdiagnostic)]
28+
#[note("...which requires {$desc}...")]
29+
pub(crate) struct CycleStack {
30+
#[primary_span]
31+
pub span: Span,
32+
pub desc: String,
33+
}
34+
35+
#[derive(Subdiagnostic)]
36+
pub(crate) enum StackCount {
37+
#[note("...which immediately requires {$stack_bottom} again")]
38+
Single,
39+
#[note("...which again requires {$stack_bottom}, completing the cycle")]
40+
Multiple,
41+
}
42+
43+
#[derive(Subdiagnostic)]
44+
pub(crate) enum Alias {
45+
#[note("type aliases cannot be recursive")]
46+
#[help("consider using a struct, enum, or union instead to break the cycle")]
47+
#[help(
48+
"see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information"
49+
)]
50+
Ty,
51+
#[note("trait aliases cannot be recursive")]
52+
Trait,
53+
}
54+
55+
#[derive(Subdiagnostic)]
56+
#[note("cycle used when {$usage}")]
57+
pub(crate) struct CycleUsage {
58+
#[primary_span]
59+
pub span: Span,
60+
pub usage: String,
61+
}
62+
63+
#[derive(Diagnostic)]
64+
#[diag("cycle detected when {$stack_bottom}", code = E0391)]
65+
pub(crate) struct Cycle {
66+
#[primary_span]
67+
pub span: Span,
68+
pub stack_bottom: String,
69+
#[subdiagnostic]
70+
pub cycle_stack: Vec<CycleStack>,
71+
#[subdiagnostic]
72+
pub stack_count: StackCount,
73+
#[subdiagnostic]
74+
pub alias: Option<Alias>,
75+
#[subdiagnostic]
76+
pub cycle_usage: Option<CycleUsage>,
77+
#[note(
78+
"see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information"
79+
)]
80+
pub note_span: (),
81+
}

compiler/rustc_query_impl/src/execution.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use rustc_middle::dep_graph::DepsType;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_query_system::dep_graph::{DepGraphData, DepNodeKey, HasDepContext};
1111
use rustc_query_system::query::{
12-
ActiveKeyStatus, CycleError, CycleErrorHandling, QueryCache, QueryContext, QueryJob,
13-
QueryJobId, QueryJobInfo, QueryLatch, QueryMap, QueryMode, QueryStackDeferred, QueryStackFrame,
14-
QueryState, incremental_verify_ich, report_cycle,
12+
ActiveKeyStatus, CycleError, CycleErrorHandling, QueryCache, QueryJob, QueryJobId, QueryLatch,
13+
QueryMode, QueryStackDeferred, QueryStackFrame, QueryState, incremental_verify_ich,
1514
};
1615
use rustc_span::{DUMMY_SP, Span};
1716

1817
use crate::dep_graph::{DepContext, DepNode, DepNodeIndex};
18+
use crate::job::{QueryJobInfo, QueryMap, find_cycle_in_stack, report_cycle};
1919
use crate::{QueryCtxt, QueryFlags, SemiDynamicQueryDispatcher};
2020

2121
#[inline]
@@ -218,7 +218,7 @@ fn cycle_error<'tcx, C: QueryCache, const FLAGS: QueryFlags>(
218218
.ok()
219219
.expect("failed to collect active queries");
220220

221-
let error = try_execute.find_cycle_in_stack(query_map, &qcx.current_query_job(), span);
221+
let error = find_cycle_in_stack(try_execute, query_map, &qcx.current_query_job(), span);
222222
(mk_cycle(query, qcx, error.lift()), None)
223223
}
224224

0 commit comments

Comments
 (0)