Skip to content

Commit 548c397

Browse files
Merge pull request #2541 from swiftwasm/maxd/main-merge
Resolve conflicts with the `main` branch
2 parents 94ae6c9 + 48ac8b6 commit 548c397

File tree

284 files changed

+12565
-4031
lines changed

Some content is hidden

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

284 files changed

+12565
-4031
lines changed

.mailmap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Ankit Aggarwal <ankit_aggarwal@apple.com> <ankit.spd@gmail.com>
99
Argyrios Kyrtzidis <kyrtzidis@apple.com> <akyrtzi@gmail.com>
1010
Arsen Gasparyan <to.arsen.gasparyan@gmail.com> <frootloops@users.noreply.github.com>
1111
Ashley Garland <acgarland@apple.com> <dfarler@apple.com>
12+
Becca Royal-Gordon <beccadax@apple.com> <broyalgordon@apple.com> <becca@beccadax.com> <brentdax@apple.com> <brent@brentdax.com>
1213
Ben Cohen <ben_cohen@apple.com>
1314
Ben Cohen <ben_cohen@apple.com> <airspeedswift@users.noreply.github.com>
1415
Ben Cohen <ben_cohen@apple.com> <ben@airspeedvelocity.net>
1516
Ben Langmuir <blangmuir@apple.com> <ben.langmuir@gmail.com>
16-
Brent Royal-Gordon <brent@brentdax.com> <brent@architechies.com>
1717
Brian Croom <bcroom@apple.com> <brian.s.croom@gmail.com>
1818
Brian Gesiak <bgesiak@fb.com> <modocache@gmail.com>
1919
Bryan Chan <bryan.chan@ca.ibm.com> <bryanpkc@gmail.com>

docs/DifferentiableProgramming.md

Lines changed: 6 additions & 100 deletions
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/OpenBSD.md

Lines changed: 5 additions & 2 deletions
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

Lines changed: 9 additions & 2 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class ClangModuleLoader : public ModuleLoader {
228228
SubstitutionMap subst) = 0;
229229
};
230230

231-
/// Used to describe a template instantiation error.
231+
/// Describes a C++ template instantiation error.
232232
struct TemplateInstantiationError {
233233
/// Generic types that could not be converted to QualTypes using the
234234
/// ClangTypeConverter.

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ ERROR(where_nongeneric_toplevel,none,
16921692
"declaration", ())
16931693
ERROR(unable_to_convert_generic_swift_types,none,
16941694
"could not generate C++ types from the generic Swift types provided. "
1695-
"The following Swift type(s) provided to '%0' were unable to be "
1695+
"The following Swift type(s) provided to '%0' could not be "
16961696
"converted: %1.",
16971697
(StringRef, StringRef))
16981698

@@ -3785,9 +3785,14 @@ WARNING(guard_always_succeeds,none,
37853785
ERROR(expression_unused_closure,none,
37863786
"closure expression is unused", ())
37873787
ERROR(expression_unused_function,none,
3788-
"expression resolves to an unused function", ())
3788+
"function is unused", ())
37893789
WARNING(expression_unused_lvalue,none,
3790-
"expression resolves to an unused %select{variable|property|subscript}0", (unsigned))
3790+
"%select{"
3791+
"variable|"
3792+
"property is accessed but result|"
3793+
"subscript is accessed but result"
3794+
"}0 is unused",
3795+
(unsigned))
37913796
WARNING(expression_unused_result_call,none,
37923797
"result of call to %0 is unused", (DeclName))
37933798
WARNING(expression_unused_result_operator,none,

include/swift/AST/FileUnit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ class LoadedFile : public FileUnit {
402402
return false;
403403
}
404404

405+
virtual void collectBasicSourceFileInfo(
406+
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const {}
407+
405408
static bool classof(const FileUnit *file) {
406409
return file->getKind() == FileUnitKind::SerializedAST ||
407410
file->getKind() == FileUnitKind::ClangModule ||

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ IDENTIFIER(move)
233233
IDENTIFIER(pullback)
234234
IDENTIFIER(TangentVector)
235235
IDENTIFIER(zero)
236-
IDENTIFIER(zeroTangentVectorInitializer)
237236

238237
#undef IDENTIFIER
239238
#undef IDENTIFIER_

include/swift/AST/Module.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
626626
/// This assumes that \p module was imported.
627627
bool isImportedImplementationOnly(const ModuleDecl *module) const;
628628

629+
/// Returns true if a function, which is using \p nominal, can be serialized
630+
/// by cross-module-optimization.
631+
bool canBeUsedForCrossModuleOptimization(NominalTypeDecl *nominal) const;
632+
629633
/// Finds all top-level decls of this module.
630634
///
631635
/// This does a simple local lookup, not recursively looking through imports.
@@ -728,6 +732,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
728732
return ReverseFullNameIterator(this);
729733
}
730734

735+
/// Calls \p callback for each source file of the module.
736+
void collectBasicSourceFileInfo(
737+
llvm::function_ref<void(const BasicSourceFileInfo &)> callback);
738+
731739
SourceRange getSourceRange() const { return SourceRange(); }
732740

733741
static bool classof(const DeclContext *DC) {

include/swift/AST/RawComment.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
#ifndef SWIFT_AST_RAW_COMMENT_H
1414
#define SWIFT_AST_RAW_COMMENT_H
1515

16+
#include "swift/Basic/Fingerprint.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Basic/SourceLoc.h"
1819
#include "swift/Basic/SourceManager.h"
1920

2021
namespace swift {
22+
23+
class SourceFile;
24+
2125
struct SingleRawComment {
2226
enum class CommentKind {
2327
OrdinaryLine, ///< Any normal // comments
@@ -92,6 +96,17 @@ struct BasicDeclLocs {
9296
LineColumn EndLoc;
9397
};
9498

99+
struct BasicSourceFileInfo {
100+
StringRef FilePath;
101+
Fingerprint InterfaceHash = Fingerprint::ZERO();
102+
llvm::sys::TimePoint<> LastModified = {};
103+
uint64_t FileSize = 0;
104+
105+
BasicSourceFileInfo() {}
106+
107+
bool populate(SourceFile *SF);
108+
};
109+
95110
} // namespace swift
96111

97112
#endif // LLVM_SWIFT_AST_RAW_COMMENT_H

include/swift/AST/SourceFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ class SourceFile final : public FileUnit {
531531
out << getInterfaceHash() << '\n';
532532
}
533533

534+
/// Get this file's interface hash including the type members in the file.
535+
Fingerprint getInterfaceHashIncludingTypeMembers() const;
536+
534537
/// If this source file has been told to collect its parsed tokens, retrieve
535538
/// those tokens.
536539
ArrayRef<Token> getAllTokens() const;

0 commit comments

Comments
 (0)