Closed erichoracek closed 3 months ago
Most of Factory is locked and already thread-safe, so adding complete sendable conformance shouldn't be that difficult.
The FactoryContext
is not thread-safe. It accesses and mutates a struct
extension FactoryContext {
/// Add argument to global context.
public static func setArg(_ arg: String, forKey key: String) {
FactoryContext.current.runtimeArguments[key] = arg
}
/// Add argument to global context.
public static func removeArg(forKey key: String) {
FactoryContext.current.runtimeArguments.removeValue(forKey: key)
}
}
This leaves me to think that a lot needs to change in order to go for Swift 6 and sendable checks. Do you think it is feasible to refactor factory to conform to all that?
is there any intension to fix this?
I just sent #209 so at least Factory
doesn't fail to compile with Swift 6.
See the Swift6 branch. That's Sendable and compatible with Swift concurrency.
With Swift 5.10 released and Swift 6 on the horizon, consumers of Factory would expect
Container
to conform toSendable
as it is intended to be thread safe. However, since it contains a property ofcontainerManager
, it's not possible to mark it as such:Furthermore, when you attempt to conform
ContainerManger
to sendable, you notice that it has publicly writable properties that are not protected, namelydefaultScope
but also some other debug ones, so it cannot conform toSendable
either:To satisfy the
Sendable
contract, ideallyContainer
andContainerManager
would both haveSendable
conformances, though this might require an API rethink.