Commit Graph

159 Commits (master)

Author SHA1 Message Date
Leandro Ostera 5278e3fe37
Fix typo checks 2020-11-06 23:49:19 +01:00
Leandro Ostera f4143fd372
Document Typedtree.implementation 2020-11-06 18:25:20 +01:00
Leandro Ostera 1b085d3840
Rename Typedtree.t to Typedtree.implementation 2020-11-05 21:19:44 +01:00
Leandro Ostera ee2f3b428c
Move typed_impl to Typedtree.t 2020-11-05 19:06:12 +01:00
Thomas Refis c7f9c8e559 pat_env: I must not tell lies 2020-10-07 15:54:23 +02:00
Jacques Garrigue 603506aa34
Add injectivity annotations (#9500) 2020-06-15 13:51:50 +02:00
Thomas Refis 9fb4b05f4b typedtree.mli: un-open Types 2020-03-05 13:34:12 +01:00
Gabriel Scherer e7c681d14d typedtree: make the pat_desc field of patterns immutable 2019-11-07 14:41:59 +01:00
Gabriel Scherer 8b59222d01 typedtree: make the Tpat_value argument a private synonym
This prevents users from mistakenly constructing a Tpat_value pattern
using the natural implementation

    { pat with pat_desc = Tpat_value pat }

which breaks the attributes-placement invariant (the attributes are
duplicated with this version, instead of being placed only on the
value pattern, with empty attributes on the computation pattern).

(Suggestion from Jacques Garrigue.)
2019-10-31 13:29:28 +01:00
Gabriel Scherer dec6513105 Enforce a structure invariant in [Tpat_value p] patterns
pat_attributes and pat_extra nodes should be on the inner value
pattern, rather than on the outer computation pattern, so that a user
looking for a specific value-pattern constructor with a specific
attribute does not need to consider the Tpat_value case specifically.

(Thanks to Alain Frisch for this suggestion.)
2019-10-31 13:29:16 +01:00
Gabriel Scherer 312253ce82 split patterns into "value patterns" and "computation patterns"
Value patterns match on a value (the result of computation), while
computation patterns handle the effects (hint hint) of
a computation. The only forms of computation patterns in OCaml today
are value patterns and exception patterns (exception p).

The sub-pattern `p` of the `lazy p` construction should be
a computation pattern, rather than a value pattern. This pull-request
does not make this change.

Most of the changes in this PR are boilerplate -- it really is a lot
of work now to add a new syntactic category to the typed-tree
syntax. This boilerplate is fairly automatic and should be easy to
review.

There is a subtle part to the patch, though: the implementation of the
pattern type-checking. It now has to reconstruct the value/computation
distinction (absent from the parse-tree), and return values from two
different types. Instead of splitting the type-checker in several
functions (which risked code duplications), I choose to use a GADT to
have the same [type_pat] function return two different types depending
on the caller. This is the least invasive way to adapt this part of
the codebase, whose inherent complexity is so large (unfortunately)
that adding a GADT to the mix barely makes a difference.
2019-10-31 13:29:16 +01:00
Thomas Refis 8e928caea7
a better representation for modules with no name (#8908) 2019-10-09 14:15:37 +01:00
Gabriel Scherer 0f9ad95c46 [minor] clarify the implementation of Typedtree.pat_bound_idents_full
The previous implementation used global state and was making another
change more difficult than it had to be.

Note: I got rid of `rev_let_bound_idents` in the API because computing
it is no more efficient than `Fun.compose List.rev let_bound_idents`.

(Only the _full versions might have a more-efficient rev_ version,
and those are not exposed, which is the right choice:
                           a simpler API is worth a list reversal.)
2019-09-25 11:47:24 +02:00
Gabriel Scherer 7b10a26bc8 refactor the generic pattern traversal functions 2019-09-24 21:20:10 +02:00
Leo White 403003cad5 Add support for "let" operators 2018-11-27 13:30:55 +00:00
Runhang Li 97329f30ed Extend `open` to arbritrary module expressions in structures and to
applicative module paths in signatures
2018-11-26 16:20:37 +00:00
Alain Frisch 7a746deed1
Keep more type information in Lambda (#2156)
* Propagate type information about function parameters and return

* Keep value kind on staticcatch parameters
2018-11-23 15:34:05 +01:00
Leo White 111d4e1827 Remove positions from paths 2018-11-21 03:39:34 -05:00
Thomas Refis 6805595f57 introduce local substitutions in signatures
type [params] id := type_expr { and [params] id := type_expr }
    module Uid := extended-module-path
2018-11-09 16:43:43 +00:00
Gabriel Scherer e348103ab8 parsetree.{row,object}_field: move attributes in the wrapper record
The concrete syntax only allows attributes on tags/constructors/fields
(Rtag, Otag), not on inherited subtypes (Rinherit, Oinherit); we add
this as new enforced invariant in ast_invariants.
2018-08-20 19:57:47 +02:00
Gabriel Scherer 85785b173a parsetree: make sure that all nodes that store attributes also store a location
Florian Angeletti and myself ran into a problem when trying to use attributes
for ellision of parts of manual example. We wanted to be turn any ast-node
marked with the [@ellipsis] attribute into "..." in the rendering of the
corresponding code block, but for this we need the location of the
attributed node, and it turns out that some constructions supported
attributes without carrying a location:
- Rtag in row_field
- Otag in object_field
- type_exception record
- type_extension record

We added locations in all those positions, guaranteeing the invariant
that all nodes to which attributes can be attached have a precise
position.
2018-08-20 19:57:47 +02:00
Thomas Refis 369ea5f432 allow exceptions under or-patterns 2018-07-16 10:41:55 +01:00
Nicolás Ojeda Bär 0d6569fa1e Remove pv_name field 2018-06-07 16:11:47 +02:00
Thomas Refis f572baccd5 typedtree: export pat_bound_idents_with_loc 2018-06-05 11:59:22 +01:00
Hugo Heuzard 002815c4bb allow to attach @@ attributes on exceptions 2018-04-09 22:29:46 +01:00
octachron e30e82a219 PR#7363: start documentation headers at {1 2017-10-04 13:05:05 +02:00
Fourchaux 72cfdd56e9 Typos and basic grammar error fixing (#1280) 2017-08-10 11:59:23 +01:00
Runhang Li c39b975d43 merge trunk and update test 2017-07-23 09:31:58 +08:00
Alain Frisch fd47ba9649 Support 'let open' in class and class type expressions (#1249)
* Support 'let open' in class and class type expressions.

* Adapt ocamlprof.

* Adapt ocamldoc.

* Add tests.

* Changelog.

* Manual.
2017-07-20 08:17:30 +02:00
Mark Li 9dc86f8417
Support inherited field in object type expression.
Also add location on object field label and polymorphic variant tags.
2017-03-22 21:47:34 -07:00
Mark Shinwell 2da2fcdb66 Annotate Texp_function with an Ident.t for the parameter (#831) 2016-10-14 09:34:50 +01:00
Pierre Chambart 316756fc56 Update Texp_record documentation 2016-07-11 17:26:17 +02:00
Pierre Chambart 24f947e95d Change Texp_record into an inline record 2016-07-11 16:51:20 +02:00
Pierre Chambart c2e66f0097 Switch declaration and definition order in Tepx_record fields 2016-07-11 16:51:20 +02:00
Pierre Chambart 6f010f987c Merge record label descriptions and definition into a single array 2016-07-11 16:51:20 +02:00
Pierre Chambart 3f00684169 Change Texp_record contents to ease the use
It also allows to recover the type of kept fields in a
{ record with field = expr } expression
2016-07-11 16:50:36 +02:00
Sébastien Hinderer 50147913ac Call the '#' sign hash rather than sharp. 2016-05-09 16:34:40 +02:00
octachron 96806cf633 GPR#187: local open for patterns
This commits extends the pattern syntax to support local open in
patterns. Four new constructions mirroring the expression constructions
are added

    * `M.(pattern)`
    * `M.[pattern_list]` ⟺ M.([pattern_list])
    * `M.{labeled_pattern_list}` ⟺ M.({label_pattern_list})
    * `M.[| .. |] ⟺ M.( [| .. |] )

At the typing phase, the construction `M.(pattern)` brings all
identifiers defined within M inside the scope and then proceed with the
typing of `pattern`. All others constructions are desugared to the
`M.(..)` construction during parsing.

Questionable implementation details:
* Currently, the local pattern open use the `type_open` function like
the local expression pattern. However, this implies that values defined
inside `M` are also brought to the scope. A specialized
`type_open_for_pattern` would be more efficient.
2016-05-09 09:35:05 -04:00
alainfrisch 43f90e9f58 Local let exceptions. 2016-03-15 22:02:55 +01:00
Damien Doligez 5401ce8473 Update headers for the new license.
Remains to be done: remove all headers in testsuite/tests.
2016-02-18 16:59:16 +01:00
Damien Doligez ee8f71101b clean up whitespace and cut long lines 2016-02-17 13:36:27 +01:00
Gabriel Scherer d071da2880 Revert GPR#305 (exception patterns under or-patterns) from trunk
This week we merged several changes from Thomas Refis, to allow the
use of exception patterns under or-patterns, to write code such as

  match foo x with
    | None | exception Not_found -> ...
    | Some -> ...

Unfortunately, I failed to properly assess the impact of this change,
and in particular to make sure that Luc Maranget had properly reviewed
this code -- any change to the pattern-matching machinery should be
reviewed by Luc.

The problem that I had not foreseen and that he would have immediately
realized is that, while adapting the pattern-matching *compiler* is
relatively easy (Thomas inserted a transformation at the right place
to separate exception patterns from the others and handle them
separately, using the staticraise construct used by the
pattern-matching compiler to avoid duplicating the
right-hand-side branch), adapting the pattern-matching warnings
machinery is both more subtle and easier to overlook (it may fail
silently and nobody notices, unlike wrong code production). This part
of the compiler is subtle and best understood by Luc, but he does not
have the time to do a proper review of those changes in the timeframe
for the 4.03 feature freeze (mid-December).

I believe the right move in this case, implemented in the present
commit, is to revert the change from trunk (this is not a feature that
we must *imperatively* have in 4.03), do a proper job of understanding
the changes, and integrate the change when we are confident it is
ready. I hope to do this in 2016, together with Luc Maranget and
Thomas Refis -- hopefully this would allow Thomas and I to be more
confident when changing the pattern-matching machinery in the future.

Revert "Merge pull request #343 from trefis/pr7083"
This reverts commit 22681b8d2a, reversing
changes made to a24e4edf0a.

Revert "Merge pull request #341 from trefis/or-exception"
This reverts commit f8f68bd329, reversing
changes made to 1534fe8082.

Revert "Merge pull request #305 from trefis/or-exception"
This reverts commit cfeda89396, reversing
changes made to 77cf36cf82.
2015-12-12 11:20:21 +01:00
Thomas Refis 4b28c6ca99 PR#6422: Allow exceptions under or-patterns in match statements. 2015-12-09 11:19:59 +00:00
Jeremie Dimino ebd830b85b Add support for [%ocaml.extension_constructor <path>]
Translate [%ocaml.extension_constructor <path>] to the
runtime-representation of the extension constructor denoted by
<path>. This allows one to get the extension constructor without
having to create a dummy value.
2015-11-27 18:17:14 +00:00
Drup 718d1c998b Add comments to the typedtree 2015-11-25 17:32:55 +00:00
Nicolas Ojeda Bar a524920aa2 Remove Typedtree.optional
From comments in typedtree.mli:

When introduced in 2000, this [type] enabled a more efficient code
generation for optional arguments. However, today the information is
redundant as labels are passed to [transl_apply] too. Could be cleaned
up.
2015-11-25 00:37:46 +01:00
alainfrisch fe68945a20 Only the return idents are useful in pat_bound_idents, simplify accordingly. 2015-11-24 15:43:26 +01:00
Jacques Garrigue a335b18a45 merge branches/gadt-warnings
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@16532 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-10-23 08:33:44 +00:00
Jacques Garrigue e34f40ad87 switch to 'pat -> .' and add P/Texp_unreachable
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/gadt-warnings@16507 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-10-16 00:13:40 +00:00
Jacques Garrigue a09fb037ac add refuted cases, syntax is 'pat -> _'
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/gadt-warnings@16500 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-10-15 01:55:52 +00:00