Skip to content

Commit

Permalink
return the number of reported errors instead of boolean indication
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jul 22, 2021
1 parent 46a5d69 commit e9d3b8d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/JET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,17 @@ include("print.jl")
res::ReportResult
- `res.included_files::Set{String}`: files analyzed by JET
- `res.any_reported::Bool`: indicates if there was any error point reported
- `res.nreported::Bool`: the number of the reported errors
"""
const ReportResult = @NamedTuple begin
included_files::Set{String}
any_reported::Bool
nreported::Int
end

function report_result(io::IO, res::VirtualProcessResult; jetconfigs...)
print_result = print_reports(io, res; jetconfigs...)
nreported = print_reports(io, res; jetconfigs...)
return (; included_files = res.included_files,
any_reported = print_result)::ReportResult
nreported = nreported)::ReportResult
end

"""
Expand Down Expand Up @@ -989,12 +989,12 @@ the number of detected reports.
function report_call(@nospecialize(args...); jetconfigs...)
analyzer, frame = analyze_call(args...; jetconfigs...)
reports = get_reports(analyzer)
print_reports(reports; jetconfigs...)
nreported = print_reports(reports; jetconfigs...)
if isnothing(frame)
# if there is `GeneratorErrorReport`, it means the code generation happened and failed
return any(r->isa(r, GeneratorErrorReport), reports) ? Bottom : Any
end
return get_result(frame), length(reports)
return get_result(frame), nreported
end

# for inspection
Expand Down
16 changes: 9 additions & 7 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,17 @@ function print_reports(io::IO,
jetconfigs...)
config = PrintConfig(; jetconfigs...)

if isempty(reports)
n = length(reports)
if n == 0
if config.print_toplevel_success
printlnstyled(io, "No toplevel errors !"; color = NOERROR_COLOR)
end
return false
return 0
end

arg = :color => get(io, :color, false)
with_bufferring(arg) do io
s = string(pluralize(length(reports), "toplevel error"), " found")
s = string(pluralize(n, "toplevel error"), " found")
printlnstyled(io, LEFT_ROOF, s, RIGHT_ROOF; color = HEADER_COLOR)

color = ERROR_COLOR
Expand All @@ -220,7 +221,7 @@ function print_reports(io::IO,
end
end |> postprocess |> Fix1(print, io)

return true
return n
end

# don't show stacktrace for syntax errors
Expand Down Expand Up @@ -256,12 +257,13 @@ function print_reports(io::IO,
# here we more aggressively uniqify reports, ignoring the difference between different `MethodInstance`s
# as far as the report location and its signature are the same
reports = unique(print_identity_key, reports)
n = length(reports)

if isempty(reports)
if n == 0
if config.print_inference_success
printlnstyled(io, "No errors !"; color = NOERROR_COLOR)
end
return false
return 0
end

with_bufferring(:color => get(io, :color, false)) do io
Expand All @@ -281,7 +283,7 @@ function print_reports(io::IO,
end
end |> postprocess |> Fix1(print, io)

return true
return n
end

@withmixedhash struct VirtualFrameNoLinfo
Expand Down
8 changes: 6 additions & 2 deletions test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,37 @@ end

@testset "print inference errors" begin
let
# LINE SENSITIVITY START
res = @analyze_toplevel begin
s = "julia"
sum(s)
end

io = IOBuffer()
@test print_reports(io, res.inference_error_reports)
@test !iszero(print_reports(io, res.inference_error_reports))
let s = String(take!(io))
@test occursin("2 possible errors found", s)
@test occursin(Regex("@ $(escape_string(@__FILE__)):$((@__LINE__)-7)"), s) # toplevel call signature
end
# LINE SENSITIVITY END
end

@testset "special case splat call signature" begin
let
# LINE SENSITIVITY START
res = @analyze_toplevel begin
foo(args...) = sum(args)
foo(rand(Char, 1000000000)...)
end

io = IOBuffer()
@test print_reports(io, res.inference_error_reports, JET.gen_postprocess(res.actual2virtual))
@test !iszero(print_reports(io, res.inference_error_reports, JET.gen_postprocess(res.actual2virtual)))
let s = String(take!(io))
@test occursin("1 possible error found", s)
@test occursin(Regex("@ $(escape_string(@__FILE__)):$((@__LINE__)-8)"), s) # toplevel call signature
@test occursin("foo(rand(Char, 1000000000)...)", s)
end
# LINE SENSITIVITY END
end
end
end
8 changes: 4 additions & 4 deletions test/test_virtualprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ end
# no configuration, thus top-level analysis should fail
let
io = IOBuffer()
_, res = report_file(io, analysis_target; toplevel_logger=nothing)
@test res # error reported
_, nreported = report_file(io, analysis_target; toplevel_logger=nothing)
@test !iszero(nreported) # error reported
end

# setup a configuration file
Expand All @@ -1371,8 +1371,8 @@ end
# now any top-level analysis failure shouldn't happen
let
io = IOBuffer()
_, res = report_file(io, analysis_target; toplevel_logger=nothing)
@test !res # no error happened
_, nreported = report_file(io, analysis_target; toplevel_logger=nothing)
@test iszero(nreported) # no error happened
@test isfile("toplevel.txt") # not closed yet
end
catch err
Expand Down

0 comments on commit e9d3b8d

Please sign in to comment.