Skip to content

Commit e368e9d

Browse files
authored
Merge pull request #2716 from swiftwasm/katei/merge-main-2021-02-12
Merge main 2021-02-12
2 parents 78ffdc9 + df2ca60 commit e368e9d

File tree

759 files changed

+17614
-7037
lines changed

Some content is hidden

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

759 files changed

+17614
-7037
lines changed

CHANGELOG.md

Lines changed: 146 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,142 @@ CHANGELOG
2525

2626
</details>
2727

28+
Swift Next
29+
----------
30+
31+
* [SE-0296][]:
32+
33+
Asynchronous programming is now natively supported using async/await. Asynchronous functions can be defined using `async`:
34+
35+
```swift
36+
func loadWebResource(_ path: String) async throws -> Resource { ... }
37+
func decodeImage(_ r1: Resource, _ r2: Resource) async throws -> Image
38+
func dewarpAndCleanupImage(_ i : Image) async -> Image
39+
```
40+
41+
Calls to `async` functions may suspend, meaning that they give up the thread on which they are executing and will be scheduled to run again later. The potential for suspension on asynchronous calls requires the `await` keyword, similarly to the way in which `try` acknowledges a call to a `throws` function:
42+
43+
```swift
44+
func processImageData() async throws -> Image {
45+
let dataResource = try await loadWebResource("dataprofile.txt")
46+
let imageResource = try await loadWebResource("imagedata.dat")
47+
let imageTmp = try await decodeImage(dataResource, imageResource)
48+
let imageResult = await dewarpAndCleanupImage(imageTmp)
49+
return imageResult
50+
}
51+
```
52+
53+
* The 'lazy' keyword now works in local contexts, making the following valid:
54+
55+
```swift
56+
func test(useIt: Bool) {
57+
lazy var result = getPotentiallyExpensiveResult()
58+
if useIt {
59+
doIt(result)
60+
}
61+
}
62+
```
63+
64+
**Add new entries to the top of this section, not here!**
65+
2866
Swift 5.4
2967
---------
3068

69+
* Protocol conformance checking now considers `where` clauses when evaluating if a `typealias` is a suitable witness for an associated type requirement. The following code is now rejected:
70+
71+
```swift
72+
protocol Holder {
73+
associatedtype Contents
74+
}
75+
76+
struct Box<T> : Holder {}
77+
// error: type 'Box<T>' does not conform to protocol 'Holder'
78+
79+
extension Box where T : Hashable {
80+
typealias Contents = T
81+
}
82+
```
83+
84+
In most cases, the compiler would either crash or produce surprising results when making use of a `typealias` with an unsatisfied `where` clause, but it is possible that some previously-working code is now rejected. In the above example, the conformance can be fixed in one of various ways:
85+
86+
1) making it conditional (moving the `: Holder` from the definition of `Box` to the extension)
87+
2) moving the `typealias` from the extension to the type itself
88+
3) relaxing the `where` clause on the extension
89+
90+
* Availability checking now rejects protocols that refine less available protocols. Previously, this was accepted by the compiler but could result in linker errors or runtime crashes:
91+
92+
```swift
93+
@available(macOS 11, *)
94+
protocol Base {}
95+
96+
protocol Bad : Base {}
97+
// error: 'Base' is only available in macOS 11 or newer
98+
99+
@available(macOS 11, *)
100+
protocol Good : Base {} // OK
101+
```
102+
103+
* The `@available` attribute is no longer permitted on generic parameters, where it had no effect:
104+
105+
```swift
106+
struct Bad<@available(macOS 11, *) T> {}
107+
// error: '@available' attribute cannot be applied to this declaration
108+
109+
struct Good<T> {} // equivalent
110+
```
111+
112+
* If a type is made to conform to a protocol via an extension, the availability of the extension is now taken into account when forming generic types that use this protocol conformance. For example, consider a `Box` type whose conformance to `Hashable` uses features only available on macOS 11:
113+
114+
```swift
115+
public struct Box {}
116+
117+
@available(macOS 11, *)
118+
extension Box : Hashable {
119+
func hash(into: inout Hasher) {
120+
// call some new API to hash the value...
121+
}
122+
}
123+
124+
public func findBad(_: Set<Box>) -> Box {}
125+
// warning: conformance of 'Box' to 'Hashable' is only available in macOS 11 or newer
126+
127+
@available(macOS 11, *)
128+
public func findGood(_: Set<Box>) -> Box {} // OK
129+
```
130+
131+
In the above code, it is not valid for `findBad()` to take a `Set<Box>`, since `Set` requires that its element type conform to `Hashable`; however the conformance of `Box` to `Hashable` is not available prior to macOS 11.
132+
133+
Note that using an unavailable protocol conformance is a warning, not an error, to avoid potential source compatibility issues. This is because it was technically possible to write code in the past that made use of unavailable protocol conformances but worked anyway, if the optimizer had serendipitously eliminated all runtime dispatch through this conformance, or the code in question was entirely unreachable at runtime.
134+
135+
Protocol conformances can also be marked as completely unavailable or deprecated, by placing an appropriate `@available` attribute on the extension:
136+
137+
```swift
138+
@available(*, unavailable, message: "Not supported anymore")
139+
extension Box : Hashable {}
140+
141+
@available(*, deprecated, message: "Suggest using something else")
142+
extension Box : Hashable {}
143+
```
144+
145+
If a protocol conformance is defined on the type itself, it inherits availability from the type. You can move the protocol conformance to an extension if you need it to have narrower availability than the type.
146+
147+
* When `swift` is run with no arguments, it starts a REPL (read eval print loop) that uses LLDB. The compiler also had a second REPL implementation, known as the "integrated REPL", formerly accessible by running `swift -frontend -repl`. The "integrated REPL" was only intended for use by compiler developers, and has now been removed.
148+
149+
Note that this does not take away the ability to put Swift code in a script and run it with `swift myScript.swift`. This so-called "script mode" is distinct from the integrated REPL, and continues to be supported.
150+
151+
* Property wrappers now work in local contexts, making the following valid:
152+
153+
```swift
154+
@propertyWrapper
155+
struct Wrapper<T> {
156+
var wrappedValue: T
157+
}
158+
159+
func test() {
160+
@Wrapper var value = 10
161+
}
162+
```
163+
31164
* [SR-10069][]:
32165

