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

reduce usage of _pure_meta #32427

Merged
merged 5 commits into from
Jul 22, 2020
Merged

reduce usage of _pure_meta #32427

merged 5 commits into from
Jul 22, 2020

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Jun 26, 2019

In preparation for increasing the optimizations that are enabled by this flag (#32368), let's try to reduce the number of places we are using it.

The new single convert method here even lets us do things like convert(Tuple{Vararg{AbstractFloat}}, (2,)), which we couldn't previously express through dispatch.

base/iterators.jl Outdated Show resolved Hide resolved
base/iterators.jl Outdated Show resolved Hide resolved
base/tuple.jl Show resolved Hide resolved
@@ -14,6 +14,11 @@ true
"""
NTuple

# convenience function for extracting N from a Tuple (if defined)
# else return `nothing` for anything else given (such as Vararg or other non-sized Union)
_counttuple(::Type{<:NTuple{N,Any}}) where {N} = N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you have a @nospecialize on the argument in this case? I'm still not 💯% clear on it, but since we don't need to generate any more specializations/method-instances other than the two provided, should these be marked @nospecialize? (Or is that done automatically somehow given their tiny function bodies?)

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Sep 11, 2019

Fails CI due to #32392 (type system bug)

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jul 14, 2020

Fails CI due to #32392 (type system bug)

Realized I was probably just being foolish, and rewrote this test to be hopefully more sensible (typeintersect using top instead of subtype using bottom). Should be good for review now.

Comment on lines +19 to +20
_counttuple(::Type{<:NTuple{N,Any}}) where {N} = N
_counttuple(::Type) = nothing
Copy link
Member

@NHDaly NHDaly Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the discussion here:
#32495 (comment)

Can we name this something not private and export it? This is something we use all the time in our code at RelationalAI, where we do a lot of stuff with tuples. It also seems like something that other code will use a lot, like DataFrames, CSV, etc.

In that other comment I suggested arity(::Type{<:Tuple}) as one suggestion. I still like that best, but open to others!

  • arity()
  • tupletypewidth() / tuple_type_width()
  • tupletypecount() / tuple_type_count()
  • tuplearity()

Or maybe we can break out a separate issue to track this, so that it doesn't hold up this PR?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I made this slightly internal just so it wouldn't delay this PR. Makes sense to me to track this as a separate issue to consider exporting it!

Copy link
Member

@NHDaly NHDaly Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Opened #36820.

Resolved.

also fix the concrete_min answer for `Union{}` (which is a valid result
for the NTuple TypeVar to receive)
Avoid specifying subtype constraints on concrete types also, as this
makes them more complicated, but no different.
@vtjnash vtjnash merged commit 3699192 into master Jul 22, 2020
@vtjnash vtjnash deleted the jn/Tuple-pure branch July 22, 2020 21:02
end

tuple_type_cons(::Type, ::Type{Union{}}) = Union{}
function tuple_type_cons(::Type{S}, ::Type{T}) where T<:Tuple where S
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some important packages seem to use this; we should add it back in base/deprecated.jl.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, tuple_type_head as well.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But not tuple_type_tail?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, that one was still in use by _totuple

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.

4 participants