Skip to content

Cleanup pipe ppx #5587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2022
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
87 changes: 31 additions & 56 deletions jscomp/frontend/ast_exp_apply.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
(*
a |. f
a |. f b c [@bs] --> f a b c [@bs]
a |. M.(f b c) --> M.f a M.b M.c
a |. (g |. b)
a |. M.Some
a |. `Variant
a |. (b |. f c [@bs])
*)
Expand All @@ -128,61 +126,38 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
pexp_loc = e.pexp_loc;
pexp_attributes = e.pexp_attributes;
}
| _ -> (
match Ast_open_cxt.destruct fn [] with
| ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs },
wholes ) ->
Ast_open_cxt.restore_exp
(bound new_obj_arg (fun bounded_obj_arg ->
{
pexp_desc =
Pexp_tuple
(Ext_list.map xs (fun fn ->
match fn.pexp_desc with
| Pexp_construct (ctor, None) ->
{
fn with
pexp_desc =
Pexp_construct
(ctor, Some bounded_obj_arg);
}
| Pexp_apply (fn, args) ->
Bs_ast_invariant
.warn_discarded_unused_attributes
fn.pexp_attributes;
{
Parsetree.pexp_desc =
Pexp_apply
( fn,
(Nolabel, bounded_obj_arg)
:: args );
pexp_attributes = [];
pexp_loc = fn.pexp_loc;
}
| _ ->
Ast_compatible.app1 ~loc:fn.pexp_loc fn
bounded_obj_arg));
pexp_attributes = tuple_attrs;
pexp_loc = fn.pexp_loc;
}))
wholes
| ( { pexp_desc = Pexp_apply (e, args); pexp_attributes },
(_ :: _ as wholes) ) ->
let fn = Ast_open_cxt.restore_exp e wholes in
let args =
Ext_list.map args (fun (lab, exp) ->
(lab, Ast_open_cxt.restore_exp exp wholes))
in
Bs_ast_invariant.warn_discarded_unused_attributes
pexp_attributes;
| Pexp_tuple xs ->
bound new_obj_arg (fun bounded_obj_arg ->
{
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
pexp_attributes = [];
pexp_loc = loc;
}
| _ ->
Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn
new_obj_arg))
pexp_desc =
Pexp_tuple
(Ext_list.map xs (fun fn ->
match fn.pexp_desc with
| Pexp_construct (ctor, None) ->
{
fn with
pexp_desc =
Pexp_construct (ctor, Some bounded_obj_arg);
}
| Pexp_apply (fn, args) ->
Bs_ast_invariant
.warn_discarded_unused_attributes
fn.pexp_attributes;
{
Parsetree.pexp_desc =
Pexp_apply
(fn, (Nolabel, bounded_obj_arg) :: args);
pexp_attributes = [];
pexp_loc = fn.pexp_loc;
}
| _ ->
Ast_compatible.app1 ~loc:fn.pexp_loc fn
bounded_obj_arg));
pexp_attributes = fn.pexp_attributes;
pexp_loc = fn.pexp_loc;
})
| _ ->
Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn new_obj_arg)
| Some { op = "##"; loc; args = [ obj; rest ] } -> (
(* - obj##property
- obj#(method a b )
Expand Down
8 changes: 0 additions & 8 deletions jscomp/frontend/ast_open_cxt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ type whole =
* Parsetree.attributes)

type t = whole list

type exp = Parsetree.expression

type destruct_output = exp list

(**
Expand All @@ -50,12 +48,6 @@ let rec destruct_open_tuple (e : Parsetree.expression) (acc : t) :
| Pexp_tuple es -> Some (acc, es, e.pexp_attributes)
| _ -> None

let rec destruct (e : Parsetree.expression) (acc : t) =
match e.pexp_desc with
| Pexp_open (flag, lid, cont) ->
destruct cont (Let_open (flag, lid, e.pexp_loc, e.pexp_attributes) :: acc)
| _ -> (e, acc)

let restore_exp (xs : Parsetree.expression) (qualifiers : t) :
Parsetree.expression =
Ext_list.fold_left qualifiers xs (fun x hole ->
Expand Down
2 changes: 0 additions & 2 deletions jscomp/frontend/ast_open_cxt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ type t = whole list

val restore_exp : Parsetree.expression -> t -> Parsetree.expression

val destruct : Parsetree.expression -> t -> Parsetree.expression * t

val destruct_open_tuple :
Parsetree.expression ->
t ->
Expand Down
4 changes: 1 addition & 3 deletions jscomp/test/build.ninja

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions jscomp/test/gpr_2863_test.js

This file was deleted.

13 changes: 0 additions & 13 deletions jscomp/test/gpr_2863_test.ml

This file was deleted.

27 changes: 0 additions & 27 deletions jscomp/test/gpr_3502_test.js

This file was deleted.

5 changes: 0 additions & 5 deletions jscomp/test/gpr_3502_test.ml

This file was deleted.

8 changes: 0 additions & 8 deletions jscomp/test/pipe_syntax.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var Curry = require("../../lib/js/curry.js");
var Belt_Array = require("../../lib/js/belt_Array.js");
var Caml_option = require("../../lib/js/caml_option.js");

function t0(x, f) {
Expand Down Expand Up @@ -80,12 +79,6 @@ function f8(a) {
return Caml_option.some(Caml_option.some(a));
}

function hi(x) {
return Belt_Array.map(x, (function (x) {
return x + 1 | 0;
}));
}

var with_poly = {
NAME: "Foo",
VAL: 1
Expand All @@ -104,6 +97,5 @@ exports.f5 = f5;
exports.f6 = f6;
exports.f7 = f7;
exports.f8 = f8;
exports.hi = hi;
exports.with_poly = with_poly;
/* No side effect */
3 changes: 0 additions & 3 deletions jscomp/test/pipe_syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,4 @@ let f7 a = a |. (Some, Some, Some)

let f8 a = a |. Some |. Some

let hi x =
x |. Belt.Array.(map (fun x -> x + 1 ))

let with_poly = 1 |. `Foo
Loading