Skip to content

Commit c2e416c

Browse files
Make proof tree probing generic
1 parent 8a8bbc0 commit c2e416c

File tree

3 files changed

+51
-38
lines changed

3 files changed

+51
-38
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
471471
{
472472
self.resolve_vars_if_possible(value)
473473
}
474+
475+
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T {
476+
self.probe(|_| probe())
477+
}
474478
}
475479

476480
/// See the `error_reporting` module for more details.

compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
use crate::solve::assembly::Candidate;
22

33
use super::EvalCtxt;
4-
use rustc_infer::infer::InferCtxt;
5-
use rustc_infer::traits::BuiltinImplSource;
6-
use rustc_middle::traits::query::NoSolution;
7-
use rustc_middle::traits::solve::{inspect, CandidateSource, QueryResult};
8-
use rustc_middle::ty::TyCtxt;
4+
use rustc_next_trait_solver::solve::{
5+
inspect, BuiltinImplSource, CandidateSource, NoSolution, QueryResult,
6+
};
7+
use rustc_type_ir::{InferCtxtLike, Interner};
98
use std::marker::PhantomData;
109

11-
pub(in crate::solve) struct ProbeCtxt<'me, 'a, 'tcx, F, T> {
12-
ecx: &'me mut EvalCtxt<'a, InferCtxt<'tcx>>,
10+
pub(in crate::solve) struct ProbeCtxt<'me, 'a, Infcx, I, F, T>
11+
where
12+
Infcx: InferCtxtLike<Interner = I>,
13+
I: Interner,
14+
{
15+
ecx: &'me mut EvalCtxt<'a, Infcx, I>,
1316
probe_kind: F,
1417
_result: PhantomData<T>,
1518
}
1619

