Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

#### :house: Internal

- Upgrade the vendored Flow parser from 0.267.0 to 0.320.0, the final release of the OCaml implementation. https://github.com/rescript-lang/rescript/pull/8588
- 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
- 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
- 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
Expand Down
25 changes: 18 additions & 7 deletions compiler/flow_parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@

This directory contains the OCaml Flow parser used by the ReScript compiler.

- Upstream fork: https://github.com/rescript-lang/flow
- Flow parser version: `0.267.0`
- Source commit: `9ea4062c0b7e037415c4413a7634c459ebd5c31b`
- Upstream repository: https://github.com/facebook/flow
- Flow parser version: `0.320.0`
- Parser and Sedlex source commit: `7c64d4b077bc6fc45c12cee3cfa7368fdb2186ce`
- Collection source commit: `9ea4062c0b7e037415c4413a7634c459ebd5c31b`
from Flow parser 0.267.0
- Original source directories: `src/parser`, `src/third-party/sedlex`,
`src/third-party/sedlex-ppx`, and `src/hack_forked/utils/collections`

The collection helpers retain the MIT-licensed 0.267.0 sources. Their code is
identical in Flow 0.320.0, but that release replaces their MIT notices with
"Confidential and proprietary" notices that do not grant redistribution
rights.

The Dune files were adapted to build these sources as private libraries inside
the ReScript repository. Sources used only by the upstream JavaScript and C API
targets are not included. One ambiguous Sedlex documentation comment was
converted to a regular comment so the vendored sources build with ReScript's
warning settings.
converted to a regular comment and one unused loop index was renamed so the
vendored sources build with ReScript's warning settings. One `List.is_empty`
call uses an empty-list comparison to retain OCaml 5.0 compatibility. The
Sedlex PPX uses `Ast_helper.Exp.fun_` to generate single-argument functions
with newer ppxlib versions.

Vendored sources are excluded from the repository-wide OCamlformat check so
that they remain comparable with their upstream versions.

The Flow sources are licensed under the MIT licence in `LICENSE`. Vendored
Sedlex and collections sources retain their own licence files.
The Flow parser and retained collection sources are licensed under the MIT
licence in `LICENSE` and their source headers. Vendored Sedlex and collection
third-party sources retain the licence files in their respective directories.
94 changes: 0 additions & 94 deletions compiler/flow_parser/collections/reordered_argument_collections.ml

This file was deleted.

9 changes: 9 additions & 0 deletions compiler/flow_parser/flow_sedlexing/flow_sedlexing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,12 @@ let string_of_utf8 (lexbuf : int array) : string =

let backoff lexbuf npos =
lexbuf.pos <- lexbuf.pos - npos

let peek lexbuf n =
let i = lexbuf.pos + n in
if i >= lexbuf.len then
-1
else
lexbuf.buf.!(i)

let bump lexbuf n = lexbuf.pos <- lexbuf.pos + n
4 changes: 3 additions & 1 deletion compiler/flow_parser/flow_sedlexing/flow_sedlexing.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Utf8 : sig
val from_string : string -> lexbuf
val sub_lexeme : lexbuf -> int -> int -> string
val lexeme : lexbuf -> string
(* This API avoids another allocation. *)
(* This API avoids another allocation *)
val lexeme_to_buffer : lexbuf -> Buffer.t -> unit
val lexeme_to_buffer2 : lexbuf -> Buffer.t -> Buffer.t -> unit
end
Expand All @@ -45,3 +45,5 @@ val string_of_utf8 : int array -> string
val current_code_point : lexbuf -> int
val backoff : lexbuf -> int -> unit
val set_lexeme_start : lexbuf -> int -> unit
val peek : lexbuf -> int -> int
val bump : lexbuf -> int -> unit
10 changes: 1 addition & 9 deletions compiler/flow_parser/flow_sedlexing_ppx/ppx_sedlex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

open Ppxlib
open Ast_builder.Default
open Ast_helper

(* let ocaml_version = Versions.ocaml_408 *)

