Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
[WIP] Downgrade to Swift 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
slashmo committed Aug 17, 2020
1 parent 8e48348 commit dd96d4c
Show file tree
Hide file tree
Showing 44 changed files with 805 additions and 135 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ on: [push, pull_request]

jobs:
unit-test:
strategy:
matrix:
# GitHub Actions replaces 5.0 with 5 so we have to be specific here
swift: [5.0.3, 5.1, 5.2]
runs-on: ubuntu-latest
container: swift:5.2
container: swift:${{ matrix.swift }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Resolve Swift dependencies
run: swift package resolve
- name: Build & Test
run: swift test -c release --enable-test-discovery
run: swift test
compile-usecases:
strategy:
matrix:
# GitHub Actions replaces 5.0 with 5 so we have to be specific here
swift: [5.0.3, 5.1, 5.2]
runs-on: ubuntu-latest
container: swift:5.2
container: swift:${{ matrix.swift }}
steps:
- name: Checkout
uses: actions/checkout@v1
Expand Down
4 changes: 3 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# file options

--swiftversion 5.2
--swiftversion 5.0
--exclude .build
--exclude UseCases/.build
--exclude Tests/LinuxMain.swift
--exclude **/*Tests+XCTest.swift

# format options

Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/slashmo/gsoc-swift-baggage-context.git",
"state": {
"branch": null,
"revision": "71ef1080972a1cac47ab80d995d6bdc370fb20f2",
"version": "0.2.0"
"revision": "744d984ac940535287cb036e44e6970c2a93f012",
"version": "0.3.0"
}
},
{
Expand Down
25 changes: 12 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.2
// swift-tools-version:5.0
import PackageDescription

let package = Package(
Expand All @@ -11,9 +11,8 @@ let package = Package(
],
dependencies: [
.package(
name: "swift-baggage-context",
url: "https://github.com/slashmo/gsoc-swift-baggage-context.git",
from: "0.2.0"
from: "0.3.0"
),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0")
],
Expand All @@ -24,7 +23,7 @@ let package = Package(
.target(
name: "Instrumentation",
dependencies: [
.product(name: "Baggage", package: "swift-baggage-context"),
"Baggage",
]
),
.testTarget(
Expand All @@ -37,23 +36,23 @@ let package = Package(
.target(
name: "TracingInstrumentation",
dependencies: [
"Instrumentation"
"Instrumentation",
]
),
.testTarget(
name: "TracingInstrumentationTests",
dependencies: [
"Instrumentation",
"TracingInstrumentation",
.product(name: "BaggageLogging", package: "swift-baggage-context"),
"BaggageLogging",
]
),

.target(
name: "NIOInstrumentation",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
"NIO",
"NIOHTTP1",
"Instrumentation",
]
),
Expand All @@ -73,22 +72,22 @@ let package = Package(
.testTarget(
name: "OpenTelemetryInstrumentationSupportTests",
dependencies: [
"OpenTelemetryInstrumentationSupport"
"OpenTelemetryInstrumentationSupport",
]
),

// ==== --------------------------------------------------------------------------------------------------------
// MARK: Performance / Benchmarks

.target(
name: "Benchmarks",
name: "TracingBenchmarks",
dependencies: [
.product(name: "Baggage", package: "swift-baggage-context"),
"SwiftBenchmarkTools",
"Baggage",
"TracingBenchmarkTools",
]
),
.target(
name: "SwiftBenchmarkTools",
name: "TracingBenchmarkTools",
dependencies: []
),
]
Expand Down
6 changes: 3 additions & 3 deletions Sources/Instrumentation/InstrumentationSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public enum InstrumentationSystem {
///
/// Defaults to a no-op `Instrument` if `boostrap` wasn't called before.
public static var instrument: Instrument {
self.lock.withReaderLock { self._instrument }
return self.lock.withReaderLock { self._instrument }
}

/// Get an `Instrument` instance of the given type.
Expand All @@ -75,14 +75,14 @@ public enum InstrumentationSystem {
/// - Parameter instrumentType: The type of `Instrument` you want to retrieve an instance for.
/// - Returns: An `Instrument` instance of the given type or `nil` if no `Instrument` of that type has been bootstrapped.
public static func instrument<I>(of instrumentType: I.Type) -> I? where I: Instrument {
self._findInstrument(where: { $0 is I }) as? I
return self._findInstrument(where: { $0 is I }) as? I
}
}

extension InstrumentationSystem {
/// :nodoc: INTERNAL API: Do Not Use
public static func _findInstrument(where predicate: (Instrument) -> Bool) -> Instrument? {
self.lock.withReaderLock {
return self.lock.withReaderLock {
if let multiplex = self._instrument as? MultiplexInstrument {
return multiplex.firstInstrument(where: predicate)
} else if predicate(self._instrument) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Instrumentation/MultiplexInstrument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct MultiplexInstrument {

extension MultiplexInstrument {
func firstInstrument(where predicate: (Instrument) -> Bool) -> Instrument? {
self.instruments.first(where: predicate)
return self.instruments.first(where: predicate)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOInstrumentation/HTTPHeadersCarrier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct HTTPHeadersExtractor: ExtractorProtocol {
public init() {}

public func extract(key: String, from headers: HTTPHeaders) -> String? {
headers.first(name: key)
return headers.first(name: key)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.2)
import TracingInstrumentation

extension SpanAttributes {
Expand Down Expand Up @@ -48,3 +49,4 @@ public struct EndUserAttributes: SpanAttributeNamespace {
public var scope: SpanAttributeKey<String> { "enduser.scope" }
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.2)
import TracingInstrumentation

extension SpanAttributes {
Expand Down Expand Up @@ -98,3 +99,4 @@ public struct HTTPAttributes: SpanAttributeNamespace {
public var serverClientIP: SpanAttributeKey<String> { "http.client_ip" }
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.2)
import TracingInstrumentation

extension SpanAttributes {
Expand Down Expand Up @@ -59,3 +60,4 @@ public struct NetAttributes: SpanAttributeNamespace {
public var hostName: SpanAttributeKey<String> { "net.host.name" }
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.2)
import TracingInstrumentation

extension SpanAttributes {
Expand Down Expand Up @@ -41,3 +42,4 @@ public struct PeerAttributes: SpanAttributeNamespace {
public var service: SpanAttributeKey<String> { "peer.service" }
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func checked<T>(
class ArgumentParser<U> {
private var result: U
private var validOptions: [String] {
self.arguments.compactMap { $0.name }
return self.arguments.compactMap { $0.name }
}

private var arguments: [Argument] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import Darwin

extension BenchmarkCategory: CustomStringConvertible {
public var description: String {
self.rawValue
return self.rawValue
}
}

extension BenchmarkCategory: Comparable {
public static func < (lhs: BenchmarkCategory, rhs: BenchmarkCategory) -> Bool {
lhs.rawValue < rhs.rawValue
return lhs.rawValue < rhs.rawValue
}
}

Expand All @@ -54,7 +54,7 @@ public struct BenchmarkPlatformSet: OptionSet {
}

public static var allPlatforms: BenchmarkPlatformSet {
[.darwin, .linux]
return [.darwin, .linux]
}
}

Expand Down Expand Up @@ -124,17 +124,17 @@ public struct BenchmarkInfo {

/// Returns true if this benchmark should be run on the current platform.
var shouldRun: Bool {
!self.unsupportedPlatforms.contains(.currentPlatform)
return !self.unsupportedPlatforms.contains(.currentPlatform)
}
}

extension BenchmarkInfo: Comparable {
public static func < (lhs: BenchmarkInfo, rhs: BenchmarkInfo) -> Bool {
lhs.name < rhs.name
return lhs.name < rhs.name
}

public static func == (lhs: BenchmarkInfo, rhs: BenchmarkInfo) -> Bool {
lhs.name == rhs.name
return lhs.name == rhs.name
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public func SRand() {
}

public func Random() -> Int64 {
lfsrRandomGenerator.randInt()
return lfsrRandomGenerator.randInt()
}

@inlinable // FIXME(inline-always)
Expand All @@ -192,16 +192,16 @@ public func CheckResults(
}
}

public func False() -> Bool { false }
public func False() -> Bool { return false }

/// This is a dummy protocol to test the speed of our protocol dispatch.
public protocol SomeProtocol { func getValue() -> Int }
struct MyStruct: SomeProtocol {
init() {}
func getValue() -> Int { 1 }
func getValue() -> Int { return 1 }
}

public func someProtocolFactory() -> SomeProtocol { MyStruct() }
public func someProtocolFactory() -> SomeProtocol { return MyStruct() }

// Just consume the argument.
// It's important that this function is in another module than the tests
Expand All @@ -212,19 +212,19 @@ public func blackHole<T>(_: T) {}
// Return the passed argument without letting the optimizer know that.
@inline(never)
public func identity<T>(_ x: T) -> T {
x
return x
}

// Return the passed argument without letting the optimizer know that.
// It's important that this function is in another module than the tests
// which are using it.
@inline(never)
public func getInt(_ x: Int) -> Int { x }
public func getInt(_ x: Int) -> Int { return x }

// The same for String.
@inline(never)
public func getString(_ s: String) -> String { s }
public func getString(_ s: String) -> String { return s }

// The same for Substring.
@inline(never)
public func getSubstring(_ s: Substring) -> Substring { s }
public func getSubstring(_ s: Substring) -> Substring { return s }
Loading

0 comments on commit dd96d4c

Please sign in to comment.