-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
wip: scratch compiler plugin #44950
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
Draft
aviatesk
wants to merge
8
commits into
master
Choose a base branch
from
avi/plugin8-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
wip: scratch compiler plugin #44950
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4176f00
add entry point to construct an OpaqueClosure from pre-optimized IRCode
JeffBezanson c49662c
Merge branch 'master' into jb/ircode2oc
aviatesk c48e638
update `jl_new_codeinst` signature
aviatesk c5fae67
Merge branch 'master' into jb/ircode2oc
aviatesk 691d310
fixes to OpaqueClosure argument count handling and MethodError display
JeffBezanson 7aa4a7d
Merge branch 'master' into jb/ircode2oc
aviatesk 6c22265
more test coverage
aviatesk af34539
wip: scratch compiler plugin
aviatesk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# this simple code assumes a plugin AbstractInterpreter manages its own code cache | ||
# in a way that it is totally separated from the native code cache | ||
|
||
# TODO more composable way | ||
global PLUGIN_INTERPRETER::AbstractInterpreter = NativeInterpreter() | ||
isplugin(interp::AbstractInterpreter) = let | ||
global PLUGIN_INTERPRETER | ||
interp === PLUGIN_INTERPRETER | ||
end | ||
|
||
function new_opaque_closure(src::CodeInfo, nargs::Int, @nospecialize(rt), | ||
@nospecialize(env...)) | ||
@assert src.inferred "unoptimized IR unsupported" | ||
argt = argtypes_to_type((src.slottypes::Vector{Any})[2:nargs+1]) | ||
|
||
# M = src.parent.def | ||
# sig = Base.tuple_type_tail(src.parent.specTypes) | ||
|
||
return ccall(:jl_new_opaque_closure_from_code_info, Any, | ||
(Any, Any, Any, Any, Any, Cint, Any, Cint, Cint, Any), | ||
argt, Union{}, rt, @__MODULE__, src, 0, nothing, nargs, false, env) | ||
end | ||
|
||
function execute_with_plugin(f, args...; | ||
world::UInt = get_world_counter(), | ||
interp::AbstractInterpreter = PLUGIN_INTERPRETER) | ||
global PLUGIN_INTERPRETER = interp | ||
tt = Tuple{Core.Typeof(f), Any[Core.Typeof(args[i]) for i = 1:length(args)]...} | ||
matches = _methods_by_ftype(tt, -1, world) | ||
matches !== nothing || throw(MethodError(f, args, world)) | ||
length(matches) ≠ 1 && throw(MethodError(f, args, world)) | ||
m = first(matches)::MethodMatch | ||
src, rt = typeinf_code(interp, | ||
m.method, m.spec_types, m.sparams, true) | ||
if src === nothing | ||
# builtin, or bad generated function | ||
return f(args...) # XXX | ||
end | ||
# TODO support varargs | ||
oc = new_opaque_closure(src, length(args), rt) | ||
return oc(args...) | ||
end | ||
|
||
module Plugin | ||
import ..execute_with_plugin | ||
export execute_with_plugin | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Couldn't we just write
and then when someone writes a plugin, they add an overload
I tested this locally and it appears to work.
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.
Ah I see the problem, this doesn't work with your way of dealing with dynamic dispatch. Is that the background for #46220 then?