Expand Down Expand Up @@ -360,14 +359,7 @@ let gen_state lexbuf auto i (trans, final) =
(appfun (partition_name partition) [[%expr Sedlexing.__private__next_int [%e evar ~loc lexbuf]]])
(cases @ [case ~lhs:[%pat? _] ~guard:None ~rhs:[%expr Sedlexing.backtrack [%e evar ~loc lexbuf]]])
in
let ret body =
let lhs = pvar ~loc lexbuf in
[
value_binding ~loc
~pat:(pvar ~loc (state_fun i))
~expr:(Exp.fun_ ~loc Nolabel None lhs body);
]
in
let ret body = [ value_binding ~loc ~pat:(pvar ~loc (state_fun i)) ~expr:(Ast_helper.Exp.fun_ ~loc Nolabel None (pvar ~loc lexbuf) body) ] in
match best_final final with
| None -> ret (body ())
| Some _ when Array.length trans = 0 -> []
Expand Down
42 changes: 33 additions & 9 deletions compiler/flow_parser/parser/comment_attachment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ['loc] trailing_comments_remover ~after_pos =
let open Ast.Class.Implements.Interface in
let (loc, { id = id_; targs }) = interface in
if targs = None then
id this#identifier id_ interface (fun id' -> (loc, { id = id'; targs }))
id this#generic_identifier_type id_ interface (fun id' -> (loc, { id = id'; targs }))
else
id (map_opt this#type_args) targs interface (fun targs' ->
(loc, { id = id_; targs = targs' })
Expand All @@ -143,7 +143,7 @@ class ['loc] trailing_comments_remover ~after_pos =
method! component_declaration _loc component =
let open Ast.Statement.ComponentDeclaration in
let { body; comments; _ } = component in
let body' = this#component_body body in
let body' = map_opt this#component_body body in
let comments' = this#syntax_opt comments in
if body == body' && comments == comments' then
component
Expand Down Expand Up @@ -189,7 +189,7 @@ class ['loc] trailing_comments_remover ~after_pos =
(loc, { params with comments = comments' })
)

method! function_type _loc func =
method! function_type func =
let open Ast.Type.Function in
let { return; comments; _ } = func in
let return' = this#function_type_return_annotation return in
Expand All @@ -209,16 +209,20 @@ class ['loc] trailing_comments_remover ~after_pos =
git
else
Qualified (loc, { qualified with id = id' })
| ImportTypeAnnot _ -> git

method! import _loc expr =
method! import expr =
let open Ast.Expression.Import in
let { comments; _ } = expr in
id this#syntax_opt comments expr (fun comments' -> { expr with comments = comments' })

method! interface_type _loc t =
let open Ast.Type.Interface in
let { body; comments; _ } = t in
let body' = map_loc this#object_type body in
let body' =
let (bloc, b) = body in
id this#object_type b body (fun b' -> (bloc, b'))
in
let comments' = this#syntax_opt comments in
if body == body' && comments == comments' then
t
Expand Down Expand Up @@ -300,7 +304,7 @@ class ['loc] trailing_comments_remover ~after_pos =
let { comments; _ } = expr in
id this#syntax_opt comments expr (fun comments' -> { expr with comments = comments' })

method! object_type _loc obj =
method! object_type obj =
let open Ast.Type.Object in
let { comments; _ } = obj in
id this#syntax_opt comments obj (fun comments' -> { obj with comments = comments' })
Expand Down Expand Up @@ -485,12 +489,19 @@ let object_key_remove_trailing env key =

let generic_type_remove_trailing env ty =
let { remove_trailing; _ } = trailing_and_remover env in
remove_trailing ty (fun remover ty -> map_loc remover#generic_type ty)
remove_trailing ty (fun remover ty ->
let (tyloc, t) = ty in
id remover#generic_type t ty (fun t' -> (tyloc, t'))
)

let generic_type_list_remove_trailing env extends =
let { remove_trailing; _ } = trailing_and_remover env in
remove_trailing extends (fun remover extends ->
id_list_last (map_loc remover#generic_type) extends
id_list_last
(fun ty ->
let (tyloc, t) = ty in
id remover#generic_type t ty (fun t' -> (tyloc, t')))
extends
)

let class_implements_remove_trailing env implements =
Expand All @@ -499,7 +510,7 @@ let class_implements_remove_trailing env implements =

let string_literal_remove_trailing env str =
let { remove_trailing; _ } = trailing_and_remover env in
remove_trailing str (fun remover (loc, str) -> (loc, remover#string_literal loc str))
remove_trailing str (fun remover (loc, str) -> (loc, remover#string_literal str))

let statement_add_comments
((loc, stmt) : (Loc.t, Loc.t) Statement.t) (comments : (Loc.t, unit) Syntax.t option) :
Expand Down Expand Up @@ -557,6 +568,11 @@ let statement_add_comments
{ s with ExportDefaultDeclaration.comments = merge_comments comments }
| ExportNamedDeclaration ({ ExportNamedDeclaration.comments; _ } as s) ->
ExportNamedDeclaration { s with ExportNamedDeclaration.comments = merge_comments comments }
| ExportAssignment ({ ExportAssignment.comments; _ } as s) ->
ExportAssignment { s with ExportAssignment.comments = merge_comments comments }
| NamespaceExportDeclaration ({ NamespaceExportDeclaration.comments; _ } as s) ->
NamespaceExportDeclaration
{ s with NamespaceExportDeclaration.comments = merge_comments comments }
| Expression ({ Expression.comments; _ } as s) ->
Expression { s with Expression.comments = merge_comments comments }
| For ({ For.comments; _ } as s) -> For { s with For.comments = merge_comments comments }
Expand All @@ -569,12 +585,16 @@ let statement_add_comments
| If ({ If.comments; _ } as s) -> If { s with If.comments = merge_comments comments }
| ImportDeclaration ({ ImportDeclaration.comments; _ } as s) ->
ImportDeclaration { s with ImportDeclaration.comments = merge_comments comments }
| ImportEqualsDeclaration ({ ImportEqualsDeclaration.comments; _ } as s) ->
ImportEqualsDeclaration { s with ImportEqualsDeclaration.comments = merge_comments comments }
| InterfaceDeclaration ({ Interface.comments; _ } as s) ->
InterfaceDeclaration { s with Interface.comments = merge_comments comments }
| Labeled ({ Labeled.comments; _ } as s) ->
Labeled { s with Labeled.comments = merge_comments comments }
| Match ({ Match.comments; _ } as s) ->
Match { s with Match.comments = merge_comments comments }
| RecordDeclaration ({ RecordDeclaration.comments; _ } as s) ->
RecordDeclaration { s with RecordDeclaration.comments = merge_comments comments }
| Return ({ Return.comments; _ } as s) ->
Return { s with Return.comments = merge_comments comments }
| Switch ({ Switch.comments; _ } as s) ->
Expand Down Expand Up @@ -737,6 +757,10 @@ let object_type_property_comment_bounds property =
let collector = new comment_bounds_collector ~loc in
ignore (collector#object_mapped_type_property p);
collector
| PrivateField ((loc, _) as p) ->
let collector = new comment_bounds_collector ~loc in
ignore (collector#object_private_field_type p);
collector
in
collect_without_trailing_line_comment collector

Expand Down
Loading
Loading