-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
End the deprecation period of using the result of a comma expression. #7813
Conversation
|
I wonder if there's a way to use Depending on what we find in such a list, we might even be able to automatically parse the deprecation dates and output a list of symbols that need to be updated. In the distant (or not-so-distant?) future we could even have a script/bot that automatically submits PRs to this effect. Automation FTW! |
changelog/comma-deprecation-error.dd
Outdated
| @@ -0,0 +1,4 @@ | |||
| The deprecation period of using the result of comma expression has ended | |||
|
|
|||
| Comma expressions have proven to be a frequent source of confusion, and bug. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: bug > bugs.
src/dmd/expressionsem.d
Outdated
| @@ -5844,7 +5844,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor | |||
|
|
|||
| e.type = e.e2.type; | |||
| if (e.type !is Type.tvoid && !e.allowCommaExp && !e.isGenerated) | |||
| e.deprecation("Using the result of a comma expression is deprecated"); | |||
| e.deprecation("The result of a comma expression cant be used"); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: cant > can't.
src/dmd/expressionsem.d
Outdated
| @@ -6272,7 +6272,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor | |||
| /* Rewrite to get rid of the comma from rvalue | |||
| */ | |||
| if (!(cast(CommaExp)exp.e2).isGenerated) | |||
| exp.deprecation("Using the result of a comma expression is deprecated"); | |||
| exp.error("The result of a comma expression cant be used"); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well cant is the existing DMD style:
> ag "cant" | wc -l
466
> ag "can't" | wc -l
128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing bad grammar should not be justification for adding more bad grammar!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have seen @WalterBright repeatedly use "cant" - even in recent PRs. That was my motivation to use "cant".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"cant" is not a word. I believe @WalterBright made a mistake in those PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah let's fix those. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I changed it to can't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JinShil Actually, "cant" is a word... but it has a different meaning. :-D
@wilzbach The next time Walter submits a PR with the wrong use of "cant", somebody should point it out so that it can be fixed. :-P
test/fail_compilation/commaexp.d
Outdated
| fail_compilation/commaexp.d(38): Error: The result of a comma expression cant be used | ||
| fail_compilation/commaexp.d(39): Error: The result of a comma expression cant be used | ||
| fail_compilation/commaexp.d(41): Error: The result of a comma expression cant be used | ||
| fail_compilation/commaexp.d(42): Error: The result of a comma expression cant be used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
test/fail_compilation/diag10862.d
Outdated
| @@ -57,7 +57,7 @@ fail_compilation/diag10862.d(77): Error: assignment cannot be used as a conditio | |||
| fail_compilation/diag10862.d-mixin-80(80): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |||
| fail_compilation/diag10862.d-mixin-81(81): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |||
| fail_compilation/diag10862.d-mixin-82(82): Error: assignment cannot be used as a condition, perhaps `==` was meant? | |||
| fail_compilation/diag10862.d-mixin-83(83): Deprecation: Using the result of a comma expression is deprecated | |||
| fail_compilation/diag10862.d-mixin-83(83): Error: The result of a comma expression cant be used | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
test/fail_compilation/ice10949.d
Outdated
| @@ -1,7 +1,7 @@ | |||
| /* | |||
| TEST_OUTPUT: | |||
| --- | |||
| fail_compilation/ice10949.d(12): Deprecation: Using the result of a comma expression is deprecated | |||
| fail_compilation/ice10949.d(12): Error: the result of a comma expression cant be used | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| @@ -136,7 +136,8 @@ static assert(bazra(14)==64); | |||
|
|
|||
| void moreCommaTests() | |||
| { | |||
| auto k = (containsAsm(), containsAsm()); | |||
| (containsAsm(), containsAsm()); | |||
| auto k = containsAsm(); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh? Shouldn't this be:
containsAsm();
auto k = containsAsm();
instead? This change doesn't make sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it's nice to leave the use of the comma expression in. Here we can do this as containsAsm() is a no-op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see why now. Nevermind, carry on. :-P
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
I like the idea, but it would be a lot easier for Phobos. For dmd you are basically left with https://github.com/dlang/dmd/pull/7760/files is one of the first PRs to use the deprecated pattern in dmd too. |
544bf0c
to
be0edfa
Compare
|
So this is finally passing the testsuite 🚀 and just in case someone was wondering obviously my motivation is to make this an error with 2.079, s.t. comma expressions can be re-purposed for built-in tuples. |
test/runnable/testscope.d
Outdated
| @@ -294,7 +294,7 @@ void test11() | |||
| static int i; | |||
| bar11(p, &i); | |||
|
|
|||
| bar11((i,p), &i); // comma expressions are deprecated, but need to test them | |||
| bar11(p, &i); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was specifically testing the comma operator. Now that it produces an error, it should probably be moved to the fail_compilation tests. However, given that the equivalent expression already exists on line 295, it would probably be ok to just delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was very careful not to delete anything, but yeah in this case it does make sense. Thanks!
| @@ -7866,7 +7867,7 @@ bool test16022() | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue 16022 was very specific to the comma operator. Since the result of a comma expression now emits an error, this test should no longer compile, and should probably be moved to the fail_compilation test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I copied it to fail compilation. I don't see any reason to remove it here though.
src/dmd/expressionsem.d
Outdated
| @@ -6272,7 +6272,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor | |||
| /* Rewrite to get rid of the comma from rvalue | |||
| */ | |||
| if (!(cast(CommaExp)exp.e2).isGenerated) | |||
| exp.deprecation("Using the result of a comma expression is deprecated"); | |||
| exp.error("The result of a comma expression can't be used"); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this to say "The result of a comma expression is deprecated and can no longer be used". But, it's ok the way it is; I'll pull it regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm it's not deprecated anymore, it's a real error and should be displayed to the user as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @wilzbach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to distinguish "can't be used" (due to some technical limitation) from "can't be used" (because we decided to forbid it). How about "Using the result of a comma expression is not allowed" ?
| @@ -0,0 +1,4 @@ | |||
| The deprecation period of using the result of comma expression has ended | |||
|
|
|||
| Comma expressions have proven to be a frequent source of confusion, and bugs. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include an example that now fails to compile and show how to correct it. Perhaps include an example showing how the comma expression can still be used without using the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping I could avoid the redundancies from https://dlang.org/deprecate.html#Using%20the%20result%20of%20a%20comma%20expression, but okay copying doesn't cost us much.
I copied the text I have written for dlang.org a while ago.
changelog/comma-deprecation-error.dd
Outdated
| foo((++a, b)); | ||
|
|
||
| synchronized (lockA, lockB) {} | ||
| // isn't currently implemented, but still compiles "thanks" to the comma operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"thanks" sounds a bit condescending. Perhaps replace with due.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also submitted for dlang.org: dlang/dlang.org#2152
| } | ||
| static assert((test2!f9525(), true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the static assert not necessary anymore? Or will the static assert inside the function take care of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the static assert was only there, s.t. the function got evaluated and the static assert inside of it could trigger, hence I added evalTest1 and evalTest2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
| --- | ||
|
|
||
| It's also common to use the comma operator in for-loop increment | ||
| statements to allow multiple expressions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be clearer that this use case is not affected.
changelog/comma-deprecation-error.dd
Outdated
| ) | ||
| $(H4 Rationale) | ||
| $(P The comma operator leads to unintended behavior (see below for a selection) | ||
| Moreover it is not commonly used and it blocks the ability to implement tuples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It blocks implementing tuples as a language feature using commas, not in general
changelog/comma-deprecation-error.dd
Outdated
| $(P The comma operator leads to unintended behavior (see below for a selection) | ||
| Moreover it is not commonly used and it blocks the ability to implement tuples. | ||
|
|
||
| A selection of problems through the accidental use of the comma operator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly all of these examples are entirely unconvincing because they could be caught by a "discarding result of side-effect-free subexpression" warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took them from here: https://dlang.org/deprecate.html#Using%20the%20result%20of%20a%20comma%20expression
dlang/dlang.org#1308
If you have better examples, just let me know.
changelog/comma-deprecation-error.dd
Outdated
| // will always be reached | ||
| } | ||
|
|
||
| void foo(int x) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this example. Perhaps it would make sense for void foo(int x, int y=0) ?
src/dmd/expressionsem.d
Outdated
| @@ -6272,7 +6272,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor | |||
| /* Rewrite to get rid of the comma from rvalue | |||
| */ | |||
| if (!(cast(CommaExp)exp.e2).isGenerated) | |||
| exp.deprecation("Using the result of a comma expression is deprecated"); | |||
| exp.error("The result of a comma expression can't be used"); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to distinguish "can't be used" (due to some technical limitation) from "can't be used" (because we decided to forbid it). How about "Using the result of a comma expression is not allowed" ?
|
Addressed all comments except for:
It took them from here: https://dlang.org/deprecate.html#Using%20the%20result%20of%20a%20comma%20expression |
|
@JinShil you still have this on "requested changes". I addressed your comments and copied the files over to |
|
Woohoo!!!! The comma operator is officially dead!!! celebration |
The deprecation period could have ended a lot earlier.
DMD deprecations should really be tracked at a common place, s.t. for every
release cycle old deprecations can be bumped accordingly.
dlang.org: dlang/dlang.org#2151