Skip to content

Commit 80b1cf0

Browse files
committed
Squashed 'ocaml/' changes from 0b0aefb..ce76e02
ce76e02 flambda-backend: Bugfix for type_application (#746) 44f3afb flambda-backend: PR580 for main branch (#743) b851eaa flambda-backend: Backport first part of ocaml/ocaml PR10498 (#737) fafb4bd flambda-backend: Fix return mode for eta-expanded function in type_argument (#735) c31f6c3 flambda-backend: Fix treatment of functions called [@nontail] (#725) 847781e flambda-backend: Fix build_upstream post-PR703 (#712) bfcbbf8 flambda-backend: Extend Pblock value kind to handle variants (#703) b2cab95 flambda-backend: Merge ocaml-jst a6d6e0e flambda-backend: Merge ocaml-jst 88a4f63 flambda-backend: Use Pmakearray for immutable arrays (#699) eeaa44b flambda-backend: Install an ocamldoc binary (#695) 48d322b flambda-backend: Ensure that GC is not invoked from bounds check failures (#681) 4370fa1 flambda-backend: Review changes of term directory (#602) 65a4566 flambda-backend: Add code coverage using bisect_ppx (#352) 63ab65f flambda-backend: Bugfix for primitive inclusion (#662) 7e3e0c8 flambda-backend: Fix inclusion checks for primitives (#661) 96c68f9 flambda-backend: Speed up linking by changing cmxa format (#607) 1829150 flambda-backend: Bugfix for Translmod.all_idents (#659) git-subtree-dir: ocaml git-subtree-split: ce76e02
1 parent 58d201d commit 80b1cf0

Some content is hidden

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

45 files changed

+935
-254
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ _build
5555
/ocamlopt
5656
/ocamlopt.opt
5757
/ocamlnat
58+
/dirs-to-ignore.inc
5859

5960
# specific files and patterns in sub-directories
6061

asmcomp/cmm_helpers.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ let send_function (arity, mode) =
20022002
let cache = cache in
20032003
let fun_name = send_function_name arity mode in
20042004
let fun_args =
2005-
[obj, typ_val; tag, typ_int; cache, typ_val]
2005+
[obj, typ_val; tag, typ_int; cache, typ_addr]
20062006
@ List.map (fun id -> (id, typ_val)) (List.tl args) in
20072007
let fun_dbg = placeholder_fun_dbg ~human_name:fun_name in
20082008
Cfunction

asmcomp/cmmgen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ and transl_catch env nfail ids body handler dbg =
711711
let strict =
712712
match kind with
713713
| Pfloatval | Pboxedintval _ -> false
714-
| Pintval | Pgenval | Pblock _ | Parrayval _ -> true
714+
| Pintval | Pgenval | Pvariant _ | Parrayval _ -> true
715715
in
716716
u := join_unboxed_number_kind ~strict !u
717717
(is_unboxed_number_cmm ~strict c)
@@ -1179,7 +1179,7 @@ and transl_let env str kind id exp transl_body =
11791179
we do it only if this indeed allows us to get rid of
11801180
some allocations in the bound expression. *)
11811181
is_unboxed_number_cmm ~strict:false cexp
1182-
| _, (Pgenval | Pblock _ | Parrayval _) ->
1182+
| _, (Pgenval | Pvariant _ | Parrayval _) ->
11831183
(* Here we don't know statically that the bound expression
11841184
evaluates to an unboxable number type. We need to be stricter
11851185
and ensure that all possible branches in the expression

dune

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@
121121
(libraries ocamlbytecomp ocamlcommon)
122122
(modules main_native))
123123

124-
(data_only_dirs yacc)
124+
; Disabled since there can be only one (data_only_dirs) declaration
125+
;(data_only_dirs yacc)
126+
(include dirs-to-ignore.inc)
125127

