-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Can we have type Box{T} instead just Box? #16431
Comments
Yes, this is planned. |
Thanks @JeffBezanson . Will it go into 0.5 before release? We've mostly ported ParallelAccelerator to work with current 0.5 master, but this issue is preventing several important workloads from working. |
Yes, we will need some fix for this in 0.5. I realized another approach is possible too: instead of |
What we really want is that the type inference should give |
Problem: In Julia 0.5, the Box type is too opaque, which prevents more accurate type inference.
Example:
Function
f
is purposely constructed so that variablez
is modified by inner functiong
, whilex
is not. We can see fromg
's generated code that indeedz
is passed as aBox
, whilex
is not.However, variable
SSAValue(0)
ing
is inferred to haveAny
type because, well, the:content
ofz
is inferred to haveAny
type. The implication is that all further arithmetic operations or values that are computed fromz
will be givenAny
type.Had we given
z
a type ofBox{Int64}
, we will not have this kind of problem.Since
z
is mutable, and could be modified by inner closures to values other thanInt
, so we really do not have sufficient type information when inferencingf
. Yes, this is a valid concern, so in this case we should give it typeBox{Any}
. However, , if we writef
as:Then we should be able to safely infer
z
to beBox{Int64}
instead ofBox{Any}
. Any runtime assignment of its content to values other thanInt64
would trigger an error, like what we already do.The text was updated successfully, but these errors were encountered: