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 19532 - chunkBy errors involving non-forward input ranges #6841
Merged
dlang-bot
merged 1 commit into
dlang:master
from
jondegenhardt:fix-19532-chunkBy-input-range
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should probably be
return ref
cc @WalterBrightThere 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 it simply become:
this(return ref Range range, ElementType!Range _prev)
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.
Checked my local unit test build, the iteration.d file is built with
-dip1000
. My impression was that this flag would catch needed changes. I'll wait additional clarification before making changes.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.
@WalterBright Can you clarify? Should this be
return ref
as per @thewilsonator? The PR as written compiles with-dip1000
. I searched phobos code and looked through the DIP 1000 document, but didn't see an example usingreturn ref
in a constructor function. I'd like to identify the correct way to write this.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.
Usually, the compiler is able to infer parameter attributes like
scope
andreturn
for templates, lambdas, etc. so in many cases adding the attributes manually is not necessary / has no effect. However adding attributes is needed for cases where the compiler can't infer things on its own.Which are those cases is highly implementation specific, and it depends on a case by case basis. As rule of thumb, try to go first without
scope
/return
and if the compiler complains, add them as necessary.Most importantly, have test cases involving static arrays in
@safe
unittests, as the escape analysis enabled by-dip1000
will emit errors only in@safe
functions, and the point of the escape analysis is to disallow escaping a reference to a stack-allocated object.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.
@ZombineDev Thanks for the explanation. Current
chunkBy
unit tests are not@safe
, they are@system
instead. There is a separate issue listed for this, issue 18161. According to that report the problem is that the implementation for the forward range case usesRefCounted
.My personal preference would be to leave the issue of making
chunkBy
@safe
as a separate PR, and have this PR focus on the bug being fixed. That is, leave the implementation as written, without introducingscope / return
. However, if reviewers prefer, I could try to make the non-forward input range implementation@safe
and introduce unit tests for this purpose.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 took a closer look at this topic and experimented with creating
@safe
unit tests. Best I can tell, DIP 1000 is saying that the technique I used is not considered@safe
under-dip1000
. First time I've really looked at DIP 1000, but my interpretation is that it is saying that the GC can no longer be used to manage lifetime in@safe
code, and instead some other technique, such as reference counting, must be used. Implementing this appears be an issue, perhaps temporary, asRefCounted
is@system
at the moment.It'd be fantastic if I've missed something basic and there's an easy way satisfy
@safe
under-dip1000
. If so, great. But otherwise I recommend going forward with the PR as written. The bug being addressed is quite significant, enough that it makeschunkBy
dangerous to use. It'd be better to fix the bug even if it's@system
under-dip1000
. The forward input range implementation ofchunkBy
is@system
due to use ofRefCounted
, so presumably both pieces of thechunkBy
implementation could be made@safe
together.