-
Notifications
You must be signed in to change notification settings - Fork 107
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
Open
Leonidas-from-XIV
wants to merge
16
commits into
ocaml:master
Choose a base branch
from
Leonidas-from-XIV:zero-alloc-annotation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6300a38
Add `[@@zero_alloc]` attribute
Leonidas-from-XIV fa9f14c
Remove `Zero_alloc` from `Doc_attr`
Leonidas-from-XIV 476df66
Emit `cut` only if `zero_alloc` will be printed
Leonidas-from-XIV 4ae9929
Preserve `zero_alloc strict` and `zero_alloc opt` arguments
Leonidas-from-XIV 55a6e89
Reformat
Leonidas-from-XIV 7758f41
Add test for `val[@zero_alloc]` annotation
Leonidas-from-XIV 3eff2ba
Treat `zero_alloc` only special in OxCaml
Leonidas-from-XIV c8f5577
Parse more of zero_alloc annotation
Leonidas-from-XIV a63e476
Better names, structure and types
Leonidas-from-XIV 0a57c88
Reformat
Leonidas-from-XIV 9cdf648
fixup! Reformat
Leonidas-from-XIV a552fa1
fixup! fixup! Reformat
Leonidas-from-XIV 9ff4982
Add PR number
Leonidas-from-XIV 5593934
Replace manual parsing with reading value from compiler-libs
Leonidas-from-XIV 3948d7b
Deduplicate extraction of zero_alloc
Leonidas-from-XIV e86f3d0
Nicer API
Leonidas-from-XIV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 arity 3]}\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 arity 3]}\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 arity 3]}\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 arity 1]}\begin{ocamlindent}Alternative syntax for zero alloc annotation\end{ocamlindent}% | ||
| \medbreak | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs, the only allowed payloads are
opt,strictandarity <n>.If I understand correctly "
assume" does not correspond to the default. (Assume in a module type would be: do not check that the implementation do not allocate, but use that information in uses outside.)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
or the one that uses the fact that it has already been validated by the oxcaml compiler:
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: