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-3530] Nested self-capturing function interferes with a call to isKnownUniquelyReferenced(_:) #46118

Closed
hamishknight opened this issue Jan 3, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-3530
Radar None
Original Reporter @hamishknight
Type Bug
Status Closed
Resolution Done
Environment

Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Performance
Assignee None
Priority Medium

md5: b07c484b53a633a4d173cca9a7ed79a1

Issue Description:

The following code always prints false, even though the capturing appears as if it should be happening after the call to isKnownUniquelyReferenced:

class Foo {}

struct Bar {
    
    var foo = Foo()
    
    public mutating func bar() {
        
        print(isKnownUniquelyReferenced(&foo))
        
        func nestedFunc() {
            _ = self // capture self
        }
        nestedFunc()
    }
}

var b = Bar()
b.bar() // false ?!

From what I can tell, self is getting alloc_box'ed too early (really shouldn't be boxed at all given that Swift prevents nestedFunc from escaping). This can break implementations that utilise isKnownUniquelyReferenced to optimise copy-on-write, in a rather non-obvious manner.

@huonw
Copy link
Mannequin

huonw mannequin commented Jan 5, 2017

This seems to be fixed on master.

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance
Projects
None yet
Development

No branches or pull requests

1 participant