Skip to content

Commit dafcaf0

Browse files
committed
WIP: back port a escape bug fix from trunk and patch [+2 primitive caml_blit_bytes, caml_is_js ]
1 parent 6497b03 commit dafcaf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+790
-405
lines changed

.depend

Lines changed: 74 additions & 72 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include stdlib/StdlibModules
1919

2020
CAMLC=$(CAMLRUN) boot/ocamlc -nostdlib -I boot
2121
CAMLOPT=$(CAMLRUN) ./ocamlopt -nostdlib -I stdlib -I otherlibs/dynlink
22-
COMPFLAGS=-strict-sequence -w +33..39+48+50 -warn-error A -bin-annot \
22+
COMPFLAGS=-strict-sequence -w +33..39+48+50 -w -40 -warn-error A -bin-annot \
2323
-safe-string $(INCLUDES)
2424
LINKFLAGS=
2525

@@ -64,12 +64,12 @@ TYPING=typing/ident.cmo typing/path.cmo \
6464
typing/typemod.cmo
6565

6666
COMP=bytecomp/lambda.cmo bytecomp/printlambda.cmo \
67-
bytecomp/typeopt.cmo bytecomp/switch.cmo bytecomp/matching.cmo \
67+
bytecomp/typeopt.cmo bytecomp/switch.cmo bytecomp/matching.cmo \
6868
bytecomp/translobj.cmo bytecomp/translcore.cmo \
6969
bytecomp/translclass.cmo bytecomp/translmod.cmo \
7070
bytecomp/simplif.cmo bytecomp/runtimedef.cmo \
7171
driver/pparse.cmo driver/main_args.cmo \
72-
driver/compenv.cmo driver/compmisc.cmo
72+
driver/compenv.cmo driver/compmisc.cmo
7373

7474
COMMON=$(UTILS) $(PARSING) $(TYPING) $(COMP)
7575

asmcomp/closure.ml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ let split_default_wrapper fun_id kind params body =
119119
let inner_id = Ident.create (Ident.name fun_id ^ "_inner") in
120120
let map_param p = try List.assoc p map with Not_found -> p in
121121
let args = List.map (fun p -> Lvar (map_param p)) params in
122-
let wrapper_body = Lapply (Lvar inner_id, args, Location.none) in
122+
let wrapper_body = Lapply (Lvar inner_id, args, Lambda.default_apply_info ()) in
123123

124124
let inner_params = List.map map_param params in
125125
let new_ids = List.map Ident.rename inner_params in
@@ -144,19 +144,19 @@ let split_default_wrapper fun_id kind params body =
144144

