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

Fix inference for splatting numbers. Fixes #22291 #22292

Closed
wants to merge 1 commit into from

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Jun 8, 2017

No description provided.

@martinholters
Copy link
Member

It would be oh so nice if we could do constant propagation to the extent that abstract_iteration could figure out the constant length here, but until then this is probably OK. Assuming no-ones defines his own Number type which has other iteration properties, that is.

@Keno
Copy link
Member

Keno commented Jun 8, 2017

Assuming no-ones defines his own Number type which has other iteration properties, that is.

This is the problem though, because this would generate incorrect code in that case. We can't really have inference operate on the "let's hope nobody ever writes code like this" hypothesis.

@timholy
Copy link
Sponsor Member Author

timholy commented Jun 8, 2017

If there's no better way to fix this, to be perfectly honest I could live with tt0 <: Union{Int, UInt}.

@timholy
Copy link
Sponsor Member Author

timholy commented Jun 8, 2017

I guess another option would be to redefine number iterators so that the type system encodes the fact that they have length 1:

start(x::Number) = Val{false}()
next(x::Number, ::Val{false}) = (x, Val{true}())
done{s}(x::Number, ::Val{s}) = s

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jun 8, 2017

#18823 will also address / fix this

@timholy
Copy link
Sponsor Member Author

timholy commented Jun 8, 2017

Given that there is a more general fix on the way, how about I add the tt0 <: Union{Int, UInt} as a hack for now? With #22210 I need it for indexing. (Changes in inlining ended up changing the inferred result; presumably we don't want that to happen, but that's where we are now.)

@martinholters
Copy link
Member

Some more possible solutions that come to my mind:

  • make numbers non-iterable? #7903
  • Do this for tt0 <: Number and change jl_f__apply to effectively not splat Numbers. But having splatting subtly different from iteration may be a bit too surprising.
  • Do this for tt0 <: Number provided that the methods that would be called for start, next, and done for tt0 are the ones that are defined in Base for Number.

@JeffBezanson
Copy link
Sponsor Member

There is some precedent for inference using a corenumtype union to restrict optimizations to known types.

@timholy timholy force-pushed the teh/splatting_numbers_inference branch from 57776ab to bef89bd Compare June 17, 2017 11:19
@timholy
Copy link
Sponsor Member Author

timholy commented Jun 17, 2017

This passed tests, so barring objections I'll merge soon. Hmm, fixing the inference didn't fix all the performance problems. Would be good to pursue this further, but in #22210 I took the pragmatic route and just worked around it. I think there's no immediate pressure to merge this, so I will just let this sit until someone else feels the need.

@DilumAluthge DilumAluthge deleted the teh/splatting_numbers_inference branch March 25, 2021 22:08
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

Successfully merging this pull request may close these issues.

None yet

5 participants