Skip to content

Commit adc2d7f

Browse files
committed
Adjust to the latest Julia master (v1.14)
1 parent 7451eb9 commit adc2d7f

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

src/CthulhuCompiler.jl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
Base.Experimental.@compiler_options compile=min optimize=1
22

3-
import .Cthulhu: AbstractProvider, get_abstract_interpreter, get_inference_world, find_method_instance, generate_code_instance, get_override, lookup, find_caller_of, get_inlining_costs, show_parameters, get_ci, get_rt, get_pc_remarks, get_pc_effects, get_pc_excts, show_callsite, show_callinfo, print_callsite_info, cthulhu_source, cthulhu_typed, cthulhu_ast, cthulhu_llvm, cthulhu_native, find_callsites, ir_to_src
4-
using .Cthulhu: CthulhuState, CthulhuConfig, CallInfo, Callsite, cached_exception_type, get_mi
3+
import .Cthulhu:
4+
AbstractProvider, cthulhu_ast, cthulhu_llvm, cthulhu_native, cthulhu_source,
5+
cthulhu_typed, find_caller_of, find_callsites, find_method_instance,
6+
generate_code_instance, get_abstract_interpreter, get_ci, get_inference_world,
7+
get_inlining_costs, get_override, get_pc_effects, get_pc_excts, get_pc_remarks, get_rt,
8+
ir_to_src, lookup, print_callsite_info, show_callinfo, show_callsite, show_parameters
9+
using .Cthulhu:
10+
CthulhuState, CthulhuConfig, CallInfo, Callsite,
11+
cached_exception_type, get_mi
512

6-
using Base: isvarargtype, unwrapva, unwrap_unionall, mapany, get_world_counter
13+
using Base: get_world_counter, isvarargtype, mapany, unwrap_unionall, unwrapva
714
using JuliaSyntax: JuliaSyntax, children, is_leaf
815

9-
using .CC: AbstractInterpreter, CallMeta, ApplyCallInfo, CallInfo as CCCallInfo, ConstCallInfo,
10-
EFFECTS_TOTAL, Effects, IncrementalCompact, InferenceParams, InferenceResult,
11-
InferenceState, IRCode, LimitedAccuracy, MethodMatchInfo, MethodResultPure,
12-
NativeInterpreter, NoCallInfo, OptimizationParams, OptimizationState,
13-
UnionSplitApplyCallInfo, UnionSplitInfo, WorldRange, WorldView,
14-
argextype, argtypes_to_type, compileable_specialization, ignorelimited, singleton_type,
15-
specialize_method, sptypes_from_meth_instance, widenconst, method_table, findsup,
16-
cached_return_type
16+
using .CC: AbstractInterpreter, ApplyCallInfo, CallInfo as CCCallInfo, CallMeta,
17+
EFFECTS_TOTAL, Effects, IncrementalCompact, InferenceParams,
18+
InferenceResult, InferenceState, IRCode, LimitedAccuracy, MethodMatchInfo,
19+
MethodResultPure, NativeInterpreter, NoCallInfo, OptimizationParams, OptimizationState,
20+
UnionSplitApplyCallInfo, UnionSplitInfo,
21+
argextype, argtypes_to_type, cached_return_type, compileable_specialization, findsup,
22+
ignorelimited, method_table, singleton_type, specialize_method, sptypes_from_meth_instance,
23+
widenconst
1724

1825
const ArgTypes = Vector{Any}
1926

@@ -29,6 +36,8 @@ get_effects(codeinst::CodeInstance) = CC.decode_effects(codeinst.ipo_purity_bits
2936
get_effects(codeinst::CodeInfo) = CC.decode_effects(codeinst.purity)
3037
get_effects(result::InferenceResult) = result.ipo_effects
3138
get_effects(source::InferredSource) = source.effects
39+
@static if VERSION < v"1.14.0-DEV.60"
3240
get_effects(result::CC.ConstPropResult) = get_effects(result.result)
41+
end
3342
get_effects(result::CC.ConcreteResult) = result.effects
3443
get_effects(result::CC.SemiConcreteResult) = result.effects

src/compiler/reflection.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,37 @@ function find_callsites(provider::AbstractProvider, result::LookupResult, ci::Co
122122
return callsites, sourcenodes
123123
end
124124

125-
function process_const_info(provider::AbstractProvider, ::LookupResult, @nospecialize(thisinfo),
125+
@static if VERSION v"1.14.0-DEV.60"
126+
function process_result(
127+
::AbstractProvider, ::LookupResult, argtypes::ArgTypes,
128+
@nospecialize(rt), @nospecialize(result), @nospecialize(exct)
129+
)
130+
if isnothing(result)
131+
return nothing
132+
elseif isa(result, CC.ConcreteResult)
133+
edge = result.edge
134+
effects = get_effects(result)
135+
mici = EdgeCallInfo(edge, rt, effects, exct)
136+
return ConcreteCallInfo(mici, argtypes)
137+
elseif isa(result, CC.SemiConcreteResult)
138+
effects = get_effects(result)
139+
mici = EdgeCallInfo(result.edge, rt, effects, exct)
140+
return SemiConcreteCallInfo(mici, result.ir)
141+
else
142+
@assert isa(result, CC.InferenceResult)
143+
overridden_by_const = result.overridden_by_const
144+
if overridden_by_const !== nothing && any(overridden_by_const)
145+
effects = get_effects(result)
146+
mici = EdgeCallInfo(result.ci_as_edge, rt, effects, exct)
147+
return ConstPropCallInfo(mici, result)
148+
else
149+
effects = get_effects(result)
150+
return EdgeCallInfo(result.ci_as_edge, rt, effects, exct)
151+
end
152+
end
153+
end
154+
else
155+
function process_const_info(::AbstractProvider, ::LookupResult, @nospecialize(thisinfo),
126156
argtypes::ArgTypes, @nospecialize(rt), @nospecialize(result),
127157
@nospecialize(exct))
128158
if isnothing(result)
@@ -152,6 +182,7 @@ function process_const_info(provider::AbstractProvider, ::LookupResult, @nospeci
152182
return ConstPropCallInfo(mici, result)
153183
end
154184
end
185+
end
155186

156187
function process_info(provider::AbstractProvider, result::LookupResult, @nospecialize(info::CCCallInfo),
157188
argtypes::ArgTypes, @nospecialize(rt),
@@ -176,10 +207,16 @@ function process_info(provider::AbstractProvider, result::LookupResult, @nospeci
176207
if edge === nothing
177208
RTCallInfo(unwrapconst(argtypes[1]), argtypes[2:end], rt, exct)
178209
else
210+
@static if VERSION v"1.14.0-DEV.60"
211+
@something(
212+
process_result(provider, result, argtypes, rt, info.call_results[i], exct),
213+
RTCallInfo(unwrapconst(argtypes[1]), argtypes[2:end], rt, exct))
214+
else
179215
effects = @something(effects, get_effects(edge))
180216
EdgeCallInfo(edge, rt, effects, exct)
217+
end
181218
end
182-
end for edge in info.edges if edge !== nothing]
219+
end for (i, edge) in enumerate(info.edges) if edge !== nothing]
183220
elseif isa(info, UnionSplitInfo)
184221
return mapreduce(process_recursive, vcat, info.split; init=CallInfo[])::Vector{CallInfo}
185222
elseif isa(info, UnionSplitApplyCallInfo)
@@ -188,7 +225,7 @@ function process_info(provider::AbstractProvider, result::LookupResult, @nospeci
188225
# XXX: This could probably use its own info. For now,
189226
# we ignore any implicit iterate calls.
190227
return process_recursive(info.call)
191-
elseif isa(info, ConstCallInfo)
228+
elseif (@static VERSION < v"1.14.0-DEV.60" ? true : false) && isa(info, CC.ConstCallInfo)
192229
infos = process_recursive(info.call)
193230
@assert length(infos) == length(info.results)
194231
return CallInfo[let

test/test_AbstractInterpreter.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ from the native code cache, satisfying the minimum interface requirements.
1414
1515
When the `ephemeral_cache=true` option is specified, `NewInterpreter` will hold
1616
`CodeInstance` in an ephemeral non-integrated cache, rather than in the integrated
17-
`Core.Compiler.InternalCodeCache`.
17+
`Core.CC.InternalCodeCache`.
1818
Keep in mind that ephemeral cache lacks support for invalidation and doesn't persist across
19-
sessions. However it is an usual Julia object of the type `code_cache::IdDict{MethodInstance,CodeInstance}`,
20-
making it easier for debugging and inspecting the compiler behavior.
19+
sessions. However it is an usual Julia object of the type
20+
`global_cache::IdDict{MethodInstance,CodeInstance}`,
21+
making it easier for debugging and inspecting the CC behavior.
2122
"""
2223
macro newinterp(InterpName, ephemeral_cache::Bool=false)
2324
cache_token = QuoteNode(gensym(string(InterpName, "CacheToken")))
@@ -38,17 +39,17 @@ macro newinterp(InterpName, ephemeral_cache::Bool=false)
3839
inf_params::$CC.InferenceParams
3940
opt_params::$CC.OptimizationParams
4041
inf_cache::Vector{$CC.InferenceResult}
41-
$(ephemeral_cache && :(code_cache::$InterpCacheName))
42+
$(ephemeral_cache && :(global_cache::$InterpCacheName))
4243
function $InterpName(meta = nothing;
4344
world::UInt = Base.get_world_counter(),
4445
inf_params::$CC.InferenceParams = $CC.InferenceParams(),
4546
opt_params::$CC.OptimizationParams = $CC.OptimizationParams(),
4647
inf_cache::Vector{$CC.InferenceResult} = $CC.InferenceResult[],
4748
$(ephemeral_cache ?
48-
Expr(:kw, :(code_cache::$InterpCacheName), :($InterpCacheName())) :
49+
Expr(:kw, :(global_cache::$InterpCacheName), :($InterpCacheName())) :
4950
Expr(:kw, :_, :nothing)))
5051
return $(ephemeral_cache ?
51-
:(new(meta, world, inf_params, opt_params, inf_cache, code_cache)) :
52+
:(new(meta, world, inf_params, opt_params, inf_cache, global_cache)) :
5253
:(new(meta, world, inf_params, opt_params, inf_cache)))
5354
end
5455
end
@@ -57,8 +58,14 @@ macro newinterp(InterpName, ephemeral_cache::Bool=false)
5758
$CC.get_inference_world(interp::$InterpName) = interp.world
5859
$CC.get_inference_cache(interp::$InterpName) = interp.inf_cache
5960
$CC.cache_owner(::$InterpName) = $cache_token
60-
$(ephemeral_cache && quote
61-
$CC.code_cache(interp::$InterpName) = $CC.WorldView(interp.code_cache, $CC.WorldRange(interp.world))
61+
$(ephemeral_cache && @static VERSION "1.14.0-DEV.60" ? quote
62+
$CC.code_cache(interp::$InterpName) = $CC.OverlayCodeCache(interp.global_cache, interp.inf_cache)
63+
$CC.get(cache::$InterpCacheName, mi::$C.MethodInstance, default) = get(cache.dict, mi, default)
64+
$CC.getindex(cache::$InterpCacheName, mi::$C.MethodInstance) = getindex(cache.dict, mi)
65+
$CC.haskey(cache::$InterpCacheName, mi::$C.MethodInstance) = haskey(cache.dict, mi)
66+
$CC.setindex!(cache::$InterpCacheName, ci::$C.CodeInstance, mi::$C.MethodInstance) = setindex!(cache.dict, ci, mi)
67+
end : quote
68+
$CC.code_cache(interp::$InterpName) = $CC.WorldView(interp.global_cache, $CC.WorldRange(interp.world))
6269
$CC.get(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance, default) = get(wvc.cache.dict, mi, default)
6370
$CC.getindex(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance) = getindex(wvc.cache.dict, mi)
6471
$CC.haskey(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance) = haskey(wvc.cache.dict, mi)

test/test_Cthulhu.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ Base.@assume_effects :terminates_locally function issue41694(x)
259259
end
260260
return res
261261
end
262-
@testset "ConstResult" begin
263-
# constant prop' on all the splits
262+
@testset "Concrete eval result" begin
264263
callsites = find_callsites_by_ftt(() -> issue41694(12); optimize = false)
265264
callinfo = only(callsites).info
266265
@test isa(callinfo, Cthulhu.ConcreteCallInfo)

0 commit comments

Comments
 (0)