-
Notifications
You must be signed in to change notification settings - Fork 106
Zero alloc annotation for OxCaml #1422
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
base: master
Are you sure you want to change the base?
Changes from all commits
6300a38
fa9f14c
476df66
4ae9929
55a6e89
7758f41
3eff2ba
c8f5577
a63e476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -321,12 +321,26 @@ end = | |||||||||||||||||||||||||||||||||
| and Value : sig | ||||||||||||||||||||||||||||||||||
| type value = Abstract | External of string list | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| module Zero_alloc : sig | ||||||||||||||||||||||||||||||||||
| type respect = { | ||||||||||||||||||||||||||||||||||
| opt : unit option; | ||||||||||||||||||||||||||||||||||
| strict : unit option; | ||||||||||||||||||||||||||||||||||
| arity : int option; | ||||||||||||||||||||||||||||||||||
| custom_error_message : string option | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| type t = | ||||||||||||||||||||||||||||||||||
| | Ignore | ||||||||||||||||||||||||||||||||||
| | Respect of respect | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| type attr = Zero_alloc of Zero_alloc.t | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+324
to
+335
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs, the only allowed payloads are If I understand correctly " Moreover, it seems possible to use multiple (valid) payloads. So I think we have two options in terms of type representation: the "more correct" one
Suggested change
or the one that uses the fact that it has already been validated by the oxcaml compiler:
Suggested change
Both are fine to me! And the second one is probably less work. Here are some examples of zero_alloc uses in module types to "validate" the oxcaml doc: # module type T = sig val[@zero_alloc] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc] end
(** The error says the accepted attributes {e for implementation}, not interface, unfortunately *)
# module type T = sig val[@zero_alloc gloubli-boulga] f : int -> int -> int end ;;
Warning 47 [attribute-payload]: illegal payload for attribute 'zero_alloc'.
It must be either 'assume', 'assume_unless_opt', 'strict', 'opt', 'opt strict', 'assume strict', 'assume never_returns_normally', 'assume never_returns_normally strict', 'assume error', 'ignore', 'arity <int_constant>', 'custom_error_message <string_constant>' or empty
(** assume is not allowed *)
# module type T = sig val[@zero_alloc assume] f : int -> int -> int end ;;
Error: zero_alloc assume attributes are not supported in signatures
(** strict, opt, and arity <n> (and combinations) are allowed *)
# module type T = sig val[@zero_alloc strict] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc strict] end
# module type T = sig val[@zero_alloc opt] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc opt] end
# module type T = sig val[@zero_alloc arity 1] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc arity 1] end
# module type T = sig val[@zero_alloc strict opt] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc strict opt] end
# module type T = sig val[@zero_alloc strict arity 2] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc strict] end
# module type T = sig val[@zero_alloc arity 1 opt strict] f : int -> int -> int end ;;
module type T =
sig val f : int -> int -> int [@@zero_alloc strict opt arity 1] end
# module type T = sig val[@zero_alloc] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc] end
# module type T = sig val[@zero_alloc] f : int -> int -> int end ;;
module type T = sig val f : int -> int -> int [@@zero_alloc] end |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| type t = { | ||||||||||||||||||||||||||||||||||
| id : Identifier.Value.t; | ||||||||||||||||||||||||||||||||||
| source_loc : Identifier.SourceLocation.t option; | ||||||||||||||||||||||||||||||||||
| value : value; | ||||||||||||||||||||||||||||||||||
| doc : Comment.docs; | ||||||||||||||||||||||||||||||||||
| type_ : TypeExpr.t; | ||||||||||||||||||||||||||||||||||
| ext_attr : attr list; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| end = | ||||||||||||||||||||||||||||||||||
| Value | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,18 @@ | ||
| val f : int -> ('a . 'a -> 'a) -> unit | ||
| (** Polymorphic arguments require parentheses *) | ||
|
|
||
| val add : bool -> int -> int -> int [@@zero_alloc] | ||
| (** Zero allocation bindings have an extension attribute attached. | ||
| See https://oxcaml.org/documentation/miscellaneous-extensions/zero_alloc_check/ | ||
| *) | ||
|
|
||
| val add_opt : bool -> int -> int -> int [@@zero_alloc opt] | ||
| (** Like [add] but with an [opt] attribute. | ||
| *) | ||
|
|
||
| val add_strict : bool -> int -> int -> int [@@zero_alloc strict] | ||
| (** Like [add] but with a [strict] attribute. | ||
| *) | ||
|
|
||
| val[@zero_alloc] f : int -> int | ||
| (** Alternative syntax for zero alloc annotation *) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| \section{Module \ocamlinlinecode{Oxcaml}}\label{Oxcaml}% | ||
| \label{Oxcaml--val-f}\ocamlcodefragment{\ocamltag{keyword}{val} f : int \ocamltag{arrow}{$\rightarrow$} ('a.\allowbreak{} \ocamltag{type-var}{'a} \ocamltag{arrow}{$\rightarrow$} \ocamltag{type-var}{'a}) \ocamltag{arrow}{$\rightarrow$} unit}\begin{ocamlindent}Polymorphic arguments require parentheses\end{ocamlindent}% | ||
| \label{Oxcaml--val-add}\ocamlcodefragment{\ocamltag{keyword}{val} add : bool \ocamltag{arrow}{$\rightarrow$} int \ocamltag{arrow}{$\rightarrow$} int \ocamltag{arrow}{$\rightarrow$} int [@@zero\_\allowbreak{}alloc]}\begin{ocamlindent}Zero allocation bindings have an extension attribute attached. See https://oxcaml.org/documentation/miscellaneous-extensions/zero\_alloc\_check/\end{ocamlindent}% | ||
| \medbreak | ||
| \label{Oxcaml--val-add_opt}\ocamlcodefragment{\ocamltag{keyword}{val} add\_\allowbreak{}opt : bool \ocamltag{arrow}{$\rightarrow$} int \ocamltag{arrow}{$\rightarrow$} int \ocamltag{arrow}{$\rightarrow$} int [@@zero\_\allowbreak{}alloc opt]}\begin{ocamlindent}Like \ocamlinlinecode{add} but with an \ocamlinlinecode{opt} attribute.\end{ocamlindent}% | ||
| \medbreak | ||
| \label{Oxcaml--val-add_strict}\ocamlcodefragment{\ocamltag{keyword}{val} add\_\allowbreak{}strict : bool \ocamltag{arrow}{$\rightarrow$} int \ocamltag{arrow}{$\rightarrow$} int \ocamltag{arrow}{$\rightarrow$} int [@@zero\_\allowbreak{}alloc strict]}\begin{ocamlindent}Like \ocamlinlinecode{add} but with a \ocamlinlinecode{strict} attribute.\end{ocamlindent}% | ||
| \medbreak | ||
| \label{Oxcaml--val-f}\ocamlcodefragment{\ocamltag{keyword}{val} f : int \ocamltag{arrow}{$\rightarrow$} int [@@zero\_\allowbreak{}alloc]}\begin{ocamlindent}Alternative syntax for zero alloc annotation\end{ocamlindent}% | ||
| \medbreak | ||
|
|
||
|
|
Uh oh!
There was an error while loading. Please reload this page.