Skip to content

Commit 1551b15

Browse files
committed
Lots of fixes after rebase (makes separate commits useless)
too much diff to fix up in the right commit
1 parent 049ee74 commit 1551b15

31 files changed

+123
-152
lines changed

backend/cfg/cfg.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ let rec of_cmm_codegen_option : Cmm.codegen_option list -> codegen_option list =
5757
match hd with
5858
| No_CSE -> No_CSE :: of_cmm_codegen_option tl
5959
| Reduce_code_size -> Reduce_code_size :: of_cmm_codegen_option tl
60-
| Use_linscan_regalloc | Assume_zero_alloc _ | Check_zero_alloc _
61-
->
60+
| Use_linscan_regalloc | Assume_zero_alloc _ | Check_zero_alloc _ ->
6261
of_cmm_codegen_option tl)
6362

6463
type t =

backend/cmm.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ type codegen_option =
318318
| Reduce_code_size
319319
| No_CSE
320320
| Use_linscan_regalloc
321-
| Assume of { strict: bool; never_returns_normally: bool;
321+
| Assume_zero_alloc of { strict: bool; never_returns_normally: bool;
322322
never_raises: bool;
323323
loc: Location.t }
324324
| Check_zero_alloc of { strict: bool; loc: Location.t }

backend/zero_alloc_checker.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,8 @@ end = struct
14671467
never_raises = false;
14681468
loc
14691469
}
1470-
| Assume_zero_alloc { never_returns_normally; never_raises; loc } ->
1470+
| Assume_zero_alloc
1471+
{ strict; never_returns_normally; never_raises; loc } ->
14711472
Some
14721473
{ strict;
14731474
assume = true;
@@ -1853,7 +1854,11 @@ end = struct
18531854
in cmx and memory consumption Compilenv. Different components have
18541855
different frequencies of Top/Bot. The most likely value is encoded as None
18551856
(i.e., not stored). *)
1856-
let encode (v : V.t) = match v with Top _ -> 0 | Safe -> 1 | Bot -> 2
1857+
let encode (v : V.t) =
1858+
V.match_with v
1859+
~top:(fun _ -> 0)
1860+
~safe:1 ~bot:2
1861+
~unresolved:(fun () -> assert false)
18571862

