Skip to content

Commit 4d09706

Browse files
committed
Merge branch 'main' into class_templates
2 parents 71a9065 + f205b20 commit 4d09706

File tree

381 files changed

+22289
-7212
lines changed

Some content is hidden

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

381 files changed

+22289
-7212
lines changed

docs/DifferentiableProgramming.md

+6-100
Original file line numberDiff line numberDiff line change
@@ -986,44 +986,6 @@ public protocol Differentiable {
986986
/// equivalent to exponential map, which moves `self` on the geodesic
987987
/// surface along the given tangent vector.
988988
mutating func move(along direction: TangentVector)
989-
990-
/// A closure that produces a zero tangent vector and does not capture `self`.
991-
///
992-
/// In some cases, the zero tangent vector of `self` is equal to
993-
/// `TangentVector.zero`. In other cases, the zero tangent vector depends on
994-
/// information in `self`, such as shape for an n-dimensional array type.
995-
/// For differentiable programming, it is more memory-efficient to define a
996-
/// custom `zeroTangentVectorInitializer` property which returns a closure
997-
/// that captures and uses only the necessary information to create a zero
998-
/// tangent vector. For example:
999-
///
1000-
/// ```swift
1001-
/// struct Vector {
1002-
/// var scalars: [Float]
1003-
/// var count: Int { scalars.count }
1004-
/// init(repeating repeatedElement: Float, count: Int) { ... }
1005-
/// }
1006-
///
1007-
/// extension Vector: Differentiable {
1008-
/// typealias TangentVector = Vector
1009-
///
1010-
/// @noDerivative
1011-
/// var zeroTangentVectorInitializer: () -> TangentVector {
1012-
/// let count = self.count
1013-
/// return { TangentVector(repeating: 0, count: count) }
1014-
/// }
1015-
/// }
1016-
/// ```
1017-
///
1018-
@noDerivative
1019-
var zeroTangentVectorInitializer: () -> TangentVector { get }
1020-
}
1021-
1022-
extension Differentiable {
1023-
/// A tangent vector such that `move(along: zeroTangentVector)` will not modify
1024-
/// `self`.
1025-
@noDerivative
1026-
var zeroTangentVector: TangentVector { zeroTangentVectorInitializer() }
1027989
}
1028990
```
1029991

@@ -1092,13 +1054,6 @@ public extension Differentiable where Self == TangentVector {
10921054
}
10931055
```
10941056

1095-
The `zeroTangentVector` property returns a tangent vector such that calling
1096-
`move(along:)` on the vector will not modify `self`. A zero tangent vector is
1097-
often used in the initialization of mathematical optimization, where tangent
1098-
vectors are initially zero and modified iteratively. This property may be
1099-
different from `TangentVector.zero` because some tangent vectors depend on
1100-
instance properties of `self`, e.g. the `count` property in `Array`.
1101-
11021057
#### `Differentiable` conformances
11031058

11041059
Conforming a type to `Differentiable` tells Swift that changes in values of this
@@ -1146,13 +1101,6 @@ extension Array: Differentiable where Element: Differentiable {
11461101
self[i].move(along: Element.TangentVector(direction.elements[i]))
11471102
}
11481103
}
1149-
1150-
@noDerivative
1151-
public var zeroTangentVectorInitializer: () -> TangentVector {
1152-
{ [zeroInits = map(\.zeroTangentVectorInitializer)] in
1153-
TangentVector(zeroInits.map { $0() })
1154-
}
1155-
}
11561104
}
11571105

11581106
// struct Dictionary<Key: Hashable, Value>
@@ -1173,14 +1121,6 @@ extension Dictionary: Differentiable where Value: Differentiable {
11731121
self[i].move(along: Value.TangentVector(direction.elements[i]))
11741122
}
11751123
}
1176-
1177-
@noDerivative
1178-
public var zeroTangentVectorInitializer: () -> TangentVector {
1179-
{ [keys = self.keys] in
1180-
let pairs = zip(keys, sequence(first: .zero, next: {$0}))
1181-
return TangentVector(Dictionary(uniqueKeysWithValues: pairs))
1182-
}
1183-
}
11841124
}
11851125

