Skip to content

add @pure docstring and example #24817

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
wants to merge 8 commits into from
Closed
Changes from all commits
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
19 changes: 18 additions & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,24 @@ macro noinline(ex)
esc(isa(ex, Expr) ? pushmeta!(ex, :noinline) : ex)
end

macro pure(ex)
"""
@hyperpure

Annotates a function to ease type inference by strictly specifying the
output is completely determined by the input.

Usage can easily lead to whole program corruption or crashes and should be avoided
by all users.

Do not use if the function involved:

- Involves globals, pointers
- Does not return exactly (`===`) the same result for the same input
- Gets its methods extended after it is called
- Uses dispatch on any of its arguments

"""
macro hyperpure(ex)
esc(isa(ex, Expr) ? pushmeta!(ex, :pure) : ex)
end

Expand Down