-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Fix Issue 19213 - goto skips declaration of variable in std.algorithm… #6803
Conversation
|
Thanks for your pull request and interest in making D better, @edi33416! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "stable + phobos#6803" |
|
Changes to Note: the regression can be fixed just with the changes done in |
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.
Needs a test
| // we need to .save each subrange we traverse. | ||
| static if (isForwardRange!RoR && isForwardRange!(ElementType!RoR)) | ||
| _current = _items.front.save; | ||
| if (!_items.empty) |
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 is sub-optimal as it will be executed one-more time than strictly necessary.
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 should be faster to do sth. this:
while (!_items.empty) {
if (!_items.front.empty) {
_items.popFront();
} else {
// <- static if code here
break;
}
}
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 still need the outside if (!_items.empty) { } else { } block, or the compiler will complain with Error: one path skips field _current.
This is because, in the case of an empty ROR, _current won't be initialised.
| end: | ||
| assert(1); // required to avoid 'EOF instead of statement' error | ||
| { | ||
| _current = typeof(_current).init; |
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.
Why is this required?
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.
The compiler requires that _current is initialised on all possible paths.
| else | ||
| _currentBack = _items.back; | ||
| _current = typeof(_current).init; | ||
| _currentBack = typeof(_currentBack).init; |
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.
Why is this required?
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 see above comments
| // consumed when a .save'd copy of ourselves is iterated over. So | ||
| // we need to .save each subrange we traverse. | ||
| static if (isForwardRange!RoR && isForwardRange!(ElementType!RoR)) | ||
| if (!_items.empty) |
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 is sub-optimal as it will be executed one-more time than strictly necessary.
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 see above comments
48e2215 to
17b7366
Compare
std/algorithm/iteration.d
Outdated
| auto results = [[1,2], [3,4]] | ||
| .map!(q => q.map!Rec.chunkBy!"a.foo") | ||
| .joiner; | ||
| })); |
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.
No need to use __traits(compiles here. Use the range directly and even assert that its still iterated correctly.
Also, it would be good to add a test for iterating this range backwards and checking the result.
std/algorithm/iteration.d
Outdated
| @@ -2948,6 +2955,20 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR)) | |||
| assert(!equal(js2, js)); | |||
| } | |||
|
|
|||
| // Bugzilla issue 19213 | |||
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.
Use links to Bugzilla.
17b7366 to
a89e791
Compare
std/algorithm/iteration.d
Outdated
| { | ||
| auto results = [[1,2], [3,4]].map!(q => q.chunkBy!"a").joiner; | ||
| int i = 1; | ||
| foreach(ref e; results) |
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.
Style target fails here due to missing whitespace after foreach. Why not use equals?
Also, we should probably test the bidirectional code too (use e.g. retro)
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.
The result is not a bidirectional range, so I can't use retro.
….iteration.joiner
a89e791 to
6572e4a
Compare
ok let's at least fix the bug before 2.084
….iteration.joiner