126128
(rule
127129
(deps (source_tree yacc))

lambda/lambda.ml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ and float_comparison =
220220

221221
and value_kind =
222222
Pgenval | Pfloatval | Pboxedintval of boxed_integer | Pintval
223-
| Pblock of { tag : int; fields : value_kind list }
223+
| Pvariant of {
224+
consts : int list;
225+
non_consts : (int * value_kind list) list;
226+
}
224227
| Parrayval of array_kind
225228

226229
and block_shape =
@@ -273,11 +276,20 @@ let rec equal_value_kind x y =
273276
| Pboxedintval bi1, Pboxedintval bi2 -> equal_boxed_integer bi1 bi2
274277
| Pintval, Pintval -> true
275278
| Parrayval elt_kind1, Parrayval elt_kind2 -> elt_kind1 = elt_kind2
276-
| Pblock { tag = tag1; fields = fields1 },
277-
Pblock { tag = tag2; fields = fields2 } ->
278-
tag1 = tag2 && List.length fields1 = List.length fields2 &&
279-
List.for_all2 equal_value_kind fields1 fields2
280-
| (Pgenval | Pfloatval | Pboxedintval _ | Pintval | Pblock _
279+
| Pvariant { consts = consts1; non_consts = non_consts1; },
280+
Pvariant { consts = consts2; non_consts = non_consts2; } ->
281+
let consts1 = List.sort Int.compare consts1 in
282+
let consts2 = List.sort Int.compare consts2 in
283+
let compare_by_tag (tag1, _) (tag2, _) = Int.compare tag1 tag2 in
284+
let non_consts1 = List.sort compare_by_tag non_consts1 in
285+
let non_consts2 = List.sort compare_by_tag non_consts2 in
286+
List.equal Int.equal consts1 consts2
287+
&& List.equal (fun (tag1, fields1) (tag2, fields2) ->
288+
Int.equal tag1 tag2
289+
&& List.length fields1 = List.length fields2
290+
&& List.for_all2 equal_value_kind fields1 fields2)
291+
non_consts1 non_consts2
292+
| (Pgenval | Pfloatval | Pboxedintval _ | Pintval | Pvariant _
281293
| Parrayval _), _ -> false
282294

283295

lambda/lambda.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ and array_kind =
193193

194194
and value_kind =
195195
Pgenval | Pfloatval | Pboxedintval of boxed_integer | Pintval
196-
| Pblock of { tag : int; fields : value_kind list }
196+
| Pvariant of {
197+
consts : int list;
198+
non_consts : (int * value_kind list) list;
199+
(** [non_consts] must be non-empty. For constant variants [Pintval]
200+
must be used. This causes a small loss of precision but it is not
201+
expected to be significant. *)
202+
}
197203
| Parrayval of array_kind
198204

199205
and block_shape =

lambda/printlambda.ml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,37 @@ let boxed_integer_name = function
6363
| Pint32 -> "int32"
6464
| Pint64 -> "int64"
6565

66+
let variant_kind print_contents ppf ~consts ~non_consts =
67+
fprintf ppf "@[<hov 1>[(consts (%a))@ (non_consts (%a))]@]"
68+
(Format.pp_print_list ~pp_sep:Format.pp_print_space Format.pp_print_int)
69+
consts
70+
(Format.pp_print_list ~pp_sep:Format.pp_print_space
71+
(fun ppf (tag, fields) ->
72+
fprintf ppf "@[<hov 1>[%d:@ %a]@]"
73+
tag
74+
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
75+
print_contents)
76+
fields
77+
))
78+
non_consts
79+
6680
let rec value_kind ppf = function
6781
| Pgenval -> ()
6882
| Pintval -> fprintf ppf "[int]"
6983
| Pfloatval -> fprintf ppf "[float]"
7084
| Parrayval elt_kind -> fprintf ppf "[%sarray]" (array_kind elt_kind)
7185
| Pboxedintval bi -> fprintf ppf "[%s]" (boxed_integer_name bi)
72-
| Pblock { tag; fields } ->
73-
fprintf ppf "[%d: %a]" tag
74-
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
75-
value_kind') fields
86+
| Pvariant { consts; non_consts; } ->
87+
variant_kind value_kind' ppf ~consts ~non_consts
7688

7789
and value_kind' ppf = function
7890
| Pgenval -> fprintf ppf "*"
7991
| Pintval -> fprintf ppf "[int]"
8092
| Pfloatval -> fprintf ppf "[float]"
8193
| Parrayval elt_kind -> fprintf ppf "[%sarray]" (array_kind elt_kind)
8294
| Pboxedintval bi -> fprintf ppf "[%s]" (boxed_integer_name bi)
83-
| Pblock { tag; fields } ->
84-
fprintf ppf "[%d: %a]" tag
85-
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
86-
value_kind') fields
95+
| Pvariant { consts; non_consts; } ->
96+
variant_kind value_kind' ppf ~consts ~non_consts
8797

8898
let return_kind ppf (mode, kind) =
8999
let smode = alloc_mode mode in
@@ -95,21 +105,27 @@ let return_kind ppf (mode, kind) =
95105
| Parrayval elt_kind ->
96106
fprintf ppf ": %s%sarray@ " smode (array_kind elt_kind)
97107
| Pboxedintval bi -> fprintf ppf ": %s%s@ " smode (boxed_integer_name bi)
98-
| Pblock { tag; fields } ->
99-
fprintf ppf ": %s[%d: %a]@ " smode tag
100-
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
101-
value_kind') fields
108+
| Pvariant { consts; non_consts; } ->
109+
variant_kind value_kind' ppf ~consts ~non_consts
102110

103111
let field_kind ppf = function
104112
| Pgenval -> pp_print_string ppf "*"
105113
| Pintval -> pp_print_string ppf "int"
106114
| Pfloatval -> pp_print_string ppf "float"
107115
| Parrayval elt_kind -> fprintf ppf "%s-array" (array_kind elt_kind)
108116
| Pboxedintval bi -> pp_print_string ppf (boxed_integer_name bi)
109-
| Pblock { tag; fields } ->
110-
fprintf ppf "[%d: %a]" tag
111-
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
112-
value_kind') fields
117+
| Pvariant { consts; non_consts; } ->
118+
fprintf ppf "@[<hov 1>[(consts (%a))@ (non_consts (%a))]@]"
119+
(Format.pp_print_list ~pp_sep:Format.pp_print_space Format.pp_print_int)
120+
consts
121+
(Format.pp_print_list ~pp_sep:Format.pp_print_space
122+
(fun ppf (tag, fields) ->
123+
fprintf ppf "@[<hov 1>[%d:@ %a]@]"
124+
tag
125+
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
126+
value_kind') fields
127+
))
128+
non_consts
113129

114130
let alloc_kind = function
115131
| Alloc_heap -> ""

lambda/printlambda.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ val lambda: formatter -> lambda -> unit
2424
val program: formatter -> program -> unit
2525
val primitive: formatter -> primitive -> unit
2626
val name_of_primitive : primitive -> string
27+
val variant_kind : (formatter -> value_kind -> unit) ->
28+
formatter -> consts:int list -> non_consts:(int * value_kind list) list ->
29+
unit
2730
val value_kind : formatter -> value_kind -> unit
2831
val value_kind' : formatter -> value_kind -> unit
2932
val block_shape : formatter -> value_kind list option -> unit

lambda/translcore.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ let rec iter_exn_names f pat =
299299
let transl_ident loc env ty path desc kind =
300300
match desc.val_kind, kind with
301301
| Val_prim p, Id_prim pmode ->
302-
let poly_mode = transl_alloc_mode pmode in
302+
let poly_mode = Option.map transl_alloc_mode pmode in
303303
Translprim.transl_primitive loc p env ty ~poly_mode (Some path)
304304
| Val_anc _, Id_value ->
305305
raise(Error(to_location loc, Free_super_var))
@@ -374,7 +374,7 @@ and transl_exp0 ~in_new_scope ~scopes e =
374374
if extra_args = [] then transl_apply_position pos
375375
else Rc_normal
376376
in
377-
let prim_mode = transl_alloc_mode pmode in
377+
let prim_mode = Option.map transl_alloc_mode pmode in
378378
let lam =
379379
Translprim.transl_primitive_application
380380
(of_location ~scopes e.exp_loc) p e.exp_env prim_type prim_mode
@@ -557,12 +557,16 @@ and transl_exp0 ~in_new_scope ~scopes e =
557557
of_location ~scopes e.exp_loc)
558558
| cl ->
559559
let imm_array =
560-
match kind with
561-
| Paddrarray | Pintarray ->
560+
if Config.flambda2 then
561+
Lprim (Pmakearray (kind, Immutable, mode), ll,
562+
of_location ~scopes e.exp_loc)
563+
else
564+
match kind with
565+
| Paddrarray | Pintarray ->
562566
Lconst(Const_block(0, cl))
563-
| Pfloatarray ->
567+
| Pfloatarray ->
564568
Lconst(Const_float_array(List.map extract_float cl))
565-
| Pgenarray ->
569+
| Pgenarray ->
566570
raise Not_constant (* can this really happen? *)
567571
in
568572
Lprim (Pduparray (kind, Mutable), [imm_array],

lambda/translmod.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ let rec apply_coercion loc strict restr arg =
9797
let carg = apply_coercion loc Alias cc_arg (Lvar param) in
9898
apply_coercion_result loc strict arg [param, Pgenval] [carg] cc_res
9999
| Tcoerce_primitive { pc_desc; pc_env; pc_type; pc_poly_mode } ->
100-
let poly_mode = Translcore.transl_alloc_mode pc_poly_mode in
100+
let poly_mode = Option.map Translcore.transl_alloc_mode pc_poly_mode in
101101
Translprim.transl_primitive loc pc_desc pc_env pc_type ~poly_mode None
102102
| Tcoerce_alias (env, path, cc) ->
103103
let lam = transl_module_path loc env path in
@@ -613,7 +613,8 @@ and transl_structure ~scopes loc fields cc rootpath final_env = function
613613
| Tcoerce_primitive p ->
614614
let loc = of_location ~scopes p.pc_loc in
615615
let poly_mode =
616-
Translcore.transl_alloc_mode p.pc_poly_mode
616+
Option.map
617+
Translcore.transl_alloc_mode p.pc_poly_mode
617618
in
618619
Translprim.transl_primitive
619620
loc p.pc_desc p.pc_env p.pc_type ~poly_mode None
@@ -987,8 +988,9 @@ and all_idents = function
987988
| Tstr_class_type _ -> all_idents rem
988989

989990
| Tstr_include{incl_type; incl_mod={mod_desc =
990-
Tmod_constraint ({mod_desc = Tmod_structure str},
991-
_, _, _)}} ->
991+
( Tmod_constraint ({mod_desc = Tmod_structure str},
992+
_, _, _)
993+
| Tmod_structure str ) }} ->
992994
bound_value_identifiers incl_type
993995
@ all_idents str.str_items
994996
@ all_idents rem
@@ -1038,7 +1040,7 @@ let field_of_str loc str =
10381040
fun (pos, cc) ->
10391041
match cc with
10401042
| Tcoerce_primitive { pc_desc; pc_env; pc_type; pc_poly_mode } ->
1041-
let poly_mode = Translcore.transl_alloc_mode pc_poly_mode in
1043+
let poly_mode = Option.map Translcore.transl_alloc_mode pc_poly_mode in
10421044
Translprim.transl_primitive loc pc_desc pc_env pc_type ~poly_mode None
10431045
| Tcoerce_alias (env, path, cc) ->
10441046
let lam = transl_module_path loc env path in
@@ -1379,7 +1381,9 @@ let transl_store_structure ~scopes glob map prims aliases str =
13791381
List.fold_right (add_ident may_coerce) idlist subst
13801382

