Skip to content

Commit afdaaa8

Browse files
authored
Vendor Flow parser 0.267.0 (#8587)
* Vendor Flow parser 0.267.0 Signed-off-by: Christoph Knittel <ck@cca.io> * Add Flow parser vendoring changelog entry Signed-off-by: Christoph Knittel <ck@cca.io> --------- Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 0f66af5 commit afdaaa8

90 files changed

Lines changed: 31502 additions & 9 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ocamlformat-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
compiler/flow_parser/**

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#### :house: Internal
5959

60+
- Vendor the Flow parser 0.267.0 sources used by the compiler, removing the external `flow_parser` dependency and establishing a maintained baseline for future OCaml upgrades. https://github.com/rescript-lang/rescript/pull/8587
6061
- Store processed external declarations as structured data instead of serialized values in `pval_prim`, and lower external calls during Lambda translation. This removes `Pccall`, `external_spec`, and the unsupported `%absfloat` primitive. The AST, CMI, and CMT magic numbers are bumped (`ResImpl01301`/`ResIntf01301`, `Caml1999I025`, `Caml1999T026`). https://github.com/rescript-lang/rescript/pull/8581
6162
- Resolve dynamic-import targets during Lambda translation and store the module and export path directly in `Pimport`. This removes the `dynamic_import` flags from `Pjs_call` and `Lglobal_module`, along with backend expression-shape detection. https://github.com/rescript-lang/rescript/pull/8582
6263
- Give nominal variants one canonical runtime layout: compute their JavaScript representation once after typing each declaration, replace positional constructor tags with semantic runtime descriptors, and make construction, matching, coercion, printing, diagnostics, and GenType consume the stored representation instead of reinterpreting annotations. Pattern matching keeps occurrence-specific plans local without adding another Lambda or Lam expression form. https://github.com/rescript-lang/rescript/pull/8579

compiler/flow_parser/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Meta Platforms, Inc. and affiliates.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

compiler/flow_parser/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Vendored Flow parser
2+
3+
This directory contains the OCaml Flow parser used by the ReScript compiler.
4+
5+
- Upstream fork: https://github.com/rescript-lang/flow
6+
- Flow parser version: `0.267.0`
7+
- Source commit: `9ea4062c0b7e037415c4413a7634c459ebd5c31b`
8+
- Original source directories: `src/parser`, `src/third-party/sedlex`,
9+
`src/third-party/sedlex-ppx`, and `src/hack_forked/utils/collections`
10+
11+
The Dune files were adapted to build these sources as private libraries inside
12+
the ReScript repository. Sources used only by the upstream JavaScript and C API
13+
targets are not included. One ambiguous Sedlex documentation comment was
14+
converted to a regular comment so the vendored sources build with ReScript's
15+
warning settings.
16+
17+
Vendored sources are excluded from the repository-wide OCamlformat check so
18+
that they remain comparable with their upstream versions.
19+
20+
The Flow sources are licensed under the MIT licence in `LICENSE`. Vendored
21+
Sedlex and collections sources retain their own licence files.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(include_subdirs unqualified)
2+
3+
(library
4+
(name collections)
5+
(wrapped false)
6+
(libraries base))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
include WrappedMap.Make (IntKey)
9+
10+
let pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit =
11+
(fun pp_data -> make_pp IntKey.pp pp_data)
12+
13+
let show pp_data x = Format.asprintf "%a" (pp pp_data) x
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
include Flow_set.Make (IntKey)
9+
10+
let pp = make_pp IntKey.pp
11+
12+
let show iset = Format.asprintf "%a" pp iset
13+
14+
let to_string = show
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
type 'a t = {
9+
incoming: 'a list;
10+
outgoing: 'a list;
11+
length: int;
12+
}
13+
14+
let empty = { incoming = []; outgoing = []; length = 0 }
15+
16+
let length t = t.length
17+
18+
let is_empty t = length t = 0
19+
20+
let push t x = { t with incoming = x :: t.incoming; length = t.length + 1 }
21+
22+
let prepare_for_read t =
23+
match t.outgoing with
24+
| [] -> { t with incoming = []; outgoing = List.rev t.incoming }
25+
| _ -> t
26+
27+
let pop t =
28+
let t = prepare_for_read t in
29+
match t.outgoing with
30+
| [] -> (None, t)
31+
| hd :: tl -> (Some hd, { t with outgoing = tl; length = t.length - 1 })
32+
33+
let peek t =
34+
let t = prepare_for_read t in
35+
match t.outgoing with
36+
| [] -> (None, t)
37+
| hd :: _ -> (Some hd, t)
38+
39+
let exists t ~f = List.exists f t.outgoing || List.exists f t.incoming
40+
41+
let iter t ~f =
42+
List.iter f t.outgoing;
43+
List.iter f (List.rev t.incoming)
44+
45+
let from_list x = { incoming = []; outgoing = x; length = List.length x }
46+
47+
let to_list x = x.outgoing @ List.rev x.incoming
48+
49+
let concat t =
50+
{
51+
incoming = [];
52+
outgoing = Base.List.concat_map ~f:to_list t;
53+
length = List.map (fun u -> u.length) t |> List.fold_left ( + ) 0;
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
(*
9+
* Immutable queue implementation. Modeled loosely after the mutable stdlib
10+
* Queue. push, pop, etc. are amortized O(1).
11+
*)
12+
13+
type 'a t
14+
15+
val empty : 'a t
16+
17+
val push : 'a t -> 'a -> 'a t
18+
19+
val pop : 'a t -> 'a option * 'a t
20+
21+
val peek : 'a t -> 'a option * 'a t
22+
23+
val is_empty : 'a t -> bool
24+
25+
val length : 'a t -> int
26+
27+
val exists : 'a t -> f:('a -> bool) -> bool
28+
29+
val iter : 'a t -> f:('a -> unit) -> unit
30+
31+
(* from_list: the head of the list is the first one to be popped *)
32+
val from_list : 'a list -> 'a t
33+
34+
(* to_list: the head of the list is the first one to be popped *)
35+
val to_list : 'a t -> 'a list
36+
37+
val concat : 'a t list -> 'a t
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
type t = int
9+
10+
let compare = ( - )
11+
12+
let pp = Format.pp_print_int

0 commit comments

Comments
 (0)