Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Unhandled TypeVar #379

Closed
jakobnissen opened this issue Aug 17, 2022 · 4 comments
Closed

Error: Unhandled TypeVar #379

jakobnissen opened this issue Aug 17, 2022 · 4 comments

Comments

@jakobnissen
Copy link
Contributor

jakobnissen commented Aug 17, 2022

When doing analyze_package on v Julia 1.8-rc using JET 0.6.1, I get the following.
Unfortunately, it only happens with a package I can't share.

ERROR: unhandled TypeVar
Stacktrace:
  [1] error(s::String)
    @ Core.Compiler ./error.jl:35
  [2] widenconst(t::TypeVar)
    @ Core.Compiler ./compiler/typelattice.jl:341
  [3] isdefined_tfunc(arg1::Any, sym::Any)
    @ Core.Compiler ./compiler/tfuncs.jl:259
  [4] isdefined_tfunc(arg1::Any, sym::Any)
    @ Core.Compiler ./compiler/tfuncs.jl:307
  [5] builtin_tfunction(interp::Core.Compiler.AbstractInterpreter, f::Any, argtypes::Vector{Any}, sv::Union{Nothing, Core.Compiler.InferenceState})
    @ Core.Compiler ./compiler/tfuncs.jl:1914
  [6] builtin_tfunction
    @ ~/.julia/packages/JET/wMeAT/src/abstractinterpret/typeinfer.jl:98 [inlined]
  [7] builtin_tfunction(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, f::Any, argtypes::Vector{Any}, sv::Core.Compiler.InferenceState)
    @ JET ~/.julia/packages/JET/wMeAT/src/analyzers/jetanalyzer.jl:367
  [8] abstract_call_builtin(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, f::Core.Builtin, ::Core.Compiler.ArgInfo, sv::Core.Compiler.InferenceState, max_methods::Int64)
    @ Core.Compiler ./compiler/abstractinterpretation.jl:1401
  [9] abstract_call_known(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, f::Any, arginfo::Core.Compiler.ArgInfo, sv::Core.Compiler.InferenceState, max_methods::Int64)
    @ Core.Compiler ./compiler/abstractinterpretation.jl:1606
 [10] abstract_call(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, arginfo::Core.Compiler.ArgInfo, sv::Core.Compiler.InferenceState, max_methods::Int64)
    @ Core.Compiler ./compiler/abstractinterpretation.jl:1766
 [11] abstract_call(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, arginfo::Core.Compiler.ArgInfo, sv::Core.Compiler.InferenceState, max_methods::Int64) (repeats 2 times)
    @ JET ~/.julia/packages/JET/wMeAT/src/abstractinterpret/typeinfer.jl:243
 [12] abstract_eval_statement(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, e::Any, vtypes::Vector{Core.Compiler.VarState}, sv::Core.Compiler.InferenceState)
    @ Core.Compiler ./compiler/abstractinterpretation.jl:1890
 [13] abstract_eval_statement(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, e::Any, vtypes::Vector{Core.Compiler.VarState}, sv::Core.Compiler.InferenceState)
    @ JET ~/.julia/packages/JET/wMeAT/src/abstractinterpret/typeinfer.jl:92
 [14] typeinf_local(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, frame::Core.Compiler.InferenceState)
    @ Core.Compiler ./compiler/abstractinterpretation.jl:2366
 [15] typeinf_nocycle(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, frame::Core.Compiler.InferenceState)
    @ Core.Compiler ./compiler/abstractinterpretation.jl:2462
 [16] _typeinf(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, frame::Core.Compiler.InferenceState)