17-
impl<'tcx, F, T> ProbeCtxt<'_, '_, 'tcx, F, T>
20+
impl<Infcx, I, F, T> ProbeCtxt<'_, '_, Infcx, I, F, T>
1821
where
19-
F: FnOnce(&T) -> inspect::ProbeKind<TyCtxt<'tcx>>,
22+
F: FnOnce(&T) -> inspect::ProbeKind<I>,
23+
Infcx: InferCtxtLike<Interner = I>,
24+
I: Interner,
2025
{
21-
pub(in crate::solve) fn enter(
22-
self,
23-
f: impl FnOnce(&mut EvalCtxt<'_, InferCtxt<'tcx>>) -> T,
24-
) -> T {
26+
pub(in crate::solve) fn enter(self, f: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> T) -> T {
2527
let ProbeCtxt { ecx: outer_ecx, probe_kind, _result } = self;
2628

2729
let infcx = outer_ecx.infcx;
@@ -38,7 +40,7 @@ where
3840
tainted: outer_ecx.tainted,
3941
inspect: outer_ecx.inspect.take_and_enter_probe(),
4042
};
41-
let r = nested_ecx.infcx.probe(|_| {
43+
let r = nested_ecx.infcx.probe(|| {
4244
let r = f(&mut nested_ecx);
4345
nested_ecx.inspect.probe_final_state(infcx, max_input_universe);
4446
r
@@ -52,59 +54,64 @@ where
5254
}
5355
}
5456

55-
pub(in crate::solve) struct TraitProbeCtxt<'me, 'a, 'tcx, F> {
56-
cx: ProbeCtxt<'me, 'a, 'tcx, F, QueryResult<'tcx>>,
57-
source: CandidateSource<'tcx>,
57+
pub(in crate::solve) struct TraitProbeCtxt<'me, 'a, Infcx, I, F>
58+
where
59+
Infcx: InferCtxtLike<Interner = I>,
60+
I: Interner,
61+
{
62+
cx: ProbeCtxt<'me, 'a, Infcx, I, F, QueryResult<I>>,
63+
source: CandidateSource<I>,
5864
}
5965

60-
impl<'tcx, F> TraitProbeCtxt<'_, '_, 'tcx, F>
66+
impl<Infcx, I, F> TraitProbeCtxt<'_, '_, Infcx, I, F>
6167
where
62-
F: FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<TyCtxt<'tcx>>,
68+
Infcx: InferCtxtLike<Interner = I>,
69+
I: Interner,
70+
F: FnOnce(&QueryResult<I>) -> inspect::ProbeKind<I>,
6371
{
6472
#[instrument(level = "debug", skip_all, fields(source = ?self.source))]
6573
pub(in crate::solve) fn enter(
6674
self,
67-
f: impl FnOnce(&mut EvalCtxt<'_, InferCtxt<'tcx>>) -> QueryResult<'tcx>,
68-
) -> Result<Candidate<TyCtxt<'tcx>>, NoSolution> {
75+
f: impl FnOnce(&mut EvalCtxt<'_, Infcx>) -> QueryResult<I>,
76+
) -> Result<Candidate<I>, NoSolution> {
6977
self.cx.enter(|ecx| f(ecx)).map(|result| Candidate { source: self.source, result })
7078
}
7179
}
7280

73-
impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
81+
impl<'a, Infcx, I> EvalCtxt<'a, Infcx, I>
82+
where
83+
Infcx: InferCtxtLike<Interner = I>,
84+
I: Interner,
85+
{
7486
/// `probe_kind` is only called when proof tree building is enabled so it can be
7587
/// as expensive as necessary to output the desired information.
76-
pub(in crate::solve) fn probe<F, T>(&mut self, probe_kind: F) -> ProbeCtxt<'_, 'a, 'tcx, F, T>
88+
pub(in crate::solve) fn probe<F, T>(
89+
&mut self,
90+
probe_kind: F,
91+
) -> ProbeCtxt<'_, 'a, Infcx, I, F, T>
7792
where
78-
F: FnOnce(&T) -> inspect::ProbeKind<TyCtxt<'tcx>>,
93+
F: FnOnce(&T) -> inspect::ProbeKind<I>,
7994
{
8095
ProbeCtxt { ecx: self, probe_kind, _result: PhantomData }
8196
}
8297

8398
pub(in crate::solve) fn probe_builtin_trait_candidate(
8499
&mut self,
85100
source: BuiltinImplSource,
86-
) -> TraitProbeCtxt<
87-
'_,
88-
'a,
89-
'tcx,
90-
impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<TyCtxt<'tcx>>,
91-
> {
101+
) -> TraitProbeCtxt<'_, 'a, Infcx, I, impl FnOnce(&QueryResult<I>) -> inspect::ProbeKind<I>>
102+
{
92103
self.probe_trait_candidate(CandidateSource::BuiltinImpl(source))
93104
}
94105

95106
pub(in crate::solve) fn probe_trait_candidate(
96107
&mut self,
97-
source: CandidateSource<'tcx>,
98-
) -> TraitProbeCtxt<
99-
'_,
100-
'a,
101-
'tcx,
102-
impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<TyCtxt<'tcx>>,
103-
> {
108+
source: CandidateSource<I>,
109+
) -> TraitProbeCtxt<'_, 'a, Infcx, I, impl FnOnce(&QueryResult<I>) -> inspect::ProbeKind<I>>
110+
{
104111
TraitProbeCtxt {
105112
cx: ProbeCtxt {
106113
ecx: self,
107-
probe_kind: move |result: &QueryResult<'tcx>| inspect::ProbeKind::TraitCandidate {
114+
probe_kind: move |result: &QueryResult<I>| inspect::ProbeKind::TraitCandidate {
108115
source,
109116
result: *result,
110117
},

compiler/rustc_type_ir/src/infcx.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ pub trait InferCtxtLike: Sized {
7272
fn resolve_vars_if_possible<T>(&self, value: T) -> T
7373
where
7474
T: TypeFoldable<Self::Interner>;
75+
76+
fn probe<T>(&self, probe: impl FnOnce() -> T) -> T;
7577
}

0 commit comments

Comments
 (0)