Skip to content

Commit

Permalink
Fix some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 12, 2024
1 parent 47974c6 commit 130a0ff
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
}
}

fn root_ty_var(&self, var: TyVid) -> TyVid {
self.root_var(var)
}

fn root_const_var(&self, var: ConstVid) -> ConstVid {
self.root_const_var(var)
}

fn opportunistic_resolve_ty_var(&self, vid: TyVid) -> Ty<'tcx> {
match self.probe_ty_var(vid) {
Ok(ty) => ty,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
}

impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
fn rust() -> Self {
abi::Abi::Rust
}

fn is_rust(self) -> bool {
matches!(self, abi::Abi::Rust)
}
}

impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
fn safe() -> Self {
hir::Safety::Safe
}

fn is_safe(self) -> bool {
matches!(self, hir::Safety::Safe)
}
Expand Down
7 changes: 3 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 @@ -18,6 +18,7 @@ use rustc_span::DUMMY_SP;
use rustc_type_ir::fold::TypeSuperFoldable;
use rustc_type_ir::inherent::*;
use rustc_type_ir::relate::Relate;
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
use rustc_type_ir::{self as ir, CanonicalVarValues, Interner};
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
use std::ops::ControlFlow;
Expand Down Expand Up @@ -634,7 +635,6 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> EvalCtxt<'_, Infcx> {
}
}

/* TODO:
/// Is the projection predicate is of the form `exists<T> <Ty as Trait>::Assoc = T`.
///
/// This is the case if the `term` does not occur in any other part of the predicate
Expand Down Expand Up @@ -685,8 +685,8 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> EvalCtxt<'_, Infcx> {
match t.kind() {
ir::Infer(ir::TyVar(vid)) => {
if let ir::TermKind::Ty(term) = self.term.kind()
&& let Some(term_vid) = term.ty_vid()
&& self.infcx.root_var(vid) == self.infcx.root_var(term_vid)
&& let ir::Infer(ir::TyVar(term_vid)) = term.kind()
&& self.infcx.root_ty_var(vid) == self.infcx.root_ty_var(term_vid)
{
ControlFlow::Break(())
} else {
Expand Down Expand Up @@ -736,7 +736,6 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> EvalCtxt<'_, Infcx> {
goal.predicate.alias.visit_with(&mut visitor).is_continue()
&& goal.param_env.visit_with(&mut visitor).is_continue()
}
*/

#[instrument(level = "trace", skip(self, param_env), ret)]
pub(super) fn eq<T: Relate<I>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
goal: Goal<'tcx, NormalizesTo<'tcx>>,
) -> QueryResult<'tcx> {
self.set_is_normalizes_to_goal();
// debug_assert!(self.term_is_fully_unconstrained(goal)); TODO:
debug_assert!(self.term_is_fully_unconstrained(goal));
let normalize_result = self
.probe(|&result| ProbeKind::TryNormalizeNonRigid { result })
.enter(|this| this.normalize_at_least_one_step(goal));
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_type_ir/src/infcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub trait InferCtxtLike: Sized {
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex>;
fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex>;

fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid;
fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid;

fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> <Self::Interner as Interner>::Ty;
fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> <Self::Interner as Interner>::Ty;
fn opportunistic_resolve_float_var(
Expand Down
22 changes: 19 additions & 3 deletions compiler/rustc_type_ir/src/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ pub trait Ty<I: Interner<Ty = Self>>:
match self.kind() {
ty::FnPtr(sig) => sig,
ty::FnDef(def_id, args) => interner.fn_sig(def_id).instantiate(interner, &args),
_ => todo!("TODO:"),
ty::Error(_) => {
// ignore errors (#54954)
ty::Binder::dummy(ty::FnSig {
inputs_and_output: Default::default(),
c_variadic: false,
safety: I::Safety::safe(),
abi: I::Abi::rust(),
})
}
ty::Closure(..) => panic!(
"to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`",
),
_ => panic!("Ty::fn_sig() called on non-fn type: {:?}", self),
}
}
}
Expand All @@ -129,12 +141,16 @@ pub trait Tys<I: Interner<Tys = Self>>:
fn split_inputs_and_output(self) -> (I::FnInputTys, I::Ty);
}

pub trait Abi<I: Interner<Abi = Self>>: Copy + Debug + Hash + Eq + TypeVisitable<I> {
pub trait Abi<I: Interner<Abi = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
fn rust() -> Self;

/// Whether this ABI is `extern "Rust"`.
fn is_rust(self) -> bool;
}

pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq + TypeVisitable<I> {
pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
fn safe() -> Self;

fn is_safe(self) -> bool;

fn prefix_str(self) -> &'static str;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ pub trait Interner:
+ IntoIterator<Item = ty::Binder<Self, ty::ExistentialPredicate<Self>>>;
type AllocId: Copy + Debug + Hash + Eq;
type Pat: Copy + Debug + Hash + Eq + Debug + Relate<Self>;
type Safety: Safety<Self> + TypeFoldable<Self> + Relate<Self>;
type Abi: Abi<Self> + TypeFoldable<Self> + Relate<Self>;
type Safety: Safety<Self>;
type Abi: Abi<Self>;

// Kinds of consts
type Const: Const<Self>;
Expand Down

0 comments on commit 130a0ff

Please sign in to comment.