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 28, 2024
1 parent 50a5da1 commit f494036
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 83 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
8 changes: 4 additions & 4 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 @@ -218,7 +218,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 @@ -280,7 +280,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 Expand Up @@ -1114,7 +1114,7 @@ struct ReplaceAliasWithInfer<'me, 'a, 'tcx> {

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'_, '_, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
self.ecx.tcx()
self.ecx.interner()
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
Expand Down
Loading

0 comments on commit f494036

Please sign in to comment.