33166
Function overloading now works in local contexts, making the following valid:
@@ -317,8 +450,6 @@ Swift 5.3
317450
closure's capture list in addition to the existing 'use `self.` explicitly'
318451
fix-it.
319452

320-
**Add new entries to the top of this section, not here!**
321-
322453
Swift 5.2
323454
---------
324455

@@ -1337,10 +1468,10 @@ Swift 4.1
13371468
types, such as `index(of:)`.
13381469

13391470
* [SE-0157][] is implemented. Associated types can now declare "recursive"
1340-
constraints, which require that the associated type conform to the enclosing
1341-
protocol. The standard library protocols have been updated to make use of
1342-
recursive constraints. For example, the `SubSequence` associated type of
1343-
`Sequence` follows the enclosing protocol:
1471+
constraints, which require that the associated type conform to the enclosing
1472+
protocol. The standard library protocols have been updated to make use of
1473+
recursive constraints. For example, the `SubSequence` associated type of
1474+
`Sequence` follows the enclosing protocol:
13441475

13451476
```swift
13461477
protocol Sequence {
@@ -1357,16 +1488,15 @@ Swift 4.1
13571488
```
13581489

13591490
As a result, a number of new constraints have been introduced into the
1360-
standard library protocols:
1361-
1362-
* Make the `Indices` associated type have the same traversal requirements as
1363-
its enclosing protocol, e.g., `Collection.Indices` conforms to
1364-
`Collection`, `BidirectionalCollection.Indices` conforms to
1365-
`BidirectionalCollection`, and so on
1366-
* Make `Numeric.Magnitude` conform to `Numeric`
1367-
* Use more efficient `SubSequence` types for lazy filter and map
1368-
* Eliminate the `*Indexable` protocols
1491+
standard library protocols:
13691492

1493+
* Make the `Indices` associated type have the same traversal requirements as
1494+
its enclosing protocol, e.g., `Collection.Indices` conforms to
1495+
`Collection`, `BidirectionalCollection.Indices` conforms to
1496+
`BidirectionalCollection`, and so on
1497+
* Make `Numeric.Magnitude` conform to `Numeric`
1498+
* Use more efficient `SubSequence` types for lazy filter and map
1499+
* Eliminate the `*Indexable` protocols
13701500

13711501
* [SE-0161][] is fully implemented. KeyPaths now support subscript, optional
13721502
chaining, and optional force-unwrapping components.
@@ -8178,6 +8308,7 @@ Swift 1.0
81788308
[SE-0284]: <https://github.com/apple/swift-evolution/blob/main/proposals/0284-multiple-variadic-parameters.md>
81798309
[SE-0286]: <https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md>
81808310
[SE-0287]: <https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md>
8311+
[SE-0296]: <https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md>
81818312

81828313
[SR-75]: <https://bugs.swift.org/browse/SR-75>
81838314
[SR-106]: <https://bugs.swift.org/browse/SR-106>

