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

typeassert syntax deprecations #17445

Merged
merged 3 commits into from
Jul 21, 2016
Merged

typeassert syntax deprecations #17445

merged 3 commits into from
Jul 21, 2016

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Jul 15, 2016

deprecations for #964 and #16071

this will let us reuse global x::T and x::T = 1 to mean a typed global instead of the current meaning of type-assert

it will also let us reuse x::T (in statement position) to always mean typeassert, instead of sometimes meaning local variable declaration (depending on various positional and context rules)

@vtjnash vtjnash added this to the 0.5.0 milestone Jul 15, 2016
@tkelman tkelman added the needs decision A decision on this change is needed label Jul 15, 2016
@tkelman
Copy link
Contributor

tkelman commented Jul 15, 2016

will doing what this deprecation says and adding local x::T always mean the same for code that needs to still run on 0.4?

@vtjnash
Copy link
Member Author

vtjnash commented Jul 16, 2016

that's exactly the intent. this adds a deprecation to those codepaths, but doesn't change their behavior

@@ -1,11 +1,11 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

function convert(::Type{Float32}, val::Float16)
ival::UInt32 = reinterpret(UInt16, val)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this also deprecate this form, or did you just add local because you're deprecating the no-assignment form used for ret ?

Copy link
Member Author

Choose a reason for hiding this comment

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

the code just looked silly with only local on the ret declation. I didn't deprecate this form, since it's not clear to me that is decided.

@toivoh
Copy link
Contributor

toivoh commented Jul 16, 2016

I thought the idea was that :: in an expression should always be a type assert, and :: in local/global should mean that you create a typed variable.

Why do you want x::T = 1 to create a typed global? Seems like it will be more confusing and be an additional gotcha when you move code between global and local scope?

@tkelman
Copy link
Contributor

tkelman commented Jul 16, 2016

very hard to grep for this in packages, and the warning is kind of confusing when you do

julia> x::Float64 = 1.0

WARNING: deprecated syntax "global x::Float64".

@tkelman
Copy link
Contributor

tkelman commented Jul 16, 2016

and from

julia> function foo3(y)
    z::Float64
    z+y
end

WARNING: deprecated syntax "z::Float64".
Use "local z::Float64" instead.

WARNING: deprecated syntax "global z::Float64".

the double warning is also confusing

@vtjnash
Copy link
Member Author

vtjnash commented Jul 16, 2016

the double warning is also confusing

no kidding, but that's a fairly accurate report on what this code used to mean. because you don't have an assignment to z, what looks like a local declaration (z::Float64) instead is actually parsed as a type-assert for the global variable z (and where both meanings are now deprecated).

very hard to grep for this in packages

yes, that's pretty much the entire point behind this deprecation

@vtjnash
Copy link
Member Author

vtjnash commented Jul 16, 2016

Why do you want x::T = 1 to create a typed global? Seems like it will be more confusing and be an additional gotcha when you move code between global and local scope?

I think it's more consistent to be either a syntax error or an implicit declaration. The current meaning of a type-assert on the old value seems least useful to me, although it is consistent with the current behavior for mutating assignments such as x::Int += 1. If it means a typed global, then it would be meaningful to write:

global x
x::T = 1

@tkelman
Copy link
Contributor

tkelman commented Jul 16, 2016

the deprecation warning should say - the syntax used in the code is deprecated, and what to replace it with. right now it does neither, the warning includes keywords that the user code did not.

@vtjnash
Copy link
Member Author

vtjnash commented Jul 16, 2016

we don't have good tracking in the scheme code of what the user input, I can add that the user should use typeassert instead.

@toivoh
Copy link
Contributor

toivoh commented Jul 17, 2016

@vtjnash: I think that a syntax error for x::T = 1 would be best and most consistent, since it alerts people who would expect either way of working that they should make their intentions clear.

Quoting @StefanKarpinski from #16071:

It's confusing that x::T is an assertion in some contexts and a declaration that x is a local variable of type T in other contexts.

I think that we should reduce the confusion to a minimum and only declare typed variables using local/global.

@tkelman
Copy link
Contributor

tkelman commented Jul 18, 2016

the lack of line numbers for these warnings is really a bummer

(sorry about the repeat posts, phone being stupid)

@StefanKarpinski
Copy link
Member

@vtjnash: I think we need to make a go/no go decision on this change today. Personally, I think that we should deprecate this, but I'm not sure that it's a great idea to rush the deprecation into a release right at the very end of the process. This would be a perfectly acceptable deprecation to do early in the next release cycle.

@tkelman
Copy link
Contributor

tkelman commented Jul 20, 2016

preferably with line numbers if at all possible, so people aren't at a complete loss about what they need to fix

@vtjnash
Copy link
Member Author

vtjnash commented Jul 20, 2016

@tkelman the nice thing about error reporting features is that they can be added during the RC. the other nice thing about them is that they should not be added in the same PR as a feature decision.

@vtjnash
Copy link
Member Author

vtjnash commented Jul 20, 2016

I'm not sure that it's a great idea to rush the deprecation into a release right at the very end of the process

Can you clarify this? I don't think this'll have much of an impact on packages, since it's also not a common idiom in base. It's also not the same as adding a feature, since this is purely just deprecating old syntax by adding warnings whenever that codepath is active.

@StefanKarpinski
Copy link
Member

Putting anything into a release right at the end is kind of sketchy.

@tkelman
Copy link
Contributor

tkelman commented Jul 20, 2016

good point about separation of concerns, but with the current state of the error reporting, doing this now is a net negative. any deprecation will be noticed, base idioms don't really correlate with idioms used in packages.

@JeffBezanson
Copy link
Member

I think it's ok to keep x::T = ... as-is, since the x there is clearly not in value position. The really important thing to deprecate is x::T in statement position where x is local.

I don't think we should have a deprecation warning at all for x::T where x is global, since that is currently a typeassert and can continue to be a typeassert in the future. IIUC, the construct whose behavior will change is global x::T, which is currently a typeassert but should be a declaration (to be consistent with local x::T). This will also fix the double-warning issue. When we see an actual global keyword (as part of the syntax global x::T), we should say something like "use global x; x::T instead; declaring types of globals is not yet supported but may be in the future".

also deprecates `global x::T` meaning a typeassert

also fix a bug where a type-assert was considered to be effect-free,
causing it to be quasi-converted into a local variable declaration

ref #964
…local variable

and fix a bug in env.jl where a typeassert was intended

ref #16071
@vtjnash
Copy link
Member Author

vtjnash commented Jul 21, 2016

Any opinion on whether x[]::T = ... should be deprecated? I've opted to leave it for now, since unlike the other syntax here, we wouldn't want it to later mean something different.

@JeffBezanson
Copy link
Member

Yes, let's leave it for now to focus this change on the most urgent part.

@JeffBezanson JeffBezanson merged commit fa20d26 into master Jul 21, 2016
@JeffBezanson
Copy link
Member

I'll do NEWS and doc updates for this.

@tkelman tkelman deleted the jn/typeassert-syntax branch July 21, 2016 15:51
mfasi pushed a commit to mfasi/julia that referenced this pull request Sep 5, 2016
deprecate `x::T` as type declaration syntax, ref JuliaLang#16071

deprecate `x::T = 0` where x is global and `global x::T` meaning typeassert, ref JuliaLang#964

also fix a bug where a typeassert was considered to be effect-free,
causing it to be quasi-converted into a local variable declaration

fix a bug in env.jl where a typeassert was intended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision A decision on this change is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants