-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Compiler <-> OpaqueClosure interface code to Compiler (#56576)
After the excision, it is no longer permissable for Base to have `Compiler` data structures in arguments of methods it defines. To comply with this restriction, move the functions for creating OpaqueClosures from IRCode to `Compiler`.
- Loading branch information
Showing
3 changed files
with
57 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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,56 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
function compute_ir_rettype(ir::IRCode) | ||
rt = Union{} | ||
for i = 1:length(ir.stmts) | ||
stmt = ir[SSAValue(i)][:stmt] | ||
if isa(stmt, Core.ReturnNode) && isdefined(stmt, :val) | ||
rt = Compiler.tmerge(Compiler.argextype(stmt.val, ir), rt) | ||
end | ||
end | ||
return Compiler.widenconst(rt) | ||
end | ||
|
||
function compute_oc_signature(ir::IRCode, nargs::Int, isva::Bool) | ||
argtypes = Vector{Any}(undef, nargs) | ||
for i = 1:nargs | ||
argtypes[i] = Compiler.widenconst(ir.argtypes[i+1]) | ||
end | ||
if isva | ||
lastarg = pop!(argtypes) | ||
if lastarg <: Tuple | ||
append!(argtypes, lastarg.parameters) | ||
else | ||
push!(argtypes, Vararg{Any}) | ||
end | ||
end | ||
return Tuple{argtypes...} | ||
end | ||
|
||
function Core.OpaqueClosure(ir::IRCode, @nospecialize env...; | ||
isva::Bool = false, | ||
slotnames::Union{Nothing,Vector{Symbol}}=nothing, | ||
kwargs...) | ||
# NOTE: we need ir.argtypes[1] == typeof(env) | ||
ir = Core.Compiler.copy(ir) | ||
# if the user didn't specify a definition MethodInstance or filename Symbol to use for the debuginfo, set a filename now | ||
ir.debuginfo.def === nothing && (ir.debuginfo.def = :var"generated IR for OpaqueClosure") | ||
nargtypes = length(ir.argtypes) | ||
nargs = nargtypes-1 | ||
sig = compute_oc_signature(ir, nargs, isva) | ||
rt = compute_ir_rettype(ir) | ||
src = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ()) | ||
if slotnames === nothing | ||
src.slotnames = fill(:none, nargtypes) | ||
else | ||
length(slotnames) == nargtypes || error("mismatched `argtypes` and `slotnames`") | ||
src.slotnames = slotnames | ||
end | ||
src.slotflags = fill(zero(UInt8), nargtypes) | ||
src.slottypes = copy(ir.argtypes) | ||
src.isva = isva | ||
src.nargs = UInt(nargtypes) | ||
src = ir_to_codeinf!(src, ir) | ||
src.rettype = rt | ||
return Base.Experimental.generate_opaque_closure(sig, Union{}, rt, src, nargs, isva, env...; kwargs...) | ||
end |
This file contains 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
7fa26f0
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.
Executing the daily package evaluation, I will reply here when finished:
@nanosoldier
runtests(isdaily = true)
7fa26f0
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 package evaluation job you requested has completed - possible new issues were detected.
The full report is available.