Skip to content
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

Refactor CodeInfo/CodeInstance separation and interfaces #53219

Merged
merged 15 commits into from
Feb 19, 2024
Merged
14 changes: 11 additions & 3 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ mutable struct InferenceState
dont_work_on_me = false
parent = nothing

valid_worlds = WorldRange(src.min_world, src.max_world == typemax(UInt) ? get_world_counter() : src.max_world)
valid_worlds = WorldRange(1, get_world_counter())
bestguess = Bottom
exc_bestguess = Bottom
ipo_effects = EFFECTS_TOTAL
Expand All @@ -338,13 +338,21 @@ mutable struct InferenceState
InferenceParams(interp).unoptimize_throw_blocks && mark_throw_blocks!(src, handler_at)
!iszero(cache_mode & CACHE_MODE_LOCAL) && push!(get_inference_cache(interp), result)

return new(
this = new(
linfo, world, mod, sptypes, slottypes, src, cfg, method_info,
currbb, currpc, ip, handlers, handler_at, ssavalue_uses, bb_vartables, ssavaluetypes, stmt_edges, stmt_info,
pclimitations, limitations, cycle_backedges, callers_in_cycle, dont_work_on_me, parent,
result, unreachable, valid_worlds, bestguess, exc_bestguess, ipo_effects,
restrict_abstract_call_sites, cache_mode, insert_coverage,
interp)

# Apply generated function restrictions
if src.min_world != 1 || src.max_world != typemax(UInt)
# From generated functions
this.valid_worlds = WorldRange(src.min_world, src.max_world)
end
Keno marked this conversation as resolved.
Show resolved Hide resolved

return this
end
end

Expand Down Expand Up @@ -799,7 +807,7 @@ function IRInterpretationState(interp::AbstractInterpreter,
method_info = MethodInfo(src)
ir = inflate_ir(src, mi)
return IRInterpretationState(interp, method_info, ir, mi, argtypes, world,
src.min_world, src.max_world)
code.min_world, code.max_world)
end

# AbsIntState
Expand Down
9 changes: 2 additions & 7 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,17 @@ is_declared_noinline(@nospecialize src::MaybeCompressed) =
# OptimizationState #
#####################

is_source_inferred(@nospecialize src::MaybeCompressed) =
ccall(:jl_ir_flag_inferred, Bool, (Any,), src)

function inlining_policy(interp::AbstractInterpreter,
@nospecialize(src), @nospecialize(info::CallInfo), stmt_flag::UInt32)
if isa(src, MaybeCompressed)
is_source_inferred(src) || return nothing
src_inlineable = is_stmt_inline(stmt_flag) || is_inlineable(src)
return src_inlineable ? src : nothing
elseif isa(src, IRCode)
return src
elseif isa(src, SemiConcreteResult)
return src
elseif isa(src, CodeInstance)
return inlining_policy(interp, src.inferred, info, stmt_flag)
end
return nothing
end
Expand Down Expand Up @@ -222,7 +220,6 @@ end
function ir_to_codeinf!(src::CodeInfo, ir::IRCode)
replace_code_newstyle!(src, ir)
widen_all_consts!(src)
src.inferred = true
return src
end

Expand All @@ -240,8 +237,6 @@ function widen_all_consts!(src::CodeInfo)
end
end

src.rettype = widenconst(src.rettype)

return src
end

Expand Down
2 changes: 0 additions & 2 deletions base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ Mainly used for testing or interactive use.
inflate_ir(ci::CodeInfo, linfo::MethodInstance) = inflate_ir!(copy(ci), linfo)
inflate_ir(ci::CodeInfo, sptypes::Vector{VarState}, argtypes::Vector{Any}) = inflate_ir!(copy(ci), sptypes, argtypes)
function inflate_ir(ci::CodeInfo)
parent = ci.parent
isa(parent, MethodInstance) && return inflate_ir(ci, parent)
# XXX the length of `ci.slotflags` may be different from the actual number of call
# arguments, but we really don't know that information in this case
argtypes = Any[ Any for i = 1:length(ci.slotflags) ]
Expand Down
Loading