-
Notifications
You must be signed in to change notification settings - Fork 86
Static check for noalloc and friends #707
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
Closed
Closed
Conversation
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
8eda9ac
to
db8a39f
Compare
and -dcheckmach for debug output of these passes
Update format and compilenv Cache imported noalloc functions in compilenv
Propagate through Flambda to Cmm
unix has become a dependency of boot, so we can't build it with the new flags, which means the check will fail on anything that calls into Unix module. This will need to be fixed, but for now just removing the flags to re-enable the build.
I'm splitting this PR. |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds an experimental new pass on Mach that statically checks certain interprocedural properties of functions and records the results in Cmx. The checks are off by default (except on the standard library) and can be turned on using compiler flags
-noalloc-check
,-noeffect-check
,-noindirect-calls-check
.A function is "noalloc" if it satisfies the following conditions:
A function is "noalloc_exn" if it is noalloc except that any raise instructions are allowed and there are no constraints on instructions that are post-dominated by a raise with backtrace (with a somewhat conservative interpretation for raise inside loops and try-with). This is probably the most useful check in practice, as it allows allocation on error paths.
A function is "noffect" if it is noalloc and does not contain any instructions that write to heap-allocated memory. It may be useful to have a version for "noeffect_exn" similarly to "noalloc_exn" above.
A function is "noindirect_calls" if it does not contain any raise except raise_notrace, does not contain any indirect calls, and all direct calls are to functions that are "noindirect_calls". I'm not sure how useful the indirect calls check is, but it came for free.
These checks are combined with source level annotations on functions:
[@assert noalloc]
on a function that cannot be shown statically to be "noalloc" results in a compilation error when compiled with -alloc-check flag.[@assume noalloc]
is an escape hatch that would treat a function as "noalloc" without checking.Similarly, for other properties above.
The analysis is implemented on Mach after all optimizations that can possibly remove allocation. It works the same way for all "middle-ends", but adds function symbol names to cmx files. To reduce the overhead, cmx track names that pass the checks and don't duplicate, using the following implication between properties:
"noeffects" => "noalloc" => "noalloc_exn" and "noalloc" => "noindirect_calls"