@ JET ~/.julia/packages/JET/wMeAT/src/abstractinterpret/typeinfer.jl:646
 [17] typeinf(interp::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, frame::Core.Compiler.InferenceState)
    @ Core.Compiler ./compiler/typeinfer.jl:213
 [18] typeinf(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, frame::Core.Compiler.InferenceState)
    @ JET ~/.julia/packages/JET/wMeAT/src/abstractinterpret/typeinfer.jl:580
 [19] analyze_frame!
    @ ~/.julia/packages/JET/wMeAT/src/JET.jl:769 [inlined]
 [20] analyze_method_instance!(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, mi::Core.MethodInstance; set_entry::Bool)
    @ JET ~/.julia/packages/JET/wMeAT/src/JET.jl:758
 [21] #analyze_method_signature!#119
    @ ~/.julia/packages/JET/wMeAT/src/JET.jl:741 [inlined]
 [22] #analyze_method!#118
    @ ~/.julia/packages/JET/wMeAT/src/JET.jl:726 [inlined]
 [23] analyze_from_definitions!(analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, res::JET.VirtualProcessResult, config::JET.ToplevelConfig{Union{Expr, Symbol}})
    @ JET ~/.julia/packages/JET/wMeAT/src/toplevel/virtualprocess.jl:426
 [24] virtual_process(x::String, filename::String, analyzer::JET.JETAnalyzer{JET.BasicPass{typeof(JET.jetanalyzer_function_filter)}}, config::JET.ToplevelConfig{Union{Expr, Symbol}})
    @ JET ~/.julia/packages/JET/wMeAT/src/toplevel/virtualprocess.jl:345
 [25] report_text(text::String, filename::String; analyzer::Type{JET.JETAnalyzer}, source::String, jetconfigs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:concretization_patterns, :analyze_from_definitions, :toplevel_logger), Tuple{Vector{Symbol}, Bool, IOContext{Base.TTY}}}})
    @ JET ~/.julia/packages/JET/wMeAT/src/JET.jl:1007
 [26] report_file(filename::String; __default_configs::Tuple{Pair{Symbol, IOContext{Base.TTY}}, Pair{Symbol, Bool}, Pair{Symbol, Vector{Symbol}}}, source::Nothing, jetconfigs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ JET ~/.julia/packages/JET/wMeAT/src/JET.jl:836
 [27] report_package(package::Module; analyze_from_definitions::Bool, concretization_patterns::Vector{Symbol}, jetconfigs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ JET ~/.julia/packages/JET/wMeAT/src/JET.jl:971
 [28] report_package(package::Module)
    @ JET ~/.julia/packages/JET/wMeAT/src/JET.jl:962
@aviatesk
Copy link
Owner

Can you please provide the signature of method being analyzed here?
You can inspect methods being analyzed with the following diff:

diff --git a/src/toplevel/virtualprocess.jl b/src/toplevel/virtualprocess.jl
index 134a1142..015bb8d0 100644
--- a/src/toplevel/virtualprocess.jl
+++ b/src/toplevel/virtualprocess.jl
@@ -423,6 +423,7 @@ function analyze_from_definitions!(analyzer::AbstractAnalyzer, res::VirtualProce
                     (i == n ? println : print)(io, "analyzing from top-level definitions ... $succeeded/$n")
                 end
                 analyzer = AbstractAnalyzer(analyzer, _CONCRETIZED, _TOPLEVELMOD)
+                println("analyzing ", mm.method, "...")
                 analyzer, result = analyze_method!(
                     analyzer, (first(mms)::MethodMatch).method;
                     # JETAnalyzer{BasicPass}: don't report errors unless this frame is concrete

@jakobnissen
Copy link
Contributor Author

jakobnissen commented Aug 28, 2022

Sorry for the late reply, I just got back from holidays.
I used your suggested diff to track down the method that triggered the error.
Here is a MWE package based off the method I found:

module Foo

foo(x::Union{Complex{T}, T}) where T = isdefined(x, :im)

end # module Foo

aviatesk added a commit to JuliaLang/julia that referenced this issue Aug 29, 2022
…func`

Improves the robustness of `isdefined_tfunc` when it splits `Union`
with `TypeVar`s.
Originally reported at <aviatesk/JET.jl#379>.
@aviatesk
Copy link
Owner

Thanks for the very useful MRE.
Will be fixed in upstream (JuliaLang/julia#46534).

Do you want to have this fix on 1.8?

@jakobnissen
Copy link
Contributor Author

Thanks, that was fast!

No, it's fine. I don't really need this software to be stable until about 6-12 months from now, and if necessary, I can work around it.

Keno pushed a commit to JuliaLang/julia that referenced this issue Aug 29, 2022
…func` (#46534)

Improves the robustness of `isdefined_tfunc` when it splits `Union`
with `TypeVar`s.
Originally reported at <aviatesk/JET.jl#379>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants