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

poor type inference in mapreduce #43328

Closed
oscardssmith opened this issue Dec 3, 2021 · 2 comments
Closed

poor type inference in mapreduce #43328

oscardssmith opened this issue Dec 3, 2021 · 2 comments

Comments

@oscardssmith
Copy link
Member

In Julia Master (and 1.6)

julia> f(x) = (T=eltype(x); mapreduce(v->T(v), +, x))
julia> @code_warntype f([3,4,5])
MethodInstance for f(::Vector{Int64})
  from f(x) in Main at REPL[2]:1
Arguments
  #self#::Core.Const(f)
  x::Vector{Int64}
Locals
  #3::var"#3#4"{DataType}
  T::Type{Int64}
Body::Any
1 ─      (T = Main.eltype(x))
│   %2 = Main.:(var"#3#4")::Core.Const(var"#3#4")
│   %3 = Core.typeof(T::Core.Const(Int64))::Core.Const(DataType)
│   %4 = Core.apply_type(%2, %3)::Core.Const(var"#3#4"{DataType})
│        (#3 = %new(%4, T::Core.Const(Int64)))
│   %6 = #3::Core.Const(var"#3#4"{DataType}(Int64))
│   %7 = Main.mapreduce(%6, Main.:+, x)::Any
└──      return %7

Could we make type inference smarter here?

@oscardssmith oscardssmith added compiler:inference Type inference fold sum, maximum, reduce, foldl, etc. labels Dec 3, 2021
@tkf
Copy link
Member

tkf commented Dec 3, 2021

It looks like #23618 (which could be solved by #40985).

@simeonschaub
Copy link
Member

Yes, it's a duplicate of #23618

@simeonschaub simeonschaub removed compiler:inference Type inference fold sum, maximum, reduce, foldl, etc. labels Dec 3, 2021
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

3 participants