@@ -22,29 +22,43 @@ let%expect_test "direct calls without --effects=cps" =
2222 let code =
2323 compile_and_parse
2424 {|
25+ let l = ref []
26+
2527 (* Arity of the argument of a function / direct call *)
2628 let test1 () =
27- let f g x = try g x with e -> raise e in
29+ let f g x =
30+ l := (fun () -> ()) :: ! l; (* pervent inlining *)
31+ try g x with e -> raise e in
2832 ignore (f (fun x -> x + 1 ) 7 );
2933 ignore (f (fun x -> x *. 2. ) 4. )
3034
3135 (* Arity of the argument of a function / CPS call *)
3236 let test2 () =
33- let f g x = try g x with e -> raise e in
37+ let f g x =
38+ l := (fun () -> ()) :: ! l; (* pervent inlining *)
39+ try g x with e -> raise e in
3440 ignore (f (fun x -> x + 1 ) 7 );
3541 ignore (f (fun x -> x ^ " a" ) " a" )
3642
3743 (* Arity of functions in a functor / direct call *)
3844 let test3 x =
39- let module F(_ : sig end ) = struct let f x = x + 1 end in
45+ let module F(_ : sig end ) = struct
46+ let r = ref 0
47+ let () = for _ = 0 to 2 do incr r done (* pervent inlining *)
48+ let f x = x + 1
49+ end in
4050 let module M1 = F (struct end ) in
4151 let module M2 = F (struct end ) in
4252 (M1. f 1 , M2. f 2 )
4353
4454 (* Arity of functions in a functor / CPS call *)
4555 let test4 x =
4656 let module F(_ : sig end ) =
47- struct let f x = Printf. printf " %d" x end in
57+ struct
58+ let r = ref 0
59+ let () = for _ = 0 to 2 do incr r done (* pervent inlining *)
60+ let f x = Printf. printf " %d" x
61+ end in
4862 let module M1 = F (struct end ) in
4963 let module M2 = F (struct end ) in
5064 M1. f 1 ; M2. f 2
@@ -58,6 +72,7 @@ let%expect_test "direct calls without --effects=cps" =
5872 {|
5973 function test1(param){
6074 function f(g, x){
75+ l[1 ] = [0 , function(param){return 0 ;}, l[1 ]];
6176 try {caml_call1(g, x); return;}
6277 catch(e$ 0 ){
6378 var e = caml_wrap_exception(e$ 0 );
@@ -71,6 +86,7 @@ let%expect_test "direct calls without --effects=cps" =
7186 // end
7287 function test2(param){
7388 function f(g, x){
89+ l[1 ] = [0 , function(param){return 0 ;}, l[1 ]];
7490 try {caml_call1(g, x); return;}
7591 catch(e$ 0 ){
7692 var e = caml_wrap_exception(e$ 0 );
@@ -83,19 +99,26 @@ let%expect_test "direct calls without --effects=cps" =
8399 }
84100 // end
85101 function test3(x){
86- function F (symbol){function f(x){return x + 1 | 0 ;} return [0 , f];}
87- var M1 = F ([0 ]), M2 = F ([0 ]), _a_ = M2 [1 ].call(null, 2 );
88- return [0 , M1 [1 ].call(null, 1 ), _a_];
102+ function F (symbol){
103+ var r = [0 , 0 ], for $ = 0 ;
104+ for (;;){r[1 ]++ ; var _b_ = for $ + 1 | 0 ; if (2 === for $ ) break; for $ = _b_;}
105+ function f(x){return x + 1 | 0 ;}
106+ return [0 , , f];
107+ }
108+ var M1 = F ([0 ]), M2 = F ([0 ]), _b_ = M2 [2 ].call(null, 2 );
109+ return [0 , M1 [2 ].call(null, 1 ), _b_];
89110 }
90111 // end
91112 function test4(x){
92113 function F (symbol){
114+ var r = [0 , 0 ], for $ = 0 ;
115+ for (;;){r[1 ]++ ; var _b_ = for $ + 1 | 0 ; if (2 === for $ ) break; for $ = _b_;}
93116 function f(x){return caml_call2(Stdlib_Printf [2 ], _a_, x);}
94- return [0 , f];
117+ return [0 , , f];
95118 }
96119 var M1 = F ([0 ]), M2 = F ([0 ]);
97- M1 [1 ].call(null, 1 );
98- return M2 [1 ].call(null, 2 );
120+ M1 [2 ].call(null, 1 );
121+ return M2 [2 ].call(null, 2 );
99122 }
100123 // end
101124 | }]
@@ -105,29 +128,43 @@ let%expect_test "direct calls with --effects=cps" =
105128 compile_and_parse
106129 ~effects: `Cps
107130 {|
131+ let l = ref []
132+
108133 (* Arity of the argument of a function / direct call *)
109134 let test1 () =
110- let f g x = try g x with e -> raise e in
135+ let f g x =
136+ l := (fun () -> ()) :: ! l; (* pervent inlining *)
137+ try g x with e -> raise e in
111138 ignore (f (fun x -> x + 1 ) 7 );
112139 ignore (f (fun x -> x *. 2. ) 4. )
113140
114141 (* Arity of the argument of a function / CPS call *)
115142 let test2 () =
116- let f g x = try g x with e -> raise e in
143+ let f g x =
144+ l := (fun () -> ()) :: ! l; (* pervent inlining *)
145+ try g x with e -> raise e in
117146 ignore (f (fun x -> x + 1 ) 7 );
118147 ignore (f (fun x -> x ^ " a" ) " a" )
119148
120149 (* Arity of functions in a functor / direct call *)
121150 let test3 x =
122- let module F(_ : sig end ) = struct let f x = x + 1 end in
151+ let module F(_ : sig end ) = struct
152+ let r = ref 0
153+ let () = for _ = 0 to 2 do incr r done (* pervent inlining *)
154+ let f x = x + 1
155+ end in
123156 let module M1 = F (struct end ) in
124157 let module M2 = F (struct end ) in
125158 (M1. f 1 , M2. f 2 )
126159
127160 (* Arity of functions in a functor / CPS call *)
128161 let test4 x =
129162 let module F(_ : sig end ) =
130- struct let f x = Printf. printf " %d" x end in
163+ struct
164+ let r = ref 0
165+ let () = for _ = 0 to 2 do incr r done (* pervent inlining *)
166+ let f x = Printf. printf " %d" x
167+ end in
131168 let module M1 = F (struct end ) in
132169 let module M2 = F (struct end ) in
133170 M1. f 1 ; M2. f 2
@@ -141,6 +178,7 @@ let%expect_test "direct calls with --effects=cps" =
141178 {|
142179 function test1(param, cont){
143180 function f(g, x){
181+ l[1 ] = [0 , function(param, cont){return cont(0 );}, l[1 ]];
144182 try {g() ; return;}
145183 catch(e$ 0 ){
146184 var e = caml_wrap_exception(e$ 0 );
@@ -154,49 +192,57 @@ let%expect_test "direct calls with --effects=cps" =
154192 // end
155193 function test2(param, cont){
156194 function f(g, x, cont){
195+ l[1 ] = [0 , function(param, cont){return cont(0 );}, l[1 ]];
157196 runtime.caml_push_trap
158197 (function(e){
159198 var raise = caml_pop_trap() , e$ 0 = caml_maybe_attach_backtrace(e, 0 );
160199 return raise(e$ 0 );
161200 });
162201 return caml_exact_trampoline_cps_call
163- (g, x, function(_a_ ){caml_pop_trap() ; return cont() ;});
202+ (g, x, function(_b_ ){caml_pop_trap() ; return cont() ;});
164203 }
165204 return caml_exact_trampoline_cps_call$ 0
166205 (f,
167206 function(x, cont){return cont() ;},
168207 7 ,
169- function(_a_ ){
208+ function(_b_ ){
170209 return caml_exact_trampoline_cps_call$ 0
171210 (f,
172211 function(x, cont){
173212 return caml_trampoline_cps_call3
174213 (Stdlib [28 ], x, cst_a$ 0 , cont);
175214 },
176215 cst_a,
177- function(_a_ ){return cont(0 );});
216+ function(_b_ ){return cont(0 );});
178217 });
179218 }
180219 // end
181220 function test3(x, cont){
182- function F (symbol){function f(x){return x + 1 | 0 ;} return [0 , f];}
183- var M1 = F () , M2 = F () , _a_ = M2 [1 ].call(null, 2 );
184- return cont([0 , M1 [1 ].call(null, 1 ), _a_]);
221+ function F (symbol){
222+ var r = [0 , 0 ], for $ = 0 ;
223+ for (;;){r[1 ]++ ; var _b_ = for $ + 1 | 0 ; if (2 === for $ ) break; for $ = _b_;}
224+ function f(x){return x + 1 | 0 ;}
225+ return [0 , , f];
226+ }
227+ var M1 = F () , M2 = F () , _b_ = M2 [2 ].call(null, 2 );
228+ return cont([0 , M1 [2 ].call(null, 1 ), _b_]);
185229 }
186230 // end
187231 function test4(x, cont){
188232 function F (symbol){
233+ var r = [0 , 0 ], for $ = 0 ;
234+ for (;;){r[1 ]++ ; var _b_ = for $ + 1 | 0 ; if (2 === for $ ) break; for $ = _b_;}
189235 function f(x, cont){
190236 return caml_trampoline_cps_call3(Stdlib_Printf [2 ], _a_, x, cont);
191237 }
192- return [0 , f];
238+ return [0 , , f];
193239 }
194240 var M1 = F () , M2 = F () ;
195241 return caml_exact_trampoline_cps_call
196- (M1 [1 ],
242+ (M1 [2 ],
197243 1 ,
198244 function(_a_){
199- return caml_exact_trampoline_cps_call(M2 [1 ], 2 , cont);
245+ return caml_exact_trampoline_cps_call(M2 [2 ], 2 , cont);
200246 });
201247 }
202248 // end
0 commit comments