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

Add retainContainer method #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion FormatTool/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/apple/swift-format.git",
exact: "508.0.0"
exact: "508.0.1"
),
],
targets: [
Expand Down
16 changes: 16 additions & 0 deletions Sources/MQDo/Container/Features.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
public protocol Features: Sendable {

@Sendable func retainContainer(
file: StaticString,
line: UInt
) throws -> FeaturesContainer

@Sendable func branch<Scope>(
_ scope: Scope.Type,
context: Scope.Context,
Expand Down Expand Up @@ -60,6 +65,17 @@ public protocol Features: Sendable {

extension Features {

@_transparent
@Sendable func retainContainer(
file: StaticString = #file,
line: UInt = #line
) throws -> FeaturesContainer {
try self.retainContainer(
file: file,
line: line
)
}

@_transparent
@Sendable public func require<Scope>(
_ scope: Scope.Type,
Expand Down
22 changes: 22 additions & 0 deletions Sources/MQDo/Container/Internal/FeaturesProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ internal struct FeaturesProxy {

extension FeaturesProxy: Features {

@Sendable internal func retainContainer(
file: StaticString,
line: UInt
) throws -> FeaturesContainer {
if let container: FeaturesContainer = self.container {
return container
}
else {
throw
FeaturesContainerUnavailable
.error(
file: file,
line: line
)
.asRuntimeWarning(
message: "Using detached features container. This is likely a memory issue.",
file: file,
line: line
)
}
}

@_transparent
@Sendable internal func require<Scope>(
_ scope: Scope.Type,
Expand Down
8 changes: 8 additions & 0 deletions Sources/MQDo/Container/Internal/RootFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ extension RootFeatures: @unchecked Sendable {}

extension RootFeatures: FeaturesContainer {

@_transparent
@Sendable internal func retainContainer(
file: StaticString,
line: UInt
) throws -> FeaturesContainer {
self
}

@_transparent
@Sendable internal func require<Scope>(
_ scope: Scope.Type,
Expand Down
8 changes: 8 additions & 0 deletions Sources/MQDo/Container/Internal/ScopedFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ extension ScopedFeatures: @unchecked Sendable {}

extension ScopedFeatures: FeaturesContainer {

@_transparent
@Sendable internal func retainContainer(
file: StaticString,
line: UInt
) throws -> FeaturesContainer {
self
}

@Sendable internal func require<RequestedScope>(
_ scope: RequestedScope.Type,
file: StaticString,
Expand Down
8 changes: 8 additions & 0 deletions Sources/MQDummy/Container/DummyFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ extension DummyFeatures: @unchecked Sendable {}

extension DummyFeatures: FeaturesContainer {

@_transparent
@Sendable public func retainContainer(
file: StaticString,
line: UInt
) throws -> FeaturesContainer {
self
}

@Sendable public func context<Scope>(
for scope: Scope.Type,
file: StaticString,
Expand Down