Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Sep 6, 2021
1 parent 30ac9f5 commit f7b78c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
version:
- 'nightly'
- '1.7-nightly'
os:
- ubuntu-latest
- macOS-latest
Expand Down
5 changes: 4 additions & 1 deletion src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,10 @@ function do_typeinf!(interp::CthulhuInterpreter, mi::MethodInstance)
# we may want to handle the case when `InferenceState(...)` returns `nothing`,
# which indicates code generation of a `@generated` has been failed,
# and show it in the UI in some way ?
frame = InferenceState(result, true, interp)::InferenceState
# branch on https://github.com/JuliaLang/julia/pull/42082
frame = @static hasmethod(InferenceState, (InferenceResult,Symbol,AbstractInterpreter)) ?
InferenceState(result, #=cache=# :global, interp)::InferenceState :
InferenceState(result, #=cached=# true, interp)::InferenceState
Core.Compiler.typeinf(interp, frame)
return nothing
end
Expand Down
9 changes: 8 additions & 1 deletion src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@ end

# branch on https://github.com/JuliaLang/julia/pull/41328
@static if isdefined(Compiler, :is_stmt_inline)
function Compiler.inlining_policy(interp::CthulhuInterpreter, @nospecialize(src), stmt_flag::UInt8)
function Compiler.inlining_policy(
interp::CthulhuInterpreter, @nospecialize(src), stmt_flag::UInt8,
mi::MethodInstance, argtypes::Vector{Any})
@assert isa(src, OptimizedSource) || isnothing(src)
if isa(src, OptimizedSource)
if Compiler.is_stmt_inline(stmt_flag) || src.isinlineable
return src.ir
end
else
# the default inlining policy may try additional effor to find the source in a local cache
return Base.@invoke Compiler.inlining_policy(
interp::AbstractInterpreter, nothing, stmt_flag::UInt8,
mi::MethodInstance, argtypes::Vector{Any})
end
return nothing
end
Expand Down
49 changes: 26 additions & 23 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,32 @@ let callsites = find_callsites_by_ftt(call_by_apply, Tuple{Tuple{Int}}; optimize
@test length(callsites) == 1
end

if Base.JLOptions().check_bounds (0, 2)
@testset "DCE & boundscheck" begin
Base.@propagate_inbounds function f(x)
@boundscheck error()
end
g(x) = @inbounds f(x)
h(x) = f(x)

(_,CI, _, _, _, _) = process(g, Tuple{Vector{Float64}})
@test all(CI.stmts.inst) do stmt
isa(stmt, Core.GotoNode) || (isa(stmt, Core.ReturnNode) && isdefined(stmt, :val)) || Base.Meta.isexpr(stmt, :code_coverage_effect, 0)
end

(_,CI, _, _, _, _) = process(h, Tuple{Vector{Float64}})
i = 1
while CI.stmts.inst[i] === nothing || Base.Meta.isexpr(CI.stmts.inst[i], :code_coverage_effect, 0)
i += 1
end
@test length(CI.stmts) - i + 1 == 2
stmt = CI.stmts.inst[end]
@test isa(stmt, Core.ReturnNode) && !isdefined(stmt, :val)
end
end
# # TODO run this testset in a separate process
# # julia --check-bounds=auto --code-coverage=none
# @testset "DCE & boundscheck" begin
# M = Module()
# @eval M begin
# Base.@propagate_inbounds function f(x)
# @boundscheck error()
# end
# g(x) = @inbounds f(x)
# h(x) = f(x)
# end
#
# let
# (_,CI, _, _, _, _) = process(M.g, Tuple{Vector{Float64}})
# @test all(CI.stmts.inst) do stmt
# isa(stmt, Core.GotoNode) || (isa(stmt, Core.ReturnNode) && isdefined(stmt, :val))
# end
# end
#
# let
# (_,CI, _, _, _, _) = process(M.h, Tuple{Vector{Float64}})
# @test count(!isnothing, CI.stmts.inst) == 2
# stmt = CI.stmts.inst[end]
# @test isa(stmt, Core.ReturnNode) && !isdefined(stmt, :val)
# end
# end

# Something with many methods, but enough to be under the match limit
g_matches(a::Int, b::Int) = a+b
Expand Down

0 comments on commit f7b78c8

Please sign in to comment.