-
Notifications
You must be signed in to change notification settings - Fork 10
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
Split should_rewrite_ft
for call
and invoke
expressions, and overlay Base._unique_dims
#505
Changes from 1 commit
2825485
e90e79f
96745de
39a9ba0
f697b34
2c10398
0047220
5f6c31c
2bd1c9d
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 |
---|---|---|
|
@@ -89,7 +89,7 @@ function has_ancestor(query::Module, target::Module) | |
end | ||
end | ||
|
||
function should_rewrite_ft(@nospecialize(ft)) | ||
function should_rewrite_call(@nospecialize(ft)) | ||
# Don't rewrite builtin or intrinsics | ||
if ft <: Core.IntrinsicFunction || ft <: Core.Builtin | ||
return false | ||
|
@@ -171,6 +171,20 @@ function should_rewrite_ft(@nospecialize(ft)) | |
return true | ||
end | ||
|
||
# by default, same as `should_rewrite_call` | ||
function should_rewrite_invoke(@nospecialize(ft), @nospecialize(args)) | ||
Core.println(Core.stderr, "[should_rewrite_invoke] ft = $ft, parameters = $(args)") | ||
return should_rewrite_call(ft) | ||
end | ||
|
||
function should_rewrite_invoke(::typeof(Base.unique), @nospecialize(args)) | ||
Core.println(Core.stderr, "[should_rewrite_invoke] Base.unique catched!") | ||
if args === Tuple{Vector{Symbol}} | ||
return false | ||
end | ||
return true | ||
end | ||
|
||
# Avoid recursively interpreting into methods we define explicitly | ||
# as overloads, which we assume should handle the entirety of the | ||
# translation (and if not they can use call_in_reactant). | ||
|
@@ -231,7 +245,7 @@ function rewrite_inst(inst, ir, interp, RT, guaranteed_error) | |
end | ||
if ft == typeof(Core._apply_iterate) | ||
ft = Core.Compiler.widenconst(maybe_argextype(inst.args[3], ir)) | ||
if Base.invokelatest(should_rewrite_ft, ft) | ||
if Base.invokelatest(should_rewrite_call, ft) | ||
if RT === Union{} | ||
rep = Expr( | ||
:call, | ||
|
@@ -245,7 +259,7 @@ function rewrite_inst(inst, ir, interp, RT, guaranteed_error) | |
return true, rep, Any | ||
end | ||
end | ||
elseif Base.invokelatest(should_rewrite_ft, ft) | ||
elseif Base.invokelatest(should_rewrite_call, ft) | ||
if RT === Union{} | ||
rep = Expr(:call, call_with_reactant, MustThrowError(), inst.args...) | ||
return true, rep, Union{} | ||
|
@@ -259,10 +273,13 @@ function rewrite_inst(inst, ir, interp, RT, guaranteed_error) | |
omi = inst.args[1]::Core.MethodInstance | ||
sig = omi.specTypes | ||
ft = sig.parameters[1] | ||
argsig = sig.parameters[2:end] | ||
if ft == typeof(Core.kwcall) | ||
ft = sig.parameters[3] | ||
argsig = sig.parameters[4:end] | ||
end | ||
if Base.invokelatest(should_rewrite_ft, ft) && !is_reactant_method(omi) | ||
argsig = Core.apply_type(Core.Tuple, argsig...) | ||
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'd probably be lazy and do Tuple{argsize...} but sure 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 the same right? 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 |
||
if Base.invokelatest(should_rewrite_invoke, ft, argsig) && !is_reactant_method(omi) | ||
method = omi.def::Core.Method | ||
|
||
min_world = Ref{UInt}(typemin(UInt)) | ||
|
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.
[JuliaFormatter] reported by reviewdog 🐶
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.
probably remove the print?
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.
yeah, i'm using the prints for debugging.
invokelatest
is just calling the genericshould_rewrite_invoke
method, and not the specialized one forBase.unique
.will remove them once i fix it.
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.
yeah I'm just suggesting to use https://github.com/JuliaLang/julia/blob/37b8b61ee0bd4b8db1b210a5389cf794a1358ed1/base/essentials.jl#L1062 instead where world is interp.world