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-7167] Extra retain or formIndex(...) should be removed #49715
Comments
@belkadan That remark doesn't make any sense to me:
|
1. The problem that |
We've talked about making non-mutating methods calls semantically borrow `self` instead of semantically copying. Note that that would make the call `g(&i)` ill-formed as an exclusivity violation. |
In general, I see no way that we can both remove the copy of `self` and allow `&self.i` to be passed off simultaneously, because obviously mutating `self.i` can invalidate parts of `self`. So is that just a convenience for your reduction, or is it core to the pattern you need? I wouldn't think that collections usually store indices into themselves, but if you tell me that's important, I will believe you. |
@rjmccall This is a reduction of https://github.com/dabrahams/KillSequence/blob/master/GeneratorCollection.swift#L318 . Most collections don't store indices, but slices do. I'm afraid I don't understand what you mean about invalidation. |
Good point (reminds self not to file bugs while sick). |
But the slices you're talking about presumably also store their parent collection and could presumably advance the index using that instead. The invalidation issue is just that there's a real exclusivity issue here: you want to pass a field of `self` by mutable reference while also passing all of `self` by immutable reference. The latter can observe changes made to the former. |
The SubSequence in the code referenced does not store its parent collection. If it did, it would keep buffers alive longer than necessary. I see what you mean about the exclusivity problem, now, thanks. |
> The SubSequence in the code referenced does not store its parent collection. If it did, it would keep buffers alive longer than necessary. Oh, right, of course. But in this case you should be able to advance the index without needing the collection. |
Yep, that's my fallback. So I think this bug is bogus and will close. |
Additional Detail from JIRA
md5: fa6332a4759c24e5edbc8453c9a0f788
Issue Description:
The following program prints
"true\nfalse"
. I conclude that either we should find a way to remove the extra retain caused wheng
is called fromf
, or if that is impossible for correctness reasons we should probably remove theformIndex([before|after]: )
methods from Collections, becauseg
is an effective analogue forformIndex
when used from such methods asdropFirst()
.The text was updated successfully, but these errors were encountered: