Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,9 @@ function deserialize(s::AbstractSerializer, ::Type{CodeInfo})
ci.code = code
ci.debuginfo = NullDebugInfo
# allow older-style IR with return and gotoifnot Exprs
if current_module[] !== nothing
map!(x->symbol_to_globalref(x, current_module[]), code)
end
for i in 1:length(code)
stmt = code[i]
if isa(stmt, Expr)
Expand All @@ -1221,12 +1224,19 @@ function deserialize(s::AbstractSerializer, ::Type{CodeInfo})
code[i] = ReturnNode(isempty(ex.args) ? nothing : ex.args[1])
elseif ex.head === :gotoifnot
code[i] = GotoIfNot(ex.args[1], ex.args[2])
elseif ex.head === :(=) && ex.args[1] isa GlobalRef
# An explicit declaration is required before calling setglobal!, so doing this eval
# might make some code more likely to work. Clearly we do not want to do this kind of
# side effect during deserialization, but you can try it if you're desperate.
#Core.eval(ex.args[1].mod, Expr(:global, ex.args[1]))
code[i] = Expr(:call, GlobalRef(Core, :setglobal!), ex.args[1].mod, QuoteNode(ex.args[1].name), ex.args[2])
elseif ex.head === :call && ex.args[1] == GlobalRef(Core, :_typebody!) && s.version < 30
insert!(ex.args, 2, false)
elseif ex.head === :isdefined && ex.args[1] isa GlobalRef
code[i] = Expr(:call, GlobalRef(Core, :isdefinedglobal), ex.args[1].mod, QuoteNode(ex.args[1].name))
end
end
end
if current_module[] !== nothing
map!(x->symbol_to_globalref(x, current_module[]), code)
end
_x = deserialize(s)
have_debuginfo = _x isa Core.DebugInfo
if have_debuginfo
Expand Down