fix #11028: std.bitmanip.write does not work with ranges with slicing#11032
Open
jmdavis wants to merge 1 commit into
Open
fix #11028: std.bitmanip.write does not work with ranges with slicing#11032jmdavis wants to merge 1 commit into
jmdavis wants to merge 1 commit into
Conversation
…icing The basic problem here is that the code assumed that an immutable(ubyte)[] can be assigned to a slice of the range. It's _technically_ possible to implement that with opIndexAssign, but it's highly unlikely that anyone has actually done that, particularly because that operation is not actually part of the range API. The other issue is that the template constraint did not check that the elements were assignable (individually or as a slice), which it needs to do if it's going to assign to the elements like it needs to; otherwise, ranges which pass the template constraint will fail to compile with the function. These changes make it so that the template constraint verifies that the elements are assignable, and it upgrades the range requirement to a random-access range, whereas previously, it just required that the range be a forward range with slicing. Forward ranges with slicing are nonsensical, because if you can implement that, the range can easily be a random-access range. And since the odds of the code having compiled for anyone previously with anything other than arrays is extremely low, IMHO, it's just cleaner to require a random-access range with assignable elements rather than worrying about the bizarre corner case where a forward range has implemented slicing and an opIndexAssign which accepts immutable(ubyte)[], but the range hasn't implemented the functions required to be a random-access range. So, there _is_ a very small chance that this will cause a regression, but I'd be extremely surprised if it does. Either way, it fixes it so that random-access ranges with assignable elements work with write, whereas realistically, all that worked previously was dynamic arrays.
Contributor
|
Thanks for your pull request, @jmdavis! 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.
|
Contributor
|
This module seems to have a few reimplementations of |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The basic problem here is that the code assumed that an immutable(ubyte)[] can be assigned to a slice of the range. It's technically possible to implement that with opIndexAssign, but it's highly unlikely that anyone has actually done that, particularly because that operation is not actually part of the range API. The other issue is that the template constraint did not check that the elements were assignable (individually or as a slice), which it needs to do if it's going to assign to the elements like it needs to; otherwise, ranges which pass the template constraint will fail to compile with the function.
These changes make it so that the template constraint verifies that the elements are assignable, and it upgrades the range requirement to a random-access range, whereas previously, it just required that the range be a forward range with slicing. Forward ranges with slicing are nonsensical, because if you can implement that, the range can easily be a random-access range. And since the odds of the code having compiled for anyone previously with anything other than arrays is extremely low, IMHO, it's just cleaner to require a random-access range with assignable elements rather than worrying about the bizarre corner case where a forward range has implemented slicing and an opIndexAssign which accepts immutable(ubyte)[], but the range hasn't implemented the functions required to be a random-access range.
So, there is a very small chance that this will cause a regression, but I'd be extremely surprised if it does.
Either way, it fixes it so that random-access ranges with assignable elements work with write, whereas realistically, all that worked previously was dynamic arrays.