Skip to content

Commit

Permalink
remove unnecesasry interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 15, 2024
1 parent 6e5b96e commit e4aaf29
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
29 changes: 15 additions & 14 deletions src/JET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1060,22 +1060,23 @@ function call_test_ex(funcname::Symbol, testname::Symbol, ex0, __module__, __sou
deleteat!(ex0, idx)

testres, orig_expr = _call_test_ex(funcname, testname, ex0, __module__, __source__)
isskip, isbroken = (!isnothing(skip) && skip), (!isnothing(broken) && broken)

return quote
if $(!isnothing(skip) && skip)
$(Test.record)($get_testset(), $Broken(:skipped, $orig_expr))
if $isskip
Test.record(get_testset(), Broken(:skipped, $orig_expr))
else
testres = $testres
if $(!isnothing(broken) && broken)
if isa(testres, $JETTestFailure)
testres = $Broken($(QuoteNode(testname)), $orig_expr)
elseif isa(testres, $Pass)
testres = $Error(:test_unbroken, $orig_expr, nothing, nothing, $(QuoteNode(__source__)))
if $isbroken
if isa(testres, JETTestFailure)
testres = Broken($(QuoteNode(testname)), $orig_expr)
elseif isa(testres, Pass)
testres = Error(:test_unbroken, $orig_expr, nothing, nothing, $(QuoteNode(__source__)))
end
else
isa(testres, $Pass) || ccall(:jl_breakpoint, $Cvoid, ($Any,), testres)
isa(testres, Pass) || ccall(:jl_breakpoint, Cvoid, (Any,), testres)
end
$(Test.record)($get_testset(), testres)
Test.record(get_testset(), testres)
end
end
end
Expand All @@ -1086,14 +1087,14 @@ function _call_test_ex(funcname::Symbol, testname::Symbol, ex0, __module__, __so
source = QuoteNode(__source__)
testres = :(try
result = $analysis
if $length($get_reports(result)) == 0
$Pass($(QuoteNode(testname)), $orig_expr, nothing, nothing, $source)
if length(get_reports(result)) == 0
Pass($(QuoteNode(testname)), $orig_expr, nothing, nothing, $source)
else
$JETTestFailure($orig_expr, $source, result)
JETTestFailure($orig_expr, $source, result)
end
catch err
isa(err, $InterruptException) && rethrow()
$Error(:test_error, $orig_expr, err, $(Base.current_exceptions()), $source)
isa(err, InterruptException) && rethrow()
Error(:test_error, $orig_expr, err, Base.current_exceptions(), $source)
end) |> Base.remove_linenums!
return testres, orig_expr
end
Expand Down
47 changes: 21 additions & 26 deletions test/interactive_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,31 @@ using JET, InteractiveUtils

const CC = JET.CC

import .CC:
Bottom, widenconst,
using .CC: Bottom, widenconst,

import JET:
using JET:
AbstractAnalyzer, AbstractGlobal, InferenceErrorReport, JETAnalyzer, ToplevelConfig,
ToplevelErrorReport, gen_virtual_module, get_reports, get_result, print_reports,
virtual_process, virtualize_module_context

import Base.Meta:
isexpr
using Base.Meta: isexpr

get_cache(analyzer::AbstractAnalyzer) = JET.get_inf_cache(analyzer)

function subtypes_recursive!(t, ts)
push!(ts, t)
if isabstracttype(t)
for ct in subtypes(t)
subtypes_recursive!(ct, ts)
let ts = Type[]
function subtypes_recursive!(t)
push!(ts, t)
if isabstracttype(t)
for ct in subtypes(t)
subtypes_recursive!(ct)
end
end
end
return ts
end

let ts = Type[]
subtypes_recursive!(ToplevelErrorReport, ts)
subtypes_recursive!(InferenceErrorReport, ts)
subtypes_recursive!(ToplevelErrorReport)
subtypes_recursive!(InferenceErrorReport)
for t in ts
canonicalname = Symbol(parentmodule(t), '.', nameof(t))
canonicalpath = Symbol.(split(string(canonicalname), '.'))

modpath = Expr(:., canonicalpath[1:end-1]...)
symname = Expr(:., last(canonicalpath))
ex = Expr(:import, Expr(:(:), modpath, symname))
Expand All @@ -48,13 +43,13 @@ Creates a virtual module and defines fixtures from toplevel expression `ex`
"""
macro fixturedef(ex)
@assert isexpr(ex, :block)
return quote let
vmod = $gen_virtual_module()
return :(let
vmod = gen_virtual_module()
for x in $(ex.args)
Core.eval(vmod, x)
end
vmod # return virtual module
end end
end)
end

"""
Expand Down Expand Up @@ -87,7 +82,7 @@ macro analyze_toplevel2(xs...)
jetconfigs = (:(virtualize = false), jetconfigs...,)
ex2 = _analyze_toplevel(ex, __source__, jetconfigs)
return :(let
$(esc(vmod)) = $gen_virtual_module()
$(esc(vmod)) = gen_virtual_module()
ret2 = $ex2
$(esc(vmod)), ret2
end)
Expand All @@ -99,12 +94,12 @@ function _analyze_toplevel(ex, lnn, jetconfigs)
Expr(:toplevel, lnn, ex)
) |> QuoteNode
return :(let
analyzer = $(GlobalRef(JET, :JETAnalyzer))(; $(map(esc, jetconfigs)...))
analyzer = JETAnalyzer(; $(map(esc, jetconfigs)...))
config = ToplevelConfig(; $(map(esc, jetconfigs)...))
res = $virtual_process($toplevelex,
$(string(lnn.file)),
analyzer,
config)
res = virtual_process($toplevelex,
$(string(lnn.file)),
analyzer,
config)
JET.JETToplevelResult(analyzer, res, "analyze_toplevel"; $(map(esc, jetconfigs)...))
end)
end
Expand Down

0 comments on commit e4aaf29

Please sign in to comment.