Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
VSCode integration, update to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 2, 2021
1 parent 74059c3 commit bee5718
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
JET = "0.4.2"
JET = "0.5.0"
MacroTools = "0.5.6"
julia = "1.6"

Expand Down
2 changes: 0 additions & 2 deletions docs/src/toolset/dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ These macros/functions are the entries of dispatch analysis:
```@docs
@report_dispatch
report_dispatch
@analyze_dispatch
analyze_dispatch
@test_nodispatch
test_nodispatch
```
Expand Down
2 changes: 0 additions & 2 deletions src/JETTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ end
include("dispatch.jl")

export
analyze_dispatch,
@analyze_dispatch,
report_dispatch,
@report_dispatch,
test_nodispatch,
Expand Down
52 changes: 11 additions & 41 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ JETInterfaces.AbstractAnalyzer(analyzer::DispatchAnalyzer, state::AnalyzerState)
DispatchAnalyzer(state, analyzer.opts, analyzer.frame_filter, analyzer.function_filter, analyzer.concrete_frame, analyzer.skip_unoptimized_throw_blocks)
JETInterfaces.ReportPass(analyzer::DispatchAnalyzer) = DispatchAnalysisPass()

# VSCode integration
JETInterfaces.vscode_diagnostics_order(analyzer::DispatchAnalyzer) = false

# we want to run different analysis with a different filter, so include its hash into the cache key
function JET.get_cache_key(analyzer::DispatchAnalyzer)
h = @invoke get_cache_key(analyzer::AbstractAnalyzer)
Expand Down Expand Up @@ -273,28 +276,11 @@ end # @static if isdefined(CC, :finish!)
# =======

