1
Fork 0

Improve debugging experience

This commit is contained in:
Nadrieril 2024-03-29 19:40:54 +01:00
parent 204805a092
commit 8cf2c0dc67
3 changed files with 10 additions and 7 deletions

View file

@ -974,7 +974,6 @@ impl<Cx: PatCx> ConstructorSet<Cx> {
/// any) are missing; 2/ split constructors to handle non-trivial intersections e.g. on ranges /// any) are missing; 2/ split constructors to handle non-trivial intersections e.g. on ranges
/// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation /// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation
/// and its invariants. /// and its invariants.
#[instrument(level = "debug", skip(self, ctors), ret)]
pub fn split<'a>( pub fn split<'a>(
&self, &self,
ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone, ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone,

View file

@ -186,7 +186,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
/// Returns the types of the fields for a given constructor. The result must have a length of /// Returns the types of the fields for a given constructor. The result must have a length of
/// `ctor.arity()`. /// `ctor.arity()`.
#[instrument(level = "trace", skip(self))]
pub(crate) fn ctor_sub_tys<'a>( pub(crate) fn ctor_sub_tys<'a>(
&'a self, &'a self,
ctor: &'a Constructor<'p, 'tcx>, ctor: &'a Constructor<'p, 'tcx>,
@ -283,7 +282,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
/// Creates a set that represents all the constructors of `ty`. /// Creates a set that represents all the constructors of `ty`.
/// ///
/// See [`crate::constructor`] for considerations of emptiness. /// See [`crate::constructor`] for considerations of emptiness.
#[instrument(level = "debug", skip(self), ret)]
pub fn ctors_for_ty( pub fn ctors_for_ty(
&self, &self,
ty: RevealedTy<'tcx>, ty: RevealedTy<'tcx>,

View file

@ -871,12 +871,14 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
where where
Cx: 'a, Cx: 'a,
{ {
debug!(?self.ty);
if self.private_uninhabited { if self.private_uninhabited {
// Skip the whole column // Skip the whole column
return Ok((smallvec![Constructor::PrivateUninhabited], vec![])); return Ok((smallvec![Constructor::PrivateUninhabited], vec![]));
} }
let ctors_for_ty = cx.ctors_for_ty(&self.ty)?; let ctors_for_ty = cx.ctors_for_ty(&self.ty)?;
debug!(?ctors_for_ty);
// We treat match scrutinees of type `!` or `EmptyEnum` differently. // We treat match scrutinees of type `!` or `EmptyEnum` differently.
let is_toplevel_exception = let is_toplevel_exception =
@ -895,6 +897,7 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
// Analyze the constructors present in this column. // Analyze the constructors present in this column.
let mut split_set = ctors_for_ty.split(ctors); let mut split_set = ctors_for_ty.split(ctors);
debug!(?split_set);
let all_missing = split_set.present.is_empty(); let all_missing = split_set.present.is_empty();
// Build the set of constructors we will specialize with. It must cover the whole type, so // Build the set of constructors we will specialize with. It must cover the whole type, so
@ -1254,7 +1257,7 @@ impl<'p, Cx: PatCx> Matrix<'p, Cx> {
/// + true + [Second(true)] + /// + true + [Second(true)] +
/// + false + [_] + /// + false + [_] +
/// + _ + [_, _, tail @ ..] + /// + _ + [_, _, tail @ ..] +
/// | ✓ | ? | // column validity /// | ✓ | ? | // validity
/// ``` /// ```
impl<'p, Cx: PatCx> fmt::Debug for Matrix<'p, Cx> { impl<'p, Cx: PatCx> fmt::Debug for Matrix<'p, Cx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -1285,7 +1288,7 @@ impl<'p, Cx: PatCx> fmt::Debug for Matrix<'p, Cx> {
write!(f, " {sep}")?; write!(f, " {sep}")?;
} }
if is_validity_row { if is_validity_row {
write!(f, " // column validity")?; write!(f, " // validity")?;
} }
write!(f, "\n")?; write!(f, "\n")?;
} }
@ -1617,7 +1620,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: PatCx>(
}; };
// Analyze the constructors present in this column. // Analyze the constructors present in this column.
debug!("ty: {:?}", place.ty);
let ctors = matrix.heads().map(|p| p.ctor()); let ctors = matrix.heads().map(|p| p.ctor());
let (split_ctors, missing_ctors) = place.split_column_ctors(mcx.tycx, ctors)?; let (split_ctors, missing_ctors) = place.split_column_ctors(mcx.tycx, ctors)?;
@ -1669,7 +1671,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: PatCx>(
for row in matrix.rows() { for row in matrix.rows() {
if row.useful { if row.useful {
if let PatOrWild::Pat(pat) = row.head() { if let PatOrWild::Pat(pat) = row.head() {
mcx.useful_subpatterns.insert(pat.uid); let newly_useful = mcx.useful_subpatterns.insert(pat.uid);
if newly_useful {
debug!("newly useful: {pat:?}");
}
} }
} }
} }
@ -1768,6 +1773,7 @@ pub fn compute_match_usefulness<'p, Cx: PatCx>(
.map(|arm| { .map(|arm| {
debug!(?arm); debug!(?arm);
let usefulness = collect_pattern_usefulness(&cx.useful_subpatterns, arm.pat); let usefulness = collect_pattern_usefulness(&cx.useful_subpatterns, arm.pat);
debug!(?usefulness);
(arm, usefulness) (arm, usefulness)
}) })
.collect(); .collect();