From acd29c1394182f48fb3d11a80ae75027f6d9e21c Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Thu, 28 Sep 2023 19:09:02 +0900 Subject: [PATCH] virtualprocess: get rid of unncessary `CodeInfo` allocation --- src/toplevel/virtualprocess.jl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/toplevel/virtualprocess.jl b/src/toplevel/virtualprocess.jl index 864e34c55..4d2d550aa 100644 --- a/src/toplevel/virtualprocess.jl +++ b/src/toplevel/virtualprocess.jl @@ -1464,8 +1464,8 @@ function analyze_toplevel!(analyzer::AbstractAnalyzer, src::CodeInfo) mi.specTypes = Tuple{} mi.def = mod = get_toplevelmod(analyzer) - src = transform_abstract_global_symbols!(analyzer, src) - src = resolve_toplevel_symbols!(mod, src) + transform_abstract_global_symbols!(src, analyzer) + resolve_toplevel_symbols!(src, mod) @static if VERSION ≥ v"1.10.0-DEV.112" @atomic mi.uninferred = src else @@ -1489,7 +1489,7 @@ end # NOTE that `transform_abstract_global_symbols!` will produce really invalid code for # actual interpretation or execution, but all the statements won't be interpreted anymore # by `ConcreteInterpreter` nor executed by the native compilation pipeline anyway -function transform_abstract_global_symbols!(analyzer::AbstractAnalyzer, src::CodeInfo) +function transform_abstract_global_symbols!(src::CodeInfo, analyzer::AbstractAnalyzer) nslots = length(src.slotnames) abstract_global_variables = Dict{Symbol,Int}() concretized = get_concretized(analyzer) @@ -1528,15 +1528,14 @@ function transform_abstract_global_symbols!(analyzer::AbstractAnalyzer, src::Cod return src end -# resolve toplevel symbols (and other expressions like `:foreigncall`) -# so that the returned `CodeInfo` is eligible for abstractintepret and optimization -# TODO `jl_resolve_globals_in_ir` may throw, and we want to redirect it to `ToplevelErrorReport` -function resolve_toplevel_symbols!(mod::Module, src::CodeInfo) - newsrc = copy(src) +# resolve toplevel symbols (and other expressions like `:foreigncall`) within `src` +# so that it is eligible for abstractintepret and optimization +# TODO `jl_resolve_globals_in_ir` may throw, and we should redirect the error to `ToplevelErrorReport` +function resolve_toplevel_symbols!(src::CodeInfo, mod::Module) @ccall jl_resolve_globals_in_ir( - #=jl_array_t *stmts=# newsrc.code::Any, + #=jl_array_t *stmts=# src.code::Any, #=jl_module_t *m=# mod::Any, #=jl_svec_t *sparam_vals=# svec()::Any, #=int binding_effects=# 0::Int)::Cvoid - return newsrc + return src end