Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

Remove usage of CommaExp#1561

Merged
MartinNowak merged 1 commit intodlang:masterfrom
mathias-lang-sociomantic:no-more-commaexp
May 8, 2016
Merged

Remove usage of CommaExp#1561
MartinNowak merged 1 commit intodlang:masterfrom
mathias-lang-sociomantic:no-more-commaexp

Conversation

@mathias-lang-sociomantic
Copy link
Contributor

This removes all usage of the comma expression in D runtime.
One of the commit is a bug fix, the second one should be no-ops.
The only useful pattern I could find for CommaExp is within for loops, however the cost/benefit ratio is too damn low to justify it.
Ideally we should have a way to do it in a more D-ish maner, e.g. for (; i < j; { i++; j-- }) however this isn't currently inlined in -O -inline by DMD, so I do not want to introduce such a syntax ATM.

About the changes: If the condition is dependent on both the post-loop operations, I moved them together to make it more readable (see the for -> while change for example).

@ibuclaw
Copy link
Member

ibuclaw commented May 6, 2016

Bugzilla reference for bugfix?

@ibuclaw
Copy link
Member

ibuclaw commented May 6, 2016

Unittests for bug fix?

@Geod24
Copy link
Member

Geod24 commented May 6, 2016

Updated with an issue number. But unittesting a constant doesn't really makes sense.

@schveiguy
Copy link
Member

schveiguy commented May 6, 2016

As much as I want to remove general comma operator use support, I don't think we will ever get acceptance from @WalterBright on removing it inside for loop increments. I'd say leave those. I could be wrong, but the rewrites for those for loops are... awful. The others I agree with completely.

@wilzbach
Copy link
Contributor

wilzbach commented May 6, 2016

@mathias-lang-sociomantic how about enabling dscanner in the build setup?
It allows to check for the use of the comma operator (and a lot of other cool stuff), we use it at Phobos and it's not that hard to setup ;-)

@schveiguy
Copy link
Member

Note: if we were to overtake comma operator for tuple use, We can go in stages:

  1. Deprecate/remove general comma operator use. Leave for increments as allowed
  2. Add tuple support, still allow comma operator in for loop increment, but treat whole expression as a tuple.
  3. (optional) remove support for comma operator in for-loop, require using specific tuple syntax (.e.g. for(;;(i++, j++)) )

@leandro-lucarella-sociomantic
Copy link
Contributor

I recommend splitting the PR in two, one for the fixed issue (which seems uncontroversial) and the comma thing (that seems a bit more controversial).

@Geod24
Copy link
Member

Geod24 commented May 6, 2016

As much as I want to remove general comma operator use support, I don't think we will ever get acceptance from @WalterBright on removing it inside for loop increments. I'd say leave those. I could be wrong, but the rewrites for those for loops are... awful. The others I agree with completely.

The usage in for loop is the only valid usage I could find through the code base so far (and luckily the most common one). I wouldn't call the rewrite awful, except for the requirement to duplicate statement when continue is used.

There is more usage of the comma operator in for loop than just increment. I found some quite common for(; !a.empty; a.popFront, b.popFront). Some assignments as well.
Ultimately, I'd like the {} syntax to not introduce so much overhead.

@mathias-lang-sociomantic how about enabling dscanner in the build setup?

Feel free to do it, but that's not the point of this P.R.

Note: if we were to overtake comma operator for tuple use, We can go in stages:

Good points. I had a wrong memory about the proposed tuple syntax, and thought it would make the grammar ambiguous. I'll rework the DMD code to allow it in for loops.

I recommend splitting the PR in two, one for the fixed issue (which seems uncontroversial) and the comma thing (that seems a bit more controversial).

Will do.

@schveiguy
Copy link
Member

There is more usage of the comma operator in for loop than just increment.

By increment, I just meant the increment (3rd) expression of the for statement.

@Geod24
Copy link
Member

Geod24 commented May 6, 2016

Updated

Using CommaExpression is discouraged anywhere except increment of `for` loops.
@schveiguy
Copy link
Member

OK, this looks good I think. Even if we don't remove comma operators from the language in some capacity, these changes are very minor and I think the new code is clearer.

@DmitryOlshansky
Copy link
Member

LGTM

BOOL ListView_GetSubItemRect(HWND w, int i, int isi, int c, LPRECT p) {
return cast(BOOL) SendMessage(w, LVM_GETSUBITEMRECT, i,
p ? (p.left = c, p.top = isi, cast(LPARAM) p) : 0);
if (p) {
Copy link
Member

Choose a reason for hiding this comment

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

brace on its own line

Copy link
Member

@MartinNowak MartinNowak May 8, 2016

Choose a reason for hiding this comment

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

brace on its own line

done 8e09c99

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

@MartinNowak MartinNowak merged commit 0bba5cf into dlang:master May 8, 2016
MartinNowak added a commit that referenced this pull request May 8, 2016
@Geod24 Geod24 deleted the no-more-commaexp branch May 8, 2016 12:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants