Skip to content

Commit

Permalink
prepare for updating to 1.12, require 1.11 as the minimum compat (#691)
Browse files Browse the repository at this point in the history
* bump to v0.10, compat with Julia 1.11 and higher, remove outdated compat

* use `analysis_results` for caching analysis results
  Which allows us to simplify overloads related to the management of
  analysis result cache.

* fix typo
  • Loading branch information
aviatesk authored Feb 20, 2025
1 parent 265d512 commit b9acd65
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 380 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- version: '1' # current stable
os: ubuntu-latest
arch: x64
- version: '1.10.0' # lowerest version supported
- version: '1.11' # lowest version supported
os: ubuntu-latest
arch: x64
- version: '1.12-nightly' # next release
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JET"
uuid = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
authors = ["Shuhei Kadowaki <aviatesk@gmail.com>"]
version = "0.9.18"
version = "0.10.0"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down Expand Up @@ -44,7 +44,7 @@ Revise = "3.3"
StaticArrays = "1.7.0"
TOML = "1.0.3"
Test = "1.10"
julia = "1.10"
julia = "1.11"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand Down
1 change: 0 additions & 1 deletion docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ passing `AbstractAnalyzer` to the subsequent (maybe overloaded) callees.
JET.AnalysisResult
JET.CachedAnalysisResult
JET.AnalysisCache
Core.Compiler.inlining_policy
```

## [Top-level Analysis](@id toplevel)
Expand Down
62 changes: 16 additions & 46 deletions src/JETBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,9 @@ __init__() = foreach(@nospecialize(f)->f(), INIT_HOOKS)
# compat
# ------

@static if VERSION v"1.11.0-DEV.439"
using Base: generating_output
else
function generating_output(incremental::Union{Bool,Nothing}=nothing)
ccall(:jl_generating_output, Cint, ()) == 0 && return false
if incremental !== nothing
Base.JLOptions().incremental == incremental || return false
end
return true
end
end
using Base: generating_output

@static if VERSION v"1.11.0-DEV.1498"
import .CC: get_inference_world
else
import .CC: get_world_counter as get_inference_world
end
import .CC: get_inference_world

# macros
# ------
Expand Down Expand Up @@ -682,17 +668,10 @@ function analyze_method_instance!(analyzer::AbstractAnalyzer, mi::MethodInstance
return analyze_frame!(analyzer, frame)
end

@static if VERSION v"1.11.0-DEV.843"
function InferenceState(result::InferenceResult, cache_mode::UInt8, analyzer::AbstractAnalyzer)
init_result!(analyzer, result)
return @invoke InferenceState(result::InferenceResult, cache_mode::UInt8, analyzer::AbstractInterpreter)
end
else
function InferenceState(result::InferenceResult, cache_mode::Symbol, analyzer::AbstractAnalyzer)
init_result!(analyzer, result)
return @invoke InferenceState(result::InferenceResult, cache_mode::Symbol, analyzer::AbstractInterpreter)
end
end

function analyze_frame!(analyzer::AbstractAnalyzer, frame::InferenceState)
set_entry!(analyzer, frame.linfo)
Expand Down Expand Up @@ -1201,7 +1180,7 @@ include("analyzers/jetanalyzer.jl")
include("analyzers/optanalyzer.jl")

using PrecompileTools
@static v"1.11.0-DEV.1552" > VERSION && @setup_workload let
false && @setup_workload let
@compile_workload let
result = @report_call sum("julia")
show(IOContext(devnull, :color=>true), result)
Expand All @@ -1212,30 +1191,21 @@ using PrecompileTools
result = @report_opt rand(String)
show(IOContext(devnull, :color=>true), result)
end
@static VERSION v"1.11.0-DEV.1255" && let
# register an initialization callback that fixes up `max_world` which is overridden
# to `one(UInt) == WORLD_AGE_REVALIDATION_SENTINEL` by staticdata.c
# otherwise using cached analysis results would result in world age assertion error
function override_precompiled_cache()
for precache in (JET_ANALYZER_CACHE, OPT_ANALYZER_CACHE),
(_, cache) in precache
for (_, codeinst) in cache.cache
@static if VERSION v"1.11.0-DEV.1390"
if ((@atomic :monotonic codeinst.min_world) > zero(UInt) &&
(@atomic :monotonic codeinst.max_world) == one(UInt)) # == WORLD_AGE_REVALIDATION_SENTINEL
@atomic :monotonic codeinst.max_world = typemax(UInt)
end
else
if (codeinst.min_world > zero(UInt) &&
codeinst.max_world == one(UInt)) # == WORLD_AGE_REVALIDATION_SENTINEL
codeinst.max_world = typemax(UInt)
end
end
# register an initialization callback that fixes up `max_world` which is overridden
# to `one(UInt) == WORLD_AGE_REVALIDATION_SENTINEL` by staticdata.c
# otherwise using cached analysis results would result in world age assertion error
function override_precompiled_cache()
for precache in (JET_ANALYZER_CACHE, OPT_ANALYZER_CACHE),
(_, cache) in precache
for (_, codeinst) in cache.cache
if ((@atomic :monotonic codeinst.min_world) > zero(UInt) &&
(@atomic :monotonic codeinst.max_world) == one(UInt)) # == WORLD_AGE_REVALIDATION_SENTINEL
@atomic :monotonic codeinst.max_world = typemax(UInt)
end
Base.rehash!(cache.cache) # HACK to avoid JuliaLang/julia#52915
end
Base.rehash!(cache.cache) # HACK to avoid JuliaLang/julia#52915
end
override_precompiled_cache() # to precompile this callback itself
push_inithook!(override_precompiled_cache)
end
override_precompiled_cache() # to precompile this callback itself
push_inithook!(override_precompiled_cache)
end
52 changes: 4 additions & 48 deletions src/abstractinterpret/abstractanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ a global cache maintained by `AbstractAnalyzer`. That means,
is expected to have its field `codeinf.inferred::CachedAnalysisResult`.
"""
struct CachedAnalysisResult
src
reports::Vector{InferenceErrorReport}
CachedAnalysisResult(@nospecialize(src), reports::Vector{InferenceErrorReport}) = new(src, reports)
end

const AnyAnalysisResult = Union{AnalysisResult,CachedAnalysisResult}

"""
mutable struct AnalyzerState
...
Expand Down Expand Up @@ -119,7 +115,7 @@ mutable struct AnalyzerState

## AbstractAnalyzer ##

results::IdDict{InferenceResult,AnyAnalysisResult}
results::IdDict{InferenceResult,AnalysisResult}

# the temporal stash to keep reports that are collected within the currently-analyzed frame:
# they will be appended to the caller when returning back to the caller inference/optimization
Expand Down Expand Up @@ -158,7 +154,7 @@ for fld in fieldnames(AnalyzerState)
end

function AnalyzerState(world::UInt = get_world_counter();
results::IdDict{InferenceResult,AnyAnalysisResult} = IdDict{InferenceResult,AnyAnalysisResult}(),
results::IdDict{InferenceResult,AnalysisResult} = IdDict{InferenceResult,AnalysisResult}(),
inf_params::Union{Nothing,InferenceParams} = nothing,
opt_params::Union{Nothing,OptimizationParams} = nothing,
concretized::BitVector = _CONCRETIZED,
Expand All @@ -174,7 +170,7 @@ function AnalyzerState(world::UInt = get_world_counter();
#=inf_cache::Vector{InferenceResult}=# inf_cache,
#=inf_params::InferenceParams=# inf_params,
#=opt_params::OptimizationParams=# opt_params,
#=results::IdDict{InferenceResult,AnyAnalysisResult}=# results,
#=results::IdDict{InferenceResult,AnalysisResult}=# results,
#=report_stash::Vector{InferenceErrorReport}=# report_stash,
#=cache_target::Union{Nothing,Pair{Symbol,InferenceState}}=# nothing,
#=concretized::BitVector=# concretized,
Expand Down Expand Up @@ -504,21 +500,14 @@ end
# define how AbstractAnalyzer manages `InferenceResult`

Base.getindex(analyzer::AbstractAnalyzer, result::InferenceResult) = get_results(analyzer)[result]
Base.setindex!(analyzer::AbstractAnalyzer, analysis_result::AnyAnalysisResult, result::InferenceResult) =
get_results(analyzer)[result] = analysis_result
Base.setindex!(analyzer::AbstractAnalyzer, analysis_result::AnalysisResult, result::InferenceResult) = get_results(analyzer)[result] = analysis_result

function init_result!(analyzer::AbstractAnalyzer, result::InferenceResult)
analyzer[result] = AnalysisResult(InferenceErrorReport[])
return nothing
end
function set_cached_result!(analyzer::AbstractAnalyzer, result::InferenceResult, cache::Vector{InferenceErrorReport})
analyzer[result] = CachedAnalysisResult(result.src, cache)
return nothing
end

get_reports(analyzer::AbstractAnalyzer, result::InferenceResult) = (analyzer[result]::AnalysisResult).reports
get_cached_reports(analyzer::AbstractAnalyzer, result::InferenceResult) = (analyzer[result]::CachedAnalysisResult).reports
get_any_reports(analyzer::AbstractAnalyzer, result::InferenceResult) = (analyzer[result]::AnyAnalysisResult).reports

"""
add_new_report!(analyzer::AbstractAnalyzer, result::InferenceResult, report::InferenceErrorReport)
Expand Down Expand Up @@ -552,36 +541,3 @@ CC.may_compress(::AbstractAnalyzer) = generating_output()

# this overload is necessary to avoid caching with the const ABI
CC.may_discard_trees(::AbstractAnalyzer) = false

let # overload `inlining_policy`
@static if VERSION v"1.11.0-DEV.879"
sigs_ex = :(analyzer::AbstractAnalyzer, @nospecialize(src), @nospecialize(info::CC.CallInfo), stmt_flag::UInt32)
args_ex = :(analyzer::AbstractInterpreter, src::Any, info::CC.CallInfo, stmt_flag::UInt32)
elseif VERSION v"1.11.0-DEV.377"
sigs_ex = :(analyzer::AbstractAnalyzer,
@nospecialize(src), @nospecialize(info::CC.CallInfo), stmt_flag::UInt32, mi::MethodInstance, argtypes::Argtypes)
args_ex = :(analyzer::AbstractInterpreter,
src::Any, info::CC.CallInfo, stmt_flag::UInt32, mi::MethodInstance, argtypes::Argtypes)
else
sigs_ex = :(analyzer::AbstractAnalyzer,
@nospecialize(src), @nospecialize(info::CC.CallInfo), stmt_flag::UInt8, mi::MethodInstance, argtypes::Argtypes)
args_ex = :(analyzer::AbstractInterpreter,
src::Any, info::CC.CallInfo, stmt_flag::UInt8, mi::MethodInstance, argtypes::Argtypes)
end
@eval begin
@doc """
inlining_policy(analyzer::AbstractAnalyzer, @nospecialize(src), ...) -> source::Any
Implements inlining policy for `AbstractAnalyzer`.
Since `AbstractAnalyzer` works on `InferenceResult` whose `src` field keeps
[`AnalysisResult`](@ref) or [`CachedAnalysisResult`](@ref), this implementation needs to forward
their wrapped source to `inlining_policy(::AbstractInterpreter, ::Any, ::UInt8)`.
"""
function CC.inlining_policy($(sigs_ex.args...))
if isa(src, CachedAnalysisResult)
src = src.src
end
return @invoke CC.inlining_policy($(args_ex.args...))
end
end
end
Loading

0 comments on commit b9acd65

Please sign in to comment.