1
Fork 0

Log the output of is_useful in the or-pattern case too

This commit is contained in:
Nadrieril 2020-12-17 00:47:31 +00:00
parent 7009d20290
commit 170fae2c18

View file

@ -904,8 +904,14 @@ fn is_useful<'p, 'tcx>(
assert!(rows.iter().all(|r| r.len() == v.len())); assert!(rows.iter().all(|r| r.len() == v.len()));
// FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).
let ty = matrix.heads().next().map(|r| r.ty).unwrap_or(v.head().ty);
let pcx = PatCtxt { cx, matrix, ty, span: v.head().span, is_top_level };
debug!("is_useful_expand_first_col: ty={:#?}, expanding {:#?}", pcx.ty, v.head());
// If the first pattern is an or-pattern, expand it. // If the first pattern is an or-pattern, expand it.
if let Some(vs) = v.expand_or_pat() { let ret = if let Some(vs) = v.expand_or_pat() {
// We expand the or pattern, trying each of its branches in turn and keeping careful track // We expand the or pattern, trying each of its branches in turn and keeping careful track
// of possible unreachable sub-branches. // of possible unreachable sub-branches.
let mut matrix = matrix.clone(); let mut matrix = matrix.clone();
@ -920,30 +926,30 @@ fn is_useful<'p, 'tcx>(
} }
(u, span) (u, span)
}); });
return Usefulness::merge(usefulnesses, v.len()); Usefulness::merge(usefulnesses, v.len())
} } else {
v.head_ctor(cx)
// FIXME(Nadrieril): Hack to work around type normalization issues (see #72476). .split(pcx, Some(hir_id))
let ty = matrix.heads().next().map(|r| r.ty).unwrap_or(v.head().ty); .into_iter()
let pcx = PatCtxt { cx, matrix, ty, span: v.head().span, is_top_level }; .map(|ctor| {
// We cache the result of `Fields::wildcards` because it is used a lot.
debug!("is_useful_expand_first_col: ty={:#?}, expanding {:#?}", pcx.ty, v.head()); let ctor_wild_subpatterns = Fields::wildcards(pcx, &ctor);
let matrix = pcx.matrix.specialize_constructor(pcx, &ctor, &ctor_wild_subpatterns);
let ret = v let v = v.pop_head_constructor(&ctor_wild_subpatterns);
.head_ctor(cx) let usefulness = is_useful(
.split(pcx, Some(hir_id)) pcx.cx,
.into_iter() &matrix,
.map(|ctor| { &v,
// We cache the result of `Fields::wildcards` because it is used a lot. witness_preference,
let ctor_wild_subpatterns = Fields::wildcards(pcx, &ctor); hir_id,
let matrix = pcx.matrix.specialize_constructor(pcx, &ctor, &ctor_wild_subpatterns); is_under_guard,
let v = v.pop_head_constructor(&ctor_wild_subpatterns); false,
let usefulness = );
is_useful(pcx.cx, &matrix, &v, witness_preference, hir_id, is_under_guard, false); usefulness.apply_constructor(pcx, &ctor, &ctor_wild_subpatterns)
usefulness.apply_constructor(pcx, &ctor, &ctor_wild_subpatterns) })
}) .find(|result| result.is_useful())
.find(|result| result.is_useful()) .unwrap_or(NotUseful)
.unwrap_or(NotUseful); };
debug!("is_useful::returns({:#?}, {:#?}) = {:?}", matrix, v, ret); debug!("is_useful::returns({:#?}, {:#?}) = {:?}", matrix, v, ret);
ret ret
} }