"""
analyze_dispatch(f, types = Tuple{}; jetconfigs...) -> (analyzer::DispatchAnalyzer, frame::Union{InferenceFrame,Nothing})
analyze_dispatch(tt::Type{<:Tuple}; jetconfigs...) -> (analyzer::DispatchAnalyzer, frame::Union{InferenceFrame,Nothing})
Analyzes the generic function call with the given type signature, and returns:
- `analyzer::DispatchAnalyzer`: contains analyzed optimization failures and runtime dispatch points
- `frame::Union{InferenceFrame,Nothing}`: the final state of the abstract interpretation,
or `nothing` if `f` is a generator and the code generation has been failed
"""
function analyze_dispatch(@nospecialize(args...);
analyzer = DispatchAnalyzer,
jetconfigs...)
@assert analyzer === DispatchAnalyzer "analyzer is fixed to $DispatchAnalyzer"
return analyze_call(args...; analyzer, jetconfigs...)
end
report_dispatch(f, types = Tuple{}; jetconfigs...) -> JETCallResult
report_dispatch(tt::Type{<:Tuple}; jetconfigs...) -> JETCallResult
"""
report_dispatch(f, types = Tuple{}; jetconfigs...) -> result_type::Any
report_dispatch(tt::Type{<:Tuple}; jetconfigs...) -> result_type::Any
Analyzes the generic function call with the given type signature, and then prints detected
optimization failures and runtime dispatch points to `stdout`, and finally returns the result
type of the call.
Analyzes the generic function call with the given type signature with `DispatchAnalyzer`,
which collects optimization failures and runtime dispatches involved within the call stack.
"""
function report_dispatch(@nospecialize(args...);
analyzer = DispatchAnalyzer,
Expand All @@ -303,22 +289,6 @@ function report_dispatch(@nospecialize(args...);
return report_call(args...; analyzer, jetconfigs...)
end

"""
@analyze_dispatch [jetconfigs...] f(args...)
Evaluates the arguments to the function call, determines its types, and then calls
[`analyze_dispatch`](@ref) on the resulting expression.
As with `@code_typed` and its family, any of [JET configurations](https://aviatesk.github.io/JET.jl/dev/config/)
or [dispatch analysis specific configurations](@ref dispatch-analysis-configurations) can be given as the optional arguments like this:
```julia
# reports `rand(::Type{Bool})` with `unoptimize_throw_blocks` configuration turned on
julia> @analyze_dispatch unoptimize_throw_blocks=true rand(Bool)
```
"""
macro analyze_dispatch(ex0...)
return gen_call_with_extracted_types_and_kwargs(__module__, :analyze_dispatch, ex0)
end

"""
@report_dispatch [jetconfigs...] f(args...)
Expand Down Expand Up @@ -353,7 +323,7 @@ Test Passed
Expression: #= none:1 =# JETTest.@test_nodispatch sincos(10)
```
As with [`@report_dispatch`](@ref) or [`@analyze_dispatch`](@ref), any of [JET configurations](https://aviatesk.github.io/JET.jl/dev/config/)
As with [`@report_dispatch`](@ref), any of [JET configurations](https://aviatesk.github.io/JET.jl/dev/config/)
or [dispatch analysis specific configurations](@ref dispatch-analysis-configurations) can be given as the optional arguments like this:
```julia
julia> function f(n)
Expand Down Expand Up @@ -460,12 +430,12 @@ end
end

function test_dispatch_exs(ex0, m, source)
analyzer_call = gen_call_with_extracted_types_and_kwargs(m, :analyze_dispatch, ex0)
analysis = gen_call_with_extracted_types_and_kwargs(m, :report_dispatch, ex0)
orig_expr = QuoteNode(
Expr(:macrocall, GlobalRef(JETTest, Symbol("@test_nodispatch")), source, ex0...))
source = QuoteNode(source)
testres = :(try
analyzer, frame = $analyzer_call
analyzer, = $analysis
reports = $get_reports(analyzer)
if $length(reports) == 0
$Pass(:test_nodispatch, $orig_expr, nothing, nothing, $source)
Expand Down Expand Up @@ -498,7 +468,7 @@ function test_nodispatch(@nospecialize(args...);
record(get_testset(), Broken(:skipped, orig_expr))
else
testres = try
analyzer, frame = analyze_dispatch(args...; jetconfigs...)
analyzer, = report_dispatch(args...; jetconfigs...)
reports = get_reports(analyzer)
if length(reports) == 0
Pass(:test_nodispatch, orig_expr, nothing, nothing, source)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ using JETTest, Test
return ft !== typeof(Core.Compiler.widenconst) # `widenconst` is very untyped, ignore
end

@test_nodispatch frame_filter=frame_filter function_filter=function_filter skip_nonconcrete_calls=false analyze_dispatch(sin, (Int,))
@test_nodispatch frame_filter=frame_filter function_filter=function_filter skip_nonconcrete_calls=false report_dispatch(sin, (Int,))
end
end
16 changes: 8 additions & 8 deletions test/test_dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import JET: get_reports
f(a) = a
f(a::Number) = a
let
analyzer, = @analyze_dispatch f(10) # should be ok
analyzer, = @report_dispatch f(10) # should be ok
@test isempty(get_reports(analyzer))
end

# if the argument type isn't well typed, compiler can't determine which method to call,
# and it will lead to runtime dispatch
let
analyzer, = analyze_dispatch((Vector{Any},)) do ary
analyzer, = report_dispatch((Vector{Any},)) do ary
f(ary[1]) # runtime dispatch !
end
@test length(get_reports(analyzer)) == 1
Expand All @@ -34,7 +34,7 @@ end
@inline g1(a) = return a
@noinline g2(a) = return a
let
analyzer, = analyze_dispatch((Vector{Any},)) do ary
analyzer, = report_dispatch((Vector{Any},)) do ary
a = ary[1]
g1(a) # this call should be statically resolved and inlined
g2(a) # this call should be statically resolved but not inlined, and will be dispatched
Expand All @@ -56,7 +56,7 @@ end
# the `unoptimize_throw_blocks` configuration disables optimizations on "throw blocks" by default,
# but `DispatchAnalyzer` ignores problems from them, so we don't get error reports here
let
analyzer, = @analyze_dispatch sin(10)
analyzer, = @report_dispatch sin(10)
@test isempty(get_reports(analyzer))
end

Expand All @@ -81,12 +81,12 @@ end

# we will get bunch of reports from the `println` call
let
analyzer, = @analyze_dispatch compute(30)
analyzer, = @report_dispatch compute(30)
@test !isempty(get_reports(analyzer))
end
# if we use different `frame_filter`, a fresh analysis should run
let
analyzer, = @analyze_dispatch frame_filter=module_filter(@__MODULE__) compute(30)
analyzer, = @report_dispatch frame_filter=module_filter(@__MODULE__) compute(30)
@test isempty(get_reports(analyzer))
end

Expand All @@ -98,7 +98,7 @@ f1(a) = sin(a)
f1(a::Number) = cos(a)
let
# by default, we'd ignore error reports from `f1` calls
analyzer, = analyze_dispatch((Vector{Any},)) do ary
analyzer, = report_dispatch((Vector{Any},)) do ary
f1(ary[1]) # runtime dispatch !
end
@test length(get_reports(analyzer)) == 1
Expand All @@ -108,7 +108,7 @@ end
let
# when the `skip_nonconcrete_calls` configuration is turned off, we will get error reports
# from those non-concrete calls of `f1`
analyzer, = analyze_dispatch((Vector{Any},); skip_nonconcrete_calls=false) do ary
analyzer, = report_dispatch((Vector{Any},); skip_nonconcrete_calls=false) do ary
f1(ary[1]) # runtime dispatch !
end
@test length(get_reports(analyzer)) 3
Expand Down

0 comments on commit bee5718

Please sign in to comment.