Skip to content
Draft
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
12 changes: 7 additions & 5 deletions compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use rustc_type_ir::data_structures::{HashMap, ensure_sufficient_stack};
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
use rustc_type_ir::inherent::Ty as _;
use rustc_type_ir::inherent::*;
use rustc_type_ir::solve::{Goal, QueryInput};
use rustc_type_ir::{
self as ty, Canonical, CanonicalParamEnvCacheEntry, CanonicalVarKind, Flags, InferCtxtLike,
Interner, PlaceholderConst, PlaceholderType, TypeFlags, TypeFoldable, TypeFolder,
Interner, PlaceholderConst, PlaceholderType, Ty, TypeFlags, TypeFoldable, TypeFolder,
TypeSuperFoldable, TypeVisitableExt,
};

Expand Down Expand Up @@ -78,7 +80,7 @@ pub(super) struct Canonicalizer<'a, D: SolverDelegate<Interner = I>, I: Interner

/// We can simply cache based on the ty itself, because we use
/// `ty::BoundVarIndexKind::Canonical`.
cache: HashMap<I::Ty, I::Ty>,
cache: HashMap<Ty<I>, Ty<I>>,
}

impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
Expand Down Expand Up @@ -316,7 +318,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
(max_universe, self.variables, var_kinds)
}

