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

Inference failure when splatting a number #19957

Closed
dpsanders opened this issue Jan 10, 2017 · 11 comments · Fixed by #30578
Closed

Inference failure when splatting a number #19957

dpsanders opened this issue Jan 10, 2017 · 11 comments · Fixed by #30578
Labels
compiler:inference Type inference good first issue Indicates a good issue for first-time contributors to Julia

Comments

@dpsanders
Copy link
Contributor

dpsanders commented Jan 10, 2017

Minimal reproducible example:

julia> immutable MyFunc{F}
               func::F
          end

julia> (f::MyFunc{F}){F}(x) = f.func(x...)

julia> f = MyFunc(x -> 1 + x)
MyFunc{##15#16}(#15)

julia> f((1,))
2

julia> g(f, x) = f(x...)
g (generic function with 1 method)


julia> @code_warntype g(f, (1,))
Variables:
  #self#::#g
  f::MyFunc{##15#16}
  x::Tuple{Int64}

Body:
  begin
      return (Core._apply)((Core.getfield)(f::MyFunc{##15#16},:func)::##15#16,(Core.getfield)(x::Tuple{Int64},1)::Int64)::Any
  end::Any

cc @jrevels

@dpsanders dpsanders changed the title Inference failure when splatting tuple argument in a higher-order function Inference failure when splatting tuple argument into a function object Jan 10, 2017
@yuyichao
Copy link
Contributor

yuyichao commented Jan 10, 2017

It's due to splatting of a number and not a tuple.

julia> f(x) = (x...)
f (generic function with 1 method)

julia> @code_warntype f(1)
Variables:
  #self#::#f
  x::Int64

Body:
  begin 
      return (Core._apply)(Core.tuple,x::Int64)::Tuple
  end::Tuple

julia> f(1)
(1,)

@yuyichao yuyichao changed the title Inference failure when splatting tuple argument into a function object Inference failure when splatting a number Jan 10, 2017
@yuyichao
Copy link
Contributor

And this seems to be caused by the special handling of Core._apply not being able to handle scalar input (or generic iterables). Handling of generic iterables with compile time known size might be useful although it seems non-trivial....

@kshyatt kshyatt added the compiler:inference Type inference label Jan 10, 2017
@vtjnash
Copy link
Member

vtjnash commented Jan 10, 2017

would be fixed by #12579 then?

@yuyichao
Copy link
Contributor

Sort of. Although it doesn't infer the length?

@JeffBezanson
Copy link
Member

As long as numbers are iterable (which, most likely, they will continue to be) it's worth adding handling for this to _apply inference.

@dpsanders
Copy link
Contributor Author

dpsanders commented May 27, 2017

This has now been fixed:

julia> @code_warntype g(f, (1,))
Variables:
  #self#::#g
  f::#f
  x::Tuple{Int64}

Body:
  begin
      return (Core.tuple)((Core.getfield)(x::Tuple{Int64}, 1)::Int64, 1)::Tuple{Int64,Int64}
  end::Tuple{Int64,Int64}

@tkelman
Copy link
Contributor

tkelman commented May 27, 2017

could use a test

@dpsanders dpsanders reopened this May 27, 2017
@dpsanders
Copy link
Contributor Author

Good point.

@tkelman
Copy link
Contributor

tkelman commented May 27, 2017

a partial related test was added in #20343, but it looks a bit different?

@mbauman
Copy link
Member

mbauman commented Dec 10, 2018

Does this really just need a test in order to close it?

@mbauman mbauman added the good first issue Indicates a good issue for first-time contributors to Julia label Dec 10, 2018
@StefanKarpinski
Copy link
Member

@kshyatt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants