Commit Graph

2662 Commits (f6279a64b5f8812fed05e8bfeaa9bffcf7b6933f)

Author SHA1 Message Date
Nicolás Ojeda Bär 358a6c1ae8 Rename Unused_argument => Unreachable_argument 2020-07-20 08:31:18 +02:00
Nicolás Ojeda Bär e05f119ea1 Rename Without_principality => Non_principal_labels 2020-07-20 08:31:18 +02:00
Nicolás Ojeda Bär b2606e0f18 Rename Unused_pat => Unused_subpat 2020-07-20 08:31:18 +02:00
Nicolás Ojeda Bär 45d14467cd Rename Unused_match => Unused_case 2020-07-20 08:31:18 +02:00
Nicolás Ojeda Bär fd48548c05 Rename Statement_type => Non_unit_statement 2020-07-20 08:31:18 +02:00
Thomas Refis 4edc4b9928
pattern aliases do not ignore type constraints (#1655) 2020-07-09 12:20:37 +02:00
Thomas Refis 167e66e15d
type_cases: rely on levels to enforce principality (#1931)
Instead of the erasure scheme that was used up to now, where we
considered that the type was always principal.

Note: the erasure still happens when polymorphic variants appear in the
patterns, and the type of the scrutinee contains a Reither.
2020-07-08 10:35:40 +02:00
Jacques Garrigue 46cec117a4
Fix #9721: Injectivity and recursive modules (#9727) 2020-07-07 09:04:23 +02:00
Jacques Garrigue e0ec63ae21
Fix #8747: incorrect principality warning on functional updates of records (#9709) 2020-06-28 23:20:12 +02:00
Leo White 042b1ca737 Fix handling of presence when comparing package types 2020-06-26 14:27:00 +01:00
Leo White b4361282c1 Fix PR#7897 2020-06-26 12:35:35 +01:00
Florian Angeletti 7d3a3f8c24
Merge pull request #9416 from lpw25/fix-warning-58-flambda-ocamlnat
Avoid warning 58 in flambda ocamlnat
2020-06-26 09:37:41 +02:00
Florian Angeletti 1fb6a464a8
Merge pull request #9244 from lpw25/fix-usage-warnings
Fix usage warnings
2020-06-25 18:21:04 +02:00
Florian Angeletti 457304d075
Merge pull request #9673 from xvw/attempt-to-fix-6633
Add Hint when a module is used in place of a module type
2020-06-25 17:00:37 +02:00
Leo White 9e61a063c3 Avoid warning 58 in flambda ocamlnat 2020-06-25 14:45:45 +01:00
Leo White bc8c0d2538 Make the `mark` parameters in `Includemod` non-optional 2020-06-25 11:35:00 +01:00
Leo White 1f9be49f02
Merge pull request #9385 from lpw25/fix-copy-scope-bugs
Fix copy scope bugs
2020-06-25 10:59:59 +01:00
xvw 50848feb10 Add Hint when a module is used in place of a module type
Add hint when a module is used instead of a module type or when a
module type is used instead of a module or when a class type is
used instead of a class.
2020-06-24 14:37:03 +02:00
Jacques Garrigue 95a8fbfd5b change API for Env.open_signature to clarify errors 2020-06-23 16:36:55 +02:00
Jacques Garrigue 6ccab9b9b0 Fix #9695: no error when opening an alias to a missing module 2020-06-23 15:31:45 +02:00
Jacques Garrigue 603506aa34
Add injectivity annotations (#9500) 2020-06-15 13:51:50 +02:00
Jacques Garrigue 24d087325c
Fix #7902: Type-checker infers a recursive type, even though -rectype… (#9556) 2020-06-15 10:26:26 +02:00
Leo White b0e1540ac1 Fix missing unused variables warning with functor application 2020-06-14 08:38:03 +01:00
Leo White 81902098b6 Fix incorrect copy_scopes in Subst 2020-06-14 08:30:33 +01:00
Gabriel Scherer 6ea0fbdddb
Merge pull request #9602 from garrigue/document-variance-flags
add explanation for variance flags
2020-06-10 13:53:03 +02:00
Gabriel Scherer a3b66f1b32 Parmatch.exhaust: single-row optimization
(See testsuite and code comments for an explanation.)
2020-06-07 08:03:57 +02:00
Jacques Garrigue 83ae23d249 comment for module alias + factorize with_type/with_typesubst 2020-06-05 18:17:20 +02:00
Jacques Garrigue 9dc7df741b factorize in merge_constraint 2020-06-05 17:41:06 +02:00
Jacques Garrigue a96a610a95 Fix #9640: regression introduced by #9623 2020-06-05 14:56:51 +02:00
Gabriel Scherer 84c87bb8f1
Merge pull request #9623 from gasche/unboxed-merge-constraint
fix an environment problem in merge_constraint
2020-06-04 13:16:27 +02:00
Jacques Garrigue abb8db459d
Fix #7520: Odd behaviour of refutation cases with polymorphic variants (#9547) 2020-06-03 17:47:12 +02:00
Jacques Garrigue 13a081b04e
Fix #7741: Failure to report escaping type variable (#9545) 2020-06-03 17:31:38 +02:00
Gabriel Scherer 8b2f64c2ce Typemod.merge_constraint: fix computation of the signature environment
(suggested by Leo White and Jacques Garrigue)
2020-06-03 14:33:55 +02:00
Gabriel Scherer 7068266b32 Typemod.merge_constraint: be careful about the typing environments
This PR fixes an old bug in the interaction between [merge_constraint]
and [Typedecl.transl_with_constraint], where
variance (and now separability) are recomputed in an invalid type
environment. See #9624 and the new tests.
2020-06-03 14:33:50 +02:00
David Allsopp ca64723db3 s/@raises/@raise 2020-06-03 10:25:25 +01:00
Nicolás Ojeda Bär 836d62470b
Fix load path ordering (#9611) 2020-06-03 00:10:38 +02:00
Jacques Garrigue ee20f5e648
Fix the polymorphic recursion problem of #9603 (#9617) 2020-06-02 22:05:30 +02:00
Stephen Dolan fd1bb255e1 More partial application warnings 2020-06-02 12:11:41 +01:00
Gabriel Scherer 8e83130a18 compute the same separability signatures in either "(no) flat float" modes
In -no-flat-float-array mode, instead of always returning
`best_msig` (the most permissive signature), we first compute the
flat-float-array separability signature -- falling back to `best_msig`
if it fails.

This discipline is conservative: it never rejects -no-flat-float-array
programs. At the same time it guarantees that, for any program that is
also accepted in -flat-float-array mode, the same separability will be
inferred in the two modes. In particular, the same .cmi files and
digests will be produced.

Before we introduced this hack, the production of different .cmi files
would break the build system of the compiler itself, when trying to
build a -no-flat-float-array system from a bootstrap compiler itself
using -flat-float-array. See #9291.
2020-06-01 12:19:08 +02:00
Gabriel Scherer d8acfa92e4 parmatch: ensure specialized submatrices are in source order
We produce exhaustivity counter-example in the order of the
specialized submatrices. Having submatrices in source order gives the
nice behavior that the clause that would naturally been inserted first
in the source is given first as a counter-example.

Consider for example:

    function
    | true, true -> true
    | false, false -> false

The two counter-examples are (true, false) and (false, true).

Before this patch, (false, true) would be shown first.
After this patch, (true, false) is shown first.
This corresponds to the following natural completion order:

    function
    | true, true -> true
    | true, false -> ?
    | false, false -> false
    | false, true -> ?

On the other hand, the ordering of the default submatrix, with respect
to the specialized submatrices, is not preserved -- it is always
ordered last.
One could intuitively expect the default submatrix to appear in the
position of the first omega row in the source. We tried this, and
it is not a good idea:
- the change is much more invasive as the interface of
  `build_specialized_submatrices` has to change
- the behavior of the result is in fact unpleasant; it is not
  intuitive to order counter-examples in this way.

For example, consider:

    function
    | _, None -> false
    | true, Some true -> false

The two exhaustivity counter-examples are (true, Some false)
and (false, Some _). The second comes from the default submatrix:
morally it is (_, Some _), with "some other constructor missing from
the column" instead of the first _. There is no reason to suppose that
the user would want to place this (_, Some _) or (false, Some _)
counter-example first in the completed code; indeed, this intuition
would suggest writing an exhaustive covering of patterns of the
form (_, foo), inserted after the first clause, but then the other
clauses below become unnecessary!

When an omega patterns appears high in the column like this, it is
usually because there is a very specific matching condition to the
rest of its row, that justifies some shortcutting behavior. The
program is typically *not* completed by adding more specific matching
conditions.
2020-05-30 17:11:54 +02:00
Gabriel Scherer 8f71174eb2 parmatch: make 'exhaust' lazy by returning a Seq.t
This solves exponential-blowup issue with the strict traversal and/or
strict witness computation in cases where an exponential number of
counter-examples is generated. This fixes Stack Overflow and
exponential-time issues on examples using or-patterns heavily,
including one that naturally found its way in real-world user
code (see the following testsuite commit).

We now systematically keep only one counter-example, instead of
letting the type-checker decide whether to discard
counter-examples (in Backtrack_or mode) or to preserve
them (in Refine_or mode).

Note: in the exhaustivity warning, there are sub-messages printed to
indicate that:

- the exhaustivity counter-example is related to an extensible type, or
- that a when-guarded clause does match the counter-example

In both cases the warning is there to explain the counter-example(s)
shown (not a property of all counter-examples); keeping at most one
valid counter-example means that they will be printed less often, but
it is the correct/intended behavior in that case.
2020-05-30 17:10:37 +02:00
Gabriel Scherer ec74335158 typedecl: prevent the mistake of not updating transl_with_constraint 2020-05-27 22:18:06 +02:00
Gabriel Scherer 9b1bfc3b7c typedecl: correct update separability in transl_with_constraint
fixes #9607
2020-05-27 21:32:36 +02:00
Gabriel Scherer e68b75eb82
Merge pull request #9599 from trefis/rematch-complete-constrs
pattern-matching refactoring: refine the type of `complete_constrs`
2020-05-27 09:26:29 +02:00
Gabriel Scherer bf95a24739 Matching: propagate constructor descriptions in complete_pats_constrs
This simplifies this particular interface boundary between Matching
and Parmatch.

(Suggested by Florian Angeletti)
2020-05-26 15:47:41 +02:00
Jacques Garrigue 1bb388bd15
Fix PR#7817: Unsound inclusion check for polymorphic variant (#9546) 2020-05-25 19:12:09 +02:00
Jacques Garrigue 1d270251c3 add explanation for variance flags 2020-05-25 19:04:34 +02:00
Gabriel Scherer 8150e47525
Merge pull request #9563 from trefis/rematch-standalone-patterns
pattern-matching refactoring: move pattern types to a new module typing/Patterns
2020-05-25 17:06:01 +02:00
Gabriel Scherer 1ee6ee4194 fixup! matching: use pattern views in Parmatch as well 2020-05-21 09:51:30 +02:00
octachron 9fe4b963cb import Jacques comment on flatten_fields from the issue tracker 2020-05-18 11:37:40 +02:00
Gabriel Scherer 9ca2a352c8 make check-typo happy 2020-05-16 12:32:49 +02:00
Gabriel Scherer 68dc87c9e9 matching: use pattern views in Parmatch as well 2020-05-14 10:27:50 +02:00
Gabriel Scherer e19a3afcb4 matching: move {general,simple,half_simple}_view to Patterns 2020-05-14 10:27:15 +02:00
Gabriel Scherer 4d6267d3ba matching: move (Non_empty_row, views, General) to patterns.ml 2020-05-14 10:26:01 +02:00
Gabriel Scherer 0e979b7ea9 patterns: reuse ('a Typedtree.pattern_) to define Patterns.Head.t 2020-05-14 10:26:01 +02:00
Gabriel Scherer ffb6caef8b patterns: move Parmatch.Pattern_head into Patterns.Head
The aim is to also move the Simple/Half_simple/General stuff from
matching, but we need to split in those modules the part that are
purely structural (they go in Patterns) and the parts that are
actually compilation logic (Half_simple.of_clause), those stay in
Matching.
2020-05-14 10:11:36 +02:00
Florian Angeletti 3903f9fab5 parmatch: normalize_pat is not used anymore 2020-05-01 21:58:28 +02:00
Leo White 3b42d0ac8e Avoid rechecking functor applications
Take advantage of the existing functor application cache to avoid
repeating checks that a functor application is valid.
2020-04-23 17:02:47 +01:00
Leo White 2a50fef1ae
Merge pull request #9415 from lpw25/fix-open-struct-in-flambda-toplevel
Treat `open struct` as `include struct` in toplevel
2020-04-23 14:00:24 +01:00
Gabriel Scherer 4943a373f3
Merge pull request #9464 from gasche/rematch-exceptionless-matcher
pattern-matching refactoring: simplify `Default_env.specialize_matrix` by avoiding exceptions
2020-04-23 12:18:13 +02:00
Leo White 2ea16f6a8e Treat `open struct` as `include struct` in toplevel 2020-04-23 10:51:44 +01:00
Florian Angeletti c041b0389e env summary: don't record implicit cmi files
We don't want to record the state of the file system at the start
of the compilation in the compiled files.
Consequently, we only add persistent modules to the env summary
if they have an observable action on the initial environment.
This is only the case if they shadow a non-persistent module of the
initially opened library (which can only be Stdlib currently).
2020-04-20 10:13:20 +02:00
Thomas Refis e01966a8b1 illegal commutation: more information in error message 2020-04-18 11:09:32 +02:00
Thomas Refis 384aa215fa optional arguments eliminated only when followed by unlabelled argument 2020-04-18 11:09:32 +02:00
Gabriel Scherer 3306f4a1e4 parmatch: Pattern_head.arity 2020-04-18 11:08:12 +02:00
Thomas Refis ed654dc98f type_application: better variable name 2020-04-18 11:01:52 +02:00
Thomas Refis 1294b28578 Typeclass.type_args rewrite in the same way 2020-04-18 11:01:52 +02:00
Thomas Refis 22657fa622 type_application: better names, some more comments 2020-04-18 11:01:52 +02:00
Thomas Refis 02a7388602 type_application: implement ignored and omitted in the same way 2020-04-18 11:01:52 +02:00
Thomas Refis 21656b259c inline type_unknown_args 2020-04-18 11:01:52 +02:00
Thomas Refis 5e78b177b8 type_unknown_args is a fold 2020-04-18 11:01:52 +02:00
Thomas Refis f444ecde29 type_application: primitives inspection helper 2020-04-18 11:01:52 +02:00
Thomas Refis 9632e02d6a type_args: some comments (and formatting noise) 2020-04-18 11:01:52 +02:00
Thomas Refis 0deda5100c type_args: remove ty_old
This was useful when commuting optional arguments was allowed with
`ignore_labels = true`. Which it isn't anymore.
2020-04-18 11:01:52 +02:00
Thomas Refis 9e0515f554 type_args: forbid optional arguments commuting when [ignore_labels=true] 2020-04-18 11:01:52 +02:00
Thomas Refis aa5c1d37f6 typeclass: further simplification as suggested by reviewer 2020-04-18 11:01:52 +02:00
Thomas Refis b703371d7d extract_label: return an option instead of raising 2020-04-18 11:01:52 +02:00
Thomas Refis 6d43867011 apply the same treatment to Pcl_apply 2020-04-18 11:01:52 +02:00
Thomas Refis 2b1e211df9 type_application: merge sargs and more_sargs 2020-04-18 11:01:52 +02:00
Leo White a40889d6d9
Merge pull request #9393 from lpw25/improve-recmodule-usage-warnings
Improve recursive module usage warnings
2020-04-18 09:11:22 +01:00
Leo White a8987e7a4f
Merge pull request #9388 from lpw25/no-siglocal-type-constraints
Prohibit signature local types with constraints
2020-04-18 09:10:13 +01:00
Leo White 5f16c55316 Improve usage warnings for recursive modules 2020-04-18 08:08:54 +01:00
Leo White 80324bae54 Make substitution of type functions more robust 2020-04-18 08:02:02 +01:00
Leo White 8dcdda9674 Prohibit signature local types with constraints 2020-04-18 07:54:12 +01:00
octachron 35dbd85b3e packed modtype lookup can fail due to missing cmi
This commit removes an assert false and makes the missing
cmi case behaves like the abstract case.
2020-04-17 11:22:38 +02:00
Jacques Garrigue d67c704c4d
In `{expr with ...}`, always evaluate `expr` even if all labels are redefined (#9432)
This commit reverts c1a7ace (originally c545e04), which was a
temporary fix that is no longer needed because it was superseded by
#6608.

The temporary fix caused `{expr with lbl1 = e1; ... }` to not evaluate
`expr` if all labels of its type are overriden.  As reported in #7696
this is not desirable.  Reverting the temporary fix causes `expr` to
be evaluated always.

As a consequence, a corner case of value "let rec" is no longer accepted.
The corresponding test was updated.

Closes: #7696
2020-04-08 18:58:43 +02:00
octachron 4f9f41e73a disambiguation for extension constructors
This commit exposes all extension constructors when looking up for
a construction with a given type in the environment.

This makes constructor disambiguation work for extension constructors.

Going one step further, when the name of an extension constructors
is misspelled, we cannot rely on the type to find all possible
names. However, since we are in an error path, we have some
path at hand.
Thus, this commit alters the "lookup_from_type" function in the
Constructor module to make it scan the whole environment for
extension constructors with the right type.

This commit should not change anything for labels and standard constructors.
2020-04-03 16:05:23 +02:00
muskangarg21 52dc5d793b [Refactor]: Typing/typeclass.ml 2020-03-24 04:33:45 +05:30
Nicolás Ojeda Bär 57d329e07b
Deprecate -annot (#2141)
* Move driver code from Cmt2annot to Read_cmt
* Move cmt2annot.ml into typing/
* make depend
* Use standard error handling
* Move specific logic to read_cmt
* Do not pass full cmt record as argument
* Better locations
* Emit .annot files produced from cmt data
* Remove direct calls to Stypes
* Deprecate -annot
* Changes
* make depend
* Adapt doc
* make -C tools depend
2020-03-13 12:59:34 +01:00
Thomas Refis abeaef92fb
Merge pull request #9322 from trefis/rematch-structured-rows
[matching.ml cleanup] structured rows
2020-03-10 17:02:14 +01:00
Thomas Refis 9504ede328 parmatch: export Pattern_head 2020-03-10 12:08:39 +01:00
Gabriel Scherer 0fff7a43c5
Merge pull request #9196 from gasche/clarify-disambiguation-3
disambiguation: improve the interface of `NameChoice.disambiguate`
2020-03-09 13:39:32 +01:00
Gabriel Scherer bf6c8d4b95 disambiguation: improve the API of NameChoice.disambiguate 2020-03-07 14:35:05 +01:00
Thomas Refis c323d11144
Merge pull request #8934 from trefis/usage
Stop relying on location to track usage
2020-03-06 16:49:44 +01:00
Florian Angeletti b82d5194c2
Merge pull request #9343 from lpw25/fix-short-paths-environments
Re-enable `-short-paths` for some error messages
2020-03-06 09:38:40 +01:00
Thomas Refis bea2d04582
build_subtype: assert arrow type is known (#9348)
`build_subtype` is invoked only through `enlarge_type` when typechecking Pexp_coerce.

The type passed to `build_subtype` can only have `Cok` arrows because:
- the base type is the direct result of `Typetexp.transl_simple_type_delayed` which only introduces `Cok` arrows
- the other source of arrows could be the result of unification; however at this point the type variables are fresh, they have not been unified with any existing types.

Adding this assertion ensures that this property won't be broken by accident.
2020-03-05 16:18:59 +01:00
Thomas Refis b67779b45e add forgotten word in comment 2020-03-05 14:54:21 +01:00
Thomas Refis 0a09add592
printtyp: inline a function call (#9347) 2020-03-05 14:21:35 +01:00
Thomas Refis 86b33bc450 Uid.reinit 2020-03-05 14:20:04 +01:00
Thomas Refis 3fe25383ba Types.Uid: include Identifiable 2020-03-05 13:36:11 +01:00