145145
let prim_size prim args =
146146
match prim with
147-
Pidentity -> 0
147+
| (Pidentity | Pbytes_to_string | Pbytes_of_string | Pchar_to_int | Pchar_of_int | Pmark_ocaml_object) -> 0
148148
| Pgetglobal id -> 1
149149
| Psetglobal id -> 1
150-
| Pmakeblock(tag, mut) -> 5 + List.length args
150+
| Pmakeblock(tag, _, mut) -> 5 + List.length args
151151
| Pfield f -> 1
152152
| Psetfield(f, isptr) -> if isptr then 4 else 1
153153
| Pfloatfield f -> 1
154154
| Psetfloatfield f -> 1
155155
| Pduprecord _ -> 10 + List.length args
156156
| Pccall p -> (if p.prim_alloc then 10 else 4) + List.length args
157157
| Praise _ -> 4
158-
| Pstringlength -> 5
159-
| Pstringrefs | Pstringsets -> 6
158+
| Pstringlength | Pbyteslength -> 5
159+
| Pstringrefs | Pstringsets | Pbytesrefs | Pbytessets -> 6
160160
| Pmakearray kind -> 5 + List.length args
161161
| Parraylength kind -> if kind = Pgenarray then 6 else 2
162162
| Parrayrefu kind -> if kind = Pgenarray then 12 else 2
@@ -241,6 +241,7 @@ let rec is_pure_clambda = function
241241
| Uconst _ -> true
242242
| Uprim((Psetglobal _ | Psetfield _ | Psetfloatfield _ | Pduprecord _ |
243243
Pccall _ | Praise _ | Poffsetref _ | Pstringsetu | Pstringsets |
244+
Pbytessetu | Pbytessets |
244245
Parraysetu _ | Parraysets _ | Pbigarrayset _), _, _) -> false
245246
| Uprim(p, args, _) -> List.for_all is_pure_clambda args
246247
| _ -> false
@@ -453,7 +454,7 @@ let field_approx n = function
453454
let simplif_prim_pure fpc p (args, approxs) dbg =
454455
match p, args, approxs with
455456
(* Block construction *)
456-
| Pmakeblock(tag, Immutable), _, _ ->
457+
| Pmakeblock(tag, _, Immutable), _, _ ->
457458
let field = function
458459
| Value_const c -> c
459460
| _ -> raise Exit
@@ -475,10 +476,10 @@ let simplif_prim_pure fpc p (args, approxs) dbg =
475476
when n < List.length ul ->
476477
(List.nth ul n, field_approx n approx)
477478
(* Strings *)
478-
| Pstringlength, _, [ Value_const(Uconst_ref(_, Uconst_string s)) ] ->
479+
| (Pstringlength | Pbyteslength), _, [ Value_const(Uconst_ref(_, Uconst_string s)) ] ->
479480
make_const_int (String.length s)
480481
(* Identity *)
481-
| Pidentity, [arg1], [app1] ->
482+
| (Pidentity | Pbytes_of_string | Pbytes_to_string | Pchar_to_int | Pchar_of_int | Pmark_ocaml_object), [arg1], [app1] ->
482483
(arg1, app1)
483484
(* Kind test *)
484485
| Pisint, _, [a1] ->
@@ -508,7 +509,7 @@ let simplif_prim fpc p (args, approxs as args_approxs) dbg =
508509
(* XXX : always return the same approxs as simplif_prim_pure? *)
509510
let approx =
510511
match p with
511-
| Pmakeblock(_, Immutable) ->
512+
| Pmakeblock(_, _, Immutable) ->
512513
Value_tuple (Array.of_list approxs)
513514
| _ ->
514515
Value_unknown
@@ -640,8 +641,8 @@ let rec bind_params_rec fpc subst params args body =
640641
let p1' = Ident.rename p1 in
641642
let u1, u2 =
642643
match Ident.name p1, a1 with
643-
| "*opt*", Uprim(Pmakeblock(0, Immutable), [a], dbg) ->
644-
a, Uprim(Pmakeblock(0, Immutable), [Uvar p1'], dbg)
644+
| "*opt*", Uprim(Pmakeblock(0, tag_info, Immutable), [a], dbg) ->
645+
a, Uprim(Pmakeblock(0, tag_info, Immutable), [Uvar p1'], dbg)
645646
| _ ->
646647
a1, Uvar p1'
647648
in
@@ -666,6 +667,7 @@ let rec is_pure = function
666667
| Lconst cst -> true
667668
| Lprim((Psetglobal _ | Psetfield _ | Psetfloatfield _ | Pduprecord _ |
668669
Pccall _ | Praise _ | Poffsetref _ | Pstringsetu | Pstringsets |
670+
Pbytessetu | Pbytessets |
669671
Parraysetu _ | Parraysets _ | Pbigarrayset _), _) -> false
670672
| Lprim(p, args) -> List.for_all is_pure args
671673
| Levent(lam, ev) -> is_pure lam
@@ -791,8 +793,8 @@ let rec close fenv cenv = function
791793
let rec transl = function
792794
| Const_base(Const_int n) -> Uconst_int n
793795
| Const_base(Const_char c) -> Uconst_int (Char.code c)
794-
| Const_pointer n -> Uconst_ptr n
795-
| Const_block (tag, fields) ->
796+
| Const_pointer (n,_) -> Uconst_ptr n
797+
| Const_block (tag, _, fields) ->
796798
str (Uconst_block (tag, List.map transl fields))
797799
| Const_float_array sl ->
798800
(* constant float arrays are really immutable *)
@@ -818,7 +820,7 @@ let rec close fenv cenv = function
818820
let nargs = List.length args in
819821
begin match (close fenv cenv funct, close_list fenv cenv args) with
820822
((ufunct, Value_closure(fundesc, approx_res)),
821-
[Uprim(Pmakeblock(_, _), uargs, _)])
823+
[Uprim(Pmakeblock(_,_, _), uargs, _)])
822824
when List.length uargs = - fundesc.fun_arity ->
823825
let app = direct_apply fundesc funct ufunct uargs in
824826
(app, strengthen_approx app approx_res)
@@ -913,7 +915,7 @@ let rec close fenv cenv = function
913915
end
914916
| Lprim(Pdirapply loc,[funct;arg])
915917
| Lprim(Prevapply loc,[arg;funct]) ->
916-
close fenv cenv (Lapply(funct, [arg], loc))
918+
close fenv cenv (Lapply(funct, [arg], Lambda.default_apply_info ~loc ()))
917919
| Lprim(Pgetglobal id, []) as lam ->
918920
check_constant_result lam
919921
(getglobal id)

asmcomp/cmmgen.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ let rec expr_size env = function
635635
expr_size (Ident.add id (expr_size env exp) env) body
636636
| Uletrec(bindings, body) ->
637637
expr_size env body
638-
| Uprim(Pmakeblock(tag, mut), args, _) ->
638+
| Uprim(Pmakeblock(tag,_, mut), args, _) ->
639639
RHS_block (List.length args)
640640
| Uprim(Pmakearray(Paddrarray | Pintarray), args, _) ->
641641
RHS_block (List.length args)
@@ -1020,7 +1020,7 @@ let check_bound unsafe dbg a1 a2 k =
10201020

10211021
let default_prim name =
10221022
{ prim_name = name; prim_arity = 0 (*ignored*);
1023-
prim_alloc = true; prim_native_name = ""; prim_native_float = false }
1023+
prim_alloc = true; prim_native_name = ""; prim_native_float = false ; prim_attributes = [] ; prim_ty = None}
10241024

10251025
let simplif_primitive_32bits = function
10261026
Pbintofint Pint64 -> Pccall (default_prim "caml_int64_of_int")
@@ -1385,9 +1385,9 @@ let rec transl = function
13851385
begin match (simplif_primitive prim, args) with
13861386
(Pgetglobal id, []) ->
13871387
Cconst_symbol (Ident.name id)
1388-
| (Pmakeblock(tag, mut), []) ->
1388+
| (Pmakeblock(tag, _, mut), []) ->
13891389
assert false
1390-
| (Pmakeblock(tag, mut), args) ->
1390+
| (Pmakeblock(tag,_, mut), args) ->
13911391
make_alloc tag (List.map transl args)
13921392
| (Pccall prim, args) ->
13931393
if prim.prim_native_float then
@@ -1555,7 +1555,7 @@ let rec transl = function
15551555
and transl_prim_1 p arg dbg =
15561556
match p with
15571557
(* Generic operations *)
1558-
Pidentity ->
1558+
| (Pidentity | Pbytes_to_string | Pbytes_of_string | Pchar_to_int | Pchar_of_int | Pmark_ocaml_object) ->
15591559
transl arg
15601560
| Pignore ->
15611561
return_unit(remove_unit (transl arg))
@@ -1607,7 +1607,7 @@ and transl_prim_1 p arg dbg =
16071607
| Pabsfloat ->
16081608
box_float(Cop(Cabsf, [transl_unbox_float arg]))
16091609
(* String operations *)
1610-
| Pstringlength ->
1610+
| (Pstringlength | Pbyteslength) ->
16111611
tag_int(string_length (transl arg))
16121612
(* Array operations *)
16131613
| Parraylength kind ->
@@ -1732,10 +1732,10 @@ and transl_prim_2 p arg1 arg2 dbg =
17321732
[transl_unbox_float arg1; transl_unbox_float arg2]))
17331733

