Skip to content

Commit 5c3535f

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 564a451 + ad755cd commit 5c3535f

File tree

2,144 files changed

+386696
-112844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,144 files changed

+386696
-112844
lines changed

CHANGELOG.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,60 @@ CHANGELOG
2424
Swift 5.0
2525
---------
2626

27+
* [SR-7251][]:
28+
29+
In Swift 5 mode, attempting to declare a static property with the same name as a
30+
nested type is now always correctly rejected. Previously, it was possible to
31+
perform such a redeclaration in an extension of a generic type.
32+
33+
For example:
34+
```swift
35+
struct Foo<T> {}
36+
extension Foo {
37+
struct i {}
38+
39+
// compiler error: Invalid redeclaration of 'i'
40+
// (prior to Swift 5, this did not produce an error)
41+
static var i: Int { return 0 }
42+
}
43+
```
44+
45+
* [SR-4248][]:
46+
47+
In Swift 5 mode, when casting an optional value to a generic placeholder type,
48+
the compiler will be more conservative with the unwrapping of the value. The
49+
result of such a cast now more closely matches the result you would get in a
50+
non-generic context.
51+
52+
For example:
53+
```swift
54+
func forceCast<U>(_ value: Any?, to type: U.Type) -> U {
55+
return value as! U
56+
}
57+
58+
let value: Any? = 42
59+
print(forceCast(value, to: Any.self))
60+
// prints: Optional(42)
61+
// (prior to Swift 5, this would print: 42)
62+
63+
print(value as! Any)
64+
// prints: Optional(42)
65+
```
66+
67+
* [SE-0227][]:
68+
69+
Key paths now support the `\.self` keypath, which is a `WritableKeyPath`
70+
that refers to its entire input value:
71+
72+
```swift
73+
let id = \Int.self
74+
75+
var x = 2
76+
print(x[keyPath: id]) // prints 2
77+
x[keyPath: id] = 3
78+
print(x[keyPath: id]) // prints 3
79+
```
80+
2781
* [SE-0214][]:
2882

2983
Renamed the `DictionaryLiteral` type to `KeyValuePairs`.
@@ -72,6 +126,47 @@ Swift 5.0
72126
Swift 4.2
73127
---------
74128

129+
### 2018-09-17 (Xcode 10.0)
130+
131+
* [SE-0202][]
132+
133+
The standard library now provides a unified set of randomization functionality.
134+
Integer types, floating point types, and Bool all introduce a new static
135+
method that creates a random value.
136+
137+
```swift
138+
let diceRoll = Int.random(in: 1 ... 6)
139+
let randomUnit = Double.random(in: 0 ..< 1)
140+
let randomBool = Bool.random()
141+
```
142+
143+
There are also additions to select a random element from a collection or
144+
shuffle its contents.
145+
146+
```swift
147+
let greetings = ["hey", "hello", "hi", "hola"]
148+
let randomGreeting = greetings.randomElement()! // This returns an Optional
149+
let newGreetings = greetings.shuffled() // ["hola", "hi", "hey", "hello"]
150+
```
151+
152+
Core to the randomization functionality is a new `RandomNumberGenerator`
153+
protocol. The standard library defines its own random number generator
154+
called `SystemRandomNumberGenerator` which is backed by a secure and
155+
thread-safe random number generator on each platform. All the randomization
156+
functions have a `using:` parameter that take a `RandomNumberGenerator` that
157+
users can pass in their own random number generator.
158+
159+
```swift
160+
struct MersenneTwister: RandomNumberGenerator {
161+
func next() -> UInt64 {
162+
// implementation
163+
}
164+
}
165+
166+
var mt = MersenneTwister()
167+
let diceRoll = Int.random(in: 1 ... 6, using: &mt)
168+
```
169+
75170
* [SE-0194][]
76171

77172
The new CaseIterable protocol describes types which have a static
@@ -277,8 +372,6 @@ Swift 4.2
277372
conditionally conforms to `P`, will succeed when the conditional
278373
requirements are met.
279374

280-
**Add new entries to the top of this section, not here!**
281-
282375
Swift 4.1
283376
---------
284377

@@ -7176,3 +7269,5 @@ Swift 1.0
71767269
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
71777270
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
71787271
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7272+
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
7273+
[SR-7251]: <https://bugs.swift.org/browse/SR-7251>

