Commit Graph

50 Commits (master)

Author SHA1 Message Date
Leandro Ostera ee2f3b428c
Move typed_impl to Typedtree.t 2020-11-05 19:06:12 +01:00
Thomas Refis 9ca9df88c0
Untypeast: define untype_expression, untype_pattern (#9920)
Convenience functions that have been defined in merlin for a while.
2020-09-16 20:49:05 +02:00
Drup 9c8b63f4ce Annotated Asttypes.constant's string with content location. 2019-11-13 16:08:40 +01:00
Drup abc53d1a6e Annotate constant literals with the location of their content. 2019-11-13 16:08:40 +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 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
Leo White c19e8b2350 Refactor environment lookup functions 2019-08-15 15:56:50 +01:00
Leo White acd06f1eff Remove Misc.may_map and similar 2019-05-23 16:27:58 +01: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
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
Daniel Bünzli a7afd89003 s/string_of_int/Int.to_string/g 2018-11-07 13:52:02 +01: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
Hugo Heuzard 8043144494 Add locations to attributes
Changes

fix typo
2018-08-06 13:19:28 +01:00
Thomas Refis 369ea5f432 allow exceptions under or-patterns 2018-07-16 10:41:55 +01:00
Hugo Heuzard 002815c4bb allow to attach @@ attributes on exceptions 2018-04-09 22:29:46 +01:00
Gabriel Radanne b073f825de Make Ident.t abstract and immutable. (#1704) 2018-04-09 10:19:23 +01:00
Leo White 5cb27d8ebb Merge pull request #792 from sliquister/generalize-destr-subst2
Fixing the limitations on destructive substitutions
2017-09-15 09:29:29 +01:00
Alain Frisch 7eba1178ea Remove spurious semicolons after non-unit expressions (#1305) 2017-08-29 15:14:50 +01:00
Valentin Gatien-Baron ff05023fde Support syntax: S with module M.N := .. 2017-08-01 07:40:01 -04:00
Valentin Gatien-Baron f29cd5ab6d Support syntax: S with M.N.t := ... 2017-08-01 07:32:08 -04: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
Fabrice Le Fessant a424f0aae1 Add missing locations in the parsetree (#749)
They are not propagated to the typedtree yet.
2016-08-29 16:21:38 +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
alainfrisch 502e4f9336 More warnings when compiling the compiler. 2016-03-15 22:46:35 +01: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
Drup 6095df954e Rename parsetree constants.
PConst -> Pconst
int -> integer
2016-01-18 00:12:38 +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
Hugo Heuzard 9eca3e4519 Parse arbitrary precision integers ..
.. and allow any letter in [g-zG-Z] as modifier (previously 'l','L','n')
Also allow modifier for floats
This give more freedom to ppx rewritters (what about a ppx for zarith)

Checks are performed when translating from Parsetree to Typedtree.
Invalid_literal is raised if the modifier is not recognized ([lLn]?)
Integer_overflow is raised as before.

Lexer: use g-zG-Z for integer literal modifier

Lexer: Allow modifier on float

Clean wrt previous commits

Lexer: use named substring

Cleanup

typo

doc

fix after rebase

rebase on  trunk

Update typecore.ml

Fix printast.ml
2015-12-03 17:20:48 +01: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
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
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
Leo White 5c55e4cc08 Attach documentation comments to Parsetree
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@16189 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-06-28 13:11:50 +00:00
Jérémie Dimino bcc9e6adfa Update ocamldoc and other utilities to support "type
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15923 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-03-13 11:09:08 +00:00
Gabriel Scherer 1ecdd68c21 untypeast: small change to avoid producing new compiler warnings.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15889 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-03-08 10:22:37 +00:00
Gabriel Scherer ad85a8c1df use open recursion in untypeast.ml
This allows library user to override the untyping behavior of specific
typedtree nodes.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15888 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-03-08 10:22:35 +00:00
Gabriel Scherer 786e69e846 move tools/untypeast.ml to typing/untypeast.ml
This makes them available in compiler-libs, enabling various uses
outside the compiler.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15886 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-03-08 10:22:32 +00:00