11861126
// enum Optional<Wrapped>
@@ -1199,18 +1139,6 @@ extension Optional: Differentiable where Wrapped: Differentiable {
11991139
self?.move(along: value)
12001140
}
12011141
}
1202-
1203-
@noDerivative
1204-
public var zeroTangentVectorInitializer: () -> TangentVector {
1205-
switch self {
1206-
case nil:
1207-
return { TangentVector(nil) }
1208-
case let x?:
1209-
return { [zeroTanInit = x.zeroTangentVectorInitializer] in
1210-
TangentVector(zeroTanInit())
1211-
}
1212-
}
1213-
}
12141142
}
12151143
```
12161144

@@ -1261,13 +1189,12 @@ product manifold of the manifolds each differentiable variable's type
12611189
represents. Differentiable variables' types are required to conform to
12621190
`Differentiable` because the synthesized implementation needs to access each
12631191
differentiable variable's type's `TangentVector` associated type and invoke each
1264-
differentiable variable's implementation of `move(along:)` and
1265-
`zeroTangentVectorInitializer`. Because the synthesized implementation needs to
1266-
invoke `move(along:)` on each differentiable variable, the differentiable
1267-
variables must have a `move(along:)` which satisfies the protocol requirement
1268-
and can be invoked on the property. That is, the property must be either a
1269-
variable (`var`) or a constant (`let`) with a non-`mutating` implementation of
1270-
the `move(along:)` protocol requirement.
1192+
differentiable variable's implementation of `move(along:)`. Because the
1193+
synthesized implementation needs to invoke `move(along:)` on each differentiable
1194+
variable, the differentiable variables must have a `move(along:)` which satisfies the
1195+
protocol requirement and can be invoked on the property. That is, the property
1196+
must be either a variable (`var`) or a constant (`let`) with a non-`mutating`
1197+
implementation of the `move(along:)` protocol requirement.
12711198

12721199
The synthesized `TangentVector` has the same effective access level as the
12731200
original type declaration. Properties in the synthesized `TangentVector` have
@@ -1282,12 +1209,6 @@ example, synthesized `TangentVector`s always adopt the `AdditiveArithmetic` and
12821209
The synthesized `move(along:)` method calls `move(along:)` for each pair of a
12831210
differentiable variable and its corresponding property in `TangentVector`.
12841211

1285-
The synthesized `zeroTangentVectorInitializer` property returns a closure that
1286-
captures and calls each stored property's `zeroTangentVectorInitializer`
1287-
closure. When memberwise derivation is not possible (e.g. for custom
1288-
user-defined `TangentVector` types), `zeroTangentVectorInitializer` is
1289-
synthesized as a `{ TangentVector.zero }` closure.
1290-
12911212
```swift
12921213
struct Foo<T: Differentiable, U: Differentiable>: @memberwise Differentiable {
12931214
// `x` and `y` are the "differentiable variables".
@@ -1306,13 +1227,6 @@ struct Foo<T: Differentiable, U: Differentiable>: @memberwise Differentiable {
13061227
// x.move(along: direction.x)
13071228
// y.move(along: direction.y)
13081229
// }
1309-
//
1310-
// var zeroTangentVectorInitializer: () -> TangentVector {
1311-
// { [xTanInit = x.zeroTangentVectorInitializer,
1312-
// yTanInit = y.zeroTangentVectorInitializer] in
1313-
// TangentVector(x: xTanInit(), y: yTanInit())
1314-
// }
1315-
// }
13161230
}
13171231
```
13181232

@@ -1404,14 +1318,6 @@ struct Point<T: Real>: @memberwise Differentiable, @memberwise AdditiveArithmeti
14041318
// The compiler synthesizes:
14051319
//
14061320
// typealias TangentVector = Self
1407-
//
1408-
// @noDerivative
1409-
// var zeroTangentVectorInitializer: () -> TangentVector {
1410-
// { [xTanInit = x.zeroTangentVectorInitializer,
1411-
// yTanInit = y.zeroTangentVectorInitializer] in
1412-
// TangentVector(x: xTanInit(), y: yTanInit())
1413-
// }
1414-
// }
14151321
}
14161322
```
14171323

docs/DynamicCasting.md

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ Casting from a function type F1 to a function type F2 will succeed iff the follo
299299
* Corresponding arguments have identical types
300300
* The return types are identical
301301
* If F1 is a throwing function type, then F2 must be a throwing function type. If F1 is not throwing, then F2 may be a throwing or non-throwing function type.
302+
* F1 and F2 have the same calling convention.
302303

303304
Note that it is _not_ sufficient for argument and return types to be castable; they must actually be identical.
304305

docs/HowToGuides/GettingStarted.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ toolchain as a one-off, there are a couple of differences:
6060

6161
1. Create a directory for the whole project:
6262
```sh
63-
mkdir -p swift-project/swift
64-
cd swift-project/swift
63+
mkdir swift-project
64+
cd swift-project
6565
```
6666
2. Clone the sources:
6767
- Via SSH (recommended):

docs/OpenBSD.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Getting started with Swift on OpenBSD
22

3-
Swift builds and runs on OpenBSD (tested on 6.8-beta), with some special considerations.
3+
Swift builds and runs on OpenBSD (tested on 6.8), with some special considerations.
44

55
## Preparing
66

@@ -66,7 +66,7 @@ These options are:
6666
* `--skip-build-clang-tools-extra` and `--skip-build-compiler-rt`: to ensure LLVM builds cleanly,
6767
* `--extra-cmake-options=`
6868
* `-DCMAKE_DISABLE_FIND_PACKAGE_Backtrace=TRUE,-DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=TRUE,-DLLVM_VERSION_SUFFIX=''`: to ensure LLVM builds cleanly,
69-
* `-DSWIFT_BUILD_SOURCEKIT=OFF,-DSWIFT_BUILD_SYNTAXPARSERLIB=OFF`: to ensure Swift does not attempt to build libdispatch, which is not yet supported on OpenBSD,
69+
* `-DSWIFT_BUILD_SOURCEKIT=OFF,-DSWIFT_BUILD_SYNTAXPARSERLIB=OFF,-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=OFF`: to ensure Swift does not attempt to build libdispatch, which is not yet supported on OpenBSD,
7070
* `-DSWIFT_USE_LINKER=lld`: to specify that `lld` should be used over `gold`,
7171
* `-DCMAKE_INSTALL_DIR=/usr/local"`: to set the correct platform install directory.
7272

@@ -81,8 +81,11 @@ $ ./utils/build-script \
8181
-DLLVM_VERSION_SUFFIX='',\
8282
-DSWIFT_BUILD_SOURCEKIT=OFF,\
8383
-DSWIFT_BUILD_SYNTAXPARSERLIB=OFF,\
84+
-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=OFF,\
8485
-DSWIFT_USE_LINKER=lld,\
8586
-DCMAKE_INSTALL_DIR=/usr/local"
8687
```
8788

8889
You may wish to also supply the flag `--llvm-targets-to-build=host`, to speed up the LLVM build slightly.
90+
91+
For debug builds especially, consider also installing the `llvm` package and setting `-DCMAKE_AR=/usr/local/bin/llvm-ar` with the `extra-cmake-options` flag, to work around problems creating indexes to archives containing object files with large numbers of section headers.

include/swift/AST/ASTContext.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,15 @@ class ASTContext final {
629629
ArrayRef<SILParameterInfo> params, Optional<SILResultInfo> result,
630630
SILFunctionType::Representation trueRep);
631631

632-
/// Instantiates "Impl.Converter" if needed, then calls
633-
/// ClangTypeConverter::getClangTemplateArguments.
632+
/// Instantiates "Impl.Converter" if needed, then translate Swift generic
633+
/// substitutions to equivalent C++ types using \p templateParams and \p
634+
/// genericArgs. The converted Clang types are placed into \p templateArgs.
635+
///
636+
/// \p templateArgs must be empty. \p templateParams and \p genericArgs must
637+
/// be equal in size.
638+
///
639+
/// \returns nullptr if successful. If an error occors, returns a list of
640+
/// types that couldn't be converted.
634641
std::unique_ptr<TemplateInstantiationError> getClangTemplateArguments(
635642
const clang::TemplateParameterList *templateParams,
636643
ArrayRef<Type> genericArgs,

include/swift/AST/ASTMangler.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ASTMangler : public Mangler {
222222
GenericSignature signature,
223223
ResilienceExpansion expansion);
224224

225-
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC);
225+
std::string mangleTypeForDebugger(Type decl, GenericSignature sig);
226226

227227
/// Create a mangled name to be used for _typeName constant propagation.
228228
std::string mangleTypeForTypeName(Type type);
@@ -282,9 +282,7 @@ class ASTMangler : public Mangler {
282282
void appendOpWithGenericParamIndex(StringRef,
283283
const GenericTypeParamType *paramTy);
284284

285-
void bindGenericParameters(const DeclContext *DC);
286-
287-
void bindGenericParameters(CanGenericSignature sig);
285+
void bindGenericParameters(GenericSignature sig);
288286

289287
/// Mangles a sugared type iff we are mangling for the debugger.
290288
template <class T> void appendSugaredType(Type type,

include/swift/AST/ClangModuleLoader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class ClangModuleLoader : public ModuleLoader {
238238
SubstitutionMap subst) = 0;
239239
};
240240

241-
/// Used to describe a template instantiation error.
241+
/// Describes a C++ template instantiation error.
242242
struct TemplateInstantiationError {
243243
/// Generic types that could not be converted to QualTypes using the
244244
/// ClangTypeConverter.

include/swift/AST/Decl.h

+17-17
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class alignas(1 << DeclAlignInBits) Decl {
333333
NumElements : 32
334334
);
335335

336-
SWIFT_INLINE_BITFIELD(ValueDecl, Decl, 1+1+1,
336+
SWIFT_INLINE_BITFIELD(ValueDecl, Decl, 1+1+1+1,
337337
AlreadyInLookupTable : 1,
338338

339339
/// Whether we have already checked whether this declaration is a
@@ -342,7 +342,11 @@ class alignas(1 << DeclAlignInBits) Decl {
342342

343343
/// Whether the decl can be accessed by swift users; for instance,
344344
/// a.storage for lazy var a is a decl that cannot be accessed.
345-
IsUserAccessible : 1
345+
IsUserAccessible : 1,
346+
347+
/// Whether this member was synthesized as part of a derived
348+
/// protocol conformance.
349+
Synthesized : 1
346350
);
347351

348352
SWIFT_INLINE_BITFIELD(AbstractStorageDecl, ValueDecl, 1,
@@ -387,7 +391,7 @@ class alignas(1 << DeclAlignInBits) Decl {
387391
SWIFT_INLINE_BITFIELD(SubscriptDecl, VarDecl, 2,
388392
StaticSpelling : 2
389393
);
390-
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1+1,
394+
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1,
391395
/// \see AbstractFunctionDecl::BodyKind
392396
BodyKind : 3,
393397

@@ -406,10 +410,6 @@ class alignas(1 << DeclAlignInBits) Decl {
406410
/// Whether the function body throws.
407411
Throws : 1,
408412

409-
/// Whether this member was synthesized as part of a derived
410-
/// protocol conformance.
411-
Synthesized : 1,
412-
413413
/// Whether this member's body consists of a single expression.
414414
HasSingleExpressionBody : 1,
415415

@@ -2020,6 +2020,7 @@ class ValueDecl : public Decl {
20202020
Bits.ValueDecl.AlreadyInLookupTable = false;
20212021
Bits.ValueDecl.CheckedRedeclaration = false;
20222022
Bits.ValueDecl.IsUserAccessible = true;
2023+
Bits.ValueDecl.Synthesized = false;
20232024
}
20242025

20252026
// MemberLookupTable borrows a bit from this type
@@ -2057,6 +2058,14 @@ class ValueDecl : public Decl {
20572058
return Bits.ValueDecl.IsUserAccessible;
20582059
}
20592060

2061+
bool isSynthesized() const {
2062+
return Bits.ValueDecl.Synthesized;
2063+
}
2064+
2065+
void setSynthesized(bool value = true) {
2066+
Bits.ValueDecl.Synthesized = value;
2067+
}
2068+
20602069
bool hasName() const { return bool(Name); }
20612070
bool isOperator() const { return Name.isOperator(); }
20622071

@@ -3544,7 +3553,7 @@ class ClassDecl final : public NominalTypeDecl {
35443553

35453554
friend class SuperclassDeclRequest;
35463555
friend class SuperclassTypeRequest;
3547-
friend class SemanticMembersRequest;
3556+
friend class ABIMembersRequest;
35483557
friend class HasMissingDesignatedInitializersRequest;
35493558
friend class InheritsSuperclassInitializersRequest;
35503559

@@ -5589,7 +5598,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
55895598
Bits.AbstractFunctionDecl.Overridden = false;
55905599
Bits.AbstractFunctionDecl.Async = Async;
55915600
Bits.AbstractFunctionDecl.Throws = Throws;
5592-
Bits.AbstractFunctionDecl.Synthesized = false;
55935601
Bits.AbstractFunctionDecl.HasSingleExpressionBody = false;
55945602
Bits.AbstractFunctionDecl.HasNestedTypeDeclarations = false;
55955603
}
@@ -5796,14 +5804,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57965804
/// vtable.
57975805
bool needsNewVTableEntry() const;
57985806

5799-
bool isSynthesized() const {
5800-
return Bits.AbstractFunctionDecl.Synthesized;
5801-
}
5802-
5803-
void setSynthesized(bool value = true) {
5804-
Bits.AbstractFunctionDecl.Synthesized = value;
5805-
}
5806-
58075807
public:
58085808
/// Retrieve the source range of the function body.
58095809
SourceRange getBodySourceRange() const;

include/swift/AST/DeclContext.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,17 @@ class IterableDeclContext {
778778
/// the implementation.
779779
ArrayRef<Decl *> getParsedMembers() const;
780780

781-
/// Get all the members that are semantically within this context,
782-
/// including any implicitly-synthesized members.
781+
/// Get all of the members within this context that can affect ABI, including
782+
/// any implicitly-synthesized members.
783+
///
784+
/// The resulting list of members will be stable across translation units.
785+
ArrayRef<Decl *> getABIMembers() const;
786+
787+
/// Get all of the members within this context, including any
788+
/// implicitly-synthesized members.
789+
///
783790
/// The resulting list of members will be stable across translation units.
784-
ArrayRef<Decl *> getSemanticMembers() const;
791+
ArrayRef<Decl *> getAllMembers() const;
785792

786793
/// Retrieve the set of members in this context without loading any from the
787794
/// associated lazy loader; this should only be used as part of implementing

0 commit comments

Comments
 (0)