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

type inference problem (regression?) in nightly #36486

Closed
sbromberger opened this issue Jun 30, 2020 · 5 comments
Closed

type inference problem (regression?) in nightly #36486

sbromberger opened this issue Jun 30, 2020 · 5 comments
Labels
compiler:inference Type inference

Comments

@sbromberger
Copy link
Contributor

sbromberger commented Jun 30, 2020

For the last several days, our CI for nightly has been failing with an unexpected type inference issue. This is as minimal a WE as I can come up with right now (and it's not really minimal, so my apologies):

using LightGraphs, LightGraphs.Parallel, LightGraphs.VertexSubsets
g = Graph(0x10, 20)
julia> @code_warntype Parallel.vertex_cover(g, 4, RandomVertexCover(); parallel=:threads)
Variables
  #unused#::Core.Compiler.Const(LightGraphs.Parallel.var"#vertex_cover##kw"(), false)
  @_2::NamedTuple{(:parallel,),Tuple{Symbol}}
  @_3::Core.Compiler.Const(LightGraphs.Parallel.vertex_cover, false)
  g::LightGraphs.SimpleGraphsCore.SimpleGraph{UInt8}
  reps::Int64
  alg::Core.Compiler.Const(LightGraphs.VertexSubsets.RandomSubset{Random._GLOBAL_RNG}(Random._GLOBAL_RNG()), false)
  parallel::Symbol
  seed::Int64
  @_9::Symbol
  @_10::Int64

Body::Any
1 ─ %1  = Base.haskey(@_2, :parallel)::Core.Compiler.Const(true, false)
│         %1
│         (@_9 = Base.getindex(@_2, :parallel))
└──       goto #3
2 ─       Core.Compiler.Const(:(@_9 = :threads), false)
3 ┄       (parallel = @_9)
│   %7  = Base.haskey(@_2, :seed)::Core.Compiler.Const(false, false)
└──       goto #5 if not %7
4 ─       Core.Compiler.Const(:(@_10 = Base.getindex(@_2, :seed)), false)
└──       Core.Compiler.Const(:(goto %12), false)
5 ┄       (@_10 = -1)
│         (seed = @_10::Core.Compiler.Const(-1, false))
│   %13 = (:parallel, :seed)::Core.Compiler.Const((:parallel, :seed), false)
│   %14 = Core.apply_type(Core.NamedTuple, %13)::Core.Compiler.Const(NamedTuple{(:parallel, :seed),T} where T<:Tuple, false)
│   %15 = Base.structdiff(@_2, %14)::Core.Compiler.Const(NamedTuple(), false)
│   %16 = Base.pairs(%15)::Core.Compiler.Const(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}(), false)
│   %17 = Base.isempty(%16)::Core.Compiler.Const(true, false)
│         %17
└──       goto #7
6 ─       Core.Compiler.Const(:(Base.kwerr(@_2, @_3, g, reps, alg)), false)
7 ┄ %21 = LightGraphs.Parallel.:(var"#vertex_cover#16")(parallel, seed::Core.Compiler.Const(-1, false), @_3, g, reps, alg)::Any
└──       return %21

This infers correctly on 1.4.1 but does not on 1.6.0-dev.

The call is actually just this:

alg = parallel == :threads ?  LightGraphs.VertexSubsets.ThreadedRandomSubset(reps, rng=rng) : LightGraphs.VertexSubsets.DistributedRandomSubset(reps, rng=rng)

LightGraphs.VertexSubsets.vertex_cover(g, alg)

and each possibility returns a Vector{eltype(g)}. (Edit: that is, if you run the function in each branch by itself, it infers correctly.)

Again, this is fine in 1.4.1 but breaks in 1.6.0.

@sbromberger
Copy link
Contributor Author

Here's the code_warntype for 1.4.1, for completeness:

julia> @code_warntype Parallel.vertex_cover(g, 4, RandomVertexCover(); parallel=:threads)
Variables
  #unused#::Core.Compiler.Const(LightGraphs.Parallel.var"#vertex_cover##kw"(), false)
  @_2::NamedTuple{(:parallel,),Tuple{Symbol}}
  @_3::Core.Compiler.Const(LightGraphs.Parallel.vertex_cover, false)
  g::LightGraphs.SimpleGraphsCore.SimpleGraph{UInt8}
  reps::Int64
  alg::Core.Compiler.Const(LightGraphs.VertexSubsets.RandomSubset{Random._GLOBAL_RNG}(Random._GLOBAL_RNG()), false)
  parallel::Symbol
  seed::Int64
  @_9::Symbol
  @_10::Int64

Body::Array{UInt8,1}
1 ─ %1  = Base.haskey(@_2, :parallel)::Core.Compiler.Const(true, false)
│         %1
│         (@_9 = Base.getindex(@_2, :parallel))
└──       goto #3
2 ─       Core.Compiler.Const(:(@_9 = :threads), false)
3 ┄       (parallel = @_9)
│   %7  = Base.haskey(@_2, :seed)::Core.Compiler.Const(false, false)
└──       goto #5 if not %7
4 ─       Core.Compiler.Const(:(@_10 = Base.getindex(@_2, :seed)), false)
└──       Core.Compiler.Const(:(goto %12), false)
5 ┄       (@_10 = -1)
│         (seed = @_10::Core.Compiler.Const(-1, false))
│   %13 = (:parallel, :seed)::Core.Compiler.Const((:parallel, :seed), false)
│   %14 = Core.apply_type(Core.NamedTuple, %13)::Core.Compiler.Const(NamedTuple{(:parallel, :seed),T} where T<:Tuple, false)
│   %15 = Base.structdiff(@_2, %14)::Core.Compiler.Const(NamedTuple(), false)
│   %16 = Base.pairs(%15)::Core.Compiler.Const(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}(), false)
│   %17 = Base.isempty(%16)::Core.Compiler.Const(true, false)
│         %17
└──       goto #7
6 ─       Core.Compiler.Const(:(Base.kwerr(@_2, @_3, g, reps, alg)), false)
7 ┄ %21 = LightGraphs.Parallel.:(var"#vertex_cover#16")(parallel, seed::Core.Compiler.Const(-1, false), @_3, g, reps, alg)::Array{UInt8,1}
└──       return %21

@JeffBezanson JeffBezanson added the compiler:inference Type inference label Jun 30, 2020
@JeffBezanson
Copy link
Member

Looks similar in nature to #35800.

@sbromberger
Copy link
Contributor Author

I don't think we saw these errors going back to May. It's just been in the last couple of weeks, but I'll need to check.

@sbromberger
Copy link
Contributor Author

We were good as of June 4 at the earliest; perhaps even later than that: sbromberger/LightGraphs.jl#1440

@sbromberger
Copy link
Contributor Author

@abhinavmehndiratta noticed that the inference issues only happen when the vector returned is empty. If the vector contains values, then no inference error is generated in our test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

3 participants