From e9da468755852b81750c3a5e10030e97444aed50 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Thu, 14 Nov 2024 17:57:01 +0900 Subject: [PATCH] use `Compiler` stdlib if available This requires JuliaLang/julia#56553 to be merged, and the new Compiler.jl stdlib to be registered in General beforehand. --- .github/workflows/CI.yml | 2 +- Project.toml | 6 ++- src/Cthulhu.jl | 20 +++++++-- src/codeview.jl | 24 +++++------ src/interpreter.jl | 4 -- src/reflection.jl | 14 +++---- test/irutils.jl | 12 +++--- test/setup.jl | 6 ++- test/test_AbstractInterpreter.jl | 60 +++++++++++++++++++-------- test/test_Cthulhu.jl | 69 +++++++++++++++++--------------- test/test_codeview.jl | 2 +- 11 files changed, 129 insertions(+), 90 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a262cf31..e8e0c086 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -16,7 +16,7 @@ jobs: - version: '1' # current stable os: ubuntu-latest arch: x64 - - version: '1.10.0' # lowerest version supported + - version: '1.10' # lowest version supported os: ubuntu-latest arch: x64 - version: '1.12-nightly' # next release diff --git a/Project.toml b/Project.toml index 30f42ab3..d29e35ac 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,11 @@ name = "Cthulhu" uuid = "f68482b8-f384-11e8-15f7-abe071a5a75f" +version = "2.16.0" authors = ["Valentin Churavy and contributors"] -version = "2.15.3" [deps] CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" +Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1" FoldingTrees = "1eca21be-9b9b-4ed8-839a-6d8ae26b1781" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4" @@ -18,6 +19,7 @@ WidthLimitedIO = "b8c1c048-cf81-46c6-9da0-18c1d99e41f2" [compat] CodeTracking = "0.5, 1" +Compiler = "0.0.2" FoldingTrees = "1" InteractiveUtils = "1.9" JuliaSyntax = "0.4" @@ -28,7 +30,7 @@ TypedSyntax = "1.3.0" UUIDs = "1.9" Unicode = "1.9" WidthLimitedIO = "1" -julia = "1.10.0" +julia = "1.10" [extras] DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6" diff --git a/src/Cthulhu.jl b/src/Cthulhu.jl index 9c388be6..6b0f3246 100644 --- a/src/Cthulhu.jl +++ b/src/Cthulhu.jl @@ -12,9 +12,21 @@ using TypedSyntax using WidthLimitedIO using Core: MethodInstance, MethodMatch -const CC = Core.Compiler -using .CC: Effects, EFFECTS_TOTAL, LimitedAccuracy, - compileable_specialization, ignorelimited, specialize_method +@static if VERSION ≥ v"1.12.0-DEV.1581" + using Compiler: Compiler as CC + using Compiler.IRShow: IRShow +else + const CC = Core.Compiler + const IRShow = Base.IRShow +end +using Core.IR +using .CC: AbstractInterpreter, ApplyCallInfo, CallInfo as CCCallInfo, ConstCallInfo, + EFFECTS_TOTAL, Effects, IncrementalCompact, InferenceParams, InferenceResult, + InferenceState, IRCode, LimitedAccuracy, MethodMatchInfo, MethodResultPure, + NativeInterpreter, NoCallInfo, OptimizationParams, OptimizationState, + UnionSplitApplyCallInfo, UnionSplitInfo, WorldRange, WorldView, + argextype, argtypes_to_type, compileable_specialization, ignorelimited, singleton_type, + specialize_method, sptypes_from_meth_instance, widenconst using Base: @constprop, default_tt, isvarargtype, unwrapva, unwrap_unionall, rewrap_unionall const mapany = Base.mapany @@ -803,7 +815,7 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs @static if VERSION < v"1.12.0-DEV.669" view_cmd(iostream, mi, optimize, debuginfo, world, CONFIG) else - src = Core.Compiler.typeinf_code(interp, mi, true) + src = CC.typeinf_code(interp, mi, true) view_cmd(iostream, mi, src, optimize, debuginfo, world, CONFIG) end display_CI = false diff --git a/src/codeview.jl b/src/codeview.jl index c6cee5d6..3ab19d95 100644 --- a/src/codeview.jl +++ b/src/codeview.jl @@ -100,17 +100,15 @@ function cthulhu_ast(io::IO, mi, ::Bool, debuginfo, ::UInt, config::CthulhuConfi end end -using Base.IRShow: IRShow, _stmt, _type, should_print_ssa_type, IRShowConfig, show_ir - const __debuginfo = merge(IRShow.__debuginfo, Dict( - :compact => src -> src isa CodeInfo ? __debuginfo[:source](src) - : IRShow.inline_linfo_printer(src) -)) + :compact => function (src) + src isa CodeInfo ? IRShow.__debuginfo[:source](src) : IRShow.inline_linfo_printer(src) + end)) function is_type_unstable(code::Union{IRCode, CodeInfo}, idx::Int, used::BitSet) - stmt = _stmt(code, idx) - type = _type(code, idx) - should_print_ssa_type(stmt) || return false + stmt = IRShow._stmt(code, idx) + type = IRShow._type(code, idx) + IRShow.should_print_ssa_type(stmt) || return false # `used` only contains used SSA values and ignores slots in_use = in(idx, used) || Meta.isexpr(stmt, :(=)) return in_use && is_type_unstable(type) @@ -308,7 +306,7 @@ function cthulhu_typed(io::IO, debuginfo::Symbol, should_print_stmt = hide_type_stable ? is_type_unstable : Returns(true) bb_color = (src isa IRCode && debuginfo === :compact) ? :normal : :light_black - irshow_config = IRShowConfig(preprinter, postprinter; should_print_stmt, bb_color) + irshow_config = IRShow.IRShowConfig(preprinter, postprinter; should_print_stmt, bb_color) if !inline_cost && iswarn print(lambda_io, "Body") @@ -319,14 +317,14 @@ function cthulhu_typed(io::IO, debuginfo::Symbol, println(lambda_io) else isa(mi, MethodInstance) || throw("`mi::MethodInstance` is required") - cfg = src isa IRCode ? src.cfg : Core.Compiler.compute_basic_blocks(src.code) + cfg = src isa IRCode ? src.cfg : CC.compute_basic_blocks(src.code) max_bb_idx_size = length(string(length(cfg.blocks))) str = irshow_config.line_info_preprinter(lambda_io, " "^(max_bb_idx_size + 2), -1) callsite = Callsite(0, MICallInfo(mi, rettype, effects, exct), :invoke) println(lambda_io, "∘ ", "─"^(max_bb_idx_size), str, " ", callsite) end - show_ir(lambda_io, src, irshow_config) + IRShow.show_ir(lambda_io, src, irshow_config) return nothing end @@ -547,7 +545,7 @@ else raw = false, config = CONFIG, ) - src = Core.Compiler.typeinf_code(b.interp, b.mi, true) + src = CC.typeinf_code(b.interp, b.mi, true) return cthulhu_llvm( io, b.mi, @@ -570,7 +568,7 @@ else raw = false, config = CONFIG, ) - src = Core.Compiler.typeinf_code(b.interp, b.mi, true) + src = CC.typeinf_code(b.interp, b.mi, true) return cthulhu_native( io, b.mi, diff --git a/src/interpreter.jl b/src/interpreter.jl index 716dfaa3..74ed04d4 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -1,7 +1,3 @@ -using .CC: AbstractInterpreter, CallInfo as CCCallInfo, CodeInfo, CodeInstance, - InferenceParams, InferenceResult, InferenceState, IRCode, NativeInterpreter, - NoCallInfo, OptimizationParams, OptimizationState, SSAValue, WorldRange, WorldView - struct InferredSource src::CodeInfo stmt_info::Vector{CCCallInfo} diff --git a/src/reflection.jl b/src/reflection.jl index 3ac48100..d1613ea7 100644 --- a/src/reflection.jl +++ b/src/reflection.jl @@ -3,11 +3,7 @@ ## using Base.Meta -import .CC: widenconst, argextype, Const, MethodMatchInfo, - UnionSplitApplyCallInfo, UnionSplitInfo, ConstCallInfo, - MethodResultPure, ApplyCallInfo, - sptypes_from_meth_instance, argtypes_to_type -import Base: may_invoke_generator +using Base: may_invoke_generator transform(::Val, callsite) = callsite function transform(::Val{:CuFunction}, callsite, callexpr, CI, mi, slottypes; world=get_world_counter()) @@ -269,8 +265,8 @@ function is_call_expr(x::Expr, optimize::Bool) end function dce!(ir::IRCode) - ir = Core.Compiler.compact!(ir, #=allow_cfg_transform=#true) - ir = Core.Compiler.compact!(ir, #=allow_cfg_transform=#true) + ir = CC.compact!(ir, #=allow_cfg_transform=#true) + ir = CC.compact!(ir, #=allow_cfg_transform=#true) return ir end @@ -355,14 +351,14 @@ end function add_sourceline!(locs::Vector{Tuple{Core.LineInfoNode,Int}}, src::Union{CodeInfo,IRCode}, stmtidx::Int, caller::MethodInstance) @static if VERSION ≥ v"1.12.0-DEV.173" - stack = Base.IRShow.buildLineInfoNode(src.debuginfo, caller, stmtidx) + stack = IRShow.buildLineInfoNode(src.debuginfo, caller, stmtidx) for (i, di) in enumerate(stack) loc = Core.LineInfoNode(Main, di.method, di.file, di.line, zero(Int32)) push!(locs, (loc, i-1)) end else # VERSION < v"1.12.0-DEV.173" if isa(src, IRCode) - stack = Base.IRShow.compute_loc_stack(src.linetable, src.stmts.line[stmtidx]) + stack = IRShow.compute_loc_stack(src.linetable, src.stmts.line[stmtidx]) for (i, idx) in enumerate(stack) line = src.linetable[idx] line.line == 0 && continue diff --git a/test/irutils.jl b/test/irutils.jl index e20fd8da..453b4ccb 100644 --- a/test/irutils.jl +++ b/test/irutils.jl @@ -1,10 +1,10 @@ -using Core: CodeInfo, ReturnNode, MethodInstance -using Core.Compiler: IRCode, IncrementalCompact, singleton_type +using Core.IR +using Cthulhu: Cthulhu using Base.Meta: isexpr using InteractiveUtils: gen_call_with_extracted_types_and_kwargs -argextype(@nospecialize args...) = Core.Compiler.argextype(args...) -argextype(@nospecialize(x), src::CodeInfo) = argextype(x, src, Core.Compiler.VarState[]) +argextype(@nospecialize args...) = Cthulhu.CC.argextype(args...) +argextype(@nospecialize(x), src::CodeInfo) = argextype(x, src, Cthulhu.CC.VarState[]) code_typed1(args...; kwargs...) = first(only(code_typed(args...; kwargs...)))::CodeInfo macro code_typed1(ex0...) return gen_call_with_extracted_types_and_kwargs(__module__, :code_typed1, ex0) @@ -20,9 +20,9 @@ isreturn(@nospecialize x) = isa(x, ReturnNode) # check if `x` is a dynamic call of a given function iscall(y) = @nospecialize(x) -> iscall(y, x) -function iscall((src, f)::Tuple{IR,Base.Callable}, @nospecialize(x)) where IR<:Union{CodeInfo,IRCode,IncrementalCompact} +function iscall((src, f), @nospecialize(x)) return iscall(x) do @nospecialize x - singleton_type(argextype(x, src)) === f + Cthulhu.CC.singleton_type(argextype(x, src)) === f end end function iscall(pred::Base.Callable, @nospecialize(x)) diff --git a/test/setup.jl b/test/setup.jl index a2a80aeb..498ebcd2 100644 --- a/test/setup.jl +++ b/test/setup.jl @@ -3,8 +3,12 @@ if isdefined(parentmodule(@__MODULE__), :VSCodeServer) using ..VSCodeServer end +@static if VERSION ≥ v"1.12.0-DEV.1581" +InteractiveUtils.@activate Compiler # use the Compiler.jl stdlib for the Base reflections too +end + function cthulhu_info(@nospecialize(f), @nospecialize(tt=()); - optimize=true, interp=Core.Compiler.NativeInterpreter()) + optimize=true, interp=Cthulhu.CC.NativeInterpreter()) (interp, mi) = Cthulhu.mkinterp(f, tt; interp) (; src, rt, exct, infos, slottypes, effects) = Cthulhu.lookup(interp, mi, optimize; allow_no_src=true) diff --git a/test/test_AbstractInterpreter.jl b/test/test_AbstractInterpreter.jl index ece9669c..38aaf88c 100644 --- a/test/test_AbstractInterpreter.jl +++ b/test/test_AbstractInterpreter.jl @@ -5,34 +5,65 @@ if isdefined(parentmodule(@__MODULE__), :VSCodeServer) using ..VSCodeServer end -const CC = Core.Compiler +@doc """ + @newinterp NewInterpreter [ephemeral_cache::Bool=false] + +Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated +from the native code cache, satisfying the minimum interface requirements. +When the `ephemeral_cache=true` option is specified, `NewInterpreter` will hold +`CodeInstance` in an ephemeral non-integrated cache, rather than in the integrated +`Core.Compiler.InternalCodeCache`. +Keep in mind that ephemeral cache lacks support for invalidation and doesn't persist across +sessions. However it is an usual Julia object of the type `code_cache::IdDict{MethodInstance,CodeInstance}`, +making it easier for debugging and inspecting the compiler behavior. +""" @static if VERSION ≥ v"1.11.0-DEV.1552" -macro newinterp(InterpName) - InterpCacheName = QuoteNode(Symbol(string(InterpName, "Cache"))) +macro newinterp(InterpName, ephemeral_cache::Bool=false) + cache_token = QuoteNode(gensym(string(InterpName, "CacheToken"))) + InterpCacheName = esc(Symbol(string(InterpName, "Cache"))) InterpName = esc(InterpName) C = Core - CC = Core.Compiler + CC = Cthulhu.CC quote + $(ephemeral_cache && quote + struct $InterpCacheName + dict::IdDict{$C.MethodInstance,$C.CodeInstance} + end + $InterpCacheName() = $InterpCacheName(IdDict{$C.MethodInstance,$C.CodeInstance}()) + end) struct $InterpName <: $CC.AbstractInterpreter meta # additional information world::UInt inf_params::$CC.InferenceParams opt_params::$CC.OptimizationParams inf_cache::Vector{$CC.InferenceResult} + $(ephemeral_cache && :(code_cache::$InterpCacheName)) function $InterpName(meta = nothing; - world::UInt = Base.get_world_counter(), - inf_params::$CC.InferenceParams = $CC.InferenceParams(), - opt_params::$CC.OptimizationParams = $CC.OptimizationParams(), - inf_cache::Vector{$CC.InferenceResult} = $CC.InferenceResult[]) - return new(meta, world, inf_params, opt_params, inf_cache) + world::UInt = Base.get_world_counter(), + inf_params::$CC.InferenceParams = $CC.InferenceParams(), + opt_params::$CC.OptimizationParams = $CC.OptimizationParams(), + inf_cache::Vector{$CC.InferenceResult} = $CC.InferenceResult[], + $(ephemeral_cache ? + Expr(:kw, :(code_cache::$InterpCacheName), :($InterpCacheName())) : + Expr(:kw, :_, :nothing))) + return $(ephemeral_cache ? + :(new(meta, world, inf_params, opt_params, inf_cache, code_cache)) : + :(new(meta, world, inf_params, opt_params, inf_cache))) end end $CC.InferenceParams(interp::$InterpName) = interp.inf_params $CC.OptimizationParams(interp::$InterpName) = interp.opt_params $CC.get_inference_world(interp::$InterpName) = interp.world $CC.get_inference_cache(interp::$InterpName) = interp.inf_cache - $CC.cache_owner(::$InterpName) = $InterpCacheName + $CC.cache_owner(::$InterpName) = $cache_token + $(ephemeral_cache && quote + $CC.code_cache(interp::$InterpName) = $CC.WorldView(interp.code_cache, $CC.WorldRange(interp.world)) + $CC.get(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance, default) = get(wvc.cache.dict, mi, default) + $CC.getindex(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance) = getindex(wvc.cache.dict, mi) + $CC.haskey(wvc::$CC.WorldView{$InterpCacheName}, mi::$C.MethodInstance) = haskey(wvc.cache.dict, mi) + $CC.setindex!(wvc::$CC.WorldView{$InterpCacheName}, ci::$C.CodeInstance, mi::$C.MethodInstance) = setindex!(wvc.cache.dict, ci, mi) + end) end end else @@ -79,16 +110,11 @@ macro newinterp(InterpName) end end # if VERSION ≥ v"1.11.0-DEV.1552" -@doc """ -@newinterp NewInterpreter - -Defines new `NewInterpreter <: AbstractInterpreter` whose cache is separated -from the native code cache, satisfying the minimum interface requirements. -""" var"@newinterp" +const CC = Cthulhu.CC # `OverlayMethodTable` # -------------------- -import Base.Experimental: @MethodTable, @overlay +using Base.Experimental: @MethodTable, @overlay @newinterp MTOverlayInterp @MethodTable OverlayedMT diff --git a/test/test_Cthulhu.jl b/test/test_Cthulhu.jl index ebc66ee7..e013adbc 100644 --- a/test/test_Cthulhu.jl +++ b/test/test_Cthulhu.jl @@ -1,10 +1,15 @@ module test_Cthulhu using Test, Cthulhu, StaticArrays, Random +const CC = Cthulhu.CC include("setup.jl") include("irutils.jl") +# NOTE: From Julia version `v"1.12.0-DEV.1581"` onwards, Cthulhu uses the Compiler.jl stdlib. +# Therefore, for queries on its data structures, use the utilities from `Compiler === Cthulhu.CC` +# instead of those from `Base.Compiler === Core.Compiler`. + @testset "ambiguity check" begin @test isempty(detect_ambiguities(Cthulhu)) end @@ -147,7 +152,7 @@ let callsites = find_callsites_by_ftt(foo_callsite_assign, Tuple{}; optimize=fal end @eval function call_rt() - S = $(Core.Compiler.return_type)(+, Tuple{Int, Int}) + S = $(CC.return_type)(+, Tuple{Int, Int}) end let callsites = find_callsites_by_ftt(call_rt, Tuple{}; optimize=false) @test length(callsites) == 1 @@ -198,7 +203,7 @@ let callsites = find_callsites_by_ftt(f_matches, Tuple{Any, Any}; optimize=false @test length(callsites) == 1 callinfo = callsites[1].info @test callinfo isa Cthulhu.MultiCallInfo - @test Cthulhu.get_effects(callinfo) |> Core.Compiler.is_foldable + @test Cthulhu.get_effects(callinfo) |> CC.is_foldable io = IOBuffer() Cthulhu.show_callinfo(io, callinfo) @test occursin(r"→ g_matches\(::Any, ?::Any\)::Union{Float64, ?Int\d+}", String(take!(io))) @@ -215,10 +220,10 @@ uncached_call3(a) = uncached_call1(Type{a}) ci = first(callsites).info @test isa(ci, Cthulhu.UncachedCallInfo) effects = Cthulhu.get_effects(ci) - @test !Core.Compiler.is_consistent(effects) - @test Core.Compiler.is_effect_free(effects) - @test !Core.Compiler.is_nothrow(effects) - @test !Core.Compiler.is_terminates(effects) + @test !CC.is_consistent(effects) + @test CC.is_effect_free(effects) + @test !CC.is_nothrow(effects) + @test !CC.is_terminates(effects) @test Cthulhu.is_callsite(ci, ci.wrapped.mi) io = IOBuffer() show(io, first(callsites)) @@ -307,7 +312,7 @@ end callinfo = only(callsites).info @test isa(callinfo, Cthulhu.ConcreteCallInfo) @test Cthulhu.get_rt(callinfo) == Core.Const(factorial(12)) - @test Cthulhu.get_effects(callinfo) |> Core.Compiler.is_foldable + @test Cthulhu.get_effects(callinfo) |> CC.is_foldable io = IOBuffer() print(io, only(callsites)) @test occursin("= < concrete eval > issue41694(::Core.Const(12))", String(take!(io))) @@ -337,7 +342,7 @@ end callinfo = only(callsites).info @test isa(callinfo, Cthulhu.SemiConcreteCallInfo) @test Cthulhu.get_rt(callinfo) == Core.Const(semi_concrete_eval(42, 0)) - # @test Cthulhu.get_effects(callinfo) |> Core.Compiler.is_semiconcrete_eligible + # @test Cthulhu.get_effects(callinfo) |> CC.is_semiconcrete_eligible io = IOBuffer() print(io, only(callsites)) @test occursin("= < semi-concrete eval > semi_concrete_eval(::Core.Const(42),::$Int)", String(take!(io))) @@ -369,8 +374,8 @@ struct SingletonPureCallable{N} end @test occursin("SingletonPureCallable{1}()(::Float64)::Float64", s) - @test Cthulhu.get_effects(c1) |> Core.Compiler.is_foldable_nothrow - @test Cthulhu.get_effects(c2) |> Core.Compiler.is_foldable_nothrow + @test Cthulhu.get_effects(c1) |> CC.is_foldable_nothrow + @test Cthulhu.get_effects(c2) |> CC.is_foldable_nothrow end @testset "ReturnTypeCallInfo" begin @@ -402,8 +407,8 @@ end print(io, callsites[2]) @test occursin("return_type < only_ints(::Float64)::Union{} >", String(take!(io))) - @test Cthulhu.get_effects(callinfo1) |> Core.Compiler.is_foldable_nothrow - @test Cthulhu.get_effects(callinfo2) |> Core.Compiler.is_foldable_nothrow + @test Cthulhu.get_effects(callinfo1) |> CC.is_foldable_nothrow + @test Cthulhu.get_effects(callinfo2) |> CC.is_foldable_nothrow end @testset "OCCallInfo" begin @@ -414,7 +419,7 @@ end @test length(callsites) == 1 callinfo = only(callsites).info @test callinfo isa Cthulhu.OCCallInfo - @test Cthulhu.get_effects(callinfo) |> !Core.Compiler.is_foldable_nothrow + @test Cthulhu.get_effects(callinfo) |> !CC.is_foldable_nothrow # TODO not sure what these effects are (and neither is Base.infer_effects yet) @test callinfo.ci.rt === Base.return_types((Int,Int)) do a, b sin(a) + cos(b) @@ -442,7 +447,7 @@ end buf = IOBuffer() Cthulhu.show_callinfo(buf, callinfo.ci) - s = "opaque closure(::$(Core.Compiler.Const(42)))::$(Core.Compiler.Const(sin(42)))" + s = "opaque closure(::$(Const(42)))::$(Const(sin(42)))" @test String(take!(buf)) == s print(buf, only(callsites)) @test occursin("< opaque closure call > $s", String(take!(buf))) @@ -472,8 +477,8 @@ invoke_constcall(a::Number, c::Bool) = c ? Number : :number callsite = only(callsites) info = callsite.info @test isa(info, Cthulhu.InvokeCallInfo) - @test Cthulhu.get_effects(info) |> Core.Compiler.is_foldable_nothrow - rt = Core.Compiler.Const(:Integer) + @test Cthulhu.get_effects(info) |> CC.is_foldable_nothrow + rt = CC.Const(:Integer) @test info.ci.rt === rt buf = IOBuffer() show(buf, callsite) @@ -485,8 +490,8 @@ invoke_constcall(a::Number, c::Bool) = c ? Number : :number callsite = only(callsites) info = callsite.info @test isa(info, Cthulhu.InvokeCallInfo) - @test Cthulhu.get_effects(info) |> Core.Compiler.is_foldable_nothrow - @test info.ci.rt === Core.Compiler.Const(:Int) + @test Cthulhu.get_effects(info) |> CC.is_foldable_nothrow + @test info.ci.rt === CC.Const(:Int) end # const prop' / semi-concrete callsite @@ -496,14 +501,14 @@ invoke_constcall(a::Number, c::Bool) = c ? Number : :number callsite = only(callsites) info = callsite.info @test isa(info, Cthulhu.InvokeCallInfo) - @test Cthulhu.get_effects(info) |> Core.Compiler.is_foldable_nothrow + @test Cthulhu.get_effects(info) |> CC.is_foldable_nothrow inner = info.ci - rt = Core.Compiler.Const(Any) + rt = Const(Any) @test Cthulhu.get_rt(info) === rt buf = IOBuffer() show(buf, callsite) @test isa(inner, Cthulhu.SemiConcreteCallInfo) - @test occursin("= invoke < invoke_constcall(::Any,::$(Core.Compiler.Const(true)))::$rt", String(take!(buf))) + @test occursin("= invoke < invoke_constcall(::Any,::$(Const(true)))::$rt", String(take!(buf))) end end @@ -665,18 +670,18 @@ end f1() = x function f2() y = x - return sum(y) + return @noinline sum(y) end end function doprint(f) - (; src, mi, rt, exct, effects) = cthulhu_info(f) + (; src, mi, rt, exct, effects) = cthulhu_info(f; optimize=false) io = IOBuffer() Cthulhu.cthulhu_typed(io, :none, src, rt, exct, effects, mi; iswarn=false) return String(take!(io)) end @test occursin("invoke f1()::…\n", doprint(getfield(m, :f1))) str = doprint(getfield(m, :f2)) - @test occursin("x::Core.Const([1, 2, 3", str) + @test occursin("y::Core.Const([1, 2, 3", str) @test !occursin("500,", str) end @@ -748,7 +753,7 @@ end # tree = Cthulhu.treelist(similar(fst5(1.0), 0)) # @test isempty(tree.data.callstr) # @test isempty(Cthulhu.callstring(io, similar(stacktrace(fst5(1.0)), 0))) -# @test Cthulhu.instance(similar(stacktrace(fst5(1.0)), 0)) === Core.Compiler.Timings.ROOTmi +# @test Cthulhu.instance(similar(stacktrace(fst5(1.0)), 0)) === CC.Timings.ROOTmi # end @testset "ascend" begin @@ -767,9 +772,9 @@ end micaller = Cthulhu.get_specialization(caller, Tuple{Int}) micallee_Int = Cthulhu.get_specialization(callee, Tuple{Int}) micallee_Float64 = Cthulhu.get_specialization(callee, Tuple{Float64}) - info, lines = only(Cthulhu.find_caller_of(Core.Compiler.NativeInterpreter(), micallee_Int, micaller)) + info, lines = only(Cthulhu.find_caller_of(CC.NativeInterpreter(), micallee_Int, micaller)) @test info == (:caller, Symbol(@__FILE__), 0) && lines == [line1, line3] - info, lines = only(Cthulhu.find_caller_of(Core.Compiler.NativeInterpreter(), micallee_Float64, micaller)) + info, lines = only(Cthulhu.find_caller_of(CC.NativeInterpreter(), micallee_Float64, micaller)) @test info == (:caller, Symbol(@__FILE__), 0) && lines == [line2] M = Module() @@ -800,7 +805,7 @@ end _, line1, line2 = outercaller(7) micaller = Cthulhu.get_specialization(outercaller, Tuple{Int}) micallee = Cthulhu.get_specialization(nicallee, Tuple{Int}) - callerinfo = Cthulhu.find_caller_of(Core.Compiler.NativeInterpreter(), micallee, micaller) + callerinfo = Cthulhu.find_caller_of(CC.NativeInterpreter(), micallee, micaller) @test length(callerinfo) == 2 info, lines = callerinfo[1] @test info == (:outercaller, Symbol(@__FILE__), 0) @@ -889,13 +894,13 @@ end @testset "code_typed(bookmark)" begin ci, rt = code_typed(b) - @test ci isa Core.Compiler.CodeInfo + @test ci isa CodeInfo @test rt isa Type end @testset "code_typed(bookmark; optimize = false)" begin ci, rt = code_typed(b; optimize = false) - @test ci isa Core.Compiler.CodeInfo + @test ci isa CodeInfo @test rt isa Type end @@ -986,7 +991,7 @@ end # Get IR for a function, wrap it in a minimal methodinstance (ir, rt) = only(Base.code_ircode(sqrt, (Float64,))) mi = ccall(:jl_new_method_instance_uninit, Ref{Core.MethodInstance}, ()); - mi.specTypes = Tuple{map(Core.Compiler.widenconst, ir.argtypes)...} + mi.specTypes = Tuple{map(CC.widenconst, ir.argtypes)...} # Just state that the definition of this MI is the module it was defined in mi.def = @__MODULE__ @@ -997,7 +1002,7 @@ end @test isempty(root.children) # Create an MICallInfo for this `mi`, ensure it works with `show_callinfo()` - callinfo = Cthulhu.MICallInfo(mi, rt, Core.Compiler.Effects()) + callinfo = Cthulhu.MICallInfo(mi, rt, CC.Effects()) io = IOBuffer() Cthulhu.show_callinfo(io, callinfo) diff --git a/test/test_codeview.jl b/test/test_codeview.jl index 13f6ff7c..2cfb9dc2 100644 --- a/test/test_codeview.jl +++ b/test/test_codeview.jl @@ -25,7 +25,7 @@ Revise.track(TestCodeViewSandbox, normpath(@__DIR__, "TestCodeViewSandbox.jl")) @static if VERSION < v"1.12.0-DEV.669" codeview(io, mi, optimize, debuginfo, Cthulhu.get_inference_world(interp), config) else - src = Core.Compiler.typeinf_code(interp, mi, true) + src = Cthulhu.CC.typeinf_code(interp, mi, true) codeview(io, mi, src, optimize, debuginfo, Cthulhu.get_inference_world(interp), config) end @test !isempty(String(take!(io))) # just check it works