Skip to content

Commit ae65175

Browse files
committed
Compiler: fix 2083
1 parent 0ea4a48 commit ae65175

File tree

3 files changed

+16
-51
lines changed

3 files changed

+16
-51
lines changed

compiler/lib/inline.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ let functor_like ~context info =
364364
full_size ~context info - body_size ~context info <= 20 * closure_count ~context info
365365

366366
let trivial_function ~context info =
367-
body_size ~context info <= 1 && closure_count ~context info = 0
367+
(not info.recursive) && body_size ~context info <= 1 && closure_count ~context info = 0
368368

369369
(*
370370
We inline small functions which are simple (no closure, no

compiler/tests-compiler/gh1320.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ let () = myfun ()
5555
},
5656
g = function(x){return app(f$0, x);};
5757
let f$0 = f, g$0 = g;
58-
var _c_ = app(f, i);
59-
caml_call2(Stdlib_Printf[3], _a_, _c_);
60-
var _b_ = i + 1 | 0;
58+
var _b_ = g(i);
59+
caml_call2(Stdlib_Printf[3], _a_, _b_);
60+
var _c_ = i + 1 | 0;
6161
if(4 === i) return 0;
62-
i = _b_;
62+
i = _c_;
6363
}
6464
}
6565
//end

compiler/tests-compiler/tailcall.ml

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -164,51 +164,16 @@ let rec grow (iters : int) (n : t) : t =
164164
in
165165
let program = Util.compile_and_parse ~flags:[ "--debug"; "js_assign" ] prog in
166166
Util.print_fun_decl program (Some "grow");
167-
[%expect.unreachable]
168-
[@@expect.uncaught_exn {|
169-
(* CR expect_test_collector: This test expectation appears to contain a backtrace.
170-
This is strongly discouraged as backtraces are fragile.
171-
Please change this test to not include a backtrace. *)
172-
(Failure "non-zero exit code")
173-
Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 213, characters 18-35
174-
Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string.loop in file "compiler/tests-compiler/util/util.ml", line 169, characters 4-52
175-
Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14
176-
177-
Trailing output
178-
---------------
179-
(function(globalThis){
180-
"use strict";
181-
var runtime = globalThis.jsoo_runtime;
182-
function caml_call1(f, a0){
183-
return (f.l >= 0 ? f.l : f.l = f.length) === 1
184-
? f(a0)
185-
: runtime.caml_call_gen(f, [a0]);
186-
}
187-
var _a_ = [0, 0];
188-
function rules(rules, param){
189-
if(! param) return _a_;
190-
var n = param[1];
191-
return [0, caml_call1(rules, n)];
192-
}
193-
function step(n){return rules(step, n);}
194-
function grow(iters$1, n$0){
195-
var iters = iters$1, n = n$0;
196-
for(;;){
197-
if(0 > iters) return n;
198-
var n$1 = rules(<v26{step}>, n), iters$0 = iters - 1 | 0;
199-
iters = iters$0;
200-
n = n$1;
201-
}
167+
[%expect
168+
{|
169+
function grow(iters$1, n$1){
170+
var iters = iters$1, n = n$1;
171+
for(;;){
172+
if(0 > iters) return n;
173+
var n$0 = step(n), iters$0 = iters - 1 | 0;
174+
iters = iters$0;
175+
n = n$0;
202176
}
203-
var Test = [0, rules, step, grow];
204-
runtime.caml_register_global(1, Test, "Test");
205-
return;
206177
}
207-
(globalThis));
208-
Some variables escaped: <v26{step}>
209-
/home/hugo/js_of_ocaml/_build/default/compiler/bin-js_of_ocaml/js_of_ocaml.exe: You found a bug. Please report it at https://github.com/ocsigen/js_of_ocaml/issues :
210-
Error: File "compiler/lib/js_assign.ml", line 503, characters 5-11: Assertion failed
211-
212-
process exited with error code 125
213-
/home/hugo/js_of_ocaml/_build/default/compiler/bin-js_of_ocaml/js_of_ocaml.exe --pretty --debug var --sourcemap --effects=disabled --disable=use-js-string --disable header --debug js_assign --Werror test.cmo -o test.js
214-
|}]
178+
//end
179+
|}]

0 commit comments

Comments
 (0)