CMakeLists.txt

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
187187
"Path to the directory that contains the Android NDK tools that are executable on the build machine")
188188
set(SWIFT_ANDROID_NDK_GCC_VERSION "" CACHE STRING
189189
"The GCC version to use when building for Android. Currently only 4.9 is supported.")
190-
set(SWIFT_ANDROID_SDK_PATH "" CACHE STRING
191-
"Path to the directory that contains the Android SDK tools that will be passed to the swiftc frontend")
192190
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
193191
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
194192

@@ -594,7 +592,7 @@ else()
594592
set(SWIFT_HOST_VARIANT_ARCH_default "x86_64")
595593
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
596594
set(SWIFT_HOST_VARIANT_ARCH_default "itanium")
597-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
595+
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86|i686)")
598596
set(SWIFT_HOST_VARIANT_ARCH_default "i686")
599597
else()
600598
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
@@ -637,83 +635,56 @@ endif()
637635
# To fix it, we would need to append the architecture to the SDKs,
638636
# for example: 'OSX-x86_64;IOS-armv7;...etc'.
639637
# We could easily do that - we have all of that information in build-script-impl.
640-
# Also, we would need to be provided with the sysroot for each SDK (see SWIFT_ANDROID_SDK_PATH/SWIFT_SDK_ANDROID_PATH).
641638
# Darwin targets cheat and use `xcrun`.
642639

643640
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
644641

645-
set(CMAKE_EXECUTABLE_FORMAT "ELF")
646642
set(SWIFT_HOST_VARIANT "linux" CACHE STRING
647643
"Deployment OS for Swift host tools (the compiler) [linux].")
648644

