Skip to content

Commit 5123d61

Browse files
authored
Revert "Add a proper top and bottom layout" (#1169)
1 parent a73ceca commit 5123d61

21 files changed

+40
-204
lines changed

backend/cmm_helpers.ml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,11 +2654,7 @@ let rec make_curry_apply result narity args_type args clos n =
26542654
:: args)
26552655
newclos (n - 1) )
26562656

2657-
let machtype_of_layout (layout : Lambda.layout) =
2658-
match layout with
2659-
| Ptop -> Misc.fatal_error "No machtype for layout [Ptop]"
2660-
| Pbottom -> Misc.fatal_error "No unique machtype for layout [Pbottom]"
2661-
| Pvalue _ -> typ_val
2657+
let machtype_of_layout = function Lambda.Pvalue _ -> typ_val
26622658

26632659
let final_curry_function nlocal arity result =
26642660
let last_arg = V.create_local "arg" in
@@ -3993,9 +3989,4 @@ let transl_attrib : Lambda.check_attribute -> Cmm.codegen_option list = function
39933989
| Assert p -> [Assert (transl_property p)]
39943990
| Assume p -> [Assume (transl_property p)]
39953991

3996-
let kind_of_layout (layout : Lambda.layout) =
3997-
match layout with
3998-
| Ptop | Pbottom ->
3999-
(* This is incorrect but only used for unboxing *)
4000-
Vval Pgenval
4001-
| Pvalue kind -> Vval kind
3992+
let kind_of_layout (Lambda.Pvalue kind) = Vval kind

