Skip to content

Commit 0ea58e9

Browse files
authored
flambda-backend: Revert "Add a proper top and bottom layout" (#1169)
1 parent 1e5e23a commit 0ea58e9

File tree

12 files changed

+27
-121
lines changed

12 files changed

+27
-121
lines changed

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+

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)

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;

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

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 "*"

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
@@ -696,11 +696,6 @@ and to_clambda_set_of_closures t env
696696
let not_scanned_fv, scanned_fv =
697697
Variable.Map.partition (fun _ (free_var : Flambda.specialised_to) ->
698698
match free_var.kind with
699-
| Ptop -> Misc.fatal_error "[Ptop] can't be stored in a closure."
700-
| Pbottom ->
701-
Misc.fatal_error
702-
"[Pbottom] should have been eliminated as dead code \
703-
and not stored in a closure."
704699
| Pvalue Pintval -> true
705700
| Pvalue _ -> false)
706701
free_vars

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

typing/typeopt.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,5 @@ let value_kind_union (k1 : Lambda.value_kind) (k2 : Lambda.value_kind) =
411411
if Lambda.equal_value_kind k1 k2 then k1
412412
else Pgenval
413413

414-
let layout_union l1 l2 =
415-
match l1, l2 with
416-
| Pbottom, l
417-
| l, Pbottom -> l
418-
| Pvalue layout1, Pvalue layout2 ->
419-
Pvalue (value_kind_union layout1 layout2)
420-
| Ptop, _ | _, Ptop -> Ptop
414+
let layout_union (Pvalue layout1) (Pvalue layout2) =
415+
Pvalue (value_kind_union layout1 layout2)

0 commit comments

Comments
 (0)