17341734
(* String operations *)
1735-
| Pstringrefu ->
1735+
| (Pstringrefu | Pbytesrefu) ->
17361736
tag_int(Cop(Cload Byte_unsigned,
17371737
[add_int (transl arg1) (untag_int(transl arg2))]))
1738-
| Pstringrefs ->
1738+
| (Pstringrefs | Pbytesrefs) ->
17391739
tag_int
17401740
(bind "str" (transl arg1) (fun str ->
17411741
bind "index" (untag_int (transl arg2)) (fun idx ->
@@ -1892,11 +1892,11 @@ and transl_prim_2 p arg1 arg2 dbg =
18921892
and transl_prim_3 p arg1 arg2 arg3 dbg =
18931893
match p with
18941894
(* String operations *)
1895-
Pstringsetu ->
1895+
| (Pstringsetu | Pbytessetu) ->
18961896
return_unit(Cop(Cstore Byte_unsigned,
18971897
[add_int (transl arg1) (untag_int(transl arg2));
18981898
untag_int(transl arg3)]))
1899-
| Pstringsets ->
1899+
| (Pstringsets | Pbytessets) ->
19001900
return_unit
19011901
(bind "str" (transl arg1) (fun str ->
19021902
bind "index" (untag_int (transl arg2)) (fun idx ->

boot/ocamlc

7.5 MB
Binary file not shown.

boot/ocamldep

2.43 MB
Binary file not shown.

boot/ocamllex

1.52 MB
Binary file not shown.

bytecomp/bytegen.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ let rec size_of_lambda = function
149149
end
150150
| Llet(str, id, arg, body) -> size_of_lambda body
151151
| Lletrec(bindings, body) -> size_of_lambda body
152-
| Lprim(Pmakeblock(tag, mut), args) -> RHS_block (List.length args)
152+
| Lprim(Pmakeblock(tag, _, mut), args) -> RHS_block (List.length args)
153153
| Lprim (Pmakearray (Paddrarray|Pintarray), args) ->
154154
RHS_block (List.length args)
155155
| Lprim (Pmakearray Pfloatarray, args) -> RHS_floatblock (List.length args)
@@ -300,7 +300,7 @@ let comp_primitive p args =
300300
Pgetglobal id -> Kgetglobal id
301301
| Psetglobal id -> Ksetglobal id
302302
| Pintcomp cmp -> Kintcomp cmp
303-
| Pmakeblock(tag, mut) -> Kmakeblock(List.length args, tag)
303+
| Pmakeblock(tag, _, mut) -> Kmakeblock(List.length args, tag)
304304
| Pfield n -> Kgetfield n
305305
| Psetfield(n, ptr) -> Ksetfield n
306306
| Pfloatfield n -> Kgetfloatfield n
@@ -335,11 +335,11 @@ let comp_primitive p args =
335335
| Pfloatcomp Cgt -> Kccall("caml_gt_float", 2)
336336
| Pfloatcomp Cle -> Kccall("caml_le_float", 2)
337337
| Pfloatcomp Cge -> Kccall("caml_ge_float", 2)
338-
| Pstringlength -> Kccall("caml_ml_string_length", 1)
339-
| Pstringrefs -> Kccall("caml_string_get", 2)
340-
| Pstringsets -> Kccall("caml_string_set", 3)
341-
| Pstringrefu -> Kgetstringchar
342-
| Pstringsetu -> Ksetstringchar
338+
| Pstringlength | Pbyteslength -> Kccall("caml_ml_string_length", 1)
339+
| Pstringrefs | Pbytesrefs -> Kccall("caml_string_get", 2)
340+
| Pstringsets | Pbytessets -> Kccall("caml_string_set", 3)
341+
| Pstringrefu | Pbytesrefu -> Kgetstringchar
342+
| Pstringsetu | Pbytessetu -> Ksetstringchar
343343
| Pstring_load_16(_) -> Kccall("caml_string_get16", 2)
344344
| Pstring_load_32(_) -> Kccall("caml_string_get32", 2)
345345
| Pstring_load_64(_) -> Kccall("caml_string_get64", 2)
@@ -555,13 +555,13 @@ let rec comp_expr env exp sz cont =
555555
in
556556
comp_init env sz decl_size
557557
end
558-
| Lprim(Pidentity, [arg]) ->
558+
| Lprim((Pidentity | Pbytes_to_string | Pbytes_of_string | Pchar_to_int | Pchar_of_int | Pmark_ocaml_object), [arg]) ->
559559
comp_expr env arg sz cont
560560
| Lprim(Pignore, [arg]) ->
561561
comp_expr env arg sz (add_const_unit cont)
562562
| Lprim(Pdirapply loc, [func;arg])
563563
| Lprim(Prevapply loc, [arg;func]) ->
564-
let exp = Lapply(func, [arg], loc) in
564+
let exp = Lapply(func, [arg], Lambda.default_apply_info ~loc ()) in
565565
comp_expr env exp sz cont
566566
| Lprim(Pnot, [arg]) ->
567567
let newcont =

bytecomp/emitcode.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ exception AsInt
5050
let const_as_int = function
5151
| Const_base(Const_int i) -> i
5252
| Const_base(Const_char c) -> Char.code c
53-
| Const_pointer i -> i
53+
| Const_pointer (i,_) -> i
5454
| _ -> raise AsInt
5555

5656
let is_immed i = immed_min <= i && i <= immed_max
@@ -210,11 +210,11 @@ let emit_instr = function
210210
else (out opCONSTINT; out_int i)
211211
| Const_base(Const_char c) ->
212212
out opCONSTINT; out_int (Char.code c)
213-
| Const_pointer i ->
213+
| Const_pointer (i,_) ->
214214
if i >= 0 && i <= 3
215215
then out (opCONST0 + i)
216216
else (out opCONSTINT; out_int i)
217-
| Const_block(t, []) ->
217+
| Const_block(t,_, []) ->
218218
if t = 0 then out opATOM0 else (out opATOM; out_int t)
219219
| _ ->
220220
out opGETGLOBAL; slot_for_literal sc
@@ -336,11 +336,11 @@ let rec emit = function
336336
else (out opPUSHCONSTINT; out_int i)
337337
| Const_base(Const_char c) ->
338338
out opPUSHCONSTINT; out_int(Char.code c)
339-
| Const_pointer i ->
339+
| Const_pointer (i,_) ->
340340
if i >= 0 && i <= 3
341341
then out (opPUSHCONST0 + i)
342342
else (out opPUSHCONSTINT; out_int i)
343-
| Const_block(t, []) ->
343+
| Const_block(t,_, []) ->
344344
if t = 0 then out opPUSHATOM0 else (out opPUSHATOM; out_int t)
345345
| _ ->
346346
out opPUSHGETGLOBAL; slot_for_literal sc

0 commit comments

Comments
 (0)