Skip to content

Commit 125daf7

Browse files
Merge pull request #2275 from swiftwasm/maxd/main-merge
Resolve conflicts with `main`
2 parents 7a04fb3 + 36d3b13 commit 125daf7

File tree

599 files changed

+19442
-4997
lines changed

Some content is hidden

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

599 files changed

+19442
-4997
lines changed

.mailmap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Adrian-Constantin Popescu <[email protected]> <[email protected]>
22
33
4-
4+
55
Alexis Beingessner <[email protected]> <[email protected]>
66
77
@@ -79,6 +79,7 @@ Joe Shajrawi <[email protected]> <[email protected]>
7979
8080
8181
82+
8283
8384
8485
Kevin Saldaña <[email protected]>

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ set(SWIFT_BENCH_MODULES
8080
single-source/DictionaryRemove
8181
single-source/DictionarySubscriptDefault
8282
single-source/DictionarySwap
83+
single-source/Differentiation
8384
single-source/Diffing
8485
single-source/DiffingMyers
8586
single-source/DropFirst
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//===--- Differentiation.swift -------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#if canImport(_Differentiation)
14+
15+
import TestsUtils
16+
import _Differentiation
17+
18+
public let Differentiation = [
19+
BenchmarkInfo(
20+
name: "DifferentiationIdentity",
21+
runFunction: run_DifferentiationIdentity,
22+
tags: [.regression, .differentiation]
23+
),
24+
BenchmarkInfo(
25+
name: "DifferentiationSquare",
26+
runFunction: run_DifferentiationSquare,
27+
tags: [.regression, .differentiation]
28+
),
29+
BenchmarkInfo(
30+
name: "DifferentiationArraySum",
31+
runFunction: run_DifferentiationArraySum,
32+
tags: [.regression, .differentiation],
33+
setUpFunction: { blackHole(onesArray) }
34+
),
35+
]
36+
37+
@inline(never)
38+
public func run_DifferentiationIdentity(N: Int) {
39+
func f(_ x: Float) -> Float {
40+
x
41+
}
42+
for _ in 0..<1000*N {
43+
blackHole(valueWithGradient(at: 1, in: f))
44+
}
45+
}
46+
47+
@inline(never)
48+
public func run_DifferentiationSquare(N: Int) {
49+
func f(_ x: Float) -> Float {
50+
x * x
51+
}
52+
for _ in 0..<1000*N {
53+
blackHole(valueWithGradient(at: 1, in: f))
54+
}
55+
}
56+
57+
let onesArray: [Float] = Array(repeating: 1, count: 50)
58+
59+
@inline(never)
60+
public func run_DifferentiationArraySum(N: Int) {
61+
func sum(_ array: [Float]) -> Float {
62+
var result: Float = 0
63+
for i in withoutDerivative(at: 0..<array.count) {
64+
result += array[i]
65+
}
66+
return result
67+
}
68+
for _ in 0..<N {
69+
blackHole(valueWithGradient(at: onesArray, in: sum))
70+
}
71+
}
72+
73+
#endif

benchmark/utils/TestsUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public enum BenchmarkCategory : String {
2828
case runtime, refcount, metadata
2929
// Other general areas of compiled code validation.
3030
case abstraction, safetychecks, exceptions, bridging, concurrency, existential
31-
case exclusivity
31+
case exclusivity, differentiation
3232

3333
// Algorithms are "micro" that test some well-known algorithm in isolation:
3434
// sorting, searching, hashing, fibonaci, crypto, etc.

benchmark/utils/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ import DictionaryOfAnyHashableStrings
6969
import DictionaryRemove
7070
import DictionarySubscriptDefault
7171
import DictionarySwap
72+
#if canImport(_Differentiation)
73+
import Differentiation
74+
#endif
7275
import Diffing
7376
import DiffingMyers
7477
import DropFirst
@@ -258,6 +261,9 @@ registerBenchmark(DictionaryOfAnyHashableStrings)
258261
registerBenchmark(DictionaryRemove)
259262
registerBenchmark(DictionarySubscriptDefault)
260263
registerBenchmark(DictionarySwap)
264+
#if canImport(_Differentiation)
265+
registerBenchmark(Differentiation)
266+
#endif
261267
registerBenchmark(Diffing)
262268
registerBenchmark(DiffingMyers)
263269
registerBenchmark(DropFirst)

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ macro(configure_sdk_unix name architectures)
297297
else()
298298
message(SEND_ERROR "Couldn't find SWIFT_SDK_ANDROID_ARCH_armv7_PATH")
299299
endif()
300-
set(SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE "armv7-none-linux-androideabi")
300+
set(SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE "armv7-unknown-linux-androideabi")
301301
# The Android ABI isn't part of the module triple.
302-
set(SWIFT_SDK_ANDROID_ARCH_${arch}_MODULE "armv7-none-linux-android")
302+
set(SWIFT_SDK_ANDROID_ARCH_${arch}_MODULE "armv7-unknown-linux-android")
303303
elseif("${arch}" STREQUAL "aarch64")
304304
set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE "aarch64-linux-android")
305305
set(SWIFT_SDK_ANDROID_ARCH_${arch}_ALT_SPELLING "aarch64")

cmake/modules/SwiftManpage.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ function(manpage)
3939
ALL)
4040

