Skip to content

fix #4762 #4764

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 2 commits into from
Oct 24, 2020
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
202 changes: 101 additions & 101 deletions jscomp/main/builtin_cmi_datasets.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jscomp/runtime/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end
module MapperRt = Js_mapperRt
module Internal = struct
open Fn
external unsafeInvariantApply : 'a -> 'a = "#full_apply"
external opaqueFullApply : 'a -> 'a = "#full_apply"

(* Use opaque instead of [._n] to prevent some optimizations happening *)
external run : 'a arity0 -> 'a = "#run"
Expand Down
2 changes: 1 addition & 1 deletion jscomp/snapshot.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SNAP=../lib/$snapshot_path
o snapshot: phony $SNAP/whole_compiler.ml $SNAP/bsb_helper.ml $SNAP/bsb.ml $SNAP/unstable/all_ounit_tests.ml
# $SNAP/bspp.ml
o $SNAP/whole_compiler.ml: bspack | ./bin/bspack.exe $LTO
flags = ${releaseMode} -D BS_ONLY=true -bs-MD -module-alias Config=Config_whole_compiler -bs-exclude-I config -I $OCAML_SRC_UTILS -I $OCAML_SRC_PARSING -I $OCAML_SRC_TYPING -I $OCAML_SRC_BYTECOMP -I $OCAML_SRC_DRIVER ${includes}
flags = ${releaseMode} -D BS_ONLY=true -bs-MD -module-alias Config=Config_whole_compiler -bs-exclude-I config -I $OCAML_SRC_UTILS -I $OCAML_SRC_PARSING -I $OCAML_SRC_TYPING -I $OCAML_SRC_BYTECOMP -I $OCAML_SRC_DRIVER $includes
main = Js_main
post_process = && node $LTO $SNAP/whole_compiler.ml

Expand Down
2 changes: 1 addition & 1 deletion jscomp/syntax/ast_literal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Lid = struct
(* TODO should be renamed in to {!Js.fn} *)
(* TODO should be moved into {!Js.t} Later *)
let js_internal : t = Ldot (Lident "Js", "Internal")
let js_internal_full_apply : t = Ldot (js_internal, "unsafeInvariantApply")
let js_internal_full_apply : t = Ldot (js_internal, "opaqueFullApply")
let opaque : t = Ldot (js_internal, "opaque")
let js_fn : t =
Ldot (Lident "Js", "Fn")
Expand Down
46 changes: 26 additions & 20 deletions jscomp/syntax/ast_uncurry_apply.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ type exp = Parsetree.expression
let jsInternal =
Ast_literal.Lid.js_internal

(* we use the trick
[( opaque e : _) ] to avoid it being inspected,
the type constraint is avoid some syntactic transformation, e.g ` e |. (f g [@bs])`
`opaque` is to avoid it being inspected in the type level
*)
let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
Pexp_constraint
(Exp.apply ~loc (Exp.ident {txt = Ast_literal.Lid.js_internal_full_apply; loc})
[Nolabel,e],
Typ.any ~loc ()
)
let generic_apply loc
(self : Bs_ast_mapper.mapper)
(obj : Parsetree.expression)
Expand All @@ -56,18 +67,15 @@ let generic_apply loc
(Exp.ident {txt = Ldot (jsInternal, "run");loc}, [Nolabel,fn])
else
let arity_s = string_of_int arity in

Parsetree.Pexp_apply (
Exp.ident {txt = Ast_literal.Lid.js_internal_full_apply; loc},
[Nolabel,
Exp.apply ~loc
(Exp.apply ~loc
(Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
[(Nolabel, Exp.field ~loc
(Exp.constraint_ ~loc fn
(Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_fn, "arity"^arity_s);loc}
[Typ.any ~loc ()])) {txt = Ast_literal.Lid.hidden_field arity_s; loc})])
args])
opaque_full_apply ~loc (
Exp.apply ~loc
(Exp.apply ~loc
(Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
[(Nolabel, Exp.field ~loc
(Exp.constraint_ ~loc fn
(Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_fn, "arity"^arity_s);loc}
[Typ.any ~loc ()])) {txt = Ast_literal.Lid.hidden_field arity_s; loc})])
args)

let method_apply loc
(self : Bs_ast_mapper.mapper)
Expand All @@ -91,17 +99,15 @@ let method_apply loc
(Exp.ident {txt = Ldot ((Ldot (Ast_literal.Lid.js_oo,"Internal")), "run");loc}, [Nolabel,fn])
else
let arity_s = string_of_int arity in
Parsetree.Pexp_apply (
Exp.ident {txt = Ast_literal.Lid.js_internal_full_apply; loc},
[Nolabel,
Exp.apply ~loc (
Exp.apply ~loc (Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
[(Nolabel,
opaque_full_apply ~loc (
Exp.apply ~loc (
Exp.apply ~loc (Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
[(Nolabel,
Exp.field ~loc
(Exp.constraint_ ~loc
fn (Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_meth,"arity"^arity_s);loc} [Typ.any ~loc ()]))
fn (Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_meth,"arity"^arity_s);loc} [Typ.any ~loc ()]))
{loc; txt = Ast_literal.Lid.hidden_field arity_s})])
args])
args)


let uncurry_fn_apply loc self fn args =
Expand Down
3 changes: 0 additions & 3 deletions jscomp/test/label_uncurry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ let h = fun [@bs] ~x:unit -> 3

let a = u1 u

(* let u1 (f : u) =
Js.Internal.unsafeInvariantApply ((Js.Internal.run2 (f : u)) ~y:"x" ~x:2)
*)


type u0 = ?x:int -> y : string -> int [@bs]
Expand Down
8 changes: 0 additions & 8 deletions jscomp/test/unsafe_full_apply_primitive.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@


(* external unsafeInvariantApply : 'a -> 'a = "#full_apply"


let f1 x = unsafeInvariantApply (x ())


let f2 x y = unsafeInvariantApply (x y ()) *)


let rec f = fun [@bs] a -> f a [@bs]

Expand Down
250 changes: 128 additions & 122 deletions lib/4.06.1/unstable/js_compiler.ml

Large diffs are not rendered by default.

250 changes: 128 additions & 122 deletions lib/4.06.1/unstable/js_refmt_compiler.ml

Large diffs are not rendered by default.

Loading