Navigation Menu

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-13460] Can't detect uniqueness of existential boxes #55902

Closed
dabrahams opened this issue Aug 27, 2020 · 3 comments
Closed

[SR-13460] Can't detect uniqueness of existential boxes #55902

dabrahams opened this issue Aug 27, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-13460
Radar rdar://problem/68116208
Original Reporter @dabrahams
Type Bug
Status Resolved
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: cb6a1f62096674bf5c5389bd518f8756

Issue Description:

The following code should print true, but it prints false instead.

func test() {
  let tooBigForInlineBuffer = (1, 2, 3, 4)
  var a: Any = tooBigForInlineBuffer
  withUnsafeMutablePointer(to: &a) {
    let p = UnsafeMutableRawPointer($0).assumingMemoryBound(to: AnyObject.self)
    print(isKnownUniquelyReferenced(&p.pointee))
  }
}
test()

Really there should be a first class way to detect uniqueness of existential boxes and another to access the lvalue stored in an existential without knowing its memory layout, but short of that, this technique ought to work.

Assigning to Standard Library for lack of a runtime component.

@typesanitizer
Copy link

@swift-ci create

@tbkka
Copy link
Contributor

tbkka commented Sep 3, 2020

The internal structure of `Any` and `AnyObject` are private to the implementation. There cannot be any guarantees about code like this.

I believe new library features to manipulate existentials would be a Swift Evolution proposal.

@tbkka
Copy link
Contributor

tbkka commented Sep 3, 2020

The code as written makes assumptions about Swift internal data structures that cannot be guaranteed.

@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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants