Skip to content

Commit 3ed48c7

Browse files
authored
Merge pull request swiftlang#1119 from swiftwasm/master
[pull] swiftwasm from master
2 parents 56820c1 + 88b804b commit 3ed48c7

File tree

119 files changed

+8236
-910
lines changed

Some content is hidden

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

119 files changed

+8236
-910
lines changed

CMakeLists.txt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,20 @@ set(SWIFT_COMPILER_VERSION "" CACHE STRING
147147
set(CLANG_COMPILER_VERSION "" CACHE STRING
148148
"The internal version of the Clang compiler")
149149

150-
# Indicate whether Swift should attempt to use the lld linker.
151-
if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
152-
set(SWIFT_ENABLE_LLD_LINKER_default TRUE)
150+
# Which default linker to use. Prefer LLVM_USE_LINKER if it set, otherwise use
151+
# our own defaults. This should only be possible in a unified (not stand alone)
152+
# build environment.
153+
if(LLVM_USE_LINKER)
154+
set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}")
155+
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
156+
set(SWIFT_USE_LINKER_default "lld")
157+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
158+
set(SWIFT_USE_LINKER_default "")
153159
else()
154-
set(SWIFT_ENABLE_LLD_LINKER_default FALSE)
160+
set(SWIFT_USE_LINKER_default "gold")
155161
endif()
156-
set(SWIFT_ENABLE_LLD_LINKER ${SWIFT_ENABLE_LLD_LINKER_default} CACHE BOOL
157-
"Enable using the lld linker when available")
158-
159-
# Indicate whether Swift should attempt to use the gold linker.
160-
# This is not used on Darwin.
161-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL Windows)
162-
set(SWIFT_ENABLE_GOLD_LINKER_default FALSE)
163-
else()
164-
set(SWIFT_ENABLE_GOLD_LINKER_default TRUE)
165-
endif()
166-
set(SWIFT_ENABLE_GOLD_LINKER ${SWIFT_ENABLE_GOLD_LINKER_default} CACHE BOOL
167-
"Enable using the gold linker when available")
162+
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
163+
"Build Swift with a non-default linker")
168164

169165
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
170166
must specify the form of LTO by setting this to one of: 'full', 'thin'. This

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ with version 2 shipped with Ubuntu.
154154

155155
**Note:** For Ubuntu 20.04, use `libpython2-dev` in place of the libpython-dev package above.
156156

157-
Build instructions for Ubuntu 14.04 LTS can be found [here](docs/Ubuntu14.md).
158-
159157
### Getting Sources for Swift and Related Projects
160158

161159
First create a directory for all of the Swift sources:

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function(_add_host_variant_c_compile_link_flags name)
116116
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
117117
# lld can handle targeting the android build. However, if lld is not
118118
# enabled, then fallback to the linker included in the android NDK.
119-
if(NOT SWIFT_ENABLE_LLD_LINKER)
119+
if(NOT SWIFT_USE_LINKER STREQUAL "lld")
120120
swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
121121
target_compile_options(${name} PRIVATE -B${tools_path})
122122
endif()
@@ -370,12 +370,9 @@ function(_add_host_variant_link_flags target)
370370
endif()
371371

372372
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
373-
if(SWIFT_ENABLE_LLD_LINKER)
373+
if(SWIFT_USE_LINKER)
374374
target_link_options(${target} PRIVATE
375-
-fuse-ld=lld$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
376-
elseif(SWIFT_ENABLE_GOLD_LINKER)
377-
target_link_options(${target} PRIVATE
378-
-fuse-ld=gold$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
375+
-fuse-ld=${SWIFT_USE_LINKER}$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
379376
endif()
380377
endif()
381378

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,9 @@ function(add_swift_unittest test_dirname)
5757
_ENABLE_EXTENDED_ALIGNED_STORAGE)
5858
endif()
5959

60-
find_program(LDLLD_PATH "ld.lld")
61-
# Strangely, macOS finds lld and then can't find it when using -fuse-ld=
62-
if(SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE)
60+
if(SWIFT_USE_LINKER)
6361
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
64-
LINK_FLAGS " -fuse-ld=lld")
65-
elseif(SWIFT_ENABLE_GOLD_LINKER AND
66-
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
67-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
68-
LINK_FLAGS " -fuse-ld=gold")
62+
LINK_FLAGS " -fuse-ld=${SWIFT_USE_LINKER}")
6963
endif()
7064

