Skip to content
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

[SR-3782] UnsafeMutable[Raw]BufferPointer should have nonmutating subscript setters #46367

Closed
dabrahams opened this issue Jan 29, 2017 · 9 comments
Assignees
Labels
affects ABI Flag: Affects ABI bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers standard library Area: Standard library umbrella

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-3782
Radar None
Original Reporter @dabrahams
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, AffectsABI, StarterBug
Assignee @glessard
Priority Medium

md5: c6e90cbea7ac8a60db87d54f8bb5e834

Issue Description:

...as befits a thing with reference semantics. Otherwise, you need to copy it into a mutable variable just to mutate the buffer it points at (yick).

@belkadan
Copy link
Contributor

I'm not even sure this needs a proposal. It seems like clearly just a bug.

@dabrahams
Copy link
Collaborator Author

Inclined to agree; removing "proposal" tag

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 6, 2017

Comment by Sergey Minakov (JIRA)

Is this bug present only on UnsafeMutableBufferPointer<Type> with range subscript as it's the only setter on marked with 'nonmutating' attribute? I would like to fix it, but don't quite get it yet.

@dabrahams
Copy link
Collaborator Author

Sorry naithar (JIRA User), I don't follow your question. Care to rephrase?

In case it helps, the reason for this bug is that despite its conformance to Collection, UnsafeMutable[Raw]BufferPointer has the semantics of a pointer; it does not own its elements, so mutating the elements should not be seen as a mutation of the buffer pointer.

@swift-ci
Copy link
Collaborator

Comment by Sergey Minakov (JIRA)

@dabrahams sorry 🙂
I've ment that after looking into source, it seems that only UnsafeMutableBufferPointer<T>.subscript(range: ) requires the value to be mutable. So changes should be made only to subscript(range: ) method. Did I undestand correctly?

@dabrahams
Copy link
Collaborator Author

naithar (JIRA User)Yes I think you understood correctly!

@swift-ci
Copy link
Collaborator

Comment by Sergey Minakov (JIRA)

@dabrahams is there any preferable way to implement this?
I have done changes that seem to work, but I'm not sure that's entirely correct as I had to change the validation tests: here is the commit.
Creating a temporary mutable value that would be used in `_writeBackMutableSlice` also doesn't seem like a good idea to me.

@glessard
Copy link
Contributor

#12504 implements a nonmutating range setter for UnsafeMutableBufferPointer. The other setters are nonmutating at this point.

@glessard
Copy link
Contributor

glessard commented Mar 6, 2018

#12504 got merged; marking this as resolved.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects ABI Flag: Affects ABI bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

4 participants