18581863
(* Witnesses are not used across functions and not stored in cmx. Witnesses
18591864
that appear in a function's summary are only used for error messages about
@@ -1862,9 +1867,9 @@ end = struct
18621867
let decoded_witness = Witnesses.empty
18631868

18641869
let decode = function
1865-
| 0 -> V.Top decoded_witness
1866-
| 1 -> V.Safe
1867-
| 2 -> V.Bot
1870+
| 0 -> V.top decoded_witness
1871+
| 1 -> V.safe
1872+
| 2 -> V.bot
18681873
| n -> Misc.fatal_errorf "Zero_alloc_checker cannot decode %d" n
18691874

18701875
let encode (v : Value.t) : Checks.value =
@@ -2110,10 +2115,10 @@ end = struct
21102115
(** Summary of target specific operations. *)
21112116
let transform_specific w s =
21122117
(* Conservatively assume that operation can return normally. *)
2113-
let nor = if Arch.operation_allocates s then V.Top w else V.Safe in
2114-
let exn = if Arch.operation_can_raise s then nor else V.Bot in
2118+
let nor = if Arch.operation_allocates s then V.top w else V.safe in
2119+
let exn = if Arch.operation_can_raise s then nor else V.bot in
21152120
(* Assume that the operation does not diverge. *)
2116-
let div = V.Bot in
2121+
let div = V.bot in
21172122
{ Value.nor; exn; div }
21182123

21192124
let transform_operation t (op : Mach.operation) ~next ~exn dbg =

driver/flambda_backend_args.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ module type Flambda_backend_options = sig
672672
val heap_reduction_threshold : int -> unit
673673
val zero_alloc_check : string -> unit
674674
val dzero_alloc : unit -> unit
675-
val disable_zero_alloc : unit -> unit
676-
val disable_precise_zero_alloc : unit -> unit
677-
val zero_alloc_details_cutoff : int -> unit
678-
val zero_alloc_join : int -> unit
675+
val disable_zero_alloc_checker : unit -> unit
676+
val disable_precise_zero_alloc_checker : unit -> unit
677+
val zero_alloc_checker_details_cutoff : int -> unit
678+
val zero_alloc_checker_join : int -> unit
679679

680680
val function_layout : string -> unit
681681
val disable_poll_insertion : unit -> unit
@@ -969,13 +969,13 @@ module Flambda_backend_options_impl = struct
969969
in
970970
Flambda_backend_flags.zero_alloc_checker_details_cutoff := c
971971

972-
let checkmach_join n =
973-
let c : Flambda_backend_flags.checkmach_join =
972+
let zero_alloc_checker_join n =
973+
let c : Flambda_backend_flags.zero_alloc_checker_join =
974974
if n < 0 then Error (-n)
975975
else if n = 0 then Keep_all
976976
else Widen n
977977
in
978-
Flambda_backend_flags.checkmach_join := c
978+
Flambda_backend_flags.zero_alloc_checker_join := c
979979

980980
let function_layout s =
981981
match Flambda_backend_flags.Function_layout.of_string s with
@@ -1266,10 +1266,10 @@ module Extra_params = struct
12661266
| None -> ()
12671267
end;
12681268
true
1269-
| "checkmach-join" ->
1269+
| "zero-alloc-checker-join" ->
12701270
begin match Compenv.check_int ppf name v with
12711271
| Some i ->
1272-
Flambda_backend_options_impl.checkmach_join i
1272+
Flambda_backend_options_impl.zero_alloc_checker_join i
12731273
| None -> ()
12741274
end;
12751275
true

driver/flambda_backend_flags.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ let default_zero_alloc_checker_details_cutoff = At_most 20
4747
let zero_alloc_checker_details_cutoff = ref default_zero_alloc_checker_details_cutoff
4848
(* -zero-alloc-checker-details-cutoff n *)
4949

50-
type checkmach_join =
50+
type zero_alloc_checker_join =
5151
| Keep_all
5252
| Widen of int (* n > 0 *)
5353
| Error of int (* n > 0 *)
5454

55-
let default_checkmach_join = Widen 100
56-
let checkmach_join = ref default_checkmach_join
57-
(* -checkmach-precise-join-threshold n *)
55+
let default_zero_alloc_checker_join = Widen 100
56+
let zero_alloc_checker_join = ref default_zero_alloc_checker_join
57+
(* -zero-alloc-checker-join n *)
5858

5959
module Function_layout = struct
6060
type t =

driver/flambda_backend_flags.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ type zero_alloc_checker_details_cutoff =
4949
val zero_alloc_checker_details_cutoff : zero_alloc_checker_details_cutoff ref
5050
val default_zero_alloc_checker_details_cutoff : zero_alloc_checker_details_cutoff
5151

52-
type checkmach_join =
52+
type zero_alloc_checker_join =
5353
| Keep_all
5454
| Widen of int (* n > 0 *)
5555
| Error of int (* n > 0 *)
5656

57-
val checkmach_join : checkmach_join ref
58-
val default_checkmach_join : checkmach_join
57+
val zero_alloc_checker_join : zero_alloc_checker_join ref
58+
val default_zero_alloc_checker_join : zero_alloc_checker_join
5959

6060
module Function_layout : sig
6161
type t =

middle_end/flambda2/parser/fexpr_to_flambda.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,8 @@ let rec expr env (e : Fexpr.expr) : Flambda.Expr.t =
924924
~first_complex_local_param:(Flambda_arity.num_params params_arity)
925925
~result_arity ~result_types:Unknown ~result_mode
926926
~contains_no_escaping_local_allocs:false ~stub:false ~inline
927-
~check:Default (* CR gyorsh: should [check] be set properly? *)
927+
~check:Default_check
928+
(* CR gyorsh: should [check] be set properly? *)
928929
~is_a_functor:false ~is_opaque:false ~recursive
929930
~cost_metrics (* CR poechsel: grab inlining arguments from fexpr. *)
930931
~inlining_arguments:(Inlining_arguments.create ~round:0)

middle_end/flambda2/simplify/simplify_apply_expr.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ let simplify_direct_partial_application ~simplify_expr dacc apply
631631
(Code_metadata.contains_no_escaping_local_allocs
632632
callee's_code_metadata)
633633
~stub:true ~inline:Default_inline ~poll_attribute:Default
634-
~check:Check_attribute.Default_check ~is_a_functor:false
634+
~check:Zero_alloc_attribute.Default_check ~is_a_functor:false
635635
~is_opaque:false ~recursive ~cost_metrics:cost_metrics_of_body
636636
~inlining_arguments:(DE.inlining_arguments (DA.denv dacc))
637637
~dbg ~is_tupled:false

middle_end/flambda2/simplify/simplify_set_of_closures.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ let simplify_function context ~outer_dacc function_slot code_id
510510
let never_delete =
511511
match Code_metadata.check code_metadata with
512512
| Default_check -> !Clflags.zero_alloc_check_assert_all
513-
| Assume _ -> false
514-
| Check _ -> true
513+
| Assume _ -> false
514+
| Check _ -> true
515515
in
516516
if never_delete then Code_id.Set.singleton code_id else Code_id.Set.empty
517517
in

middle_end/flambda2/terms/zero_alloc_attribute.ml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ type t =
2626
let print ppf t =
2727
match t with
2828
| Default_check -> ()
29-
| Assume { strict; never_returns_normally; never_raises; loc = _ }
30-
->
29+
| Assume { strict; never_returns_normally; never_raises; loc = _ } ->
3130
Format.fprintf ppf "@[assume_zero_alloc%s%s%s@]"
3231
(if strict then "_strict" else "")
3332
(if never_returns_normally then "_never_returns_normally" else "")
@@ -36,25 +35,17 @@ let print ppf t =
3635
Format.fprintf ppf "@[assert_zero_alloc%s@]"
3736
(if strict then "_strict" else "")
3837

39-
let from_lambda : Lambda.check_attribute -> Location.t -> t =
38+
let from_lambda : Lambda.zero_alloc_attribute -> Location.t -> t =
4039
fun a loc ->
4140
match a with
42-
| Default_check ->
41+
| Default_zero_alloc ->
4342
if !Clflags.zero_alloc_check_assert_all
44-
&& Builtin_attributes.is_check_enabled ~opt:false Zero_alloc
43+
&& Builtin_attributes.is_zero_alloc_check_enabled ~opt:false
4544
then Check { strict = false; loc }
4645
else Default_check
4746
| Ignore_assert_all -> Default_check
48-
| Assume
49-
{ strict; never_returns_normally; never_raises; loc; arity = _ }
50-
->
51-
Assume
52-
{
53-
strict;
54-
never_returns_normally;
55-
never_raises;
56-
loc
57-
}
47+
| Assume { strict; never_returns_normally; never_raises; loc; arity = _ } ->
48+
Assume { strict; never_returns_normally; never_raises; loc }
5849
| Check { strict; opt; loc; arity = _ } ->
5950
if Builtin_attributes.is_zero_alloc_check_enabled ~opt
6051
then Check { strict; loc }
@@ -63,29 +54,24 @@ let from_lambda : Lambda.check_attribute -> Location.t -> t =
6354
let equal x y =
6455
match x, y with
6556
| Default_check, Default_check -> true
66-
| ( Check { strict = s1; loc = loc1 },
67-
Check { strict = s2; loc = loc2 } ) ->
57+
| Check { strict = s1; loc = loc1 }, Check { strict = s2; loc = loc2 } ->
6858
Bool.equal s1 s2 && Location.compare loc1 loc2 = 0
6959
| ( Assume
70-
{
71-
strict = s1;
60+
{ strict = s1;
7261
never_returns_normally = n1;
7362
never_raises = r1;
7463
loc = loc1
7564
},
7665
Assume
77-
{
78-
strict = s2;
66+
{ strict = s2;
7967
never_returns_normally = n2;
8068
never_raises = r2;
8169
loc = loc2
8270
} ) ->
83-
Bool.equal s1 s2 && Bool.equal n1 n2
84-
&& Bool.equal r1 r2
71+
Bool.equal s1 s2 && Bool.equal n1 n2 && Bool.equal r1 r2
8572
&& Location.compare loc1 loc2 = 0
8673
| (Default_check | Check _ | Assume _), _ -> false
8774

8875
let is_default : t -> bool = function
8976
| Default_check -> true
9077
| Check _ | Assume _ -> false
91-

middle_end/flambda2/terms/zero_alloc_attribute.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ val equal : t -> t -> bool
2929

3030
val is_default : t -> bool
3131

32-
val from_lambda : Lambda.zero_aloc_attribute -> Location.t -> t
33-
32+
val from_lambda : Lambda.zero_alloc_attribute -> Location.t -> t

middle_end/flambda2/to_cmm/to_cmm_set_of_closures.ml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,8 @@ let transl_check_attrib : Zero_alloc_attribute.t -> Cmm.codegen_option list =
349349
function
350350
| Default_check -> []
351351
| Assume { strict; never_returns_normally; never_raises; loc } ->
352-
[ Assume_zero_alloc
353-
{ strict;
354-
never_returns_normally;
355-
never_raises;
356-
loc
357-
} ]
358-
| Check { strict; loc } ->
359-
[Check_zero_alloc { strict; loc }]
352+
[Assume_zero_alloc { strict; never_returns_normally; never_raises; loc }]
353+
| Check { strict; loc } -> [Check_zero_alloc { strict; loc }]
360354

361355
(* Translation of the bodies of functions. *)
362356

native_toplevel/opttoploop.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ let name_expression ~loc ~attrs sort exp =
344344
val_kind = Val_reg;
345345
val_loc = loc;
346346
val_attributes = attrs;
347-
val_zero_alloc = Default_check;
347+
val_zero_alloc = Default_zero_alloc;
348348
val_uid = Uid.internal_not_actually_unique; }
349349
in
350350
let sg = [Sig_value(id, vd, Exported)] in

ocaml/lambda/lambda.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ type poll_attribute =
626626
| Default_poll (* no [@poll] attribute *)
627627

628628
type zero_alloc_attribute = Builtin_attributes.zero_alloc_attribute =
629-
| Default_check
629+
| Default_zero_alloc
630630
| Ignore_assert_all
631631
| Check of { strict: bool;
632632
opt: bool;

ocaml/lambda/lambda.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ type poll_attribute =
501501
| Error_poll (* [@poll error] *)
502502
| Default_poll (* no [@poll] attribute *)
503503

504-
type zero_alloc_attribute = Builtin_attributes.check_attribute =
504+
type zero_alloc_attribute = Builtin_attributes.zero_alloc_attribute =
505505
| Default_zero_alloc
506506
| Ignore_assert_all
507507
| Check of { strict: bool;

ocaml/lambda/translattribute.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,6 @@ let add_function_attributes lam loc attr =
444444
add_local_attribute lam loc attr
445445
in
446446
let lam =
447-
<<<<<<< HEAD
448-
=======
449-
add_zero_alloc_attribute lam loc attr
450-
in
451-
let lam =
452-
>>>>>>> 2bb76db708 (Remove "Lambda.property" and rename "Lambda.check_attribute" and)
453447
add_loop_attribute lam loc attr
454448
in
455449
let lam =

ocaml/lambda/translcore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ and transl_function ~in_new_scope ~scopes e params body
16031603
~scopes e.exp_loc repr ~region params body)
16041604
in
16051605
let attr =
1606-
{ function_attribute_disallowing_arity_fusion with check = zero_alloc }
1606+
{ function_attribute_disallowing_arity_fusion with zero_alloc }
16071607
in
16081608
let loc = of_location ~scopes e.exp_loc in
16091609
let body = if region then maybe_region_layout return body else body in

ocaml/parsing/builtin_attributes.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ let is_zero_alloc_check_enabled ~opt =
698698
| Check_default -> not opt
699699
| Check_opt_only -> opt
700700

701-
let is_zero_alloc_attribute = function
702-
| Zero_alloc -> [ ["zero_alloc"; "ocaml.zero_alloc"], true ]
701+
let is_zero_alloc_attribute =
702+
[ ["zero_alloc"; "ocaml.zero_alloc"], true ]
703703

704704
let get_payload get_from_exp =
705705
let open Parsetree in
@@ -860,12 +860,12 @@ let parse_zero_alloc_payload ~loc ~arity ~warn ~empty payload =
860860
| _ :: _ ->
861861
let payload = List.sort String.compare payload in
862862
match List.assoc_opt payload zero_alloc_lookup_table with
863-
| None -> warn (); Default_check
863+
| None -> warn (); Default_zero_alloc
864864
| Some ca -> ca arity loc
865865

866866
let parse_zero_alloc_attribute ~is_arity_allowed ~default_arity attr =
867867
match attr with
868-
| None -> Default_check
868+
| None -> Default_zero_alloc
869869
| Some {Parsetree.attr_name = {txt; loc}; attr_payload = payload} ->
870870
let warn () =
871871
let ( %> ) f g x = g (f x) in
@@ -881,7 +881,7 @@ let parse_zero_alloc_attribute ~is_arity_allowed ~default_arity attr =
881881
Check { strict = false; opt = false; arity; loc; }
882882
in
883883
match get_optional_payload get_ids_and_constants_from_exp payload with
884-
| Error () -> warn (); Default_check
884+
| Error () -> warn (); Default_zero_alloc
885885
| Ok None -> empty default_arity
886886
| Ok (Some payload) ->
887887
let arity, payload =
@@ -898,29 +898,29 @@ let parse_zero_alloc_attribute ~is_arity_allowed ~default_arity attr =
898898
in
899899
parse_zero_alloc_payload ~loc ~arity ~warn ~empty:(empty arity) payload
900900

901-
let get_zero_alloc_attribute ~in_signature ~default_arity l p =
901+
let get_zero_alloc_attribute ~in_signature ~default_arity l =
902902
let attr = find_attribute is_zero_alloc_attribute l in
903903
let res =
904904
parse_zero_alloc_attribute ~is_arity_allowed:in_signature ~default_arity
905905
attr
906906
in
907907
(match attr, res with
908-
| None, Default_check -> ()
909-
| _, Default_check -> ()
908+
| None, Default_zero_alloc -> ()
909+
| _, Default_zero_alloc -> ()
910910
| None, (Check _ | Assume _ | Ignore_assert_all) -> assert false
911911
| Some _, Ignore_assert_all -> ()
912912
| Some _, Assume _ -> ()
913913
| Some attr, Check { opt; _ } ->
914-
if not in_signature && is_check_enabled ~opt p && !Clflags.native_code then
914+
if not in_signature && is_zero_alloc_check_enabled ~opt && !Clflags.native_code then
915915
(* The warning for unchecked functions will not trigger if the check is
916916
requested through the [@@@zero_alloc all] top-level annotation rather
917917
than through the function annotation [@zero_alloc]. *)
918-
register_property attr.attr_name);
918+
register_zero_alloc_attribute attr.attr_name);
919919
res
920920

921921
let assume_zero_alloc ~is_check_allowed check : Zero_alloc_utils.Assume_info.t =
922922
match check with
923-
| Default_check -> Zero_alloc_utils.Assume_info.none
923+
| Default_zero_alloc -> Zero_alloc_utils.Assume_info.none
924924
| Ignore_assert_all -> Zero_alloc_utils.Assume_info.none
925925
| Assume { strict; never_returns_normally; never_raises; } ->
926926
Zero_alloc_utils.Assume_info.create ~strict ~never_returns_normally ~never_raises

0 commit comments

Comments
 (0)