-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
add entry point to construct an OpaqueClosure from pre-optimized IRCode #44197
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
Changes from 3 commits
4176f00
c49662c
c48e638
c5fae67
691d310
7aa4a7d
6c22265
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 |
---|---|---|
|
@@ -230,3 +230,26 @@ call_global_opaque_closure() = GLOBAL_OPAQUE_CLOSURE() | |
let oc = @opaque a->sin(a) | ||
@test length(code_typed(oc, (Int,))) == 1 | ||
end | ||
|
||
# constructing an opaque closure from IRCode | ||
using Core.Compiler: IRCode | ||
using Core: CodeInfo | ||
|
||
function OC(ir::IRCode, env...) | ||
src = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ()); | ||
src.slotflags = UInt8[] | ||
nargs = length(ir.argtypes) | ||
|
||
src.slotnames = fill(:none, nargs) | ||
Core.Compiler.replace_code_newstyle!(src, ir, nargs); | ||
Core.Compiler.widen_all_consts!(src); | ||
src.inferred = true | ||
# NOTE: we need ir.argtypes[1] == typeof(env) | ||
|
||
ccall(:jl_new_opaque_closure_from_code_info, Any, (Any, Any, Any, Any, Any, Cint, Any, Cint, Cint, Any), | ||
Tuple{ir.argtypes[2:end]...}, Union{}, Any, @__MODULE__, src, 0, nothing, nargs-1, false, env) | ||
|
||
end | ||
|
||
let ci = code_typed(+, (Int, Int))[1][1] | ||
ir = Core.Compiler.inflate_ir(ci) | ||
@test OC(ir)(40, 2) == 42 | ||
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.
This code seems to segfault in certain cases, e.g. I found:
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,
resolve_globals
just needs to handleReturnNode
with an undefined field, which only occurs in optimized IR. Or even better, we could pass a flag through to prevent it from callingresolve_globals
in this case, since that should only be needed by the front end.