backend/cmmgen.ml

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,9 @@ let rec transl env e =
506506
| Ugeneric_apply(clos, args, args_layout, result_layout, kind, dbg) ->
507507
let clos = transl env clos in
508508
let args = List.map (transl env) args in
509-
if List.mem Pbottom args_layout then
510-
(* [machtype_of_layout] will fail on Pbottom, convert it to a sequence
511-
and remove the call, preserving the execution order. *)
512-
List.fold_left2 (fun rest arg arg_layout ->
513-
if arg_layout = Pbottom then
514-
arg
515-
else
516-
Csequence(remove_unit arg, rest)
517-
) (Ctuple []) args args_layout
518-
else
519-
let args_type = List.map machtype_of_layout args_layout in
520-
let return = machtype_of_layout result_layout in
521-
generic_apply (mut_from_env env clos) clos args args_type return kind dbg
509+
let args_type = List.map machtype_of_layout args_layout in
510+
let return = machtype_of_layout result_layout in
511+
generic_apply (mut_from_env env clos) clos args args_type return kind dbg
522512
| Usend(kind, met, obj, args, args_layout, result_layout, pos, dbg) ->
523513
let met = transl env met in
524514
let obj = transl env obj in
@@ -797,19 +787,10 @@ and transl_catch (kind : Cmm.value_kind) env nfail ids body handler dbg =
797787
each argument. *)
798788
let report args =
799789
List.iter2
800-
(fun (id, (layout : Lambda.layout), u) c ->
801-
match layout with
802-
| Ptop ->
803-
Misc.fatal_errorf "Variable %a with layout [Ptop] can't be compiled"
804-
VP.print id
805-
| Pbottom ->
806-
Misc.fatal_errorf
807-
"Variable %a with layout [Pbottom] can't be compiled"
808-
VP.print id
809-
| Pvalue kind ->
810-
let strict = is_strict kind in
811-
u := join_unboxed_number_kind ~strict !u
812-
(is_unboxed_number_cmm c)
790+
(fun (_id, Pvalue kind, u) c ->
791+
let strict = is_strict kind in
792+
u := join_unboxed_number_kind ~strict !u
793+
(is_unboxed_number_cmm c)
813794
)
814795
ids args
815796
in
@@ -1254,7 +1235,7 @@ and transl_unbox_sized size dbg env exp =
12541235
| Thirty_two -> transl_unbox_int dbg env Pint32 exp
12551236
| Sixty_four -> transl_unbox_int dbg env Pint64 exp
12561237

1257-
and transl_let_value env str (kind : Lambda.value_kind) id exp transl_body =
1238+
and transl_let env str (Pvalue kind : Lambda.layout) id exp transl_body =
12581239
let dbg = Debuginfo.none in
12591240
let cexp = transl env exp in
12601241
let unboxing =
@@ -1294,20 +1275,6 @@ and transl_let_value env str (kind : Lambda.value_kind) id exp transl_body =
12941275
| Mutable, bn -> Clet_mut (v, typ_of_boxed_number bn, cexp, body)
12951276
end
12961277

1297-
and transl_let env str (layout : Lambda.layout) id exp transl_body =
1298-
match layout with
1299-
| Ptop ->
1300-
Misc.fatal_errorf "Variable %a with layout [Ptop] can't be compiled"
1301-
VP.print id
1302-
| Pbottom ->
1303-
let cexp = transl env exp in
1304-
(* N.B. [body] must still be traversed even if [exp] will never return:
1305-
there may be constant closures inside that need lifting out. *)
1306-
let _cbody : expression = transl_body env in
1307-
cexp
1308-
| Pvalue kind ->
1309-
transl_let_value env str kind id exp transl_body
1310-
13111278
and make_catch (kind : Cmm.value_kind) ncatch body handler dbg =
13121279
match body with
13131280
| Cexit (Lbl nexit,[],[]) when nexit=ncatch -> handler

middle_end/clambda_primitives.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ and value_kind = Lambda.value_kind =
142142
| Parrayval of array_kind
143143

144144
and layout = Lambda.layout =
145-
| Ptop
146145
| Pvalue of value_kind
147-
| Pbottom
148146

149147
and block_shape = Lambda.block_shape
150148
and boxed_integer = Primitive.boxed_integer =

middle_end/clambda_primitives.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ and value_kind = Lambda.value_kind =
145145
| Parrayval of array_kind
146146

147147
and layout = Lambda.layout =
148-
| Ptop
149148
| Pvalue of value_kind
150-
| Pbottom
151149

152150
and block_shape = Lambda.block_shape
153151
and boxed_integer = Primitive.boxed_integer =

middle_end/closure/closure.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ let rec add_to_closure_env env_param pos cenv = function
5959

6060
let is_gc_ignorable kind =
6161
match kind with
62-
| Ptop -> Misc.fatal_error "[Ptop] can't be stored in a closure."
63-
| Pbottom -> Misc.fatal_error "[Pbottom] should not be stored in a closure."
6462
| Pvalue Pintval -> true
6563
| Pvalue (Pgenval | Pfloatval | Pboxedintval _ | Pvariant _ | Parrayval _) -> false
6664

middle_end/flambda/closure_offsets.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,7 @@ let add_closure_offsets
7070
in
7171
let gc_invisible_free_vars, gc_visible_free_vars =
7272
Variable.Map.partition (fun _ (free_var : Flambda.specialised_to) ->
73-
match free_var.kind with
74-
| Ptop ->
75-
Misc.fatal_error "[Ptop] can't be stored in a closure."
76-
| Pbottom ->
77-
Misc.fatal_error
78-
"[Pbottom] should have been eliminated as dead code \
79-
and not stored in a closure."
80-
| Pvalue Pintval -> true
81-
| Pvalue _ -> false)
73+
match free_var.kind with Pvalue Pintval -> true | Pvalue _ -> false)
8274
free_vars
8375
in
8476
let free_variable_offsets, free_variable_pos =

