Skip to content

Commit

Permalink
Revert "Revert "make Baggage Sendable (#17)" (#23)" (#24)
Browse files Browse the repository at this point in the history
This reverts commit c8457ce.
  • Loading branch information
ktoso committed Jan 29, 2022
1 parent c8457ce commit 05f21f5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Package.resolved
/*.xcodeproj
xcuserdata/
.swiftpm
.vscode/
.history
12 changes: 9 additions & 3 deletions Sources/InstrumentationBaggage/Baggage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=5.5) && canImport(_Concurrency)
public typealias _Baggage_Sendable = Swift.Sendable
#else
public typealias _Baggage_Sendable = Any
#endif

/// A `Baggage` is a heterogeneous storage type with value semantics for keyed values in a type-safe fashion.
///
/// Its values are uniquely identified via `BaggageKey`s (by type identity). These keys also dictate the type of
Expand Down Expand Up @@ -65,8 +71,8 @@
/// `Baggage` does not expose more functions on purpose to prevent abuse and treating it as too much of an
/// arbitrary value smuggling container, but only make it convenient for tracing and instrumentation systems which need
/// to access either specific or all items carried inside a baggage.
public struct Baggage {
private var _storage = [AnyBaggageKey: Any]()
public struct Baggage: _Baggage_Sendable {
private var _storage = [AnyBaggageKey: _Baggage_Sendable]()

/// Internal on purpose, please use `Baggage.TODO` or `Baggage.topLevel` to create an "empty" baggage,
/// which carries more meaning to other developers why an empty baggage was used.
Expand Down Expand Up @@ -151,7 +157,7 @@ extension Baggage {

/// Carried automatically by a "to do" baggage.
/// It can be used to track where a baggage originated and which "to do" baggage must be fixed into a real one to avoid this.
public struct TODOLocation {
public struct TODOLocation: _Baggage_Sendable {
/// Source file location where the to-do `Baggage` was created
public let file: String
/// Source line location where the to-do `Baggage` was created
Expand Down
6 changes: 3 additions & 3 deletions Sources/InstrumentationBaggage/BaggageKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
/// }
///
/// This pattern allows library authors fine-grained control over which values may be set, and which only get by end-users.
public protocol BaggageKey {
public protocol BaggageKey: _Baggage_Sendable {
/// The type of value uniquely identified by this key.
associatedtype Value
associatedtype Value: _Baggage_Sendable

/// The human-readable name of this key.
/// This name will be used instead of the type name when a value is printed.
Expand All @@ -62,7 +62,7 @@ extension BaggageKey {
}

/// A type-erased `BaggageKey` used when iterating through the `Baggage` using its `forEach` method.
public struct AnyBaggageKey {
public struct AnyBaggageKey: _Baggage_Sendable {
/// The key's type represented erased to an `Any.Type`.
public let keyType: Any.Type

Expand Down
18 changes: 18 additions & 0 deletions docker/docker-compose.2004.54.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"

services:

runtime-setup:
image: swift-distributed-tracing-baggage:20.04-5.4
build:
args:
ubuntu_version: "focal"
swift_version: "5.4"

test:
image: swift-distributed-tracing-baggage:20.04-5.4
environment: []
#- SANITIZER_ARG=--sanitize=thread

shell:
image: swift-distributed-tracing-baggage:20.04-5.4
18 changes: 18 additions & 0 deletions docker/docker-compose.2004.55.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"

services:

runtime-setup:
image: swift-distributed-tracing-baggage:20.04-5.5
build:
args:
ubuntu_version: "focal"
swift_version: "5.5"

test:
image: swift-distributed-tracing-baggage:20.04-5.5
environment: []
#- SANITIZER_ARG=--sanitize=thread

shell:
image: swift-distributed-tracing-baggage:20.04-5.5
17 changes: 17 additions & 0 deletions docker/docker-compose.2004.main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

services:

runtime-setup:
image: swift-distributed-tracing-baggage:20.04-main
build:
args:
base_image: "swiftlang/swift:nightly-main-focal"


test:
image: swift-distributed-tracing-baggage:20.04-main
environment: []
#- SANITIZER_ARG=--sanitize=thread
shell:
image: swift-distributed-tracing-baggage:20.04-main

0 comments on commit 05f21f5

Please sign in to comment.