Class PatternCoverageChecker
The algorithm converts a list of patterns into a boolean formula with several variables, then checks whether the formula is satisfiable (that is, whether there is a combination of assignments of boolean values to the variables such that the formula evaluates to true).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classPayload of aSat.Variablethat is an algebraic type.private static classList that removes one particular element from a backing list.private static classIdentifies a point in a nested pattern.private static classPath that is a child of a given parent path. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Map<PatternCoverageChecker.Path, PatternCoverageChecker.DataTypeSlot> (package private) final Sat(package private) final TypeSystem -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePatternCoverageChecker(TypeSystem typeSystem) Creates a PatternCoverageChecker. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddConsTerms(PatternCoverageChecker.Path path, List<Sat.Term> terms, Core.TuplePat tuplePat) booleanisCoveredBy(Core.Pat pat, List<Core.Pat> patList) Returns whether a pattern is covered by a list of patterns.(package private) static booleanisCoveredBy(TypeSystem typeSystem, List<Core.Pat> prevPatList, Core.Pat pat) Returns whether every possible value that could be matched by patternpatwould already have been matched by one or more ofprevPatList.(package private) static booleanisExhaustive(TypeSystem typeSystem, List<Core.Pat> patList) Returns whether a list of patterns covers every possible value.private Core.PatlistToCons(Core.ListPat listPat) Converts a list pattern into a pattern made up of theCONSandNILconstructors of the built-indatatype list.private Core.PatlistToConsRecurse(DataType listDataType, List<Core.Pat> args) private Sat.TermConverts a pattern to a logical term.private voidtoTerm(Core.Pat pat, PatternCoverageChecker.Path path, List<Sat.Term> terms) private Sat.VariabletypeConstructorTerm(PatternCoverageChecker.Path path, String con)
-
Field Details
-
typeSystem
-
sat
-
pathSlots
-
-
Constructor Details
-
PatternCoverageChecker
Creates a PatternCoverageChecker.
-
-
Method Details
-
isCoveredBy
Returns whether every possible value that could be matched by patternpatwould already have been matched by one or more ofprevPatList.For example, the pattern "(1, b: bool)" is covered by "[(1, true), (_, false)]" but not by "[(1, true)]" or "[(_, false)]".
-
isExhaustive
Returns whether a list of patterns covers every possible value. If so, any pattern added to this list would be redundant. -
toTerm
Converts a pattern to a logical term. -
toTerm
-
listToCons
Converts a list pattern into a pattern made up of theCONSandNILconstructors of the built-indatatype list.For example, converts: "[]" to "NIL", "[x]" to "CONS (x, NIL)", "[x, y]" to "CONS (x, CONS (y, NIL))", etc.
-
listToConsRecurse
-
addConsTerms
private void addConsTerms(PatternCoverageChecker.Path path, List<Sat.Term> terms, Core.TuplePat tuplePat) -
typeConstructorTerm
-
isCoveredBy
Returns whether a pattern is covered by a list of patterns.A pattern
patis said to be covered by a list of patternspatListif any possible value would be caught by one of the patterns inpatListbefore reachingpat. Thuspatis said to be redundant in that context, and could be removed without affecting behavior.
-