middle_end/flambda/flambda_to_clambda.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,6 @@ and to_clambda_set_of_closures t env
698698
let not_scanned_fv, scanned_fv =
699699
Variable.Map.partition (fun _ (free_var : Flambda.specialised_to) ->
700700
match free_var.kind with
701-
| Ptop -> Misc.fatal_error "[Ptop] can't be stored in a closure."
702-
| Pbottom ->
703-
Misc.fatal_error
704-
"[Pbottom] should have been eliminated as dead code \
705-
and not stored in a closure."
706701
| Pvalue Pintval -> true
707702
| Pvalue _ -> false)
708703
free_vars

middle_end/flambda2/kinds/flambda_kind.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,7 @@ module With_subkind = struct
516516
| Parrayval Paddrarray -> value_array
517517
| Parrayval Pgenarray -> generic_array
518518

519-
let from_lambda (layout : Lambda.layout) =
520-
match layout with
521-
| Pvalue vk -> from_lambda_value_kind vk
522-
| Ptop -> Misc.fatal_error "Can't convert layout [Ptop] to flambda kind"
523-
| Pbottom ->
524-
Misc.fatal_error "Can't convert layout [Pbottom] to flambda kind"
519+
let from_lambda (Pvalue vk : Lambda.layout) = from_lambda_value_kind vk
525520

526521
include Container_types.Make (struct
527522
type nonrec t = t

middle_end/printclambda.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ let rec value_kind0 ppf kind =
5151
non_consts
5252

5353
let value_kind kind = Format.asprintf "%a" value_kind0 kind
54-
let layout (layout : Lambda.layout) =
55-
match layout with
56-
| Pvalue kind -> value_kind kind
57-
| Ptop -> ":top"
58-
| Pbottom -> ":bottom"
54+
let layout (Lambda.Pvalue kind) = value_kind kind
5955

6056
let rec structured_constant ppf = function
6157
| Uconst_float x -> fprintf ppf "%F" x

ocaml/asmcomp/cmm_helpers.ml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,11 +2239,7 @@ let rec make_curry_apply result narity args_type args clos n =
22392239
:: args)
22402240
newclos (n - 1) )
22412241

2242-
let machtype_of_layout (layout : Lambda.layout) =
2243-
match layout with
2244-
| Ptop -> Misc.fatal_error "No machtype for layout [Ptop]"
2245-
| Pbottom -> Misc.fatal_error "No unique machtype for layout [Pbottom]"
2246-
| Pvalue _ -> typ_val
2242+
let machtype_of_layout = function Lambda.Pvalue _ -> typ_val
22472243

22482244
let final_curry_function nlocal arity result =
22492245
let last_arg = V.create_local "arg" in
@@ -3144,9 +3140,5 @@ let emit_preallocated_blocks preallocated_blocks cont =
31443140
let c1 = emit_gc_roots_table ~symbols cont in
31453141
List.fold_left preallocate_block c1 preallocated_blocks
31463142

3147-
let kind_of_layout (layout : Lambda.layout) =
3148-
match layout with
3149-
| Ptop | Pbottom ->
3150-
(* This is incorrect but only used for unboxing *)
3151-
Vval Pgenval
3152-
| Pvalue kind -> Vval kind
3143+
let kind_of_layout (Lambda.Pvalue kind) = Vval kind
3144+

