-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Enable instantiating @MainActor-bound types in Swift 5.10+ #70
Conversation
39fb223
to
b61de26
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #70 +/- ##
==========================================
+ Coverage 99.51% 99.56% +0.04%
==========================================
Files 40 44 +4
Lines 9139 9200 +61
==========================================
+ Hits 9095 9160 +65
+ Misses 44 40 -4
|
1ef19b3
to
655fa97
Compare
@@ -156,36 +156,6 @@ Property declarations within `@Instantiable` types decorated with [`@Instantiate | |||
|
|||
`@Instantiated`-decorated properties must be an `@Instantiable` type, or of an `additionalType` listed in an `@Instantiable(fulfillingAdditionalTypes:)`‘s declaration. | |||
|
|||
#### Utilizing @Instantiated with type erased properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this moved down so that we discuss it after we discuss the Instantiator
@@ -19,34 +19,40 @@ | |||
// SOFTWARE. | |||
|
|||
/// A SafeDI dependency designed for the deferred instantiation of a type-erased instance of a | |||
/// type decorated with `@Instantiable`. Instantiation is thread-safe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we're explicitly determining threading here it seemed duplicative to say Instantiation is thread-safe.
@@ -1974,7 +1974,7 @@ final class SafeDIToolTests: XCTestCase { | |||
|
|||
extension Root { | |||
public convenience init() { | |||
func __safeDI_childABuilder(recreated: Recreated) -> ChildA { | |||
nonisolated func __safeDI_childABuilder(recreated: Recreated) -> ChildA { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part of the code-gen has me pretty convinced that Nonisolated
was indeed the correct prefix on the Instantiator
102cb8c
to
f53fdb2
Compare
f53fdb2
to
d1e61c1
Compare
@@ -0,0 +1,56 @@ | |||
// Distributed under the MIT License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How I wish you could git cp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if only!
@@ -136,33 +136,48 @@ public struct Property: Codable, Hashable, Comparable, Sendable { | |||
/// An `Instantiator` property. | |||
/// The instantiated product is not forwarded down the dependency tree. This is done intentionally to avoid unexpected retains. | |||
case instantiator | |||
/// A `ErasedInstantiator` property. | |||
/// An `ErasedInstantiator` property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste error? 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most definitely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just one grammar question.
This PR makes it possible to use SafeDI with Swift 5.10+ and Strict Concurrency checking turned on. To accomplish this, we made the following changes:
init
methods on@Instantiable
be isolated to the parent actor context – removed thenonisolated
from these generatedinit
methods.instantiate(...)
method for bothInstantiator
andErasedInstantiator
become@MainActor
-boundNonisolatedInstantiator
andNonisolatedErasedInstantiator
. As the name implies, these instantiators'sinstantiate(...)
methods run in a nonisolated context.We made
Instantiator
andErasedInstantiator
@MainActor
-bound because in most applications the root of the dependency tree is@MainActor
-bound, and in applications the majority of delayed-built products are@MainActor
-bound. In an effort to make the common case simple, we have optimized for simplifying the@MainActor
-bound case.Addresses #65.
This is a breaking change.
To adopt this change locally, consumers will need to follow their build errors after updating to 0.5.0. If something requires instantiation outside of main actor isolation, utilize a
Nonisolated
-prefixed Instantiator.