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

Possible type inference regression in mapreduce #38240

Closed
jipolanco opened this issue Oct 30, 2020 · 2 comments
Closed

Possible type inference regression in mapreduce #38240

jipolanco opened this issue Oct 30, 2020 · 2 comments
Labels
regression Regression in behavior compared to a previous version
Milestone

Comments

@jipolanco
Copy link
Contributor

jipolanco commented Oct 30, 2020

On Julia master, there seems to be a type inference issue when reducing over values known at compile time. This looks similar to #35800, but I'm not sure if it's related.

For instance,

x = rand(3, 4)
y = rand(20)
ndims_max(arrays...) = Val(maximum(map(ndims, arrays)))
@code_warntype ndims_max(x, y)  # returns Val(ndims(x)) = Val(2)

On Julia master:

@code_warntype ndims_max(x, y)
Variables
  #self#::Core.Const(ndims_max)
  arrays::Tuple{Matrix{Float64}, Vector{Float64}}

Body::Val{_A} where _A
1%1 = Main.map(Main.ndims, arrays)::Core.Const((2, 1))
│   %2 = Main.maximum(%1)::Int64%3 = Main.Val(%2)::Val{_A} where _A
└──      return %3

On Julia 1.5 the result Val(2) is correctly inferred:

Variables
  #self#::Core.Compiler.Const(ndims_max, false)
  arrays::Tuple{Array{Float64,2},Array{Float64,1}}

Body::Val{2}
1%1 = Main.map(Main.ndims, arrays)::Core.Compiler.Const((2, 1), false)
│   %2 = Main.maximum(%1)::Core.Compiler.Const(2, false)
│   %3 = Main.Val(%2)::Core.Compiler.Const(Val{2}(), true)
└──      return %3

Note that in this specific case, a workaround is to replace maximum(map(ndims, arrays)) by max(map(ndims, arrays)...) (see LazyArrays PR).

It seems like the issue can be tracked down to mapreduce. The following also fails on Julia master, while it works on 1.5 (note that reduce calls mapreduce):

freduce(::Val{n}) where {n} = Val(reduce(identity, (n, )))
@code_warntype freduce(Val(3))  # returns Val(3)

The same happens with foldl and foldr.

Also note that the following is correctly inferred:

fidentity(::Val{n}) where {n} = Val(identity(n))

so the issue really seems to come from the reduction step.


Version info:

julia> versioninfo()
Julia Version 1.6.0-DEV.1381
Commit 0097bddf90* (2020-10-30 08:20 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.0 (ORCJIT, skylake)
jipolanco added a commit to jipolanco/BSplineKit.jl that referenced this issue Nov 6, 2020
@JeffBezanson JeffBezanson added the regression Regression in behavior compared to a previous version label Dec 11, 2020
@JeffBezanson JeffBezanson added this to the 1.6 blockers milestone Dec 11, 2020
@JeffBezanson
Copy link
Member

Fixed on latest master.

@oscardssmith
Copy link
Member

Does/should this have a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

3 participants