Module Ocaml_typing.Parmatch
Detection of partial matches and unused match cases.
type 'pattern parmatch_case = {pattern : 'pattern;has_guard : bool;needs_refute : bool;(*true if the program text claims the case is unreachable, a la
*)function _ -> .
}Most checks in this file need not access all information about a case, and just need a few pieces of information. parmatch_case is those few pieces of information.
type 'category typed_case :=
'category Ocaml_typing.Typedtree.general_pattern
Ocaml_typing.Parmatch.parmatch_caseval typed_case :
'category Ocaml_typing.Typedtree.case ->
'category Ocaml_typing.Parmatch.typed_caseval untyped_case :
Ocaml_parsing.Parsetree.case ->
Ocaml_parsing.Parsetree.pattern Ocaml_typing.Parmatch.parmatch_caseval const_compare :
Ocaml_typing.Typedtree.constant ->
Ocaml_typing.Typedtree.constant ->
intconst_compare c1 c2 compares the actual values represented by c1 and c2, while simply using Stdlib.compare would compare the representations.
cf. MPR#5758
val le_pat :
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Typedtree.pattern ->
boolle_pat p q means: forall V, V matches q implies V matches p
val le_pats :
Ocaml_typing.Typedtree.pattern list ->
Ocaml_typing.Typedtree.pattern list ->
boolle_pats (p1 .. pm) (q1 .. qn) means: forall i <= m, le_pat pi qi
Exported compatibility functor, abstracted over constructor equality
val lub :
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Typedtree.patternlub p q is a pattern that matches all values matched by p and q. May raise Empty, when p and q are not compatible.
val lubs :
Ocaml_typing.Typedtree.pattern list ->
Ocaml_typing.Typedtree.pattern list ->
Ocaml_typing.Typedtree.pattern listlubs [p1; ...; pn] [q1; ...; qk], where n < k, is [lub p1 q1; ...; lub pk qk].
val set_args :
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Typedtree.pattern list ->
Ocaml_typing.Typedtree.pattern listThose two functions recombine one pattern and its arguments: For instance: (_,_)::p1::p2::rem -> (p1, p2)::rem The second one will replace mutable arguments by '_'
val set_args_erase_mutable :
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Typedtree.pattern list ->
Ocaml_typing.Typedtree.pattern listval pat_of_constr :
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Types.constructor_description ->
Ocaml_typing.Typedtree.patternval complete_constrs :
Ocaml_typing.Types.constructor_description
Ocaml_typing.Typedtree.pattern_data ->
Ocaml_typing.Types.constructor_description list ->
Ocaml_typing.Types.constructor_description listval pats_of_type :
Ocaml_typing.Env.t ->
Ocaml_typing.Types.type_expr ->
Ocaml_typing.Typedtree.pattern listpats_of_type builds a list of patterns from a given expected type, for explosion of wildcard patterns in Typecore.type_pat.
There are four interesting cases:
- the type is empty ()
- no further explosion is necessary (
Pat_any) - a single pattern is generated, from a record or tuple type or a single-variant type (
tp) - a list of patterns, in the case that all branches are GADT constructors (
tp1; ..; tpn).
val pressure_variants :
Ocaml_typing.Env.t ->
Ocaml_typing.Typedtree.pattern list ->
unitval pressure_variants_in_computation_pattern :
Ocaml_typing.Env.t ->
Ocaml_typing.Typedtree.computation Ocaml_typing.Typedtree.general_pattern
list ->
unitval check_partial :
(Ocaml_typing.Typedtree.pattern -> Ocaml_typing.Typedtree.pattern option) ->
Ocaml_parsing.Location.t ->
Ocaml_typing.Typedtree.value Ocaml_typing.Parmatch.typed_case list ->
Ocaml_typing.Typedtree.partialcheck_partial pred loc caselist and check_unused refute pred caselist are called with a function pred which will be given counter-example candidates: they may be partially ill-typed, and have to be type-checked to extract a valid counter-example. pred returns a valid counter-example or None. refute indicates that check_unused was called on a refutation clause.
val check_unused :
(bool ->
Ocaml_typing.Typedtree.pattern ->
Ocaml_typing.Typedtree.pattern option) ->
Ocaml_typing.Typedtree.value Ocaml_typing.Parmatch.typed_case list ->
unitval irrefutable : Ocaml_typing.Typedtree.pattern -> boolval inactive :
partial:Ocaml_typing.Typedtree.partial ->
Ocaml_typing.Typedtree.pattern ->
boolAn inactive pattern is a pattern, matching against which can be duplicated, erased or delayed without change in observable behavior of the program. Patterns containing (lazy _) subpatterns or reads of mutable fields are active.
val check_ambiguous_bindings :
Ocaml_typing.Typedtree.value Ocaml_typing.Typedtree.case list ->
unitval some_private_tag : Ocaml_parsing.Asttypes.labelval complete_partial :
pred:
(Ocaml_typing.Typedtree.pattern -> Ocaml_typing.Typedtree.pattern option) ->
Ocaml_typing.Typedtree.pattern list list ->
Ocaml_typing.Typedtree.pattern listval return_unused :
Ocaml_typing.Typedtree.pattern list ->
[ `Unused of Ocaml_typing.Typedtree.pattern
| `Unused_subs of
Ocaml_typing.Typedtree.pattern * Ocaml_typing.Typedtree.pattern list ]
list