Skip to content

Commit

Permalink
Make ProofTreeBuilder actually generic over interner
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 27, 2024
1 parent d5d7477 commit 56e87df
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 82 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.check_and_mk_args(def_id, args)
}

fn intern_canonical_goal_evaluation_step(
self,
step: solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>,
) -> &'tcx solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>> {
self.arena.alloc(step)
}

fn parent(self, def_id: Self::DefId) -> Self::DefId {
self.parent(def_id)
}
Expand Down
28 changes: 17 additions & 11 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::solve::{
use rustc_data_structures::fx::FxHashSet;
use rustc_index::IndexVec;
use rustc_infer::infer::canonical::query_response::make_query_region_constraints;
use rustc_infer::infer::canonical::CanonicalVarValues;
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
use rustc_infer::infer::RegionVariableOrigin;
use rustc_infer::infer::{InferCtxt, InferOk};
Expand All @@ -32,22 +31,24 @@ use rustc_middle::ty::{self, BoundVar, GenericArgKind, Ty, TyCtxt, TypeFoldable}
use rustc_next_trait_solver::canonicalizer::{CanonicalizeMode, Canonicalizer};
use rustc_next_trait_solver::resolve::EagerResolver;
use rustc_span::{Span, DUMMY_SP};
use rustc_type_ir::CanonicalVarValues;
use rustc_type_ir::{InferCtxtLike, Interner};
use std::assert_matches::assert_matches;
use std::iter;
use std::ops::Deref;

trait ResponseT<'tcx> {
fn var_values(&self) -> CanonicalVarValues<'tcx>;
fn var_values(&self) -> CanonicalVarValues<TyCtxt<'tcx>>;
}

impl<'tcx> ResponseT<'tcx> for Response<TyCtxt<'tcx>> {
fn var_values(&self) -> CanonicalVarValues<'tcx> {
fn var_values(&self) -> CanonicalVarValues<TyCtxt<'tcx>> {
self.var_values
}
}

impl<'tcx, T> ResponseT<'tcx> for inspect::State<TyCtxt<'tcx>, T> {
fn var_values(&self) -> CanonicalVarValues<'tcx> {
fn var_values(&self) -> CanonicalVarValues<TyCtxt<'tcx>> {
self.var_values
}
}
Expand Down Expand Up @@ -260,7 +261,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
infcx: &InferCtxt<'tcx>,
original_values: &[ty::GenericArg<'tcx>],
response: &Canonical<'tcx, T>,
) -> CanonicalVarValues<'tcx> {
) -> CanonicalVarValues<TyCtxt<'tcx>> {
// FIXME: Longterm canonical queries should deal with all placeholders
// created inside of the query directly instead of returning them to the
// caller.
Expand Down Expand Up @@ -354,7 +355,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
original_values: &[ty::GenericArg<'tcx>],
var_values: CanonicalVarValues<'tcx>,
var_values: CanonicalVarValues<TyCtxt<'tcx>>,
) {
assert_eq!(original_values.len(), var_values.len());

Expand Down Expand Up @@ -393,13 +394,18 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
/// evaluating a goal. The `var_values` not only include the bound variables
/// of the query input, but also contain all unconstrained inference vars
/// created while evaluating this goal.
pub(in crate::solve) fn make_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
infcx: &InferCtxt<'tcx>,
var_values: &[ty::GenericArg<'tcx>],
pub(in crate::solve) fn make_canonical_state<Infcx, T, I>(
infcx: &Infcx,
var_values: &[I::GenericArg],
max_input_universe: ty::UniverseIndex,
data: T,
) -> inspect::CanonicalState<TyCtxt<'tcx>, T> {
let var_values = CanonicalVarValues { var_values: infcx.tcx.mk_args(var_values) };
) -> inspect::CanonicalState<I, T>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
T: TypeFoldable<I>,
{
let var_values = CanonicalVarValues { var_values: infcx.interner().mk_args(var_values) };
let state = inspect::State { var_values, data };
let state = state.fold_with(&mut EagerResolver::new(infcx));
Canonicalizer::canonicalize(
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct EvalCtxt<
// evaluation code.
tainted: Result<(), NoSolution>,

pub(super) inspect: ProofTreeBuilder<I>,
pub(super) inspect: ProofTreeBuilder<Infcx>,
}

#[derive(derivative::Derivative)]
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
tcx: TyCtxt<'tcx>,
search_graph: &'a mut search_graph::SearchGraph<TyCtxt<'tcx>>,
canonical_input: CanonicalInput<'tcx>,
canonical_goal_evaluation: &mut ProofTreeBuilder<TyCtxt<'tcx>>,
canonical_goal_evaluation: &mut ProofTreeBuilder<InferCtxt<'tcx>>,
f: impl FnOnce(&mut EvalCtxt<'_, InferCtxt<'tcx>>, Goal<'tcx, ty::Predicate<'tcx>>) -> R,
) -> R {
let intercrate = match search_graph.solver_mode() {
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
tcx: TyCtxt<'tcx>,
search_graph: &'a mut search_graph::SearchGraph<TyCtxt<'tcx>>,
canonical_input: CanonicalInput<'tcx>,
goal_evaluation: &mut ProofTreeBuilder<TyCtxt<'tcx>>,
goal_evaluation: &mut ProofTreeBuilder<InferCtxt<'tcx>>,
) -> QueryResult<'tcx> {
let mut canonical_goal_evaluation =
goal_evaluation.new_canonical_goal_evaluation(canonical_input);
Expand Down
Loading

0 comments on commit 56e87df

Please sign in to comment.