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

elaborate @nospecialize docstring a bit #44933

Merged
merged 1 commit into from
Apr 12, 2022
Merged

Conversation

aviatesk
Copy link
Member

Adapted from #41931.

@aviatesk aviatesk added the docs This change adds or pertains to documentation label Apr 11, 2022
@aviatesk aviatesk changed the title elaborate the @nospecialize docstring a bit elaborate @nospecialize docstring a bit Apr 11, 2022
or in the function body.
When applied to an argument, the macro must wrap the entire argument expression.
When applied to an argument, the macro must wrap the entire argument expression, e.g.,
`@nospecialize(x::Real)` or `@nospecialize(i::Integer...)` rather than wrapping just the argument name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessarily the case if the function only takes one argument:

julia> function h(@nospecialize x::Int)
       x
       end
h (generic function with 1 method)

julia> function f(@nospecialize x)
       x
       end
f (generic function with 1 method)

Not sure whether it's worth it to elaborate on this small technicality here, but maybe we could give an example below that shows this way, since it is a bit cleaner imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are general syntactical variants of syntax for invoking macros and I don't think we necessarily want to discuss it here again (as it's described in the manual).

julia> f(A::AbstractArray) = g(A)
f (generic function with 1 method)

julia> @noinline g(@nospecialize(A::AbstractArray)) = A[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
julia> @noinline g(@nospecialize(A::AbstractArray)) = A[1]
julia> @noinline g(@nospecialize A::AbstractArray) = A[1]

for ex.,

@aviatesk aviatesk requested a review from vtjnash April 12, 2022 03:27
@vtjnash vtjnash merged commit 88fcf44 into master Apr 12, 2022
@vtjnash vtjnash deleted the avi/nospecialize-doc branch April 12, 2022 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants