Skip to content

Commit

Permalink
JETAnalyzer: enable the assume_bindings_static option
Browse files Browse the repository at this point in the history
To finish the analysis a bit earlier when there are undefined bindings.
  • Loading branch information
aviatesk committed Jan 30, 2024
1 parent 6bac54e commit f54a24e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,8 @@ function CC.abstract_eval_special_value(analyzer::JETAnalyzer,
if isa(e, GlobalRef)
# report pass for undefined global reference
ReportPass(analyzer)(UndefVarErrorReport, analyzer, sv, e)

# NOTE `Core.Compiler.NativeInterpreter` should return `ret = Any` `ret` even if `mod.name`
# isn't defined and we just pass it as is to collect as much error points as possible
# we can change it to `Bottom` to suppress any further inference with this variable,
# but then we also need to make sure to invalidate the cache for the analysis on
# the future re-definition of this (currently) undefined binding
# return Bottom
# TODO enable this
# elseif isa(e, SlotNumber)
# # TODO enable this (aviatesk/JET.jl#596)
# # report pass for (local) undef var error
# ReportPass(analyzer)(UndefVarErrorReport, analyzer, sv, e, vtypes, ret)
end
Expand Down Expand Up @@ -1404,6 +1397,12 @@ function JETAnalyzer(world::UInt = Base.get_world_counter();
jetconfigs = kwargs_dict(jetconfigs)
set_if_missing!(jetconfigs, :aggressive_constant_propagation, true)
set_if_missing!(jetconfigs, :unoptimize_throw_blocks, false)
# Enable the `assume_bindings_static` option to terminate analysis a bit earlier when
# there are undefined bindings detected. Note that this option will cause inference
# cache inconsistency until JuliaLang/julia#40399 is merged. But the analysis cache of
# JETAnalyzer has the same problem already anyway, so enabling this option does not
# make the situation worse.
set_if_missing!(jetconfigs, :assume_bindings_static, true)
state = AnalyzerState(world; jetconfigs...)
config = JETAnalyzerConfig(; jetconfigs...)
return JETAnalyzer(state, report_pass, config)
Expand Down
12 changes: 12 additions & 0 deletions test/analyzers/test_jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1138,4 +1138,16 @@ end |> only === Val{3}

@test isconcretetype(only(Base.return_types(pairs, (@NamedTuple{kw1::Int,kw2::String},); interp=JET.JETAnalyzer())))

# Broken: cache consistency with undefined bindings (xref: JuliaLang/julia#40399)
func40399() = sin(Main.binding40399)
let res = report_call() do
func40399()
end
@test only(get_reports_with_test(res)) isa UndefVarErrorReport
end
global binding40399::Float64 = rand()
test_call(; broken=true) do
func40399()
end

end # module test_jetanalyzer

0 comments on commit f54a24e

Please sign in to comment.