-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
generated functions, next generation #23168
Changes from all commits
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 |
---|---|---|
|
@@ -236,21 +236,27 @@ include("broadcast.jl") | |
using .Broadcast | ||
|
||
# define the real ntuple functions | ||
@generated function ntuple(f::F, ::Val{N}) where {F,N} | ||
Core.typeassert(N, Int) | ||
(N >= 0) || return :(throw($(ArgumentError(string("tuple length should be ≥0, got ", N))))) | ||
return quote | ||
$(Expr(:meta, :inline)) | ||
@nexprs $N i -> t_i = f(i) | ||
@ncall $N tuple t | ||
@inline function ntuple(f::F, ::Val{N}) where {F,N} | ||
N::Int | ||
(N >= 0) || throw(ArgumentError(string("tuple length should be ≥0, got ", N))) | ||
if @generated | ||
quote | ||
@nexprs $N i -> t_i = f(i) | ||
@ncall $N tuple t | ||
end | ||
else | ||
Tuple(f(i) for i = 1:N) | ||
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. Why is this attempting to use the 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. I don't understand the problem. Why will we need to add this definition to Core.Inference? |
||
end | ||
end | ||
@generated function fill_to_length(t::Tuple, val, ::Val{N}) where {N} | ||
M = length(t.parameters) | ||
M > N && return :(throw($(ArgumentError("input tuple of length $M, requested $N")))) | ||
return quote | ||
$(Expr(:meta, :inline)) | ||
(t..., $(Any[ :val for i = (M + 1):N ]...)) | ||
@inline function fill_to_length(t::Tuple, val, ::Val{N}) where {N} | ||
M = length(t) | ||
M > N && throw(ArgumentError("input tuple of length $M, requested $N")) | ||
if @generated | ||
quote | ||
(t..., $(fill(:val, N-length(t.parameters))...)) | ||
end | ||
else | ||
(t..., fill(val, N-M)...) | ||
end | ||
end | ||
|
||
|
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.
Conditionally returning the source code from a different semi-related method seems sort of random. I think it would be better to now just use the trivial definition (
uncompressed_ast(m::Method) = uncompressed_ast(m, m.source)
)