Skip to content

Commit

Permalink
Lower Swift version requirement to 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dfunckt committed Aug 21, 2019
1 parent c19c712 commit 68500e5
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 68 deletions.
42 changes: 30 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@ language: generic
addons:
apt:
packages:
- build-essential
- clang
- curl
- gpg-agent
- libcurl4
- libicu-dev
- libpython2.7
- libxml2
- libz-dev
- pkg-config
- software-properties-common
homebrew:
packages:
- swiftformat
Expand All @@ -34,20 +25,47 @@ jobs:
osx_image: xcode11
script: make pretest

- stage: test
- &linux
stage: test
name: Ubuntu 18.04 / Swift 5.1
os: linux
dist: bionic
env:
- LINUX_TOOLCHAIN_URL=https://swift.org/builds/swift-5.1-branch/ubuntu1804/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a-ubuntu18.04.tar.gz
before_install: export PATH="${TRAVIS_BUILD_DIR}/usr/bin":"${PATH}"
install: make toolchain-bionic
install: make LINUX_TOOLCHAIN_URL=$LINUX_TOOLCHAIN_URL toolchain
script: make test

- stage: test
- <<: *linux
name: Ubuntu 18.04 / Swift 5.0
env:
- LINUX_TOOLCHAIN_URL=https://swift.org/builds/swift-5.0.2-release/ubuntu1804/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu18.04.tar.gz
script: make test-nosanitize

- <<: *linux
name: Ubuntu 16.04 / Swift 5.1
dist: xenial
env:
- LINUX_TOOLCHAIN_URL=https://swift.org/builds/swift-5.1-branch/ubuntu1604/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a-ubuntu16.04.tar.gz

- <<: *linux
name: Ubuntu 16.04 / Swift 5.0
dist: xenial
env:
- LINUX_TOOLCHAIN_URL=https://swift.org/builds/swift-5.0.2-release/ubuntu1604/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu16.04.tar.gz
script: make test-nosanitize

- &macos
stage: test
name: macOS 10.14 / Xcode 11.0
os: osx
osx_image: xcode11
script: make test

- <<: *macos
name: macOS 10.14 / Xcode 10.3
osx_image: xcode10.3

- stage: release
name: Documentation
os: osx
Expand Down
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SHELL = /bin/sh
MODULES = Futures FuturesSync
FOLDERS = Sources Tests

LINUX_DEV_TOOLCHAIN_URL = https://swift.org/builds/swift-5.1-branch/ubuntu1804/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a-ubuntu18.04.tar.gz
LINUX_DEV_IMAGE_NAME = swift-futures
LINUX_DEV_IMAGE_TAG = 5.1-dev
LINUX_TOOLCHAIN_URL = https://swift.org/builds/swift-5.1-branch/ubuntu1804/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-08-17-a-ubuntu18.04.tar.gz
LINUX_IMAGE_NAME = swift-futures
LINUX_IMAGE_TAG = 5.1-dev

SWIFT := $(shell command -v swift 2>/dev/null)
SWIFTFORMAT := $(shell command -v swiftformat 2>/dev/null)
Expand All @@ -25,6 +25,9 @@ build-release:
test:
$(SWIFT) test --configuration debug --sanitize thread

test-nosanitize:
$(SWIFT) test --configuration debug

test-release:
$(SWIFT) test --configuration release

Expand All @@ -37,7 +40,7 @@ clean:
precommit: gyb tests format lint
pretest: gyb tests format pristine lint

.PHONY: build test build-release test-release repl clean precommit pretest
.PHONY: build build-release test test-nosanitize test-release repl clean precommit pretest


xcodeproj:
Expand Down Expand Up @@ -81,10 +84,10 @@ endif
.PHONY: docs


toolchain-bionic:
Scripts/install-toolchain.sh "$(LINUX_DEV_TOOLCHAIN_URL)"
toolchain:
Scripts/install-toolchain.sh "$(LINUX_TOOLCHAIN_URL)"

.PHONY: toolchain-bionic
.PHONY: toolchain


_docker:
Expand All @@ -93,15 +96,15 @@ ifndef DOCKER
endif

linuximage: _docker
$(DOCKER) build --tag '$(LINUX_DEV_IMAGE_NAME):$(LINUX_DEV_IMAGE_TAG)' --build-arg TOOLCHAIN_URL="$(LINUX_DEV_TOOLCHAIN_URL)" .
$(DOCKER) build --tag '$(LINUX_IMAGE_NAME):$(LINUX_IMAGE_TAG)' --build-arg TOOLCHAIN_URL="$(LINUX_TOOLCHAIN_URL)" .