fn inner_fold_ty(&mut self, t: I::Ty) -> I::Ty {
fn inner_fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
let kind = match t.kind() {
ty::Infer(i) => match i {
ty::TyVar(vid) => {
Expand Down Expand Up @@ -400,7 +402,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {

let var = self.get_or_insert_bound_var(t, kind);

Ty::new_canonical_bound(self.cx(), var)
I::Ty::new_canonical_bound(self.cx(), var)
}
}

Expand Down Expand Up @@ -475,7 +477,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
Region::new_canonical_bound(self.cx(), var)
}

fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
if !t.flags().intersects(NEEDS_CANONICAL) {
t
} else if let Some(&ty) = self.cache.get(&t) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_index::IndexVec;
use rustc_type_ir::inherent::*;
use rustc_type_ir::relate::solver_relating::RelateExt;
use rustc_type_ir::{
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner,
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner, Ty,
TypeFoldable,
};
use tracing::instrument;
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<I: Interner, T> ResponseT<I> for inspect::State<I, T> {
pub(super) fn canonicalize_goal<D, I>(
delegate: &D,
goal: Goal<I, I::Predicate>,
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
opaque_types: &[(ty::OpaqueTypeKey<I>, Ty<I>)],
) -> (Vec<I::GenericArg>, CanonicalInput<I, I::Predicate>)
where
D: SolverDelegate<Interner = I>,
Expand Down Expand Up @@ -264,7 +264,7 @@ fn register_region_constraints<D, I>(

fn register_new_opaque_types<D, I>(
delegate: &D,
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
opaque_types: &[(ty::OpaqueTypeKey<I>, Ty<I>)],
span: I::Span,
) where
D: SolverDelegate<Interner = I>,
Expand Down
30 changes: 16 additions & 14 deletions compiler/rustc_next_trait_solver/src/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use std::fmt::Debug;
use std::ops::ControlFlow;

use derive_where::derive_where;
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
use rustc_type_ir::inherent::Ty as _;
use rustc_type_ir::inherent::*;
use rustc_type_ir::{
self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, TypeVisitable,
self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, Ty, TypeVisitable,
TypeVisitableExt, TypeVisitor,
};
use tracing::instrument;
Expand Down Expand Up @@ -47,7 +49,7 @@ pub enum Conflict {
pub fn trait_ref_is_knowable<Infcx, I, E>(
infcx: &Infcx,
trait_ref: ty::TraitRef<I>,
mut lazily_normalize_ty: impl FnMut(I::Ty) -> Result<I::Ty, E>,
mut lazily_normalize_ty: impl FnMut(Ty<I>) -> Result<Ty<I>, E>,
) -> Result<Result<(), Conflict>, E>
where
Infcx: InferCtxtLike<Interner = I>,
Expand Down Expand Up @@ -115,14 +117,14 @@ impl From<bool> for IsFirstInputType {

#[derive_where(Debug; I: Interner, T: Debug)]
pub enum OrphanCheckErr<I: Interner, T> {
NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>),
NonLocalInputType(Vec<(Ty<I>, IsFirstInputType)>),
UncoveredTyParams(UncoveredTyParams<I, T>),
}

#[derive_where(Debug; I: Interner, T: Debug)]
pub struct UncoveredTyParams<I: Interner, T> {
pub uncovered: T,
pub local_ty: Option<I::Ty>,
pub local_ty: Option<Ty<I>>,
}

/// Checks whether a trait-ref is potentially implementable by a crate.
Expand Down Expand Up @@ -222,8 +224,8 @@ pub fn orphan_check_trait_ref<Infcx, I, E: Debug>(
infcx: &Infcx,
trait_ref: ty::TraitRef<I>,
in_crate: InCrate,
lazily_normalize_ty: impl FnMut(I::Ty) -> Result<I::Ty, E>,
) -> Result<Result<(), OrphanCheckErr<I, I::Ty>>, E>
lazily_normalize_ty: impl FnMut(Ty<I>) -> Result<Ty<I>, E>,
) -> Result<Result<(), OrphanCheckErr<I, Ty<I>>>, E>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
Expand Down Expand Up @@ -262,14 +264,14 @@ struct OrphanChecker<'a, Infcx, I: Interner, F> {
lazily_normalize_ty: F,
/// Ignore orphan check failures and exclusively search for the first local type.
search_first_local_ty: bool,
non_local_tys: Vec<(I::Ty, IsFirstInputType)>,
non_local_tys: Vec<(Ty<I>, IsFirstInputType)>,
}

impl<'a, Infcx, I, F, E> OrphanChecker<'a, Infcx, I, F>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
F: FnOnce(I::Ty) -> Result<I::Ty, E>,
F: FnOnce(Ty<I>) -> Result<Ty<I>, E>,
{
fn new(infcx: &'a Infcx, in_crate: InCrate, lazily_normalize_ty: F) -> Self {
OrphanChecker {
Expand All @@ -282,12 +284,12 @@ where
}
}

fn found_non_local_ty(&mut self, t: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
fn found_non_local_ty(&mut self, t: Ty<I>) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
self.non_local_tys.push((t, self.in_self_ty.into()));
ControlFlow::Continue(())
}

fn found_uncovered_ty_param(&mut self, ty: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
fn found_uncovered_ty_param(&mut self, ty: Ty<I>) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
if self.search_first_local_ty {
return ControlFlow::Continue(());
}
Expand All @@ -305,23 +307,23 @@ where

enum OrphanCheckEarlyExit<I: Interner, E> {
NormalizationFailure(E),
UncoveredTyParam(I::Ty),
LocalTy(I::Ty),
UncoveredTyParam(Ty<I>),
LocalTy(Ty<I>),
}

impl<'a, Infcx, I, F, E> TypeVisitor<I> for OrphanChecker<'a, Infcx, I, F>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
F: FnMut(I::Ty) -> Result<I::Ty, E>,
F: FnMut(Ty<I>) -> Result<Ty<I>, E>,
{
type Result = ControlFlow<OrphanCheckEarlyExit<I, E>>;

fn visit_region(&mut self, _r: I::Region) -> Self::Result {
ControlFlow::Continue(())
}

fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
fn visit_ty(&mut self, ty: Ty<I>) -> Self::Result {
let ty = self.infcx.shallow_resolve(ty);
let ty = match (self.lazily_normalize_ty)(ty) {
Ok(norm_ty) if norm_ty.is_ty_var() => ty,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_next_trait_solver/src/delegate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::Deref;

use rustc_type_ir::solve::{Certainty, Goal, NoSolution};
use rustc_type_ir::{self as ty, InferCtxtLike, Interner, TypeFoldable};
use rustc_type_ir::{self as ty, InferCtxtLike, Interner, Ty, TypeFoldable};

pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
type Infcx: InferCtxtLike<Interner = Self::Interner>;
Expand Down Expand Up @@ -70,7 +70,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
def_id: <Self::Interner as Interner>::DefId,
args: <Self::Interner as Interner>::GenericArgs,
param_env: <Self::Interner as Interner>::ParamEnv,
hidden_ty: <Self::Interner as Interner>::Ty,
hidden_ty: Ty<Self::Interner>,
goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
);

Expand All @@ -86,8 +86,8 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {

fn is_transmutable(
&self,
src: <Self::Interner as Interner>::Ty,
dst: <Self::Interner as Interner>::Ty,
src: Ty<Self::Interner>,
dst: Ty<Self::Interner>,
assume: <Self::Interner as Interner>::Const,
) -> Result<Certainty, NoSolution>;
}
8 changes: 5 additions & 3 deletions compiler/rustc_next_trait_solver/src/placeholder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use core::panic;

use rustc_type_ir::data_structures::IndexMap;
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
use rustc_type_ir::inherent::Ty as _;
use rustc_type_ir::inherent::*;
use rustc_type_ir::{
self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType,
self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, Ty,
TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
};

Expand Down Expand Up @@ -113,7 +115,7 @@ where
}
}

fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
match t.kind() {
ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), _)
if debruijn.as_usize() + 1
Expand All @@ -130,7 +132,7 @@ where
let universe = self.universe_for(debruijn);
let p = PlaceholderType::new(universe, bound_ty);
self.mapped_types.insert(p, bound_ty);
Ty::new_placeholder(self.cx(), p)
I::Ty::new_placeholder(self.cx(), p)
}
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
_ => t,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_type_ir::data_structures::DelayedMap;
use rustc_type_ir::inherent::*;
use rustc_type_ir::{
self as ty, InferCtxtLike, Interner, TypeFoldable, TypeFolder, TypeSuperFoldable,
self as ty, InferCtxtLike, Interner, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt,
};

Expand All @@ -19,7 +19,7 @@ where
delegate: &'a D,
/// We're able to use a cache here as the folder does not have any
/// mutable state.
cache: DelayedMap<I::Ty, I::Ty>,
cache: DelayedMap<Ty<I>, Ty<I>>,
}

pub fn eager_resolve_vars<D: SolverDelegate, T: TypeFoldable<D::Interner>>(
Expand All @@ -45,7 +45,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for EagerResolv
self.delegate.cx()
}

fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
match t.kind() {
ty::Infer(ty::TyVar(vid)) => {
let resolved = self.delegate.opportunistic_resolve_ty_var(vid);
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use std::cell::Cell;
use std::ops::ControlFlow;

use derive_where::derive_where;
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]
use rustc_type_ir::inherent::Ty as _;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::SolverTraitLangItem;
use rustc_type_ir::search_graph::CandidateHeadUsages;
use rustc_type_ir::solve::Certainty::Maybe;
use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind};
use rustc_type_ir::{
self as ty, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
self as ty, Interner, Ty, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
elaborate,
};
Expand Down Expand Up @@ -46,11 +48,11 @@ where
D: SolverDelegate<Interner = I>,
I: Interner,
{
fn self_ty(self) -> I::Ty;
fn self_ty(self) -> Ty<I>;

fn trait_ref(self, cx: I) -> ty::TraitRef<I>;

fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
fn with_replaced_self_ty(self, cx: I, self_ty: Ty<I>) -> Self;

fn trait_def_id(self, cx: I) -> I::TraitId;

Expand Down Expand Up @@ -683,7 +685,7 @@ where
// hitting another overflow error something. Add a depth parameter needed later.
fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
&mut self,
self_ty: I::Ty,
self_ty: Ty<I>,
goal: Goal<I, G>,
candidates: &mut Vec<Candidate<I>>,
consider_self_bounds: AliasBoundKind,
Expand Down Expand Up @@ -1017,13 +1019,13 @@ where
struct ReplaceOpaque<I: Interner> {
cx: I,
alias_ty: ty::AliasTy<I>,
self_ty: I::Ty,
self_ty: Ty<I>,
}
impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
fn cx(&self) -> I {
self.cx
}
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
fn fold_ty(&mut self, ty: Ty<I>) -> Ty<I> {
if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() {
if alias_ty == self.alias_ty {
return self.self_ty;
Expand Down Expand Up @@ -1280,7 +1282,7 @@ where
ControlFlow::Continue(())
}

fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
fn visit_ty(&mut self, ty: Ty<I>) -> Self::Result {
let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
return ControlFlow::Break(Err(NoSolution));
Expand Down
Loading
Loading