4141
add_dependencies(${MP_INSTALL_IN_COMPONENT} ${manpage_target})
42+
set(MANPAGE_DEST "share/")
43+
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "OPENBSD")
44+
set(MANPAGE_DEST "")
45+
endif()
4246
swift_install_in_component(FILES "${output_file_name}"
43-
DESTINATION "share/man/man${MP_MAN_SECTION}"
47+
DESTINATION "${MANPAGE_DEST}man/man${MP_MAN_SECTION}"
4448
COMPONENT "${MP_INSTALL_IN_COMPONENT}")
4549
endfunction()
4650

docs/ABI/Mangling.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,11 @@ Types
492492

493493
type ::= 'Bb' // Builtin.BridgeObject
494494
type ::= 'BB' // Builtin.UnsafeValueBuffer
495+
type ::= 'Bc' // Builtin.RawUnsafeContinuation
495496
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
496497
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
497498
type ::= 'BI' // Builtin.IntLiteral
499+
type ::= 'Bj' // Builtin.Job
498500
type ::= 'BO' // Builtin.UnknownObject (no longer a distinct type, but still used for AnyObject)
499501
type ::= 'Bo' // Builtin.NativeObject
500502
type ::= 'Bp' // Builtin.RawPointer
@@ -1006,6 +1008,8 @@ Function Specializations
10061008
::
10071009

10081010
specialization ::= type '_' type* 'Tg' SPEC-INFO // Generic re-abstracted specialization
1011+
specialization ::= type '_' type* 'TB' SPEC-INFO // Alternative mangling for generic re-abstracted specializations,
1012+
// used for functions with re-abstracted resilient parameter types.
10091013
specialization ::= type '_' type* 'Ts' SPEC-INFO // Generic re-abstracted prespecialization
10101014
specialization ::= type '_' type* 'TG' SPEC-INFO // Generic not re-abstracted specialization
10111015
specialization ::= type '_' type* 'Ti' SPEC-INFO // Inlined function with generic substitutions.

docs/Android.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ $ NDK_PATH="path/to/android-ndk21"
103103
$ build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc \ # The Swift compiler built in the previous step.
104104
# The location of the tools used to build Android binaries
105105
-tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \
106-
-target armv7a-none-linux-androideabi \ # Targeting android-armv7, and supply the path to libgcc.
106+
-target armv7a-unknown-linux-androideabi \ # Targeting android-armv7, and supply the path to libgcc.
107107
-L ${NDK_PATH}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/armv7-a \
108108
-sdk ${NDK_PATH}/platforms/android-21/arch-arm \ # Use the same architecture and API version as you used to build the stdlib in the previous step.
109109
hello.swift