linuxtest: _docker
cwd=$$(pwd); \
$(DOCKER) run -it --rm --privileged --volume "$${cwd}:/src" '$(LINUX_DEV_IMAGE_NAME):$(LINUX_DEV_IMAGE_TAG)' test --configuration debug --sanitize thread
$(DOCKER) run -it --rm --privileged --volume "$${cwd}:/src" '$(LINUX_IMAGE_NAME):$(LINUX_IMAGE_TAG)' test --configuration debug --sanitize thread

linuxrepl: _docker
cwd=$$(pwd); \
$(DOCKER) run -it --rm --privileged --volume "$${cwd}:/src" '$(LINUX_DEV_IMAGE_NAME):$(LINUX_DEV_IMAGE_TAG)' run --repl --configuration debug
$(DOCKER) run -it --rm --privileged --volume "$${cwd}:/src" '$(LINUX_IMAGE_NAME):$(LINUX_IMAGE_TAG)' run --repl --configuration debug

.PHONY: _docker linuximage linuxtest linuxrepl

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.1
// swift-tools-version:5.0

import PackageDescription

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cancellation and threading, trivial.
<p>
<img src="https://img.shields.io/travis/dfunckt/swift-futures/master">
<img src="https://img.shields.io/github/v/release/dfunckt/swift-futures?sort=semver">
<img src="https://img.shields.io/badge/swift-%3E%3D5.1-orange">
<img src="https://img.shields.io/badge/swift-%3E%3D5.0-orange">
<img src="https://img.shields.io/badge/platform-Linux%20macOS%20iOS%20tvOS%20watchOS-blue">
</p>

