From baf25d601ffa5469489b815ce5d0325b5515359c Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 12 Apr 2018 13:28:32 +0800 Subject: [PATCH] fix #2731 --- jscomp/core/lam_analysis.ml | 4 +++- jscomp/test/.depend | 1 + jscomp/test/Makefile | 1 + jscomp/test/gpr_2731_test.js | 26 ++++++++++++++++++++++++++ jscomp/test/gpr_2731_test.ml | 17 +++++++++++++++++ lib/whole_compiler.ml | 4 +++- 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 jscomp/test/gpr_2731_test.js create mode 100644 jscomp/test/gpr_2731_test.ml diff --git a/jscomp/core/lam_analysis.ml b/jscomp/core/lam_analysis.ml index cc1749f7d2..1b6a60f301 100644 --- a/jscomp/core/lam_analysis.ml +++ b/jscomp/core/lam_analysis.ml @@ -260,7 +260,7 @@ let rec no_side_effects (lam : Lam.t) : bool = *) exception Too_big_to_inline -let really_big () = raise Too_big_to_inline +let really_big () = raise_notrace Too_big_to_inline let big_lambda = 1000 @@ -278,6 +278,8 @@ let rec size (lam : Lam.t) = | Lprim {primitive = Praise ; args = [l ]; _} -> size l | Lam.Lglobal_module _ -> 1 + | Lprim {primitive = Praw_js_code_exp _ | Praw_js_code_stmt _} -> + really_big () | Lprim {args = ll; _} -> size_lams 1 ll (** complicated diff --git a/jscomp/test/.depend b/jscomp/test/.depend index 38d30d61b0..223064f702 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -312,6 +312,7 @@ gpr_2633_test.cmj : gpr_2642_test.cmj : gpr_2652_test.cmj : ../others/node.cmj ../stdlib/buffer.cmj gpr_2700_test.cmj : +gpr_2731_test.cmj : gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi gpr_441.cmj : gpr_459_test.cmj : mt.cmj diff --git a/jscomp/test/Makefile b/jscomp/test/Makefile index 105721d2d1..a48932e21c 100644 --- a/jscomp/test/Makefile +++ b/jscomp/test/Makefile @@ -250,6 +250,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_ gpr_2652_test\ gpr_2614_test\ gpr_2700_test\ + gpr_2731_test\ # bs_uncurry_test # needs Lam to get rid of Uncurry arity first # simple_derive_test diff --git a/jscomp/test/gpr_2731_test.js b/jscomp/test/gpr_2731_test.js new file mode 100644 index 0000000000..b890824e55 --- /dev/null +++ b/jscomp/test/gpr_2731_test.js @@ -0,0 +1,26 @@ +'use strict'; + + +function f(x) { + return x + (1) | 0; +} + +var a = f(1); + +var b = f(2); + +function g() { + return (1); +} + +var c = g(/* () */0); + +var d = g(/* () */0); + +exports.f = f; +exports.a = a; +exports.b = b; +exports.g = g; +exports.c = c; +exports.d = d; +/* a Not a pure module */ diff --git a/jscomp/test/gpr_2731_test.ml b/jscomp/test/gpr_2731_test.ml new file mode 100644 index 0000000000..3ac581f045 --- /dev/null +++ b/jscomp/test/gpr_2731_test.ml @@ -0,0 +1,17 @@ + + + +let f x = x + [%raw{|1|}] + + + + +let a = f 1 +let b = f 2 + +let g () = + [%raw{|1|}] + + +let c = g () +let d = g () \ No newline at end of file diff --git a/lib/whole_compiler.ml b/lib/whole_compiler.ml index fc2f1e487d..120727a419 100644 --- a/lib/whole_compiler.ml +++ b/lib/whole_compiler.ml @@ -86560,7 +86560,7 @@ let rec no_side_effects (lam : Lam.t) : bool = *) exception Too_big_to_inline -let really_big () = raise Too_big_to_inline +let really_big () = raise_notrace Too_big_to_inline let big_lambda = 1000 @@ -86578,6 +86578,8 @@ let rec size (lam : Lam.t) = | Lprim {primitive = Praise ; args = [l ]; _} -> size l | Lam.Lglobal_module _ -> 1 + | Lprim {primitive = Praw_js_code_exp _ | Praw_js_code_stmt _} -> + really_big () | Lprim {args = ll; _} -> size_lams 1 ll (** complicated