13811383
and store_primitive (pos, prim) cont =
1382-
let poly_mode = Translcore.transl_alloc_mode prim.pc_poly_mode in
1384+
let poly_mode =
1385+
Option.map Translcore.transl_alloc_mode prim.pc_poly_mode
1386+
in
13831387
Lsequence(Lprim(mod_setfield pos,
13841388
[Lprim(Pgetglobal glob, [], Loc_unknown);
13851389
Translprim.transl_primitive Loc_unknown

lambda/translprim.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ let prim_sys_argv =
112112
let to_alloc_mode ~poly = function
113113
| Prim_global, _ -> alloc_heap
114114
| Prim_local, _ -> alloc_local
115-
| Prim_poly, _ -> poly
115+
| Prim_poly, _ ->
116+
match poly with
117+
| None -> assert false
118+
| Some mode -> mode
116119

117120
let lookup_primitive loc poly pos p =
118121
let mode = to_alloc_mode ~poly p.prim_native_repr_res in
@@ -714,8 +717,8 @@ let lambda_of_prim prim_name prim loc args arg_exps =
714717
let check_primitive_arity loc p =
715718
let mode =
716719
match p.prim_native_repr_res with
717-
| Prim_global, _ | Prim_poly, _ -> alloc_heap
718-
| Prim_local, _ -> alloc_local
720+
| Prim_global, _ | Prim_poly, _ -> Some alloc_heap
721+
| Prim_local, _ -> Some alloc_local
719722
in
720723
let prim = lookup_primitive loc mode Rc_normal p in
721724
let ok =

lambda/translprim.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ val check_primitive_arity :
3535
val transl_primitive :
3636
Lambda.scoped_location -> Primitive.description -> Env.t ->
3737
Types.type_expr ->
38-
poly_mode:Lambda.alloc_mode ->
38+
poly_mode:Lambda.alloc_mode option ->
3939
Path.t option ->
4040
Lambda.lambda
4141

4242
val transl_primitive_application :
4343
Lambda.scoped_location -> Primitive.description -> Env.t ->
44-
Types.type_expr -> Lambda.alloc_mode -> Path.t ->
44+
Types.type_expr -> Lambda.alloc_mode option -> Path.t ->
4545
Typedtree.expression option ->
4646
Lambda.lambda list -> Typedtree.expression list ->
4747
Lambda.region_close -> Lambda.lambda

middle_end/clambda_primitives.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ and array_kind = Lambda.array_kind =
135135
and value_kind = Lambda.value_kind =
136136
(* CR mshinwell: Pfloatval should be renamed to Pboxedfloatval *)
137137
Pgenval | Pfloatval | Pboxedintval of boxed_integer | Pintval
138-
| Pblock of { tag : int; fields : value_kind list }
138+
| Pvariant of {
139+
consts : int list;
140+
non_consts : (int * value_kind list) list;
141+
}
139142
| Parrayval of array_kind
140143

141144
and block_shape = Lambda.block_shape

middle_end/clambda_primitives.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ and array_kind = Lambda.array_kind =
138138
and value_kind = Lambda.value_kind =
139139
(* CR mshinwell: Pfloatval should be renamed to Pboxedfloatval *)
140140
Pgenval | Pfloatval | Pboxedintval of boxed_integer | Pintval
141-
| Pblock of { tag : int; fields : value_kind list }
141+
| Pvariant of {
142+
consts : int list;
143+
non_consts : (int * value_kind list) list;
144+
}
142145
| Parrayval of array_kind
143146

144147
and block_shape = Lambda.block_shape

middle_end/printclambda.ml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,33 @@ let mutable_flag = function
2424
| Lambda.Mutable-> "[mut]"
2525
| Lambda.Immutable | Lambda.Immutable_unique -> ""
2626

27-
let value_kind =
27+
let rec value_kind0 ppf kind =
2828
let open Lambda in
29-
function
30-
| Pgenval -> ""
31-
| Pintval -> ":int"
32-
| Pfloatval -> ":float"
33-
| Parrayval Pgenarray -> ":genarray"
34-
| Parrayval Pintarray -> ":intarray"
35-
| Parrayval Pfloatarray -> ":floatarray"
36-
| Parrayval Paddrarray -> ":addrarray"
37-
| Pboxedintval Pnativeint -> ":nativeint"
38-
| Pboxedintval Pint32 -> ":int32"
39-
| Pboxedintval Pint64 -> ":int64"
40-
| Pblock { tag; fields } ->
41-
asprintf ":[%d: %a]" tag
42-
(Format.pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
43-
Printlambda.value_kind') fields
29+
match kind with
30+
| Pgenval -> Format.pp_print_string ppf ""
31+
| Pintval -> Format.pp_print_string ppf ":int"
32+
| Pfloatval -> Format.pp_print_string ppf ":float"
33+
| Parrayval Pgenarray -> Format.pp_print_string ppf ":genarray"
34+
| Parrayval Pintarray -> Format.pp_print_string ppf ":intarray"
35+
| Parrayval Pfloatarray -> Format.pp_print_string ppf ":floatarray"
36+
| Parrayval Paddrarray -> Format.pp_print_string ppf ":addrarray"
37+
| Pboxedintval Pnativeint -> Format.pp_print_string ppf ":nativeint"
38+
| Pboxedintval Pint32 -> Format.pp_print_string ppf ":int32"
39+
| Pboxedintval Pint64 -> Format.pp_print_string ppf ":int64"
40+
| Pvariant { consts; non_consts } ->
41+
Format.fprintf ppf "@[<hov 1>[(consts (%a))@ (non_consts (%a))]@]"
42+
(Format.pp_print_list ~pp_sep:Format.pp_print_space Format.pp_print_int)
43+
consts
44+
(Format.pp_print_list ~pp_sep:Format.pp_print_space
45+
(fun ppf (tag, fields) ->
46+
fprintf ppf "@[<hov 1>[%d:@ %a]@]" tag
47+
(Format.pp_print_list
48+
~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
49+
value_kind0)
50+
fields))
51+
non_consts
52+
53+
let value_kind kind = Format.asprintf "%a" value_kind0 kind
4454

4555
let rec structured_constant ppf = function
4656
| Uconst_float x -> fprintf ppf "%F" x

0 commit comments

Comments
 (0)