Expand Down Expand Up @@ -185,7 +185,7 @@ func isPronic(_ n: Int) -> Bool {

### Requirements

Futures requires *Swift 5.1* (or newer) and can be deployed to any of the
Futures requires *Swift 5.0* (or newer) and can be deployed to any of the
following platforms:

- macOS 10.12+
Expand Down Expand Up @@ -218,7 +218,7 @@ exports two separate modules:
Here is an example `Package.swift`:

```swift
// swift-tools-version:5.1
// swift-tools-version:5.0
import PackageDescription

let package = Package(
Expand Down
18 changes: 6 additions & 12 deletions Sources/Futures/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ extension Channel {
public enum Unbuffered<Item>: ChannelProtocol {
public typealias Buffer = _Private.SlotBounded<Item>
public typealias Park = _Private.SPSCPark
@usableFromInline typealias _Impl = _Private.Impl<Self>
}

/// Creates a bounded, single-slot, single-sender (AKA "rendez-vous")
/// channel. Unbuffered channels are safe to use from any executor.
@inlinable
public static func makeUnbuffered<T>(itemType _: T.Type = T.self) -> Pipe<Unbuffered<T>> {
let impl = Unbuffered<T>._Impl(buffer: .init(), park: .init())
let impl = _Private.Impl<Unbuffered<T>>(buffer: .init(), park: .init())
return .init(tx: .init(impl), rx: .init(impl))
}
}
Expand All @@ -73,14 +72,13 @@ extension Channel {
public enum Passthrough<Item>: UnboundedChannelProtocol {
public typealias Buffer = _Private.SlotUnbounded<Item>
public typealias Park = _Private.SPSCPark
@usableFromInline typealias _Impl = _Private.Impl<Self>
}

/// Creates an unbounded, single-slot, single-sender (AKA "passthrough")
/// channel. Passthrough channels must only be used from a single executor.
@inlinable
public static func makePassthrough<T>(itemType _: T.Type = T.self) -> Pipe<Passthrough<T>> {
let impl = Passthrough<T>._Impl(buffer: .init(), park: .init())
let impl = _Private.Impl<Passthrough<T>>(buffer: .init(), park: .init())
return .init(tx: .init(impl), rx: .init(impl))
}
}
Expand All @@ -93,14 +91,13 @@ extension Channel {
public enum Buffered<Item>: ChannelProtocol {
public typealias Buffer = _Private.SPSCBufferBounded<Item>
public typealias Park = _Private.SPSCPark
@usableFromInline typealias _Impl = _Private.Impl<Self>
}

/// Creates a bounded, buffered, single-sender channel with the specified
/// capacity. Buffered channels are safe to use from any executor.
@inlinable
public static func makeBuffered<T>(itemType _: T.Type = T.self, capacity: Int) -> Pipe<Buffered<T>> {
let impl = Buffered<T>._Impl(buffer: .init(capacity: capacity), park: .init())
let impl = _Private.Impl<Buffered<T>>(buffer: .init(capacity: capacity), park: .init())
return .init(tx: .init(impl), rx: .init(impl))
}
}
Expand All @@ -113,14 +110,13 @@ extension Channel {
public enum BufferedUnbounded<Item>: UnboundedChannelProtocol {
public typealias Buffer = _Private.SPSCBufferUnbounded<Item>
public typealias Park = _Private.SPSCPark
@usableFromInline typealias _Impl = _Private.Impl<Self>
}

/// Creates an unbounded, buffered, single-sender channel. Buffered channels
/// are safe to use from any executor.
@inlinable
public static func makeBuffered<T>(itemType _: T.Type = T.self) -> Pipe<BufferedUnbounded<T>> {
let impl = BufferedUnbounded<T>._Impl(buffer: .init(), park: .init())
let impl = _Private.Impl<BufferedUnbounded<T>>(buffer: .init(), park: .init())
return .init(tx: .init(impl), rx: .init(impl))
}
}
Expand All @@ -133,14 +129,13 @@ extension Channel {
public enum Shared<Item>: ChannelProtocol {
public typealias Buffer = _Private.MPSCBufferBounded<Item>
public typealias Park = _Private.MPSCPark
@usableFromInline typealias _Impl = _Private.Impl<Self>
}

/// Creates a bounded, buffered, multiple-sender channel with the specified
/// capacity. Shared channels are safe to use from any executor.
@inlinable
public static func makeShared<T>(itemType _: T.Type = T.self, capacity: Int) -> Pipe<Shared<T>> {
let impl = Shared<T>._Impl(buffer: .init(capacity: capacity), park: .init())
let impl = _Private.Impl<Shared<T>>(buffer: .init(capacity: capacity), park: .init())
return .init(tx: .init(impl), rx: .init(impl))
}
}
Expand All @@ -153,14 +148,13 @@ extension Channel {
public enum SharedUnbounded<Item>: UnboundedChannelProtocol {
public typealias Buffer = _Private.MPSCBufferUnbounded<Item>
public typealias Park = _Private.MPSCPark
@usableFromInline typealias _Impl = _Private.Impl<Self>
}

/// Creates an unbounded, buffered, multiple-sender channel. Shared channels
/// are safe to use from any executor.
@inlinable
public static func makeShared<T>(itemType _: T.Type = T.self) -> Pipe<SharedUnbounded<T>> {
let impl = SharedUnbounded<T>._Impl(buffer: .init(), park: .init())
let impl = _Private.Impl<SharedUnbounded<T>>(buffer: .init(), park: .init())
return .init(tx: .init(impl), rx: .init(impl))
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Futures/Internal/TaskScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ private final class _ReadyQueue<F: FutureProtocol> {
}

var future: F? {
get { withUnsafeMutablePointerToHeader { $0.pointee.future } }
get { return withUnsafeMutablePointerToHeader { $0.pointee.future } }
set { withUnsafeMutablePointerToHeader { $0.pointee.future = newValue } }
}

var prevActive: Node? {
get { withUnsafeMutablePointerToHeader { $0.pointee.prevActive } }
get { return withUnsafeMutablePointerToHeader { $0.pointee.prevActive } }
set { withUnsafeMutablePointerToHeader { $0.pointee.prevActive = newValue } }
}

var nextActive: Node? {
get { withUnsafeMutablePointerToHeader { $0.pointee.nextActive } }
get { return withUnsafeMutablePointerToHeader { $0.pointee.nextActive } }
set { withUnsafeMutablePointerToHeader { $0.pointee.nextActive = newValue } }
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Futures/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension AnyFuture {
public init<T>(_ pollFn: @escaping (inout Context) throws -> Poll<T>) where Output == Result<T, Error> {
self.init { context in
do {
return try pollFn(&context).map(Result.success)
return try pollFn(&context).map { .success($0) }
} catch {
return .ready(.failure(error))
}
Expand All @@ -27,7 +27,7 @@ extension AnyStream {
self.init { context in
do {
return try pollNextFn(&context).map {
$0.map(Result.success)
$0.map { .success($0) }
}
} catch {
return .ready(.failure(error))
Expand Down
Loading

0 comments on commit 68500e5

Please sign in to comment.