CMakeLists.txt

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -996,133 +996,7 @@ if (LLVM_ENABLE_DOXYGEN)
996996
message(STATUS "Doxygen: enabled")
997997
endif()
998998

999-
if(SWIFT_BUILD_HOST_DISPATCH)
1000-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
1001-
if(CMAKE_C_COMPILER_ID STREQUAL Clang AND
1002-
CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.8
1003-
OR LLVM_USE_SANITIZER)
1004-
set(SWIFT_LIBDISPATCH_C_COMPILER ${CMAKE_C_COMPILER})
1005-
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
1006-
elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
1007-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
1008-
if(CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR AND
1009-
TARGET clang)
1010-
set(SWIFT_LIBDISPATCH_C_COMPILER
1011-
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
1012-
set(SWIFT_LIBDISPATCH_CXX_COMPILER
1013-
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
1014-
else()
1015-
set(SWIFT_LIBDISPATCH_C_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
1016-
set(SWIFT_LIBDISPATCH_CXX_COMPILER clang-cl${CMAKE_EXECUTABLE_SUFFIX})
1017-
endif()
1018-
else()
1019-
set(SWIFT_LIBDISPATCH_C_COMPILER $<TARGET_FILE_DIR:clang>/clang)
1020-
set(SWIFT_LIBDISPATCH_CXX_COMPILER $<TARGET_FILE_DIR:clang>/clang++)
1021-
endif()
1022-
else()
1023-
message(SEND_ERROR "libdispatch requires a newer clang compiler (${CMAKE_C_COMPILER_VERSION} < 3.9)")
1024-
endif()
1025-
1026-
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
1027-
set(SOURCEKIT_LIBDISPATCH_RUNTIME_DIR bin)
1028-
else()
1029-
set(SOURCEKIT_LIBDISPATCH_RUNTIME_DIR lib)
1030-
endif()
1031-
1032-
include(ExternalProject)
1033-
ExternalProject_Add(libdispatch
1034-
SOURCE_DIR
1035-
"${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}"
1036-
CMAKE_ARGS
1037-
-DCMAKE_AR=${CMAKE_AR}
1038-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
1039-
-DCMAKE_C_COMPILER=${SWIFT_LIBDISPATCH_C_COMPILER}
1040-
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
1041-
-DCMAKE_CXX_COMPILER=${SWIFT_LIBDISPATCH_CXX_COMPILER}
1042-
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
1043-
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
1044-
-DCMAKE_INSTALL_LIBDIR=lib
1045-
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
1046-
-DCMAKE_LINKER=${CMAKE_LINKER}
1047-
-DCMAKE_RANLIB=${CMAKE_RANLIB}
1048-
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
1049-
-DBUILD_SHARED_LIBS=YES
1050-
-DENABLE_SWIFT=NO
1051-
-DENABLE_TESTING=NO
1052-
INSTALL_COMMAND
1053-
# NOTE(compnerd) provide a custom install command to
1054-
# ensure that we strip out the DESTDIR environment
1055-
# from the sub-build
1056-
${CMAKE_COMMAND} -E env --unset=DESTDIR ${CMAKE_COMMAND} --build . --target install
1057-
STEP_TARGETS
1058-
install
1059-
BUILD_BYPRODUCTS
1060-
<INSTALL_DIR>/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
1061-
<INSTALL_DIR>/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}dispatch${CMAKE_IMPORT_LIBRARY_SUFFIX}
1062-
<INSTALL_DIR>/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}BlocksRuntime${CMAKE_SHARED_LIBRARY_SUFFIX}
1063-
<INSTALL_DIR>/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}BlocksRuntime${CMAKE_IMPORT_LIBRARY_SUFFIX}
1064-
BUILD_ALWAYS
1065-
1)
1066-
1067-
ExternalProject_Get_Property(libdispatch install_dir)
1068-
1069-
# CMake does not like the addition of INTERFACE_INCLUDE_DIRECTORIES without
1070-
# the directory existing. Just create the location which will be populated
1071-
# during the installation.
1072-
file(MAKE_DIRECTORY ${install_dir}/include)
1073-
1074-
add_library(dispatch SHARED IMPORTED)
1075-
set_target_properties(dispatch
1076-
PROPERTIES
1077-
IMPORTED_LOCATION
1078-
${install_dir}/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
1079-
IMPORTED_IMPLIB
1080-
${install_dir}/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}dispatch${CMAKE_IMPORT_LIBRARY_SUFFIX}
1081-
INTERFACE_INCLUDE_DIRECTORIES
1082-
${install_dir}/include)
1083-
1084-
add_library(BlocksRuntime SHARED IMPORTED)
1085-
set_target_properties(BlocksRuntime
1086-
PROPERTIES
1087-
IMPORTED_LOCATION
1088-
${install_dir}/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}BlocksRuntime${CMAKE_SHARED_LIBRARY_SUFFIX}
1089-
IMPORTED_IMPLIB
1090-
${install_dir}/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}BlocksRuntime${CMAKE_IMPORT_LIBRARY_SUFFIX}
1091-
INTERFACE_INCLUDE_DIRECTORIES
1092-
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
1093-
1094-
add_dependencies(dispatch libdispatch-install)
1095-
add_dependencies(BlocksRuntime libdispatch-install)
1096-
1097-
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
1098-
set(SOURCEKIT_RUNTIME_DIR bin)
1099-
else()
1100-
set(SOURCEKIT_RUNTIME_DIR lib)
1101-
endif()
1102-
add_dependencies(sourcekit-inproc BlocksRuntime dispatch)
1103-
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "OSX|WINDOWS")
1104-
swift_install_in_component(FILES
1105-
$<TARGET_FILE:dispatch>
1106-
$<TARGET_FILE:BlocksRuntime>
1107-
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
1108-
COMPONENT sourcekit-inproc)
1109-
endif()
1110-
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
1111-
swift_install_in_component(FILES
1112-
$<TARGET_LINKER_FILE:dispatch>
1113-
$<TARGET_LINKER_FILE:BlocksRuntime>
1114-
DESTINATION lib
1115-
COMPONENT sourcekit-inproc)
1116-
endif()
1117-
1118-
1119-
# FIXME(compnerd) this should be taken care of by the
1120-
# INTERFACE_INCLUDE_DIRECTORIES above
1121-
include_directories(AFTER
1122-
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime
1123-
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
1124-
endif()
1125-
endif()
999+
include(Libdispatch)
11261000

11271001
# Add all of the subdirectories, where we actually do work.
11281002

cmake/modules/AddSwift.cmake

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ function(_add_host_variant_c_compile_link_flags name)
8282
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
8383
endif()
8484

85+
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
86+
set(DEPLOYMENT_VERSION ${SWIFT_ANDROID_API_LEVEL})
87+
endif()
88+
8589
# MSVC, clang-cl, gcc don't understand -target.
8690
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
8791
get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}"
@@ -271,18 +275,6 @@ function(_add_host_variant_c_compile_flags target)
271275
target_compile_options(${target} PRIVATE -funwind-tables)
272276
endif()
273277