docs/ContinuousIntegration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ preset=buildbot,tools=RA,stdlib=RD,test=non_executable
215215

216216
### Build and Test the Minimal Freestanding Stdlib using Toolchain Specific Preset Testing
217217

218-
To test the minimal freestanding stdlib on macho, you can use the support for running a miscellanous preset against a snapshot toolchain.
218+
To test the minimal freestanding stdlib on macho, you can use the support for running a miscellaneous preset against a snapshot toolchain.
219219

220220
```
221221
preset=stdlib_S_standalone_minimal_macho_x86_64,build,test

docs/DifferentiableProgramming.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,12 @@ The synthesized `TangentVector` has the same effective access level as the
12731273
original type declaration. Properties in the synthesized `TangentVector` have
12741274
the same effective access level as their corresponding original properties.
12751275

1276+
The synthesized `TangentVector` adopts protocols from all `TangentVector`
1277+
conformance constraints implied by the declaration that triggers synthesis. For
1278+
example, synthesized `TangentVector`s always adopt the `AdditiveArithmetic` and
1279+
`Differentiable` protocols because the `Differentiable` protocol requires that
1280+
`TangentVector` conforms to `AdditiveArithmetic` and `Differentiable`.
1281+
12761282
The synthesized `move(along:)` method calls `move(along:)` for each pair of a
12771283
differentiable variable and its corresponding property in `TangentVector`.
12781284

@@ -1879,7 +1885,7 @@ Since complex numbers are not yet defined in the standard library, we extended
18791885
the complex number type defined in the
18801886
[NumericAnnex](https://github.com/xwu/NumericAnnex) library to be
18811887
differentiable.
1882-
[The full implementation is here](https://github.com/tensorflow/swift-apis/blob/master/Sources/third_party/Experimental/Complex.swift).
1888+
[The full implementation is here](https://github.com/tensorflow/swift-apis/blob/main/Sources/third_party/Experimental/Complex.swift).
18831889
The implementation adopts the
18841890
[Autograd convention](https://github.com/HIPS/autograd/blob/master/docs/tutorial.md#complex-numbers)
18851891
for derivatives of functions with complex arguments or results, so that we can

include/swift/ABI/Actor.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===--- Actor.h - ABI structures for actors --------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Swift ABI describing actors.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_ABI_ACTOR_H
18+
#define SWIFT_ABI_ACTOR_H
19+
20+
#include "swift/ABI/HeapObject.h"
21+
#include "swift/ABI/MetadataValues.h"
22+
23+
namespace swift {
24+
25+
/// The default actor implementation. This is the layout of both
26+
/// the DefaultActor and NSDefaultActor classes.
27+
class alignas(Alignment_DefaultActor) DefaultActor : public HeapObject {
28+
public:
29+
// These constructors do not initialize the actor instance, and the
30+
// destructor does not destroy the actor instance; you must call
31+
// swift_defaultActor_{initialize,destroy} yourself.
32+
constexpr DefaultActor(const HeapMetadata *metadata)
33+
: HeapObject(metadata), PrivateData{} {}
34+
35+
constexpr DefaultActor(const HeapMetadata *metadata,
36+
InlineRefCounts::Immortal_t immortal)
37+
: HeapObject(metadata, immortal), PrivateData{} {}
38+
39+
void *PrivateData[NumWords_DefaultActor];
40+
};
41+
42+
} // end namespace swift
43+
44+
#endif

include/swift/ABI/Class.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ enum class ObjCClassFlags : uint32_t {
5353
/// This class provides a non-trivial .cxx_destruct method, but
5454
/// its .cxx_construct is trivial. For backwards compatibility,
5555
/// when setting this flag, HasCXXStructors must be set as well.
56-
HasCXXDestructorOnly = 0x00100
56+
HasCXXDestructorOnly = 0x00100,
57+
58+
/// This class does not allow associated objects on instances.
59+
///
60+
/// Will cause the objc runtime to trap in objc_setAssociatedObject.
61+
ForbidsAssociatedObjects = 0x00400,
5762
};
5863
inline ObjCClassFlags &operator|=(ObjCClassFlags &lhs, ObjCClassFlags rhs) {
5964
lhs = ObjCClassFlags(uint32_t(lhs) | uint32_t(rhs));

include/swift/ABI/Executor.h

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//===--- Executor.h - ABI structures for executors --------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Swift ABI describing executors.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_ABI_EXECUTOR_H
18+
#define SWIFT_ABI_EXECUTOR_H
19+
20+
#include <inttypes.h>
21+
22+
namespace swift {
23+
class AsyncContext;
24+
class AsyncTask;
25+
class DefaultActor;
26+
class Job;
27+
28+
/// An ExecutorRef isn't necessarily just a pointer to an executor
29+
/// object; it may have other bits set.
30+
class ExecutorRef {
31+
static constexpr uintptr_t IsDefaultActor = 1;
32+
static constexpr uintptr_t PointerMask = 7;
33+
34+
uintptr_t Value;
35+
36+
constexpr ExecutorRef(uintptr_t value) : Value(value) {}
37+
38+
public:
39+
/// A generic execution environment. When running in a generic
40+
/// environment, it's presumed to be okay to switch synchronously
41+
/// to an actor. As an executor request, this represents a request
42+
/// to drop whatever the current actor is.
43+
constexpr static ExecutorRef generic() {
44+
return ExecutorRef(0);
45+
}
46+
47+
/// Given a pointer to a default actor, return an executor reference
48+
/// for it.
49+
static ExecutorRef forDefaultActor(DefaultActor *actor) {
50+
assert(actor);
51+
return ExecutorRef(reinterpret_cast<uintptr_t>(actor) | IsDefaultActor);
52+
}
53+
54+
/// Is this the generic executor reference?
55+
bool isGeneric() const {
56+
return Value == 0;
57+
}
58+
59+
/// Is this a default-actor executor reference?
60+
bool isDefaultActor() const {
61+
return Value & IsDefaultActor;
62+
}
63+
DefaultActor *getDefaultActor() const {
64+
assert(isDefaultActor());
65+
return reinterpret_cast<DefaultActor*>(Value & ~PointerMask);
66+
}
67+
68+
/// Do we have to do any work to start running as the requested
69+
/// executor?
70+
bool mustSwitchToRun(ExecutorRef newExecutor) const {
71+
return *this != newExecutor;
72+
}
73+
74+
bool operator==(ExecutorRef other) const {
75+
return Value == other.Value;
76+
}
77+
bool operator!=(ExecutorRef other) const {
78+
return Value != other.Value;
79+
}
80+
};
81+
82+
using JobInvokeFunction =
83+
SWIFT_CC(swiftasync)
84+
void (Job *, ExecutorRef);
85+
86+
using TaskContinuationFunction =
87+
SWIFT_CC(swiftasync)
88+
void (AsyncTask *, ExecutorRef, AsyncContext *);
89+
90+
template <class Fn>
91+
struct AsyncFunctionTypeImpl;
92+
template <class Result, class... Params>
93+
struct AsyncFunctionTypeImpl<Result(Params...)> {
94+
// TODO: expand and include the arguments in the parameters.
95+
using type = TaskContinuationFunction;
96+
};
97+
98+
template <class Fn>
99+
using AsyncFunctionType = typename AsyncFunctionTypeImpl<Fn>::type;
100+
101+
/// A "function pointer" for an async function.
102+
///
103+
/// Eventually, this will always be signed with the data key
104+
/// using a type-specific discriminator.
105+
template <class FnType>
106+
class AsyncFunctionPointer {
107+
public:
108+
/// The function to run.
109+
RelativeDirectPointer<AsyncFunctionType<FnType>,
110+
/*nullable*/ false,
111+
int32_t> Function;
112+
113+
/// The expected size of the context.
114+
uint32_t ExpectedContextSize;
115+
};
116+
117+
}
118+
119+
#endif

0 commit comments

Comments
 (0)