Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move zero alloc annotations into a separate file #2474

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions driver/flambda_backend_args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ let mk_heap_reduction_threshold f =
;;

let mk_zero_alloc_check f =
let annotations = Clflags.Annotations.(List.map to_string all) in
let annotations = Zero_alloc_annotations.(List.map to_string all) in
"-zero-alloc-check", Arg.Symbol (annotations, f),
" Check that annotated functions do not allocate \
and do not have indirect calls. "^Clflags.Annotations.doc
and do not have indirect calls. "^Zero_alloc_annotations.doc

let mk_dcheckmach f =
"-dcheckmach", Arg.Unit f, " (undocumented)"
Expand Down Expand Up @@ -933,7 +933,7 @@ module Flambda_backend_options_impl = struct
Flambda_backend_flags.heap_reduction_threshold := x

let zero_alloc_check s =
match Clflags.Annotations.of_string s with
match Zero_alloc_annotations.of_string s with
| None -> () (* this should not occur as we use Arg.Symbol *)
| Some a ->
Clflags.zero_alloc_check := a
Expand Down Expand Up @@ -1214,7 +1214,7 @@ module Extra_params = struct
| "basic-block-sections" -> set' Flambda_backend_flags.basic_block_sections
| "heap-reduction-threshold" -> set_int' Flambda_backend_flags.heap_reduction_threshold
| "zero-alloc-check" ->
(match Clflags.Annotations.of_string v with
(match Zero_alloc_annotations.of_string v with
| Some a -> Clflags.zero_alloc_check := a; true
| None ->
raise
Expand Down
23 changes: 17 additions & 6 deletions ocaml/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ utils/ccomp.cmx : \
utils/ccomp.cmi
utils/ccomp.cmi :
utils/clflags.cmo : \
utils/zero_alloc_annotations.cmi \
utils/profile.cmi \
utils/numbers.cmi \
utils/misc.cmi \
utils/config.cmi \
utils/arg_helper.cmi \
utils/clflags.cmi
utils/clflags.cmx : \
utils/zero_alloc_annotations.cmx \
utils/profile.cmx \
utils/numbers.cmx \
utils/misc.cmx \
utils/config.cmx \
utils/arg_helper.cmx \
utils/clflags.cmi
utils/clflags.cmi : \
utils/zero_alloc_annotations.cmi \
utils/profile.cmi \
utils/misc.cmi
utils/compilation_unit.cmo : \
Expand Down Expand Up @@ -282,6 +285,11 @@ utils/warnings.cmx : \
utils/misc.cmx \
utils/warnings.cmi
utils/warnings.cmi :
utils/zero_alloc_annotations.cmo : \
utils/zero_alloc_annotations.cmi
utils/zero_alloc_annotations.cmx : \
utils/zero_alloc_annotations.cmi
utils/zero_alloc_annotations.cmi :
utils/zero_alloc_utils.cmo : \
utils/zero_alloc_utils.cmi
utils/zero_alloc_utils.cmx : \
Expand Down Expand Up @@ -401,6 +409,7 @@ parsing/attr_helper.cmi : \
parsing/asttypes.cmi
parsing/builtin_attributes.cmo : \
utils/zero_alloc_utils.cmi \
utils/zero_alloc_annotations.cmi \
utils/warnings.cmi \
parsing/parsetree.cmi \
utils/misc.cmi \
Expand All @@ -414,6 +423,7 @@ parsing/builtin_attributes.cmo : \
parsing/builtin_attributes.cmi
parsing/builtin_attributes.cmx : \
utils/zero_alloc_utils.cmx \
utils/zero_alloc_annotations.cmx \
utils/warnings.cmx \
parsing/parsetree.cmi \
utils/misc.cmx \
Expand Down Expand Up @@ -690,20 +700,23 @@ typing/annot.cmi : \
typing/btype.cmo : \
typing/types.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
utils/local_store.cmi \
typing/ident.cmi \
parsing/asttypes.cmi \
typing/btype.cmi
typing/btype.cmx : \
typing/types.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
utils/local_store.cmx \
typing/ident.cmx \
parsing/asttypes.cmi \
typing/btype.cmi
typing/btype.cmi : \
typing/types.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
typing/jkind.cmi \
parsing/asttypes.cmi
typing/cmt2annot.cmo : \
Expand Down Expand Up @@ -1449,8 +1462,7 @@ typing/printtyp.cmi : \
parsing/location.cmi \
typing/ident.cmi \
typing/errortrace.cmi \
typing/env.cmi \
parsing/asttypes.cmi
typing/env.cmi
typing/printtyped.cmo : \
utils/zero_alloc_utils.cmi \
typing/types.cmi \
Expand Down Expand Up @@ -1932,6 +1944,7 @@ typing/typedecl.cmi : \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
utils/language_extension.cmi \
typing/jkind.cmi \
typing/includecore.cmi \
typing/ident.cmi \
Expand Down Expand Up @@ -7055,6 +7068,7 @@ toplevel/genprintval.cmo : \
typing/env.cmi \
typing/datarepr.cmi \
typing/ctype.cmi \
utils/clflags.cmi \
typing/btype.cmi \
parsing/asttypes.cmi \
toplevel/genprintval.cmi
Expand All @@ -7076,6 +7090,7 @@ toplevel/genprintval.cmx : \
typing/env.cmx \
typing/datarepr.cmx \
typing/ctype.cmx \
utils/clflags.cmx \
typing/btype.cmx \
parsing/asttypes.cmi \
toplevel/genprintval.cmi
Expand Down Expand Up @@ -7264,7 +7279,6 @@ toplevel/topprinters.cmo : \
typing/mode.cmi \
typing/ident.cmi \
typing/ctype.cmi \
parsing/asttypes.cmi \
toplevel/topprinters.cmi
toplevel/topprinters.cmx : \
typing/types.cmx \
Expand All @@ -7273,7 +7287,6 @@ toplevel/topprinters.cmx : \
typing/mode.cmx \
typing/ident.cmx \
typing/ctype.cmx \
parsing/asttypes.cmi \
toplevel/topprinters.cmi
toplevel/topprinters.cmi : \
typing/types.cmi
Expand Down Expand Up @@ -7412,7 +7425,6 @@ toplevel/byte/trace.cmo : \
bytecomp/meta.cmi \
parsing/longident.cmi \
typing/ctype.cmi \
parsing/asttypes.cmi \
toplevel/byte/trace.cmi
toplevel/byte/trace.cmx : \
typing/types.cmx \
Expand All @@ -7425,7 +7437,6 @@ toplevel/byte/trace.cmx : \
bytecomp/meta.cmx \
parsing/longident.cmx \
typing/ctype.cmx \
parsing/asttypes.cmi \
toplevel/byte/trace.cmi
toplevel/byte/trace.cmi : \
typing/types.cmi \
Expand Down
12 changes: 6 additions & 6 deletions ocaml/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1467,14 +1467,14 @@ tools/ocamldep$(EXE): OC_BYTECODE_LINKFLAGS += -compat-32
ocamlprof_LIBRARIES =
ocamlprof_MODULES = \
config build_path_prefix_map misc identifiable numbers arg_helper \
local_store load_path clflags terminfo warnings location longident \
docstrings syntaxerr ast_helper camlinternalMenhirLib parser pprintast \
lexer parse ocamlprof
local_store load_path zero_alloc_annotations clflags terminfo warnings \
location longident docstrings syntaxerr ast_helper camlinternalMenhirLib \
parser pprintast lexer parse ocamlprof

ocamlcp_ocamloptp_MODULES = \
config build_path_prefix_map misc profile warnings identifiable numbers \
arg_helper local_store load_path clflags terminfo location ccomp compenv \
main_args ocamlcp_common
arg_helper local_store load_path zero_alloc_annotations clflags terminfo \
location ccomp compenv main_args ocamlcp_common zero_alloc_annotations

ocamlcp_LIBRARIES =
ocamlcp_MODULES = $(ocamlcp_ocamloptp_MODULES) ocamlcp
Expand All @@ -1491,7 +1491,7 @@ ocamlmklib_MODULES = config build_path_prefix_map misc ocamlmklib
ocamlmktop_LIBRARIES =
ocamlmktop_MODULES = \
config build_path_prefix_map misc identifiable numbers arg_helper \
local_store load_path clflags profile ccomp ocamlmktop
local_store load_path zero_alloc_annotations clflags profile ccomp ocamlmktop

# Reading cmt files

Expand Down
1 change: 1 addition & 0 deletions ocaml/compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ UTILS = \
utils/arg_helper.cmo \
utils/local_store.cmo \
utils/load_path.cmo \
utils/zero_alloc_annotations.cmo \
utils/clflags.cmo \
utils/debug.cmo \
utils/language_extension_kernel.cmo \
Expand Down
3 changes: 2 additions & 1 deletion ocaml/dune
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
local_store target_system compilation_unit import_info linkage_name symbol
lazy_backtrack diffing diffing_with_keys
language_extension_kernel language_extension
zero_alloc_utils
zero_alloc_utils zero_alloc_annotations

;; PARSING
location longident docstrings printast syntaxerr ast_helper
Expand Down Expand Up @@ -248,6 +248,7 @@
(identifiable.mli as compiler-libs/identifiable.mli)
(numbers.mli as compiler-libs/numbers.mli)
(arg_helper.mli as compiler-libs/arg_helper.mli)
(zero_alloc_annotations.mli as compiler-libs/zero_alloc_annotations.mli)
(clflags.mli as compiler-libs/clflags.mli)
(language_extension.mli as compiler-libs/language_extension.mli)
(profile.mli as compiler-libs/profile.mli)
Expand Down
1 change: 1 addition & 0 deletions ocaml/otherlibs/dynlink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ COMPILERLIBS_SOURCES=\
utils/arg_helper.ml \
utils/local_store.ml \
utils/load_path.ml \
utils/zero_alloc_annotations.ml \
utils/clflags.ml \
utils/debug.ml \
utils/language_extension_kernel.ml \
Expand Down
3 changes: 3 additions & 0 deletions ocaml/otherlibs/dynlink/dune
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
identifiable
numbers
arg_helper
zero_alloc_annotations
clflags
debug
language_extension_kernel
Expand Down Expand Up @@ -148,6 +149,7 @@
(copy_files ../../utils/identifiable.ml)
(copy_files ../../utils/numbers.ml)
(copy_files ../../utils/arg_helper.ml)
(copy_files ../../utils/zero_alloc_annotations.ml)
(copy_files ../../utils/clflags.ml)
(copy_files ../../utils/debug.ml)
(copy_files ../../utils/language_extension_kernel.ml)
Expand Down Expand Up @@ -214,6 +216,7 @@
(copy_files ../../utils/identifiable.mli)
(copy_files ../../utils/numbers.mli)
(copy_files ../../utils/arg_helper.mli)
(copy_files ../../utils/zero_alloc_annotations.mli)
(copy_files ../../utils/clflags.mli)
(copy_files ../../utils/debug.mli)
(copy_files ../../utils/language_extension_kernel.mli)
Expand Down
8 changes: 4 additions & 4 deletions ocaml/parsing/builtin_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,10 @@ let parse_attribute_with_ident_payload attr ~name ~f =
let zero_alloc_attribute (attr : Parsetree.attribute) =
parse_attribute_with_ident_payload attr
~name:"zero_alloc" ~f:(function
| "check" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_default
| "check_opt" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_opt_only
| "check_all" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_all
| "check_none" -> Clflags.zero_alloc_check := Clflags.Annotations.No_check
| "check" -> Clflags.zero_alloc_check := Zero_alloc_annotations.Check_default
| "check_opt" -> Clflags.zero_alloc_check := Zero_alloc_annotations.Check_opt_only
| "check_all" -> Clflags.zero_alloc_check := Zero_alloc_annotations.Check_all
| "check_none" -> Clflags.zero_alloc_check := Zero_alloc_annotations.No_check
| "all" ->
Clflags.zero_alloc_check_assert_all := true
| _ ->
Expand Down
10 changes: 6 additions & 4 deletions ocaml/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ ocamldep.opt$(EXE): $(call byte2native, $(OCAMLDEP))
# The profiler

OCAMLPROF=config.cmo build_path_prefix_map.cmo misc.cmo identifiable.cmo \
numbers.cmo arg_helper.cmo clflags.cmo debug.cmo terminfo.cmo \
numbers.cmo arg_helper.cmo zero_alloc_annotations.cmo clflags.cmo \
debug.cmo terminfo.cmo \
warnings.cmo location.cmo longident.cmo docstrings.cmo \
syntaxerr.cmo ast_helper.cmo \
language_extension_kernel.cmo language_extension.cmo \
Expand All @@ -101,7 +102,7 @@ opt.opt: profiling.cmx
OCAMLCP = config.cmo build_path_prefix_map.cmo misc.cmo profile.cmo \
warnings.cmo identifiable.cmo numbers.cmo arg_helper.cmo \
language_extension_kernel.cmo language_extension.cmo \
clflags.cmo local_store.cmo \
zero_alloc_annotations.cmo clflags.cmo local_store.cmo \
terminfo.cmo location.cmo load_path.cmo ccomp.cmo compenv.cmo \
main_args.cmo

Expand Down Expand Up @@ -136,8 +137,9 @@ ocamlmklib.opt$(EXE): $(call byte2native, $(OCAMLMKLIB))
# To make custom toplevels

OCAMLMKTOP=config.cmo build_path_prefix_map.cmo misc.cmo \
identifiable.cmo numbers.cmo arg_helper.cmo clflags.cmo \
local_store.cmo load_path.cmo profile.cmo ccomp.cmo ocamlmktop.cmo
identifiable.cmo numbers.cmo arg_helper.cmo zero_alloc_annotations.cmo \
clflags.cmo local_store.cmo load_path.cmo profile.cmo ccomp.cmo \
ocamlmktop.cmo

ocamlmktop$(EXE): $(OCAMLMKTOP)
ocamlmktop.opt$(EXE): $(call byte2native, $(OCAMLMKTOP))
Expand Down
34 changes: 1 addition & 33 deletions ocaml/utils/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -648,39 +648,7 @@ let create_usage_msg program =
let print_arguments program =
Arg.usage !arg_spec (create_usage_msg program)

module Annotations = struct
type t = Check_default | Check_all | Check_opt_only | No_check

let all = [ Check_default; Check_all; Check_opt_only; No_check ]

let to_string = function
| Check_default -> "default"
| Check_all -> "all"
| Check_opt_only -> "opt"
| No_check -> "none"

let equal t1 t2 =
match t1, t2 with
| Check_default, Check_default -> true
| Check_all, Check_all -> true
| No_check, No_check -> true
| Check_opt_only, Check_opt_only -> true
| (Check_default | Check_all | Check_opt_only | No_check), _ -> false

let of_string v =
let f t =
if String.equal (to_string t) v then Some t else None
in
List.find_map f all

let doc =
"\n\ The argument specifies which annotations to check: \n\
\ \"opt\" means attributes with \"opt\" payload and is intended for debugging;\n\
\ \"default\" means attributes without \"opt\" payload; \n\
\ \"all\" covers both \"opt\" and \"default\" and is intended for optimized builds."
end

let zero_alloc_check = ref Annotations.Check_default (* -zero-alloc-check *)
let zero_alloc_check = ref Zero_alloc_annotations.Check_default (* -zero-alloc-check *)
let zero_alloc_check_assert_all = ref false (* -zero-alloc-check-assert-all *)

let no_auto_include_otherlibs = ref false (* -no-auto-include-otherlibs *)
12 changes: 2 additions & 10 deletions ocaml/utils/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,8 @@ val print_arguments : string -> unit
(* [reset_arguments ()] clear all declared arguments *)
val reset_arguments : unit -> unit

(* [Annotations] specifies which zero_alloc attributes to check. *)
module Annotations : sig
type t = Check_default | Check_all | Check_opt_only | No_check
val all : t list
val to_string : t -> string
val of_string : string -> t option
val equal : t -> t -> bool
val doc : string
end
val zero_alloc_check : Annotations.t ref
(* [zero_alloc_check] specifies which zero_alloc attributes to check. *)
val zero_alloc_check : Zero_alloc_annotations.t ref
val zero_alloc_check_assert_all : bool ref

val no_auto_include_otherlibs : bool ref
29 changes: 29 additions & 0 deletions ocaml/utils/zero_alloc_annotations.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type t = Check_default | Check_all | Check_opt_only | No_check
liam923 marked this conversation as resolved.
Show resolved Hide resolved

let all = [ Check_default; Check_all; Check_opt_only; No_check ]

let to_string = function
| Check_default -> "default"
| Check_all -> "all"
| Check_opt_only -> "opt"
| No_check -> "none"

let equal t1 t2 =
match t1, t2 with
| Check_default, Check_default -> true
| Check_all, Check_all -> true
| No_check, No_check -> true
| Check_opt_only, Check_opt_only -> true
| (Check_default | Check_all | Check_opt_only | No_check), _ -> false

let of_string v =
let f t =
if String.equal (to_string t) v then Some t else None
in
List.find_map f all

let doc =
"\n\ The argument specifies which annotations to check: \n\
\ \"opt\" means attributes with \"opt\" payload and is intended for debugging;\n\
\ \"default\" means attributes without \"opt\" payload; \n\
\ \"all\" covers both \"opt\" and \"default\" and is intended for optimized builds."
Loading
Loading