From a2fb2ebc177cc4fa5933e72f3a81791e9b0b0083 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 12 Jun 2024 18:35:51 -0400 Subject: [PATCH] Fix some TODOs --- compiler/rustc_infer/src/infer/mod.rs | 8 +++++++ compiler/rustc_middle/src/ty/context.rs | 8 +++++++ .../src/solve/eval_ctxt/mod.rs | 7 +++--- .../src/solve/normalizes_to/mod.rs | 2 +- compiler/rustc_type_ir/src/infcx.rs | 3 +++ compiler/rustc_type_ir/src/inherent.rs | 22 ++++++++++++++++--- compiler/rustc_type_ir/src/interner.rs | 4 ++-- 7 files changed, 44 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index e95949b92a9..6f40b9f7295 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -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, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ebcb47966eb..849e10a952b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -324,12 +324,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> { } impl<'tcx> rustc_type_ir::inherent::Abi> 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> for hir::Safety { + fn safe() -> Self { + hir::Safety::Safe + } + fn is_safe(self) -> bool { matches!(self, hir::Safety::Safe) } diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs index d35101b29f9..860c580374d 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs @@ -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; @@ -634,7 +635,6 @@ impl, I: Interner> EvalCtxt<'_, Infcx> { } } - /* TODO: /// Is the projection predicate is of the form `exists ::Assoc = T`. /// /// This is the case if the `term` does not occur in any other part of the predicate @@ -685,8 +685,8 @@ impl, 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 { @@ -736,7 +736,6 @@ impl, 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>( diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs index 821e1e76736..50253d81528 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs @@ -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)); diff --git a/compiler/rustc_type_ir/src/infcx.rs b/compiler/rustc_type_ir/src/infcx.rs index 4fb1069ff66..92a717a0d9e 100644 --- a/compiler/rustc_type_ir/src/infcx.rs +++ b/compiler/rustc_type_ir/src/infcx.rs @@ -12,6 +12,9 @@ pub trait InferCtxtLike: Sized { fn universe_of_lt(&self, lt: ty::RegionVid) -> Option; fn universe_of_ct(&self, ct: ty::ConstVid) -> Option; + 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) -> ::Ty; fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> ::Ty; fn opportunistic_resolve_float_var( diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index b2231d14535..3f919d4b876 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -111,7 +111,19 @@ pub trait Ty>: 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), } } } @@ -129,12 +141,16 @@ pub trait Tys>: fn split_inputs_and_output(self) -> (I::FnInputTys, I::Ty); } -pub trait Abi>: Copy + Debug + Hash + Eq + TypeVisitable { +pub trait Abi>: Copy + Debug + Hash + Eq + Relate { + fn rust() -> Self; + /// Whether this ABI is `extern "Rust"`. fn is_rust(self) -> bool; } -pub trait Safety>: Copy + Debug + Hash + Eq + TypeVisitable { +pub trait Safety>: Copy + Debug + Hash + Eq + Relate { + fn safe() -> Self; + fn is_safe(self) -> bool; fn prefix_str(self) -> &'static str; diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index f4f7a6e901c..bcf6c9b1a0e 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -72,8 +72,8 @@ pub trait Interner: + IntoIterator>>; type AllocId: Copy + Debug + Hash + Eq; type Pat: Copy + Debug + Hash + Eq + Debug + Relate; - type Safety: Safety + TypeFoldable + Relate; - type Abi: Abi + TypeFoldable + Relate; + type Safety: Safety; + type Abi: Abi; // Kinds of consts type Const: Const;