ocaml/asmcomp/cmmgen.ml

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,9 @@ let rec transl env e =
448448
| Ugeneric_apply(clos, args, args_layout, result_layout, kind, dbg) ->
449449
let clos = transl env clos in
450450
let args = List.map (transl env) args in
451-
if List.mem Pbottom args_layout then
452-
(* [machtype_of_layout] will fail on Pbottom, convert it to a sequence
453-
and remove the call, preserving the execution order. *)
454-
List.fold_left2 (fun rest arg arg_layout ->
455-
if arg_layout = Pbottom then
456-
arg
457-
else
458-
Csequence(remove_unit arg, rest)
459-
) (Ctuple []) args args_layout
460-
else
461-
let args_type = List.map machtype_of_layout args_layout in
462-
let return = machtype_of_layout result_layout in
463-
generic_apply (mut_from_env env clos) clos args args_type return kind dbg
451+
let args_type = List.map machtype_of_layout args_layout in
452+
let return = machtype_of_layout result_layout in
453+
generic_apply (mut_from_env env clos) clos args args_type return kind dbg
464454
| Usend(kind, met, obj, args, args_layout, result_layout, pos, dbg) ->
465455
let met = transl env met in
466456
let obj = transl env obj in
@@ -741,23 +731,14 @@ and transl_catch (kind : Cmm.value_kind) env nfail ids body handler dbg =
741731
each argument. *)
742732
let report args =
743733
List.iter2
744-
(fun (id, (layout : Lambda.layout), u) c ->
745-
match layout with
746-
| Ptop ->
747-
Misc.fatal_errorf "Variable %a with layout [Ptop] can't be compiled"
748-
VP.print id
749-
| Pbottom ->
750-
Misc.fatal_errorf
751-
"Variable %a with layout [Pbottom] can't be compiled"
752-
VP.print id
753-
| Pvalue kind ->
754-
let strict =
755-
match kind with
756-
| Pfloatval | Pboxedintval _ -> false
757-
| Pintval | Pgenval | Pvariant _ | Parrayval _ -> true
758-
in
759-
u := join_unboxed_number_kind ~strict !u
760-
(is_unboxed_number_cmm ~strict c)
734+
(fun (_id, Pvalue kind, u) c ->
735+
let strict =
736+
match kind with
737+
| Pfloatval | Pboxedintval _ -> false
738+
| Pintval | Pgenval | Pvariant _ | Parrayval _ -> true
739+
in
740+
u := join_unboxed_number_kind ~strict !u
741+
(is_unboxed_number_cmm ~strict c)
761742
)
762743
ids args
763744
in
@@ -1200,7 +1181,7 @@ and transl_unbox_sized size dbg env exp =
12001181
| Thirty_two -> transl_unbox_int dbg env Pint32 exp
12011182
| Sixty_four -> transl_unbox_int dbg env Pint64 exp
12021183

1203-
and transl_let_value env str (kind : Lambda.value_kind) id exp transl_body =
1184+
and transl_let env str (Pvalue kind : Lambda.layout) id exp transl_body =
12041185
let dbg = Debuginfo.none in
12051186
let cexp = transl env exp in
12061187
let unboxing =
@@ -1252,20 +1233,6 @@ and transl_let_value env str (kind : Lambda.value_kind) id exp transl_body =
12521233
| Mutable, bn -> Clet_mut (v, typ_of_boxed_number bn, cexp, body)
12531234
end
12541235

1255-
and transl_let env str (layout : Lambda.layout) id exp transl_body =
1256-
match layout with
1257-
| Ptop ->
1258-
Misc.fatal_errorf "Variable %a with layout [Ptop] can't be compiled"
1259-
VP.print id
1260-
| Pbottom ->
1261-
let cexp = transl env exp in
1262-
(* N.B. [body] must still be traversed even if [exp] will never return:
1263-
there may be constant closures inside that need lifting out. *)
1264-
let _cbody : expression = transl_body env in
1265-
cexp
1266-
| Pvalue kind ->
1267-
transl_let_value env str kind id exp transl_body
1268-
12691236
and make_catch (kind : Cmm.value_kind) ncatch body handler dbg = match body with
12701237
| Cexit (nexit,[]) when nexit=ncatch -> handler
12711238
| _ -> ccatch (ncatch, [], body, handler, dbg, kind)

ocaml/lambda/lambda.ml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ and value_kind =
255255
| Parrayval of array_kind
256256

257257
and layout =
258-
| Ptop
259258
| Pvalue of value_kind
260-
| Pbottom
261259

262260
and block_shape =
263261
value_kind list option
@@ -318,30 +316,14 @@ let rec equal_value_kind x y =
318316
| (Pgenval | Pfloatval | Pboxedintval _ | Pintval | Pvariant _
319317
| Parrayval _), _ -> false
320318

321-
let equal_layout x y =
322-
match x, y with
323-
| Pvalue x, Pvalue y -> equal_value_kind x y
324-
| Ptop, Ptop -> true
325-
| Pbottom, Pbottom -> true
326-
| _, _ -> false
319+
let equal_layout (Pvalue x) (Pvalue y) = equal_value_kind x y
327320

328-
let compatible_layout x y =
329-
match x, y with
330-
| Pbottom, _
331-
| _, Pbottom -> true
332-
| Pvalue _, Pvalue _ -> true
333-
| Ptop, Ptop -> true
334-
| Ptop, _ | _, Ptop -> false
321+
let compatible_layout (Pvalue _) (Pvalue _) = true
335322

336323
let must_be_value layout =
337324
match layout with
338325
| Pvalue v -> v
339-
| Pbottom ->
340-
(* Here, we want to get the [value_kind] corresponding to
341-
a [Pbottom] layout. Anything will do, we return [Pgenval]
342-
as a default. *)
343-
Pgenval
344-
| _ -> Misc.fatal_error "Layout is not a value"
326+
(* | _ -> Misc.fatal_error "Layout is not a value" *)
345327

346328
type structured_constant =
347329
Const_base of constant
@@ -617,9 +599,10 @@ let layout_lazy_contents = Pvalue Pgenval
617599
let layout_any_value = Pvalue Pgenval
618600
let layout_letrec = layout_any_value
619601

620-
(* CR ncourant: use [Ptop] or remove this as soon as possible. *)
621-
let layout_top = layout_any_value
622-
let layout_bottom = Pbottom
602+
let layout_top = Pvalue Pgenval
603+
let layout_bottom =
604+
(* CR pchambart: this should be an actual bottom *)
605+
Pvalue Pgenval
623606

624607
let default_function_attribute = {
625608
inline = Default_inline;

ocaml/lambda/lambda.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ and value_kind =
212212
| Parrayval of array_kind
213213

214214
and layout =
215-
| Ptop
216215
| Pvalue of value_kind
217-
| Pbottom
218216

219217
and block_shape =
220218
value_kind list option

ocaml/lambda/printlambda.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ and value_kind' ppf = function
9595
| Pvariant { consts; non_consts; } ->
9696
variant_kind value_kind' ppf ~consts ~non_consts
9797

98-
let layout ppf layout =
99-
match layout with
100-
| Pvalue k -> value_kind ppf k
101-
| Ptop -> fprintf ppf "[top]"
102-
| Pbottom -> fprintf ppf "[bottom]"
98+
let layout ppf (Pvalue k) = value_kind ppf k
10399

104100
let return_kind ppf (mode, kind) =
105101
let smode = alloc_mode mode in
@@ -113,8 +109,6 @@ let return_kind ppf (mode, kind) =
113109
| Pvalue (Pboxedintval bi) -> fprintf ppf ": %s%s@ " smode (boxed_integer_name bi)
114110
| Pvalue (Pvariant { consts; non_consts; }) ->
115111
variant_kind value_kind' ppf ~consts ~non_consts
116-
| Ptop -> fprintf ppf ": top@ "
117-
| Pbottom -> fprintf ppf ": bottom@ "
118112

119113
let field_kind ppf = function
120114
| Pgenval -> pp_print_string ppf "*"

ocaml/middle_end/clambda_primitives.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ and value_kind = Lambda.value_kind =
142142
| Parrayval of array_kind
143143

144144
and layout = Lambda.layout =
145-
| Ptop
146145
| Pvalue of value_kind
147-
| Pbottom
148146

149147
and block_shape = Lambda.block_shape
150148
and boxed_integer = Primitive.boxed_integer =

0 commit comments

Comments
 (0)