Skip to content

Commit

Permalink
CLASSIFY: extract common code
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Jun 2, 2022
1 parent f2d2d98 commit 1db9c22
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions base/src/main/java/org/aya/tyck/pat/PatClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,15 @@ private static void domination(Subst rhsSubst, Reporter reporter, int lhsIx, int
continue;
}
MCT<Term, PatErr> classified;
// The base case of classifying literals together with other patterns is that:
// the `matches` only has two kinds of patterns: bind and literal.
// The base case of classifying literals together with other patterns:
// variable `nonEmpty` only has two kinds of patterns: bind and literal.
// We should put all bind patterns altogether and check overlapping of literals, which avoids
// converting them to constructor forms and preventing possible stack overflow
// (because literal overlapping check is simple).
var hasLit = matches.filter(subPats -> subPats.pats().isNotEmpty() && head(subPats) instanceof Pat.ShapedInt);
var hasBind = matches.filter(subPats -> subPats.pats().isNotEmpty() && head(subPats) instanceof Pat.Bind);
if (hasLit.isNotEmpty() && hasBind.isNotEmpty() && hasLit.size() + hasBind.size() == matches.size()) {
var nonEmpty = matches.filter(subPats -> subPats.pats().isNotEmpty());
var hasLit = nonEmpty.filter(subPats -> head(subPats) instanceof Pat.ShapedInt);
var hasBind = nonEmpty.filter(subPats -> head(subPats) instanceof Pat.Bind);
if (hasLit.isNotEmpty() && hasBind.isNotEmpty() && hasLit.size() + hasBind.size() == nonEmpty.size()) {
// We are in the base case.
var bindsIx = hasBind.map(MCT.SubPats::ix);
// classify all literals
Expand Down

0 comments on commit 1db9c22

Please sign in to comment.