-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce trait DebugWithInfcx
to debug format types with universe info
#112984
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,39 @@ pub struct InferCtxt<'tcx> { | |
next_trait_solver: bool, | ||
} | ||
|
||
impl<'tcx> ty::InferCtxtLike<TyCtxt<'tcx>> for InferCtxt<'tcx> { | ||
fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex> { | ||
use InferTy::*; | ||
match ty { | ||
// FIXME(BoxyUwU): this is kind of jank and means that printing unresolved | ||
// ty infers will give you the universe of the var it resolved to not the universe | ||
// it actually had. It also means that if you have a `?0.1` and infer it to `u8` then | ||
// try to print out `?0.1` it will just print `?0`. | ||
TyVar(ty_vid) => match self.probe_ty_var(ty_vid) { | ||
Err(universe) => Some(universe), | ||
Ok(_) => None, | ||
}, | ||
IntVar(_) | FloatVar(_) | FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_) => None, | ||
} | ||
} | ||
|
||
fn universe_of_ct(&self, ct: ty::InferConst<'tcx>) -> Option<ty::UniverseIndex> { | ||
use ty::InferConst::*; | ||
match ct { | ||
// Same issue as with `universe_of_ty` | ||
Var(ct_vid) => match self.probe_const_var(ct_vid) { | ||
Err(universe) => Some(universe), | ||
Ok(_) => None, | ||
}, | ||
Fresh(_) => None, | ||
} | ||
} | ||
|
||
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> { | ||
Some(self.universe_of_region_vid(lt)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lmao if only we stored the universe not in the eq relation table for ty/ct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably perf-negative but I'd like to see it tested, perhaps as a follow-up by someone who's interested in contributing. |
||
} | ||
} | ||
|
||
/// See the `error_reporting` module for more details. | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)] | ||
pub enum ValuePairs<'tcx> { | ||
|
@@ -1068,6 +1101,11 @@ impl<'tcx> InferCtxt<'tcx> { | |
self.inner.borrow_mut().unwrap_region_constraints().universe(r) | ||
} | ||
|
||
/// Return the universe that the region variable `r` was created in. | ||
pub fn universe_of_region_vid(&self, vid: ty::RegionVid) -> ty::UniverseIndex { | ||
self.inner.borrow_mut().unwrap_region_constraints().var_universe(vid) | ||
} | ||
|
||
/// Number of region variables created so far. | ||
pub fn num_region_vars(&self) -> usize { | ||
self.inner.borrow_mut().unwrap_region_constraints().num_region_vars() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::arena::Arena; | ||
use rustc_data_structures::aligned::{align_of, Aligned}; | ||
use rustc_serialize::{Encodable, Encoder}; | ||
use rustc_type_ir::{InferCtxtLike, OptWithInfcx}; | ||
use std::alloc::Layout; | ||
use std::cmp::Ordering; | ||
use std::fmt; | ||
|
@@ -119,6 +120,14 @@ impl<T: fmt::Debug> fmt::Debug for List<T> { | |
(**self).fmt(f) | ||
} | ||
} | ||
impl<'tcx, T: super::DebugWithInfcx<TyCtxt<'tcx>>> super::DebugWithInfcx<TyCtxt<'tcx>> for List<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ideally, if we found some new contributor, it would be cool if we could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I would love to see a |
||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>( | ||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>, | ||
f: &mut core::fmt::Formatter<'_>, | ||
) -> core::fmt::Result { | ||
fmt::Debug::fmt(&this.map(|this| this.as_slice()), f) | ||
} | ||
} | ||
|
||
impl<S: Encoder, T: Encodable<S>> Encodable<S> for List<T> { | ||
#[inline] | ||
|
@@ -202,6 +211,8 @@ unsafe impl<T: Sync> Sync for List<T> {} | |
// We need this since `List` uses extern type `OpaqueListContents`. | ||
#[cfg(parallel_compiler)] | ||
use rustc_data_structures::sync::DynSync; | ||
|
||
use super::TyCtxt; | ||
#[cfg(parallel_compiler)] | ||
unsafe impl<T: DynSync> DynSync for List<T> {} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow yeah that's jank. The way regions does it is so much better.