-
Notifications
You must be signed in to change notification settings - Fork 7
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
Attempts at specialization transparency, ref #57 #58
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -54,37 +54,50 @@ Amend args that do not have a symbol or are destructured in the signature. Retur | |
arg expression and, if needed, an equivalent destructuring assignment for the body. | ||
""" | ||
function sanitize_arg_for_stability_check( | ||
ex::Symbol | ||
)::Tuple{Union{Expr,Symbol},Union{Expr,Nothing}} | ||
return ex, nothing | ||
ex::Symbol; genwhereparam | ||
)::Tuple{Union{Expr,Symbol},Union{Expr,Nothing},Union{Symbol,Nothing}} | ||
genwhereparam || return ex, nothing, nothing | ||
whereparam = gensym("T") | ||
return Expr(:(::), ex, whereparam), nothing, whereparam | ||
end | ||
function sanitize_arg_for_stability_check( | ||
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. Now that there are 3 returns, it might be nice to return a NamedTuple instead, for robustness. Returning tuples is always a bit risky because of things like (x, y) = (1, 2, 3) being valid Julia syntax. e.g., could be: return (; arg=Expr(:(::), ex, whereparam), destruct=nothing, whereparam=whereparam) 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. Yeah, that's a good idea! |
||
ex::Expr | ||
)::Tuple{Union{Expr,Symbol},Union{Expr,Nothing}} | ||
ex::Expr; genwhereparam | ||
)::Tuple{Union{Expr,Symbol},Union{Expr,Nothing},Union{Symbol,Nothing}} | ||
head, args = ex.head, ex.args | ||
if head == :(tuple) | ||
# (Base case) | ||
# matches things like (x,) and (; x) | ||
arg = gensym("arg") | ||
return arg, Expr(:(=), ex, arg) | ||
arg_ex, _, whereparam = sanitize_arg_for_stability_check(arg; genwhereparam) | ||
return arg_ex, Expr(:(=), ex, arg), whereparam | ||
elseif head == :(::) && length(args) == 1 | ||
# (Base case) | ||
# matches things like `::T` | ||
arg = gensym("arg") | ||
return Expr(head, arg, only(args)), nothing | ||
return Expr(head, arg, only(args)), nothing, nothing | ||
elseif head == :(...) && length(args) == 1 | ||
# (Composite case) | ||
# matches things like `::Int...` | ||
arg_ex, destructure_ex = sanitize_arg_for_stability_check(only(args)) | ||
return Expr(head, arg_ex), destructure_ex | ||
elseif head in (:kw, :(::)) && length(args) == 2 | ||
arg_ex, destructure_ex = sanitize_arg_for_stability_check( | ||
only(args); genwhereparam=false | ||
) | ||
return Expr(head, arg_ex), destructure_ex, nothing | ||
elseif head == :(::) && length(args) == 2 | ||
# (Composite case) | ||
# :(::) => matches things like `(x,)::T` and `(; x)::T` | ||
# :kw => matches things like `::Type{T}=MyType` | ||
arg_ex, destructure_ex = sanitize_arg_for_stability_check(first(args)) | ||
return Expr(head, arg_ex, last(args)), destructure_ex | ||
# matches things like `(x,)::T` and `(; x)::T` | ||
arg_ex, destructure_ex = sanitize_arg_for_stability_check( | ||
first(args); genwhereparam=false | ||
) | ||
return Expr(head, arg_ex, last(args)), destructure_ex, nothing | ||
elseif head == :kw && length(args) == 2 | ||
# (Composite case) | ||
# matches things like `::Type{T}=MyType` | ||
arg_ex, destructure_ex, whereparam = sanitize_arg_for_stability_check( | ||
first(args); genwhereparam | ||
) | ||
return Expr(head, arg_ex, last(args)), destructure_ex, whereparam | ||
Comment on lines
+93
to
+98
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. Does this one need 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. It's needed because this is also the branch that matches a regular 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. If it happens to be a 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 see, thanks! |
||
else | ||
return ex, nothing | ||
return ex, nothing, nothing | ||
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.
The error messages might need to be treated since they now show
::var"..."
after every arg.