Skip to content

Commit cbcae49

Browse files
committed
Remove subkinds from value slots (oxcaml#3981)
1 parent 1f869a5 commit cbcae49

21 files changed

+103
-74
lines changed

middle_end/flambda2/compare/compare.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ let sets_of_closures env set1 set2 : Set_of_closures.t Comparison.t =
775775
let ok = ref true in
776776
let () =
777777
let compare (kind1, value1, _var1) (kind2, value2, _var2) =
778-
let c = Flambda_kind.With_subkind.compare kind1 kind2 in
778+
let c = Flambda_kind.compare kind1 kind2 in
779779
if c = 0 then Simple.compare value1 value2 else c
780780
in
781781
iter2_merged (value_slots_by_value set1) (value_slots_by_value set2)

middle_end/flambda2/from_lambda/closure_conversion.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,17 @@ let close_functions acc external_env ~current_region function_declarations =
26272627
| None -> Ident.name id
26282628
| Some var -> Variable.name var
26292629
in
2630-
Ident.Map.add id (Value_slot.create compilation_unit ~name kind) map)
2630+
let is_always_immediate =
2631+
match[@ocaml.warning "-4"]
2632+
Flambda_kind.With_subkind.non_null_value_subkind kind
2633+
with
2634+
| Tagged_immediate -> true
2635+
| _ -> false
2636+
in
2637+
Ident.Map.add id
2638+
(Value_slot.create compilation_unit ~name ~is_always_immediate
2639+
(Flambda_kind.With_subkind.kind kind))
2640+
map)
26312641
(Function_decls.all_free_idents function_declarations)
26322642
Ident.Map.empty
26332643
in
@@ -2774,10 +2784,11 @@ let close_functions acc external_env ~current_region function_declarations =
27742784
let external_simple, kind' =
27752785
find_simple_from_id_with_kind external_env id
27762786
in
2777-
if not (K.With_subkind.equal kind kind')
2787+
if not (K.equal kind (K.With_subkind.kind kind'))
27782788
then
27792789
Misc.fatal_errorf "Value slot kinds %a and %a don't match for slot %a"
2780-
K.With_subkind.print kind K.With_subkind.print kind'
2790+
K.print kind K.print
2791+
(K.With_subkind.kind kind')
27812792
Value_slot.print value_slot;
27822793
(* We're sure [external_simple] is a variable since
27832794
[value_slot_from_idents] has already filtered constants and symbols
@@ -2946,7 +2957,7 @@ let wrap_partial_application acc env apply_continuation (apply : IR.apply)
29462957
let function_slot =
29472958
Function_slot.create
29482959
(Compilation_unit.get_current_exn ())
2949-
~name:(Ident.name wrapper_id) K.With_subkind.any_value
2960+
~name:(Ident.name wrapper_id) ~is_always_immediate:false K.value
29502961
in
29512962
let num_provided = Flambda_arity.num_params provided_arity in
29522963
let missing_arity_and_param_modes =

middle_end/flambda2/from_lambda/lambda_to_flambda.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ and cps_function env ~fid ~(recursive : Recursive.t) ?precomputed_free_idents
13531353
Function_slot.create
13541354
(Compilation_unit.get_current_exn ())
13551355
~name:(Ident.name fid ^ "_unboxed")
1356-
Flambda_kind.With_subkind.any_value
1356+
~is_always_immediate:false Flambda_kind.value
13571357
in
13581358
let unboxed_return =
13591359
if attr.unbox_return then unboxing_kind return else None
@@ -1424,7 +1424,7 @@ and cps_function env ~fid ~(recursive : Recursive.t) ?precomputed_free_idents
14241424
let function_slot =
14251425
Function_slot.create
14261426
(Compilation_unit.get_current_exn ())
1427-
~name:(Ident.name fid) Flambda_kind.With_subkind.any_value
1427+
~name:(Ident.name fid) ~is_always_immediate:false Flambda_kind.value
14281428
in
14291429
let unboxed_products = ref Ident.Map.empty in
14301430
let params =

middle_end/flambda2/identifiers/slot.ml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ module type S = sig
2020
module Lmap : Lmap.S with type key = t
2121

2222
val create :
23-
Compilation_unit.t -> name:string -> Flambda_kind.With_subkind.t -> t
23+
Compilation_unit.t ->
24+
name:string ->
25+
is_always_immediate:bool ->
26+
Flambda_kind.t ->
27+
t
2428

2529
val get_compilation_unit : t -> Compilation_unit.t
2630

@@ -32,7 +36,9 @@ module type S = sig
3236

3337
val name : t -> string
3438

35-
val kind : t -> Flambda_kind.With_subkind.t
39+
val kind : t -> Flambda_kind.t
40+
41+
val is_always_immediate : t -> bool
3642

3743
val rename : t -> t
3844
end
@@ -45,7 +51,8 @@ end) : S = struct
4551
name : string;
4652
name_stamp : int;
4753
(** [name_stamp]s are unique within any given compilation unit. *)
48-
kind : Flambda_kind.With_subkind.t
54+
kind : Flambda_kind.t;
55+
is_always_immediate : bool
4956
}
5057

5158
module Self = Container_types.Make (struct
@@ -55,12 +62,14 @@ end) : S = struct
5562
({ compilation_unit = compilation_unit1;
5663
name = _;
5764
name_stamp = name_stamp1;
58-
kind = _
65+
kind = _;
66+
is_always_immediate = _
5967
} as t1)
6068
({ compilation_unit = compilation_unit2;
6169
name = _;
6270
name_stamp = name_stamp2;
63-
kind = _
71+
kind = _;
72+
is_always_immediate = _
6473
} as t2) =
6574
if t1 == t2
6675
then 0
@@ -83,8 +92,8 @@ end) : S = struct
8392
else
8493
Format.fprintf ppf "%a.%s/%d" Compilation_unit.print t.compilation_unit
8594
t.name t.name_stamp;
86-
Format.fprintf ppf " @<1>\u{2237} %a" Flambda_kind.With_subkind.print
87-
t.kind;
95+
Format.fprintf ppf " @<1>\u{2237} %a%s" Flambda_kind.print t.kind
96+
(if t.is_always_immediate then "(immediate)" else "");
8897
Format.fprintf ppf ")%t@]" Flambda_colours.pop
8998
end)
9099

@@ -103,8 +112,13 @@ end) : S = struct
103112
incr next_stamp;
104113
stamp
105114