7165
if(SWIFT_ANALYZE_CODE_COVERAGE)

docs/DifferentiableProgramming.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,6 @@ public extension Differentiable where Self == TangentVector {
10791079
mutating func move(along direction: TangentVector) {
10801080
self += direction
10811081
}
1082-
1083-
@noDerivative
1084-
var zeroTangentVectorInitializer: () -> TangentVector {
1085-
{ .zero }
1086-
}
10871082
}
10881083
```
10891084

@@ -1144,8 +1139,8 @@ extension Array: Differentiable where Element: Differentiable {
11441139

11451140
@noDerivative
11461141
public var zeroTangentVectorInitializer: () -> TangentVector {
1147-
{ [count = self.count] in
1148-
TangentVector(Array(repeating: .zero, count: count))
1142+
{ [zeroInits = map(\.zeroTangentVectorInitializer)] in
1143+
TangentVector(zeroInits.map { $0() })
11491144
}
11501145
}
11511146
}
@@ -1238,8 +1233,15 @@ the same effective access level as their corresponding original properties.
12381233

12391234
A `move(along:)` method is synthesized with a body that calls `move(along:)` for
12401235
each pair of the original property and its corresponding property in
1241-
`TangentVector`. Similarly, `zeroTangentVector` is synthesized to return a
1242-
tangent vector that consists of each stored property's `zeroTangentVector`.
1236+
`TangentVector`.
1237+
1238+
Similarly, when memberwise derivation is possible,
1239+
`zeroTangentVectorInitializer` is synthesized to return a closure that captures
1240+
and calls each stored property's `zeroTangentVectorInitializer` closure.
1241+
When memberwise derivation is not possible (e.g. for custom user-defined
1242+
`TangentVector` types), `zeroTangentVectorInitializer` is synthesized as a
1243+
`{ TangentVector.zero }` closure.
1244+
12431245
Here's an example:
12441246

12451247
```swift
@@ -1251,14 +1253,17 @@ struct Foo<T: Differentiable, U: Differentiable>: @memberwise Differentiable {
12511253
@noDerivative let helperVariable: T
12521254

12531255
// The compiler synthesizes:
1256+
//
12541257
// struct TangentVector: Differentiable, AdditiveArithmetic {
12551258
// var x: T.TangentVector
12561259
// var y: U.TangentVector
12571260
// }
1261+
//
12581262
// mutating func move(along direction: TangentVector) {
12591263
// x.move(along: direction.x)
12601264
// y.move(along: direction.y)
12611265
// }
1266+
//
12621267
// @noDerivative
12631268
// var zeroTangentVectorInitializer: () -> TangentVector {
12641269
// { [xTanInit = x.zeroTangentVectorInitializer,
@@ -1278,16 +1283,25 @@ properties are declared to conform to `AdditiveArithmetic`. There are no
12781283
`@noDerivative` stored properties.
12791284

12801285
In these cases, the compiler will make `TangentVector` be a type alias for Self.
1281-
Method `move(along:)` and property `zeroTangentVector` will not be synthesized
1282-
because a default implementation already exists.
1286+
Method `move(along:)` will not be synthesized because a default implementation
1287+
already exists.
12831288

12841289
```swift
12851290
struct Point<T: Real>: @memberwise Differentiable, @memberwise AdditiveArithmetic {
12861291
// `x` and `y` are the "differentiation properties".
12871292
var x, y: T
12881293

12891294
// The compiler synthesizes:
1295+
//
12901296
// typealias TangentVector = Self
1297+
//
1298+
// @noDerivative
1299+
// var zeroTangentVectorInitializer: () -> TangentVector {
1300+
// { [xTanInit = x.zeroTangentVectorInitializer,
1301+
// yTanInit = y.zeroTangentVectorInitializer] in
1302+
// TangentVector(x: xTanInit(), y: yTanInit())
1303+
// }
1304+
// }
12911305
}
12921306
```
12931307

docs/Ubuntu14.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/WindowsBuild.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building Swift on Windows
22

3-
Visual Studio 2017 or newer is needed to build Swift on Windows.
3+
Visual Studio 2017 or newer is needed to build Swift on Windows. The free Community edition is sufficient to build Swift.
44

55
The commands below (with the exception of installing Visual Studio) must be entered in the "**x64 Native** Tools Command Prompt for VS2017" (or VS2019, VS2019 Preview depending on the Visual Studio that you are using) in the Start Menu. This sets environment variables to select the correct target platform.
66

@@ -32,7 +32,7 @@ The command above already installs Python 2 and 3. Alternatively, in the Visual
3232

3333
1. Install *Python 2*, either the 32-bit version (C:\Python27\\) or the 64-bit version (C:\Python27amd64\\)
3434

35-
> If you install the 64-bit version only, you will need to adjust `PYTHON_EXECUTABLE` below to `C:\Python27amd64\python.exe`
35+
**Note:** If you install the 64-bit version only, you will need to adjust `PYTHON_EXECUTABLE` below to `C:\Python27amd64\python.exe`
3636

3737
2. Install *Python 3 64 bits (3.7.x)*
3838

@@ -150,6 +150,9 @@ cmake -B "S:\b\toolchain" ^
150150
ninja -C S:\b\toolchain
151151
```
152152

153+
**Note:** If you installed only the 64-bit version of Python, you will need to adjust `PYTHON_EXECUTABLE` argument to `C:\Python27amd64\python.exe`
154+
155+
153156
## Running Swift tests on Windows
154157

155158
```cmd

include/swift/ABI/Metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ struct TargetAnyClassMetadata : public TargetHeapMetadata<Runtime> {
10251025
using TargetMetadata<Runtime>::setClassISA;
10261026
#endif
10271027

1028-
// Note that ObjC classes does not have a metadata header.
1028+
// Note that ObjC classes do not have a metadata header.
10291029

10301030
/// The metadata for the superclass. This is null for the root class.
10311031
ConstTargetMetadataPointer<Runtime, swift::TargetClassMetadata> Superclass;

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ DECL_ATTR(available, Available,
126126
CONTEXTUAL_SIMPLE_DECL_ATTR(final, Final,
127127
OnClass | OnFunc | OnAccessor | OnVar | OnSubscript |
128128
DeclModifier |
129-
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIStableToRemove,
129+
ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
130130
2)
131131
DECL_ATTR(objc, ObjC,
132132
OnAbstractFunction | OnClass | OnProtocol | OnExtension | OnVar |

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ IDENTIFIER(move)
223223
IDENTIFIER(pullback)
224224
IDENTIFIER(TangentVector)
225225
IDENTIFIER(zero)
226+
IDENTIFIER(zeroTangentVectorInitializer)
226227

227228
#undef IDENTIFIER
228229
#undef IDENTIFIER_

include/swift/AST/Types.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,17 @@ class alignas(1 << TypeAlignInBits) TypeBase {
852852
/// \returns The superclass of this type, or a null type if it has no
853853
/// superclass.
854854
Type getSuperclass(bool useArchetypes = true);
855-
855+
856+
/// Retrieve the root class of this type by repeatedly retrieving the
857+
/// superclass.
858+
///
859+
/// \param useArchetypes Whether to use context archetypes for outer generic
860+
/// parameters if the class is nested inside a generic function.
861+
///
862+
/// \returns The base class of this type, or this type itself if it has no
863+
/// superclasses.
864+
Type getRootClass(bool useArchetypes = true);
865+
856866
/// True if this type is the exact superclass of another type.
857867
///
858868
/// \param ty The potential subclass.

include/swift/Basic/LLVM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace llvm {
3636
template <typename T, unsigned N> class SmallPtrSet;
3737
#if !defined(swiftCore_EXPORTS)
3838
template <typename T> class SmallVectorImpl;
39-
#endif
4039
template <typename T, unsigned N> class SmallVector;
40+
#endif
4141
template <unsigned N> class SmallString;
4242
template <typename T, unsigned N> class SmallSetVector;
4343
#if !defined(swiftCore_EXPORTS)
@@ -86,8 +86,8 @@ namespace swift {
8686
using llvm::SmallPtrSetImpl;
8787
using llvm::SmallSetVector;
8888
using llvm::SmallString;
89-
using llvm::SmallVector;
9089
#if !defined(swiftCore_EXPORTS)
90+
using llvm::SmallVector;
9191
using llvm::SmallVectorImpl;
9292
#endif
9393
using llvm::StringLiteral;

include/swift/Demangling/DemangleNodes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,5 +287,9 @@ NODE(OpaqueTypeDescriptorAccessorVar)
287287
NODE(OpaqueReturnType)
288288
CONTEXT_NODE(OpaqueReturnTypeOf)
289289

290+
// Added in Swift 5.3
291+
NODE(CanonicalSpecializedGenericMetaclass)
292+
NODE(CanonicalSpecializedGenericTypeMetadataAccessFunction)
293+
290294
#undef CONTEXT_NODE
291295
#undef NODE

include/swift/Demangling/TypeDecoder.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class TypeDecoder {
361361
if (Node->getNumChildren() < 2)
362362
return BuiltType();
363363

364-
SmallVector<BuiltType, 8> args;
364+
llvm::SmallVector<BuiltType, 8> args;
365365

366366
const auto &genericArgs = Node->getChild(1);
367367
if (genericArgs->getKind() != NodeKind::TypeList)
@@ -474,7 +474,7 @@ class TypeDecoder {
474474
return BuiltType();
475475

476476
// Find the protocol list.
477-
SmallVector<BuiltProtocolDecl, 8> Protocols;
477+
llvm::SmallVector<BuiltProtocolDecl, 8> Protocols;
478478
auto TypeList = Node->getChild(0);
479479
if (TypeList->getKind() == NodeKind::ProtocolList &&
480480
TypeList->getNumChildren() >= 1) {
@@ -576,7 +576,7 @@ class TypeDecoder {
576576
return BuiltType();
577577

578578
bool hasParamFlags = false;
579-
SmallVector<FunctionParam<BuiltType>, 8> parameters;
579+
llvm::SmallVector<FunctionParam<BuiltType>, 8> parameters;
580580
if (!decodeMangledFunctionInputType(Node->getChild(isThrow ? 1 : 0),
581581
parameters, hasParamFlags))
582582
return BuiltType();
@@ -598,9 +598,9 @@ class TypeDecoder {
598598
}
599599
case NodeKind::ImplFunctionType: {
600600
auto calleeConvention = ImplParameterConvention::Direct_Unowned;
601-
SmallVector<ImplFunctionParam<BuiltType>, 8> parameters;
602-
SmallVector<ImplFunctionResult<BuiltType>, 8> results;
603-
SmallVector<ImplFunctionResult<BuiltType>, 8> errorResults;
601+
llvm::SmallVector<ImplFunctionParam<BuiltType>, 8> parameters;
602+
llvm::SmallVector<ImplFunctionResult<BuiltType>, 8> results;
603+
llvm::SmallVector<ImplFunctionResult<BuiltType>, 8> errorResults;
604604
ImplFunctionTypeFlags flags;
605605

606606
for (unsigned i = 0; i < Node->getNumChildren(); i++) {
@@ -684,7 +684,7 @@ class TypeDecoder {
684684
return decodeMangledType(Node->getChild(0));
685685

686686
case NodeKind::Tuple: {
687-
SmallVector<BuiltType, 8> elements;
687+
llvm::SmallVector<BuiltType, 8> elements;
688688
std::string labels;
689689
bool variadic = false;
690690
for (auto &element : *Node) {

0 commit comments

Comments
 (0)