Skip to content

[stdlib] Change _withUnsafeGuaranteedRef to use Builtin.convertUnownedUnsafeToGuaranteed. #30033

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stdlib/public/core/Unmanaged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ public struct Unmanaged<Instance: AnyObject> {
public func _withUnsafeGuaranteedRef<Result>(
_ body: (Instance) throws -> Result
) rethrows -> Result {
let (guaranteedInstance, token) = Builtin.unsafeGuaranteed(_value)
let result = try body(guaranteedInstance)
Builtin.unsafeGuaranteedEnd(token)
return result
var tmp = self
let fakeBase: Int? = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should explain what fakeBase is for, and why a "real" base isn't actually required in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that the user is stating with this API that they are putting a _fixLifetime around as per the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atrick I am happy to do that in a follow on commit.

return try body(Builtin.convertUnownedUnsafeToGuaranteed(fakeBase,
&tmp._value))
}

/// Performs an unbalanced retain of the object.
Expand Down