aviatesk / JET.jl

An experimental code analyzer for Julia. No need for additional type annotations.

Home Page:https://aviatesk.github.io/JET.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misattributed instability due to recursion

jakobnissen opened this issue · comments

I have a codebase where recent Julia master (regression has happened the last week or so) and JET 0.8.0 have started showing new instabilities.
I believe they occur due to the JSON3 package, yet they cannot be filtered away when filtering away errors from JSON3.
To see it, run the following in an environment with JSON3 version 1.13.1 and a recent version Julia master:

module t

using JSON3

struct Reference
    x::Set{String}
end

struct JSONReference
    x::Set{String}
end

function Reference(io::IO)
    Reference(JSON3.read(io, JSONReference))
    #Reference(JSONReference(Set{String}()))
end

function Reference(x::JSONReference)
    Reference(x.x)
end

f(x) = open(i -> t.Reference(i), x)

end # module

Now run @report_opt ignored_modules=(AnyFrameModule(JSON3),) t.f(""). I get:

═════ 3 possible errors found ═════
┌ f(x::String) @ Main.t /tmp/foo/foo.jl:22
│┌ open(f::Main.t.var"#1#2", args::String) @ Base ./io.jl:393
││┌ open(f::Main.t.var"#1#2", args::String; kwargs::@Kwargs{}) @ Base ./io.jl:396
│││┌ (::Main.t.var"#1#2")(i::IOStream) @ Main.t /tmp/foo/foo.jl:22
││││┌ Main.t.Reference(io::IOStream) @ Main.t /tmp/foo/foo.jl:13
│││││ failed to optimize due to recursion: Main.t.Reference(::IOStream)
││││└────────────────────
│││┌ (::Main.t.var"#1#2")(i::IOStream) @ Main.t /tmp/foo/foo.jl:22
││││ failed to optimize due to recursion: (::Main.t.var"#1#2")(::IOStream)
│││└────────────────────
││┌ open(f::Main.t.var"#1#2", args::String; kwargs::@Kwargs{}) @ Base ./io.jl:393
│││ failed to optimize due to recursion: Base.var"#open#418"(::Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, ::typeof(open), ::Main.t.var"#1#2", ::String

This is a little weird because the code doesn't do recursion as far as I know. Perhaps inside JSON3? Indeed, switching the outcommented line in the Reference(io::IO) constructor to avoid using JSON3 removes these errors.

This suggests to me that these errors ought to be removed when filtering for ignored_modules=(AnyFrameModule(JSON3),)