106-
let create compilation_unit ~name kind =
107-
{ compilation_unit; name; name_stamp = get_next_stamp (); kind }
115+
let create compilation_unit ~name ~is_always_immediate kind =
116+
{ compilation_unit;
117+
name;
118+
name_stamp = get_next_stamp ();
119+
kind;
120+
is_always_immediate
121+
}
108122

109123
let get_compilation_unit t = t.compilation_unit
110124

@@ -119,5 +133,7 @@ end) : S = struct
119133

120134
let kind t = t.kind
121135

136+
let is_always_immediate t = t.is_always_immediate
137+
122138
let rename t = { t with name_stamp = get_next_stamp () }
123139
end

middle_end/flambda2/identifiers/slot.mli

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ module type S = sig
2020
module Lmap : Lmap.S with type key = t
2121

2222
val create :
23-
Compilation_unit.t -> name:string -> Flambda_kind.With_subkind.t -> t
23+
Compilation_unit.t ->
24+
name:string ->
25+
is_always_immediate:bool ->
26+
Flambda_kind.t ->
27+
t
2428

2529
val get_compilation_unit : t -> Compilation_unit.t
2630

@@ -32,7 +36,9 @@ module type S = sig
3236

3337
val name : t -> string
3438

35-
val kind : t -> Flambda_kind.With_subkind.t
39+
val kind : t -> Flambda_kind.t
40+
41+
val is_always_immediate : t -> bool
3642

3743
val rename : t -> t
3844
end

middle_end/flambda2/parser/fexpr_to_flambda.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ let fresh_function_slot env { Fexpr.txt = name; loc = _ } =
144144
let c =
145145
Function_slot.create
146146
(Compilation_unit.get_current_exn ())
147-
~name Flambda_kind.With_subkind.any_value
147+
~name ~is_always_immediate:false Flambda_kind.value
148148
in
149149
UT.add env.function_slots name c;
150150
c
@@ -155,7 +155,11 @@ let fresh_or_existing_function_slot env ({ Fexpr.txt = name; loc = _ } as id) =
155155
| Some function_slot -> function_slot
156156

157157
let fresh_value_slot env { Fexpr.txt = name; loc = _ } kind =
158-
let c = Value_slot.create (Compilation_unit.get_current_exn ()) ~name kind in
158+
let c =
159+
Value_slot.create
160+
(Compilation_unit.get_current_exn ())
161+
~name ~is_always_immediate:false kind
162+
in
159163
WT.add env.vars_within_closures name c;
160164
c
161165

@@ -436,7 +440,7 @@ let unop env (unop : Fexpr.unop) : Flambda_primitive.unary_primitive =
436440
Opaque_identity { middle_end_only = false; kind = Flambda_kind.value }
437441
| Project_value_slot { project_from; value_slot } ->
438442
(* CR mshinwell: support non-value kinds *)
439-
let kind = Flambda_kind.With_subkind.any_value in
443+
let kind = Flambda_kind.value in
440444
let value_slot = fresh_or_existing_value_slot env value_slot kind in
441445
let project_from = fresh_or_existing_function_slot env project_from in
442446
Project_value_slot { project_from; value_slot }
@@ -562,8 +566,7 @@ let set_of_closures env fun_decls value_slots alloc =
562566
let value_slots : Simple.t Value_slot.Map.t =
563567
let convert ({ var; value } : Fexpr.one_value_slot) =
564568
(* CR mshinwell: support non-value kinds *)
565-
( fresh_or_existing_value_slot env var Flambda_kind.With_subkind.any_value,
566-
simple env value )
569+
fresh_or_existing_value_slot env var Flambda_kind.value, simple env value
567570
in
568571
List.map convert value_slots |> Value_slot.Map.of_list
569572
in

middle_end/flambda2/parser/flambda_to_fexpr.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,7 @@ let value_slots env map =
676676
List.map
677677
(fun (var, value) ->
678678
let kind = Value_slot.kind var in
679-
if not
680-
(Flambda_kind.equal
681-
(Flambda_kind.With_subkind.kind kind)
682-
Flambda_kind.value)
679+
if not (Flambda_kind.equal kind Flambda_kind.value)
683680
then
684681
Misc.fatal_errorf "Value slot %a not of kind Value" Simple.print value;
685682
let var = Env.translate_value_slot env var in

middle_end/flambda2/simplify/simplify_apply_expr.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ let simplify_direct_partial_application ~simplify_expr dacc apply
425425
let compilation_unit = Compilation_unit.get_current_exn () in
426426
let wrapper_function_slot =
427427
Function_slot.create compilation_unit ~name:"partial_app_closure"
428-
K.With_subkind.any_value
428+
~is_always_immediate:false K.value
429429
in
430430
(* The allocation mode of the closure is directly determined by the alloc_mode
431431
of the application. We check here that it is consistent with
@@ -507,7 +507,15 @@ let simplify_direct_partial_application ~simplify_expr dacc apply
507507
}
508508
end in
509509
let mk_value_slot kind =
510-
Value_slot.create compilation_unit ~name:"arg" kind
510+
let is_always_immediate =
511+
match[@ocaml.warning "-4"]
512+
K.With_subkind.non_null_value_subkind kind
513+
with
514+
| Tagged_immediate -> true
515+
| _ -> false
516+
in
517+
Value_slot.create compilation_unit ~name:"arg" ~is_always_immediate
518+
(K.With_subkind.kind kind)
511519
in
512520
let applied_value (value, kind) =
513521
Simple.pattern_match' value

middle_end/flambda2/simplify/simplify_set_of_closures.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ let simplify_and_lift_set_of_closures dacc ~closure_bound_vars_inverse
681681
let value_slot_types =
682682
Value_slot.Map.mapi
683683
(fun value_slot in_slot ->
684-
let kind = K.With_subkind.kind (Value_slot.kind value_slot) in
684+
let kind = Value_slot.kind value_slot in
685685
Simple.pattern_match in_slot
686686
~const:(fun _ -> T.alias_type_of kind in_slot)
687687
~name:(fun name ~coercion ->

middle_end/flambda2/simplify/simplify_unary_primitive.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ let simplify_project_value_slot function_slot value_slot ~min_name_mode dacc
6969
simple
7070
in
7171
let dacc =
72-
DA.add_variable dacc result_var
73-
(T.alias_type_of (K.With_subkind.kind kind) simple)
72+
DA.add_variable dacc result_var (T.alias_type_of kind simple)
7473
in
7574
SPR.create (Named.create_simple simple) ~try_reify:true dacc
7675
| Need_meet ->
@@ -81,15 +80,16 @@ let simplify_project_value_slot function_slot value_slot ~min_name_mode dacc
8180
(T.closure_with_at_least_this_value_slot
8281
~this_function_slot:function_slot value_slot
8382
~value_slot_var:(Bound_var.var result_var) ~value_slot_kind:kind)
84-
~result_var ~result_kind:(K.With_subkind.kind kind)
83+
~result_var ~result_kind:kind
8584
in
8685
let dacc = DA.add_use_of_value_slot result.dacc value_slot in
8786
SPR.with_dacc result dacc
8887
in
8988
let dacc =
9089
Simplify_common.add_symbol_projection result.dacc ~projected_from:closure
9190
(Symbol_projection.Projection.project_value_slot function_slot value_slot)
92-
~projection_bound_to:result_var ~kind
91+
~projection_bound_to:result_var
92+
~kind:(Flambda_kind.With_subkind.anything kind)
9393
in
9494
SPR.with_dacc result dacc
9595

0 commit comments

Comments
 (0)