-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add _withUnsafeGuaranteedRef to Unmanaged #1890
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
aschwaighofer
merged 3 commits into
swiftlang:master
from
aschwaighofer:unsafe_guaranteed_prototype
Mar 27, 2016
Merged
Add _withUnsafeGuaranteedRef to Unmanaged #1890
aschwaighofer
merged 3 commits into
swiftlang:master
from
aschwaighofer:unsafe_guaranteed_prototype
Mar 27, 2016
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci Please smoke test |
Please add an execution test. |
492540f
to
c3f2ea9
Compare
@swift-ci Please test |
c3f2ea9
to
0a7c539
Compare
@swift-ci Please smoke test linux platform |
0a7c539
to
fc103bc
Compare
@swift-ci Please smoke test linux platform |
These builtins can be used to denote a scope over which the parameter passed to unsafeGuaranteed can be assume to be @guaranteed: That is there is another reference that keeps the value alive. // Scope begin strong_retain %0 : $Foo %2 = builtin "unsafeGuaranteed"<Foo>(%0 : $Foo) : $(Foo, Builtin.Int8) %3 = tuple_extract %2 : $(Foo, Builtin.Int8), 0 %4 = tuple_extract %2 : $(Foo, Builtin.Int8), 1 %5 = class_method %3 : $Foo, #Foo.beep!1 : (Foo) -> () -> () %6 = apply %5(%3) : $@convention(method) (@guaranteed Foo) -> () strong_release %3 : $Foo %8 = builtin "unsafeGuaranteedEnd"(%4 : $Builtin.Int8) : $( // Scope end is semantically equivalent to: sil @guaranteed_lifetime : $@convention(method) (@guaranteed Foo) -> () { bb(%3: $Foo): %5 = class_method %3 : $Foo, #Foo.beep!1 : (Foo) -> () -> () %6 = apply %5(%3) : $@convention(method) (@guaranteed Foo) -> () } ... // Scope begin apply @guaranteed_lifetime(%0) // Scope end
We can remove the retain/release pair preceeding the builtins based on the knowledge that the lifetime of the reference is guaranteed by someone hanging on to the reference elsewhere.
This is an internal method that will go away in the future. Get the value of the unmanaged referenced as a managed reference without consuming an unbalanced retain of it and pass it to the closure. Asserts that there is some other reference ('the owning reference') to the unmanaged reference that guarantees the lifetime of the unmanaged reference for the duration of the '_withUnsafeGuaranteedRef' call. var owningReference = Instance() ... withExtendedLifetime(owningReference) { let u = Unmanaged.passUnretained(owningReference) for i in 0 ..< 100 { // Assert that the reference in 'u' is kept alive by another storage // location or value that holds the same reference. u._withUnsafeGuaranteedRef { $0.doSomething() } } } // owningReference's lifetime (reference count > 0) is guaranteed // for this scope. rdar://25129935
fc103bc
to
d454c93
Compare
MaxDesiatov
pushed a commit
that referenced
this pull request
Oct 13, 2020
[pull] swiftwasm-release/5.3 from release/5.3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in this pull request?
This is an internal method that will go away in the future.
Get the value of the unmanaged referenced as a managed reference without
consuming an unbalanced retain of it and pass it to the closure. Asserts
that there is some other reference ('the owning reference') to the
unmanaged reference that guarantees the lifetime of the unmanaged reference
for the duration of the '_withUnsafeGuaranteedRef' call.