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

Improve apply_type_nothrow precision #38071

Merged
merged 1 commit into from
Dec 16, 2020
Merged

Improve apply_type_nothrow precision #38071

merged 1 commit into from
Dec 16, 2020

Conversation

Keno
Copy link
Member

@Keno Keno commented Oct 17, 2020

No description provided.

Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

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

Could use more tests of all the different code paths / conditions.

base/compiler/tfuncs.jl Outdated Show resolved Hide resolved
base/compiler/tfuncs.jl Outdated Show resolved Hide resolved
base/compiler/tfuncs.jl Outdated Show resolved Hide resolved
@Keno Keno force-pushed the kf/apply_type_nothrow branch from 8be3593 to 484ee1b Compare October 19, 2020 23:41
@@ -1067,6 +1069,20 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
end
add_tfunc(fieldtype, 2, 3, fieldtype_tfunc, 0)

function valid_type_param(T)
Copy link
Member

Choose a reason for hiding this comment

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

Needs a more specific name to clarify the difference with valid_tparam. Maybe all_instances_valid_tparams?

Copy link
Member

Choose a reason for hiding this comment

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

valid_tparam_type?

@@ -1067,6 +1069,20 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
end
add_tfunc(fieldtype, 2, 3, fieldtype_tfunc, 0)

function valid_type_param(T)
isvarargtype(T) && return false
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this case is possible here.

Copy link
Member

Choose a reason for hiding this comment

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

This case is still wrong (it also was before, so it's not necessarily on this PR to fix it):

julia> Core.Compiler.apply_type_nothrow(Any[Core.Const(Ref),Core.Const(Vararg)],Type{<:Ref})
true

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this case is possible here.

Maybe, but we may want to use this function from other places, so I thought it better to cover all the cases.

@@ -1086,22 +1102,38 @@ function apply_type_nothrow(argtypes::Array{Any, 1}, @nospecialize(rt))
for i = 2:length(argtypes)
isa(u, UnionAll) || return false
ai = widenconditional(argtypes[i])
if ai ⊑ TypeVar
if ai ⊑ TypeVar || ai === DataType
Copy link
Member

Choose a reason for hiding this comment

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

Probably not true since Vararg isa DataType.

Copy link
Member Author

Choose a reason for hiding this comment

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

:(

Copy link
Member Author

Choose a reason for hiding this comment

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

@JeffBezanson and I talked about fixing this by making Vararg not a DataType, so we'll wait with this PR until @JeffBezanson gets to that change.

Keno added a commit that referenced this pull request Oct 22, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.VarargMarker`). The user facing
behavior should be mostly unchanged, since `boot.jl` now has:
```
const Vararg{T, N} = VarargMarker{T, N}
```
i.e. we have a handly UnionAll wrapper that looks just like it
used to. The biggest difference is probably that VarargMarker
does not have `.parameters`, so code that tries to reach into
that explicitly will need to be adjusted. We could provide
a compatibility `getproperty` method to adapt that, but I'd
prefer to see how many packages need updating first, before
going that route.

This is essentially complete, but a few cleanup items remain.
Keno added a commit that referenced this pull request Oct 24, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.VarargMarker`). The user facing
behavior should be mostly unchanged, since `boot.jl` now has:
```
const Vararg{T, N} = VarargMarker{T, N}
```
i.e. we have a handly UnionAll wrapper that looks just like it
used to. The biggest difference is probably that VarargMarker
does not have `.parameters`, so code that tries to reach into
that explicitly will need to be adjusted. We could provide
a compatibility `getproperty` method to adapt that, but I'd
prefer to see how many packages need updating first, before
going that route.

This is essentially complete, but a few cleanup items remain.
Keno added a commit that referenced this pull request Oct 29, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.VarargMarker`). The user facing
behavior should be mostly unchanged, since `boot.jl` now has:
```
const Vararg{T, N} = VarargMarker{T, N}
```
i.e. we have a handly UnionAll wrapper that looks just like it
used to. The biggest difference is probably that VarargMarker
does not have `.parameters`, so code that tries to reach into
that explicitly will need to be adjusted. We could provide
a compatibility `getproperty` method to adapt that, but I'd
prefer to see how many packages need updating first, before
going that route.

This is essentially complete, but a few cleanup items remain.
Keno added a commit that referenced this pull request Nov 2, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.VarargMarker`). The user facing
behavior should be mostly unchanged, since `boot.jl` now has:
```
const Vararg{T, N} = VarargMarker{T, N}
```
i.e. we have a handly UnionAll wrapper that looks just like it
used to. The biggest difference is probably that VarargMarker
does not have `.parameters`, so code that tries to reach into
that explicitly will need to be adjusted. We could provide
a compatibility `getproperty` method to adapt that, but I'd
prefer to see how many packages need updating first, before
going that route.

This is essentially complete, but a few cleanup items remain.
Keno added a commit that referenced this pull request Nov 7, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
Keno added a commit that referenced this pull request Nov 9, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
Keno added a commit that referenced this pull request Dec 9, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
Keno added a commit that referenced this pull request Dec 9, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
Keno added a commit that referenced this pull request Dec 14, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
Keno added a commit that referenced this pull request Dec 15, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
Keno added a commit that referenced this pull request Dec 15, 2020
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR #38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
@Keno Keno force-pushed the kf/apply_type_nothrow branch from 484ee1b to fd6df3c Compare December 15, 2020 21:17
@Keno Keno force-pushed the kf/apply_type_nothrow branch from fd6df3c to 1731ef9 Compare December 15, 2020 21:32
@Keno Keno requested a review from JeffBezanson December 15, 2020 21:55
@Keno Keno merged commit 0eb4723 into master Dec 16, 2020
@Keno Keno deleted the kf/apply_type_nothrow branch December 16, 2020 02:04
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
Currently `Vararg` is a DataType, but is special cased in a
bunch of places to give it special behavior (e.g. in subtyping
and of course in tuple construction). However, unlike all other
DataTypes, it cannot appear as a type parameter, which caused trouble in
PR JuliaLang#38071. Having it be a DataType is a bit of a pun of convenience
in the first place - it's a lot more similar to a tvar (which can
be considered an implementation detail of UnionAll in the same way
Vararg is an implementation detail of Tuple), which has its own
non-type object. This PR does the same to Vararg, and moves it
from being an abstract DataType with special cased behavior to
its own custom type (called `Core.TypeofVararg`). There are a
few small behavior differences, but they are mostly internal.
In particular, we no longer have `Vararg <: Type` and Vararg
objects no longer have the .parameters field. Also, things like
`Vararg{T} where T` are technically illegal now since Vararg is
not a type. However, since a lot of people are using that pattern,
I've brought it back with a deprecation (which is of course off
by default). The only things that's disallowed is `Vararg{N, N} where N`,
but I haven't seen anybody use that.
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 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

Successfully merging this pull request may close these issues.

3 participants