649-
# Calculate the host triple
650-
if("${SWIFT_HOST_TRIPLE}" STREQUAL "")
651-
if("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "x86_64")
652-
set(SWIFT_HOST_TRIPLE "x86_64-unknown-linux-gnu")
653-
elseif("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "aarch64")
654-
set(SWIFT_HOST_TRIPLE "aarch64-unknown-linux-gnu")
655-
elseif("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "(powerpc64|powerpc64le)")
656-
set(SWIFT_HOST_TRIPLE "${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu")
657-
elseif("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "s390x")
658-
set(SWIFT_HOST_TRIPLE "s390x-unknown-linux-gnu")
659-
elseif("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "(armv6|armv7)")
660-
set(SWIFT_HOST_TRIPLE "${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnueabihf")
661-
else()
662-
message(FATAL_ERROR "Unable to calculate triple for linux host on ${SWIFT_HOST_VARIANT_ARCH}")
663-
endif()
664-
endif()
665-
666645
# Should we build the standard library for the host?
667646
is_sdk_requested(LINUX swift_build_linux)
668647
if(swift_build_linux)
669-
configure_sdk_unix(LINUX "Linux" "linux" "${SWIFT_HOST_VARIANT}" "${SWIFT_HOST_VARIANT_ARCH}" "${SWIFT_HOST_TRIPLE}" "/")
648+
configure_sdk_unix("Linux" "${SWIFT_HOST_VARIANT_ARCH}")
670649
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
671650
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
672651
endif()
673652

674653
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "FREEBSD")
675654

676-
set(CMAKE_EXECUTABLE_FORMAT "ELF")
677655
set(SWIFT_HOST_VARIANT "freebsd" CACHE STRING
678656
"Deployment OS for Swift host tools (the compiler) [freebsd].")
679657

680-
# FIXME: Using the host OS version won't produce correct results for
681-
# cross-compilation.
682-
string(REPLACE "[-].*" "" FREEBSD_SYSTEM_VERSION ${CMAKE_SYSTEM_VERSION})
683-
message(STATUS "FreeBSD Version: ${FREEBSD_SYSTEM_VERSION}")
684-
configure_sdk_unix(FREEBSD "FreeBSD" "freebsd" "freebsd" "x86_64"
685-
"x86_64-unknown-freebsd${FREEBSD_SYSTEM_VERSION}" "/")
658+
configure_sdk_unix("FreeBSD" "${SWIFT_HOST_VARIANT_ARCH}")
686659
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
687-
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
660+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
688661

689662
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "CYGWIN")
690663

691-
# set(CMAKE_EXECUTABLE_FORMAT "ELF")
692664
set(SWIFT_HOST_VARIANT "cygwin" CACHE STRING
693665
"Deployment OS for Swift host tools (the compiler) [cygwin].")
694666

695-
configure_sdk_unix(CYGWIN "Cygwin" "cygwin" "cygwin" "x86_64" "x86_64-unknown-windows-cygnus" "/")
667+
configure_sdk_unix("Cygwin" "${SWIFT_HOST_VARIANT_ARCH}")
696668
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
697-
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
669+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
698670

699671
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
700672

701673
set(SWIFT_HOST_VARIANT "windows" CACHE STRING
702674
"Deployment OS for Swift host tools (the compiler) [windows].")
703675

704-
configure_sdk_windows(WINDOWS "Windows" "msvc" "${SWIFT_HOST_VARIANT_ARCH}")
676+
configure_sdk_windows("Windows" "msvc" "${SWIFT_HOST_VARIANT_ARCH}")
705677
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
706678
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
707679

708680
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "HAIKU")
709681

710-
set(CMAKE_EXECUTABLE_FORMAT "ELF")
711682
set(SWIFT_HOST_VARIANT "haiku" CACHE STRING
712683
"Deployment OS for Swift host tools (the compiler) [haiku].")
713684

714-
configure_sdk_unix(HAIKU "Haiku" "haiku" "haiku" "x86_64" "x86_64-unknown-haiku" "/")
685+
configure_sdk_unix("Haiku" "${SWIFT_HOST_VARIANT_ARCH}")
715686
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
716-
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
687+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
717688

718689
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
719690

@@ -760,22 +731,23 @@ endif()
760731
# Should we cross-compile the standard library for Android?
761732
is_sdk_requested(ANDROID swift_build_android)
762733
if(swift_build_android AND NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
763-
764-
configure_sdk_unix(ANDROID "Android" "android" "android" "armv7" "armv7-none-linux-androideabi" "${SWIFT_ANDROID_SDK_PATH}")
765-
766-
if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
734+
if (NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux"))
767735
message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
768-
elseif(("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT swift_build_osx) OR
769-
("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT swift_build_linux))
770-
set(SWIFT_PRIMARY_VARIANT_SDK_default "ANDROID")
771-
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
772736
endif()
737+
738+
if("${SWIFT_SDK_ANDROID_ARCHITECTURES}" STREQUAL "")
739+
set(SWIFT_SDK_ANDROID_ARCHITECTURES armv7;aarch64)
740+
endif()
741+
configure_sdk_unix("Android" "${SWIFT_SDK_ANDROID_ARCHITECTURES}")
773742
endif()
774743

775744
# Should we cross-compile the standard library for Windows?
776745
is_sdk_requested(WINDOWS swift_build_windows)
777746
if(swift_build_windows AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
778-
configure_sdk_windows(WINDOWS "Windows" "msvc" "aarch64;armv7;i686;x86_64")
747+
if("${SWIFT_SDK_WINDOWS_ARCHITECTURES}" STREQUAL "")
748+
set(SWIFT_SDK_WINDOWS_ARCHITECTURES aarch64;armv7;i686;x86_64)
749+
endif()
750+
configure_sdk_windows("Windows" "msvc" "${SWIFT_SDK_WINDOWS_ARCHITECTURES}")
779751
endif()
780752

781753
if("${SWIFT_SDKS}" STREQUAL "")
@@ -860,15 +832,14 @@ function(swift_icu_variables_set sdk arch result)
860832
endif()
861833
endfunction()
862834

863-
# ICU is provided through CoreFoundation on Darwin. On other hosts, assume that
864-
# we are compiling for the build as the host. In such a case, if the ICU
835+
# ICU is provided through CoreFoundation on Darwin. On other hosts, if the ICU
865836
# unicode and i18n include and library paths are not defined, perform a standard
866837
# package lookup. Otherwise, rely on the paths specified by the user. These
867838
# need to be defined when cross-compiling.
868839
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
869840
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
870-
swift_icu_variables_set("${SWIFT_HOST_VARIANT_SDK_default}"
871-
"${SWIFT_HOST_VARIANT_ARCH_default}"
841+
swift_icu_variables_set("${SWIFT_PRIMARY_VARIANT_SDK}"
842+
"${SWIFT_PRIMARY_VARIANT_ARCH}"
872843
ICU_CONFIGURED)
873844
if("${SWIFT_PATH_TO_LIBICU_BUILD}" STREQUAL "" AND NOT ${ICU_CONFIGURED})
874845
find_package(ICU REQUIRED COMPONENTS uc i18n)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
|**[Ubuntu 16.04 (TensorFlow with GPU)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow_gpu.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu)|
2626

2727

28-
**Welcome to Swift!**
28+
## Welcome to Swift
2929

3030
Swift is a high-performance system programming language. It has a clean
3131
and modern syntax, offers seamless access to existing C and Objective-C code
@@ -71,7 +71,7 @@ supported host development operating systems.
7171

7272
#### macOS
7373

74-
To build for macOS, you need [Xcode 10 beta 6](https://developer.apple.com/xcode/downloads/).
74+
To build for macOS, you need [Xcode 10.0](https://developer.apple.com/xcode/downloads/).
7575
The required version of Xcode changes frequently, and is often a beta release.
7676
Check this document or the host information on <https://ci.swift.org> for the
7777
current required version.

apinotes/README.md

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,12 @@ original Objective-C headers. This semantic information can then be
66
used by the Swift compiler when importing the corresponding Objective-C
77
module to provide a better mapping of Objective-C APIs into Swift.
88

9-
API notes are organized into a set of `.apinotes` files. Each
10-
`.apinotes` file contains annotations for a single Objective-C module,
11-
written in YAML (FIXME: to be) described below. These YAML sources
12-
must be manually compiled into a binary representation (`.apinotesc`)
13-
that the Swift compiler will lazily load when it builds code, also
9+
API notes are organized into a set of `.apinotes` files. Each `.apinotes` file
10+
contains annotations for a single Objective-C module, written in YAML (FIXME:
11+
to be) described in the Clang repository. These YAML sources are lazily loaded
12+
by the Swift compiler when it imports the corresponding framework, also
1413
described below.
1514

16-
# API Notes YAML Format
17-
18-
TBD...
19-
20-
# Compiling API notes
21-
22-
The Swift compiler lazily loads API notes from compiled API notes
23-
files (`.apinotesc` files) and uses these annotations to affect the
24-
Swift signatures of imported Objective-C APIs. Compiled API notes
25-
files reside in the Swift module directory, i.e., the same directory
26-
where the `.swiftmodule` file would reside for the Swift overlay of
27-
that module. For system modules, the path depends on the platform
28-
and architecture.
29-
30-
Platform | Path
31-
:------------- | :-------------
32-
macOS | `$SWIFT_EXEC/lib/swift/macosx/`
33-
iOS (32-bit) | `$SWIFT_EXEC/lib/swift/iphoneos/32`
34-
iOS (64-bit) | `$SWIFT_EXEC/lib/swift/iphoneos`
35-
iOS Simulator (32-bit) | `$SWIFT_EXEC/lib/swift/iphonesimulator/32`
36-
iOS Simulator (64-bit) | `$SWIFT_EXEC/lib/swift/iphonesimulator`
37-
38-
where `$SWIFT_EXEC/bin/swift` is the path to the Swift compiler
39-
executable.
40-
41-
When updating API notes for a system module, recompile the API notes
42-
and place the result in the appropriate directories listed above. The
43-
Swift compiler itself need not be recompiled except in rare cases
44-
where the changes affect how the SDK overlays are built. To recompile
45-
API notes for a given module `$MODULE` and place them into their
46-
47-
### macOS
48-
```
49-
xcrun swift -apinotes -yaml-to-binary -target x86_64-apple-macosx10.10 -o $SWIFT_EXEC/lib/swift/macosx/$MODULE.apinotesc $MODULE.apinotes
50-
```
51-
52-
### iOS (32-bit)
53-
```
54-
xcrun swift -apinotes -yaml-to-binary -target armv7-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphoneos/32/$MODULE.apinotesc $MODULE.apinotes
55-
```
56-
57-
### iOS (64-bit)
58-
```
59-
xcrun swift -apinotes -yaml-to-binary -target arm64-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphoneos/$MODULE.apinotesc $MODULE.apinotes
60-
```
61-
62-
### iOS Simulator (32-bit)
63-
```
64-
xcrun swift -apinotes -yaml-to-binary -target i386-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphonesimulator/32/$MODULE.apinotesc $MODULE.apinotes
65-
```
66-
67-
### iOS Simulator (64-bit)
68-
```
69-
xcrun swift -apinotes -yaml-to-binary -target x86_64-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphonesimulator/$MODULE.apinotesc $MODULE.apinotes
70-
```
71-
7215
To add API notes for a system module `$MODULE` that does not have them yet,
7316
create a new source file `$MODULE.apinotes` and update CMakeLists.txt.
7417
Updated API notes will be found by the build system during the next build.
75-
76-
Note that Swift provides decompilation of binary API notes files via
77-
the `-apinotes -binary-to-yaml` option, which allows one to inspect
78-
the information the compiler is using internally. The order of the
79-
entities in the original YAML input is not preserved, so all entities
80-
in the resulting YAML output are sorted alphabetically.

0 commit comments

Comments
 (0)