Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions compiler/rustc_middle/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
) -> Self {
let err = Ty::new_error(tcx, guar);

let arity = if let Some(frame) = cycle_error.cycle.get(0)
&& frame.query.dep_kind == dep_kinds::fn_sig
&& let Some(def_id) = frame.query.def_id
let arity = if let Some(info) = cycle_error.cycle.get(0)
&& info.frame.dep_kind == dep_kinds::fn_sig
&& let Some(def_id) = info.frame.def_id
&& let Some(node) = tcx.hir_get_if_local(def_id)
&& let Some(sig) = node.fn_sig()
{
Expand Down Expand Up @@ -85,10 +85,10 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
let mut item_and_field_ids = Vec::new();
let mut representable_ids = FxHashSet::default();
for info in &cycle_error.cycle {
if info.query.dep_kind == dep_kinds::representability
&& let Some(field_id) = info.query.def_id
if info.frame.dep_kind == dep_kinds::representability
&& let Some(field_id) = info.frame.def_id
&& let Some(field_id) = field_id.as_local()
&& let Some(DefKind::Field) = info.query.info.def_kind
&& let Some(DefKind::Field) = info.frame.info.def_kind
{
let parent_id = tcx.parent(field_id.to_def_id());
let item_id = match tcx.def_kind(parent_id) {
Expand All @@ -99,8 +99,8 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
}
}
for info in &cycle_error.cycle {
if info.query.dep_kind == dep_kinds::representability_adt_ty
&& let Some(def_id) = info.query.def_id_for_ty_in_cycle
if info.frame.dep_kind == dep_kinds::representability_adt_ty
&& let Some(def_id) = info.frame.def_id_for_ty_in_cycle
&& let Some(def_id) = def_id.as_local()
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
{
Expand Down Expand Up @@ -141,9 +141,9 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
search_for_cycle_permutation(
&cycle_error.cycle,
|cycle| {
if let Some(frame) = cycle.get(0)
&& frame.query.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = frame.query.def_id
if let Some(info) = cycle.get(0)
&& info.frame.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = info.frame.def_id
{
let n = tcx.generics_of(def_id).own_params.len();
ControlFlow::Break(vec![ty::Bivariant; n].leak())
Expand Down Expand Up @@ -189,8 +189,8 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
let diag = search_for_cycle_permutation(
&cycle_error.cycle,
|cycle| {
if cycle[0].query.dep_kind == dep_kinds::layout_of
&& let Some(def_id) = cycle[0].query.def_id_for_ty_in_cycle
if cycle[0].frame.dep_kind == dep_kinds::layout_of
&& let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle
&& let Some(def_id) = def_id.as_local()
&& let def_kind = tcx.def_kind(def_id)
&& matches!(def_kind, DefKind::Closure)
Expand All @@ -213,18 +213,18 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
tcx.def_kind_descr_article(def_kind, def_id.to_def_id()),
tcx.def_kind_descr(def_kind, def_id.to_def_id()),
);
for (i, frame) in cycle.iter().enumerate() {
if frame.query.dep_kind != dep_kinds::layout_of {
for (i, info) in cycle.iter().enumerate() {
if info.frame.dep_kind != dep_kinds::layout_of {
continue;
}
let Some(frame_def_id) = frame.query.def_id_for_ty_in_cycle else {
let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else {
continue;
};
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {
continue;
};
let frame_span =
frame.query.info.default_span(cycle[(i + 1) % cycle.len()].span);
info.frame.info.default_span(cycle[(i + 1) % cycle.len()].span);
if frame_span.is_dummy() {
continue;
}
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ where
}

#[inline(always)]
fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<'tcx, Self::Key>
where
QueryCtxt<'tcx>: 'a,
{
fn query_state(self, qcx: QueryCtxt<'tcx>) -> &'tcx QueryState<'tcx, Self::Key> {
// Safety:
// This is just manually doing the subfield referencing through pointer math.
unsafe {
Expand All @@ -100,7 +97,7 @@ where
}

#[inline(always)]
fn query_cache<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a Self::Cache {
fn query_cache(self, qcx: QueryCtxt<'tcx>) -> &'tcx Self::Cache {
// Safety:
// This is just manually doing the subfield referencing through pointer math.
unsafe {
Expand Down Expand Up @@ -216,12 +213,12 @@ trait QueryDispatcherUnerased<'tcx> {
) -> Self::UnerasedValue;
}

pub fn query_system<'a>(
pub fn query_system<'tcx>(
local_providers: Providers,
extern_providers: ExternProviders,
on_disk_cache: Option<OnDiskCache>,
incremental: bool,
) -> QuerySystem<'a> {
) -> QuerySystem<'tcx> {
QuerySystem {
states: Default::default(),
arenas: Default::default(),
Expand Down
48 changes: 19 additions & 29 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ impl<'tcx> QueryCtxt<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
QueryCtxt { tcx }
}

fn depth_limit_error(self, job: QueryJobId) {
let query_map = self.collect_active_jobs(true).expect("failed to collect active queries");
let (info, depth) = job.find_dep_kind_root(query_map);

let suggested_limit = match self.tcx.recursion_limit() {
Limit(0) => Limit(2),
limit => limit * 2,
};

self.tcx.sess.dcx().emit_fatal(QueryOverflow {
span: info.job.span,
note: QueryOverflowNote { desc: info.frame.info.extract().description, depth },
suggested_limit,
crate_name: self.tcx.crate_name(LOCAL_CRATE),
});
}
}

impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
Expand Down Expand Up @@ -104,13 +121,6 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
if complete { Ok(jobs) } else { Err(jobs) }
}

fn lift_query_info(
self,
info: &QueryStackDeferred<'tcx>,
) -> rustc_query_system::query::QueryStackFrameExtra {
info.extract()
}

// Interactions with on_disk_cache
fn load_side_effect(
self,
Expand Down Expand Up @@ -162,26 +172,6 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
tls::enter_context(&new_icx, compute)
})
}

fn depth_limit_error(self, job: QueryJobId) {
let query_map = self.collect_active_jobs(true).expect("failed to collect active queries");
let (info, depth) = job.find_dep_kind_root(query_map);

let suggested_limit = match self.tcx.recursion_limit() {
Limit(0) => Limit(2),
limit => limit * 2,
};

self.tcx.sess.dcx().emit_fatal(QueryOverflow {
span: info.job.span,
note: QueryOverflowNote {
desc: self.lift_query_info(&info.query.info).description,
depth,
},
suggested_limit,
crate_name: self.tcx.crate_name(LOCAL_CRATE),
});
}
}

pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) -> bool {
Expand Down Expand Up @@ -738,14 +728,14 @@ macro_rules! define_queries {
qmap: &mut QueryMap<'tcx>,
require_complete: bool,
) -> Option<()> {
let make_query = |tcx, key| {
let make_frame = |tcx, key| {
let kind = rustc_middle::dep_graph::dep_kinds::$name;
let name = stringify!($name);
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name)
};
let res = tcx.query_system.states.$name.collect_active_jobs(
tcx,
make_query,
make_frame,
qmap,
require_complete,
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_query_system/src/query/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DepContextOf<'tcx, This: QueryDispatcher<'tcx>> =
/// Those types are not visible from this `rustc_query_system` crate.
///
/// "Dispatcher" should be understood as a near-synonym of "vtable".
pub trait QueryDispatcher<'tcx>: Copy {
pub trait QueryDispatcher<'tcx>: Copy + 'tcx {
fn name(self) -> &'static str;

/// Query context used by this dispatcher, i.e. `rustc_query_impl::QueryCtxt`.
Expand All @@ -41,10 +41,10 @@ pub trait QueryDispatcher<'tcx>: Copy {
fn format_value(self) -> fn(&Self::Value) -> String;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(self, tcx: Self::Qcx) -> &'a QueryState<'tcx, Self::Key>;
fn query_state(self, tcx: Self::Qcx) -> &'tcx QueryState<'tcx, Self::Key>;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_cache<'a>(self, tcx: Self::Qcx) -> &'a Self::Cache;
fn query_cache(self, tcx: Self::Qcx) -> &'tcx Self::Cache;

fn will_cache_on_disk_for_key(self, tcx: DepContextOf<'tcx, Self>, key: &Self::Key) -> bool;

Expand Down
49 changes: 23 additions & 26 deletions compiler/rustc_query_system/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ use crate::query::{QueryContext, QueryStackFrame};
pub struct QueryInfo<I> {
/// The span corresponding to the reason for which this query was required.
pub span: Span,
pub query: QueryStackFrame<I>,
pub frame: QueryStackFrame<I>,
}

impl<'tcx> QueryInfo<QueryStackDeferred<'tcx>> {
pub(crate) fn lift<Qcx: QueryContext<'tcx>>(
&self,
qcx: Qcx,
) -> QueryInfo<QueryStackFrameExtra> {
QueryInfo { span: self.span, query: self.query.lift(qcx) }
pub(crate) fn lift(&self) -> QueryInfo<QueryStackFrameExtra> {
QueryInfo { span: self.span, frame: self.frame.lift() }
}
}

Expand All @@ -42,8 +39,8 @@ pub type QueryMap<'tcx> = FxHashMap<QueryJobId, QueryJobInfo<'tcx>>;
pub struct QueryJobId(pub NonZero<u64>);

impl QueryJobId {
fn query<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
map.get(&self).unwrap().query.clone()
fn frame<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
map.get(&self).unwrap().frame.clone()
}

fn span<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> Span {
Expand All @@ -61,7 +58,7 @@ impl QueryJobId {

#[derive(Clone, Debug)]
pub struct QueryJobInfo<'tcx> {
pub query: QueryStackFrame<QueryStackDeferred<'tcx>>,
pub frame: QueryStackFrame<QueryStackDeferred<'tcx>>,
pub job: QueryJob<'tcx>,
}

Expand Down Expand Up @@ -125,7 +122,7 @@ impl QueryJobId {

while let Some(job) = current_job {
let info = query_map.get(&job).unwrap();
cycle.push(QueryInfo { span: info.job.span, query: info.query.clone() });
cycle.push(QueryInfo { span: info.job.span, frame: info.frame.clone() });

if job == *self {
cycle.reverse();
Expand All @@ -140,7 +137,7 @@ impl QueryJobId {
.job
.parent
.as_ref()
.map(|parent| (info.job.span, parent.query(&query_map)));
.map(|parent| (info.job.span, parent.frame(&query_map)));
return CycleError { usage, cycle };
}

Expand All @@ -158,13 +155,13 @@ impl QueryJobId {
) -> (QueryJobInfo<'tcx>, usize) {
let mut depth = 1;
let info = query_map.get(&self).unwrap();
let dep_kind = info.query.dep_kind;
let dep_kind = info.frame.dep_kind;
let mut current_id = info.job.parent;
let mut last_layout = (info.clone(), depth);

while let Some(id) = current_id {
let info = query_map.get(&id).unwrap();
if info.query.dep_kind == dep_kind {
if info.frame.dep_kind == dep_kind {
depth += 1;
last_layout = (info.clone(), depth);
}
Expand Down Expand Up @@ -389,7 +386,7 @@ where
.iter()
.min_by_key(|v| {
let (span, query) = f(v);
let hash = query.query(query_map).hash;
let hash = query.frame(query_map).hash;
// Prefer entry points which have valid spans for nicer error messages
// We add an integer to the tuple ensuring that entry points
// with valid spans are picked first
Expand Down Expand Up @@ -473,14 +470,14 @@ fn remove_cycle<'tcx>(
stack.rotate_left(pos);
}

let usage = usage.as_ref().map(|(span, query)| (*span, query.query(query_map)));
let usage = usage.as_ref().map(|(span, query)| (*span, query.frame(query_map)));

// Create the cycle error
let error = CycleError {
usage,
cycle: stack
.iter()
.map(|&(s, ref q)| QueryInfo { span: s, query: q.query(query_map) })
.map(|&(s, ref q)| QueryInfo { span: s, frame: q.frame(query_map) })
.collect(),
};

Expand Down Expand Up @@ -559,17 +556,17 @@ pub fn report_cycle<'a>(
) -> Diag<'a> {
assert!(!stack.is_empty());

let span = stack[0].query.info.default_span(stack[1 % stack.len()].span);
let span = stack[0].frame.info.default_span(stack[1 % stack.len()].span);

let mut cycle_stack = Vec::new();

use crate::error::StackCount;
let stack_count = if stack.len() == 1 { StackCount::Single } else { StackCount::Multiple };

for i in 1..stack.len() {
let query = &stack[i].query;
let span = query.info.default_span(stack[(i + 1) % stack.len()].span);
cycle_stack.push(CycleStack { span, desc: query.info.description.to_owned() });
let frame = &stack[i].frame;
let span = frame.info.default_span(stack[(i + 1) % stack.len()].span);
cycle_stack.push(CycleStack { span, desc: frame.info.description.to_owned() });
}

let mut cycle_usage = None;
Expand All @@ -581,9 +578,9 @@ pub fn report_cycle<'a>(
}

let alias =
if stack.iter().all(|entry| matches!(entry.query.info.def_kind, Some(DefKind::TyAlias))) {
if stack.iter().all(|entry| matches!(entry.frame.info.def_kind, Some(DefKind::TyAlias))) {
Some(crate::error::Alias::Ty)
} else if stack.iter().all(|entry| entry.query.info.def_kind == Some(DefKind::TraitAlias)) {
} else if stack.iter().all(|entry| entry.frame.info.def_kind == Some(DefKind::TraitAlias)) {
Some(crate::error::Alias::Trait)
} else {
None
Expand All @@ -592,7 +589,7 @@ pub fn report_cycle<'a>(
let cycle_diag = crate::error::Cycle {
span,
cycle_stack,
stack_bottom: stack[0].query.info.description.to_owned(),
stack_bottom: stack[0].frame.info.description.to_owned(),
alias,
cycle_usage,
stack_count,
Expand Down Expand Up @@ -628,12 +625,12 @@ pub fn print_query_stack<'tcx, Qcx: QueryContext<'tcx>>(
let Some(query_info) = query_map.get(&query) else {
break;
};
let query_extra = qcx.lift_query_info(&query_info.query.info);
let query_extra = query_info.frame.info.extract();
if Some(count_printed) < limit_frames || limit_frames.is_none() {
// Only print to stderr as many stack frames as `num_frames` when present.
dcx.struct_failure_note(format!(
"#{} [{:?}] {}",
count_printed, query_info.query.dep_kind, query_extra.description
count_printed, query_info.frame.dep_kind, query_extra.description
))
.with_span(query_info.job.span)
.emit();
Expand All @@ -645,7 +642,7 @@ pub fn print_query_stack<'tcx, Qcx: QueryContext<'tcx>>(
file,
"#{} [{}] {}",
count_total,
qcx.dep_context().dep_kind_vtable(query_info.query.dep_kind).name,
qcx.dep_context().dep_kind_vtable(query_info.frame.dep_kind).name,
query_extra.description
);
}
Expand Down
Loading
Loading