Skip to content

Commit d1d4f44

Browse files
committed
Fix assert failure in double translation
We have a pass that removes empty blocks. This can trigger an assertion failure in code generation. It is safe to remove this assertion.
1 parent 70aac7f commit d1d4f44

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

compiler/lib/generate.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,6 @@ and compile_conditional st queue ~fall_through loc last scope_stack : _ * _ =
19471947
compile_branch st J.U [] e1 scope_stack ~fall_through
19481948
in
19491949
let exn_var, handler =
1950-
assert (not (List.mem x ~set:(snd e1)));
19511950
let wrap_exn x =
19521951
J.call
19531952
(Share.get_prim (runtime_fun st.ctx) "caml_wrap_exception" st.ctx.Ctx.share)

compiler/tests-compiler/dune.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,21 @@
449449
(preprocess
450450
(pps ppx_expect)))
451451

452+
(library
453+
;; compiler/tests-compiler/gh1868.ml
454+
(name gh1868_15)
455+
(enabled_if true)
456+
(modules gh1868)
457+
(libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper)
458+
(inline_tests
459+
(enabled_if true)
460+
(deps
461+
(file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe)
462+
(file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe)))
463+
(flags (:standard -open Jsoo_compiler_expect_tests_helper))
464+
(preprocess
465+
(pps ppx_expect)))
466+
452467
(library
453468
;; compiler/tests-compiler/gh747.ml
454469
(name gh747_15)

compiler/tests-compiler/gh1868.ml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
(* Js_of_ocaml compiler
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2019 Hugo Heuzard
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
20+
open Util
21+
22+
let%expect_test "" =
23+
let program =
24+
compile_and_parse
25+
~effects:`Double_translation
26+
{|
27+
exception Nested of exn
28+
let wrap f =
29+
try f () with exn ->
30+
let rec unwrap exn =
31+
match exn with
32+
| Nested e -> unwrap e
33+
| _ -> raise exn
34+
in
35+
unwrap exn
36+
|}
37+
in
38+
print_double_fun_decl program "wrap";
39+
[%expect {|
40+
function wrap$0(f){
41+
try{var _d_ = caml_call1(f, 0); return _d_;}
42+
catch(exn$2){
43+
var exn = caml_wrap_exception(exn$2), exn$0 = exn;
44+
for(;;){
45+
if(exn$0[1] !== Nested) throw caml_maybe_attach_backtrace(exn$0, 1);
46+
var exn$1 = exn$0[2];
47+
exn$0 = exn$1;
48+
}
49+
}
50+
}
51+
//end
52+
function wrap$1(f, cont){
53+
function _b_(exn$1){
54+
if(exn$1[1] === Nested){
55+
var exn$0 = exn$1[2];
56+
return caml_exact_trampoline_call1(_b_, exn$0);
57+
}
58+
var raise = caml_pop_trap(), exn = caml_maybe_attach_backtrace(exn$1, 1);
59+
return raise(exn);
60+
}
61+
runtime.caml_push_trap(_b_);
62+
return caml_trampoline_cps_call2
63+
(f, 0, function(_c_){caml_pop_trap(); return cont(_c_);});
64+
}
65+
//end
66+
var wrap = runtime.caml_cps_closure(wrap$0, wrap$1);
67+
//end |}]

compiler/tests-compiler/util/util.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,11 @@ class find_double_function_declaration r n =
527527
( S { name = Utf8 name; _ }
528528
, Some
529529
( ECall
530-
( EVar (S { name = Utf8 "caml_cps_closure"; _ })
530+
( ( EVar (S { name = Utf8 "caml_cps_closure"; _ })
531+
| EDot
532+
( EVar (S { name = Utf8 "runtime"; _ })
533+
, _
534+
, Utf8 "caml_cps_closure" ) )
531535
, _
532536
, [ Arg e1; Arg e2 ]
533537
, _ )

0 commit comments

Comments
 (0)