274-
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
275-
target_compile_options(${target} PRIVATE -nostdinc++)
276-
swift_android_libcxx_include_paths(CFLAGS_CXX_INCLUDES)
277-
swift_android_include_for_arch("${SWIFT_HOST_VARIANT_ARCH}"
278-
"${SWIFT_HOST_VARIANT_ARCH}_INCLUDE")
279-
target_include_directories(${target} SYSTEM PRIVATE
280-
${CFLAGS_CXX_INCLUDES}
281-
${${SWIFT_HOST_VARIANT_ARCH}_INCLUDE})
282-
target_compile_definitions(${target} PRIVATE
283-
__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL})
284-
endif()
285-
286278
if(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX")
287279
if(SWIFT_HOST_VARIANT_ARCH STREQUAL x86_64)
288280
# this is the minimum architecture that supports 16 byte CAS, which is
@@ -350,7 +342,7 @@ function(_add_host_variant_link_flags target)
350342
target_link_libraries(${target} PRIVATE
351343
${cxx_link_libraries})
352344

353-
swift_android_lib_for_arch(${SWIFT_HOST_VARIANT_ARCH}
345+
swift_android_libgcc_for_arch_cross_compile(${SWIFT_HOST_VARIANT_ARCH}
354346
${SWIFT_HOST_VARIANT_ARCH}_LIB)
355347
target_link_directories(${target} PRIVATE
356348
${${SWIFT_HOST_VARIANT_ARCH}_LIB})

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function(add_swift_unittest test_dirname)
4848
COMMAND "${SWIFT_SOURCE_DIR}/utils/swift-rpathize.py"
4949
"$<TARGET_FILE:${test_dirname}>")
5050
elseif("${SWIFT_HOST_VARIANT}" STREQUAL "android")
51-
swift_android_lib_for_arch(${SWIFT_HOST_VARIANT_ARCH} android_system_libs)
51+
swift_android_libgcc_for_arch_cross_compile(${SWIFT_HOST_VARIANT_ARCH} android_system_libs)
5252
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_DIRECTORIES
5353
"${android_system_libs}")
5454
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES "log")

0 commit comments

Comments
 (0)