Skip to content

Commit 2c0208f

Browse files
Merge pull request #2763 from swiftwasm/katei/merge-main-2021-02-18
Merge main 2021-02-18
2 parents 81bd5ec + ff78f61 commit 2c0208f

File tree

265 files changed

+5578
-2614
lines changed

Some content is hidden

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

265 files changed

+5578
-2614
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ CHANGELOG
2828
Swift Next
2929
----------
3030

31+
* Whenever a reference to `Self` does not impede the usage of a protocol as a value type, or a protocol member on a value of protocol type, the same is now true for references to `[Self]` and `[Key : Self]`:
32+
33+
```swift
34+
protocol Copyable {
35+
func copy() -> Self
36+
func copy(count: Int) -> [Self]
37+
}
38+
39+
func test(c: Copyable) {
40+
let copy: Copyable = c.copy() // OK
41+
let copies: [Copyable] = c.copy(count: 5) // also OK
42+
}
43+
```
44+
3145
* [SE-0296][]:
3246

3347
Asynchronous programming is now natively supported using async/await. Asynchronous functions can be defined using `async`:

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ if(SWIFT_PROFDATA_FILE AND EXISTS ${SWIFT_PROFDATA_FILE})
196196
add_definitions("-fprofile-instr-use=${SWIFT_PROFDATA_FILE}")
197197
endif()
198198

199+
option(USE_SWIFT_ASYNC_LOWERING
200+
"Indicates if Swiftc should use async-specific lowering for async
201+
functions if it is supported for the target. The runtime also checks
202+
this setting before using async-specific attributes. This only applies
203+
to the async calling convention and not to the async context attribute."
204+
FALSE)
205+
199206
#
200207
# User-configurable Swift Standard Library specific options.
201208
#

docs/ABI/Mangling.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Globals
167167
global ::= protocol-conformance protocol 'Wb' // base protocol witness table accessor
168168
global ::= type protocol-conformance 'Wl' // lazy protocol witness table accessor
169169

170+
global ::= global generic-signature? 'WJ' DIFFERENTIABILITY-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // differentiability witness
171+
170172
global ::= type 'WV' // value witness table
171173
global ::= entity 'Wvd' // field offset
172174
global ::= entity 'WC' // resilient enum tag index
@@ -222,13 +224,17 @@ types where the metadata itself has unknown layout.)
222224
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
223225
global ::= impl-function-type type 'Tz' // objc-to-swift-async completion handler block implementation
224226
global ::= impl-function-type type 'TZ' // objc-to-swift-async completion handler block implementation (predefined by runtime)
227+
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
228+
global ::= impl-function-type type generic-signature? 'Tz' // objc-to-swift-async completion handler block implementation
229+
global ::= impl-function-type type generic-signature? 'TZ' // objc-to-swift-async completion handler block implementation (predefined by runtime)
225230
global ::= from-type to-type self-type generic-signature? 'Ty' // reabstraction thunk with dynamic 'Self' capture
226231
global ::= from-type to-type generic-signature? 'Tr' // obsolete mangling for reabstraction thunk
227232
global ::= entity generic-signature? type type* 'TK' // key path getter
228233
global ::= entity generic-signature? type type* 'Tk' // key path setter
229234
global ::= type generic-signature 'TH' // key path equality
230235
global ::= type generic-signature 'Th' // key path hasher
231236
global ::= global generic-signature? 'TJ' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff function
237+
global ::= global generic-signature? 'TJV' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff derivative vtable thunk
232238
global ::= from-type to-type 'TJO' AUTODIFF-FUNCTION-KIND // autodiff self-reordering reabstraction thunk
233239
global ::= from-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff linear map subset parameters thunk
234240
global ::= global to-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff derivative function subset parameters thunk

docs/SIL.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,12 +1590,15 @@ Differentiability Witnesses
15901590
sil-differentiability-witness ::=
15911591
'sil_differentiability_witness'
15921592
sil-linkage?
1593+
'[' differentiability-kind ']'
15931594
'[' 'parameters' sil-differentiability-witness-function-index-list ']'
15941595
'[' 'results' sil-differentiability-witness-function-index-list ']'
15951596
generic-parameter-clause?
15961597
sil-function-name ':' sil-type
15971598
sil-differentiability-witness-body?
15981599

1600+
differentiability-kind ::= 'forward' | 'reverse' | 'normal' | 'linear'
1601+
15991602
sil-differentiability-witness-body ::=
16001603
'{' sil-differentiability-witness-entry?
16011604
sil-differentiability-witness-entry? '}'
@@ -1625,7 +1628,7 @@ based on the key.
16251628

16261629
::
16271630

1628-
sil_differentiability_witness hidden [parameters 0] [results 0] <T where T : Differentiable> @id : $@convention(thin) (T) -> T {
1631+
sil_differentiability_witness hidden [normal] [parameters 0] [results 0] <T where T : Differentiable> @id : $@convention(thin) (T) -> T {
16291632
jvp: @id_jvp : $@convention(thin) (T) -> (T, @owned @callee_guaranteed (T.TangentVector) -> T.TangentVector)
16301633
vjp: @id_vjp : $@convention(thin) (T) -> (T, @owned @callee_guaranteed (T.TangentVector) -> T.TangentVector)
16311634
}
@@ -7066,6 +7069,7 @@ differentiability_witness_function
70667069
sil-instruction ::=
70677070
'differentiability_witness_function'
70687071
'[' sil-differentiability-witness-function-kind ']'
7072+
'[' differentiability-kind ']'
70697073
'[' 'parameters' sil-differentiability-witness-function-index-list ']'
70707074
'[' 'results' sil-differentiability-witness-function-index-list ']'
70717075
generic-parameter-clause?
@@ -7074,7 +7078,7 @@ differentiability_witness_function
70747078
sil-differentiability-witness-function-kind ::= 'jvp' | 'vjp' | 'transpose'
70757079
sil-differentiability-witness-function-index-list ::= [0-9]+ (' ' [0-9]+)*
70767080

7077-
differentiability_witness_function [jvp] [parameters 0] [results 0] \
7081+
differentiability_witness_function [vjp] [reverse] [parameters 0] [results 0] \
70787082
<T where T: Differentiable> @foo : $(T) -> T
70797083

70807084
Looks up a differentiability witness function (JVP, VJP, or transpose) for
@@ -7086,6 +7090,7 @@ look up: ``[jvp]``, ``[vjp]``, or ``[transpose]``.
70867090
The remaining components identify the SIL differentiability witness:
70877091

70887092
- Original function name.
7093+
- Differentiability kind.
70897094
- Parameter indices.
70907095
- Result indices.
70917096
- Witness generic parameter clause (optional). When parsing SIL, the parsed

include/swift/ABI/Task.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,15 @@ class AsyncTask : public HeapObject, public Job {
300300
// therefore skip also skip pointing to that parent and point
301301
// to whichever parent it was pointing to as well, it may be its
302302
// immediate parent, or some super-parent.
303-
item->next = reinterpret_cast<uintptr_t>(parentHead->getNext());
303+
item->next = reinterpret_cast<uintptr_t>(parentHead->getNext()) |
304304
static_cast<uintptr_t>(NextLinkType::IsParent);
305305
break;
306306
case NextLinkType::IsNext:
307307
assert(false && "empty taskValue head in parent task, yet parent's 'head' is `IsNext`, "
308308
"this should not happen, as it implies the parent must have stored some value.");
309309
break;
310310
case NextLinkType::IsTerminal:
311-
item->next = reinterpret_cast<uintptr_t>(parentHead->getNext());
311+
item->next = reinterpret_cast<uintptr_t>(parentHead->getNext()) |
312312
static_cast<uintptr_t>(NextLinkType::IsTerminal);
313313
break;
314314
}
@@ -845,8 +845,10 @@ class AsyncTask : public HeapObject, public Job {
845845
/// The type of the result that will be produced by the future.
846846
const Metadata *resultType;
847847

848-
// Trailing storage for the result itself. The storage will be uninitialized,
849-
// contain an instance of \c resultType, or contain an an \c Error.
848+
SwiftError *error = nullptr;
849+
850+
// Trailing storage for the result itself. The storage will be
851+
// uninitialized, contain an instance of \c resultType.
850852

851853
friend class AsyncTask;
852854

@@ -865,25 +867,20 @@ class AsyncTask : public HeapObject, public Job {
865867
}
866868

867869
/// Retrieve the error.
868-
SwiftError *&getError() {
869-
return *reinterpret_cast<SwiftError **>(
870-
reinterpret_cast<char *>(this) + storageOffset(resultType));
871-
}
870+
SwiftError *&getError() { return *&error; }
872871

873872
/// Compute the offset of the storage from the base of the future
874873
/// fragment.
875874
static size_t storageOffset(const Metadata *resultType) {
876875
size_t offset = sizeof(FutureFragment);
877-
size_t alignment =
878-
std::max(resultType->vw_alignment(), alignof(SwiftError *));
876+
size_t alignment = resultType->vw_alignment();
879877
return (offset + alignment - 1) & ~(alignment - 1);
880878
}
881879

882880
/// Determine the size of the future fragment given a particular future
883881
/// result type.
884882
static size_t fragmentSize(const Metadata *resultType) {
885-
return storageOffset(resultType) +
886-
std::max(resultType->vw_size(), sizeof(SwiftError *));
883+
return storageOffset(resultType) + resultType->vw_size();
887884
}
888885
};
889886

@@ -1038,7 +1035,7 @@ class YieldingAsyncContext : public AsyncContext {
10381035
/// futures.
10391036
class FutureAsyncContext : public AsyncContext {
10401037
public:
1041-
SwiftError *errorResult = nullptr;
1038+
SwiftError **errorResult = nullptr;
10421039
OpaqueValue *indirectResult;
10431040

10441041
using AsyncContext::AsyncContext;

include/swift/AST/ASTMangler.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,20 @@ class ASTMangler : public Mangler {
171171
/// predefined in the Swift runtime for the given type signature.
172172
std::string mangleObjCAsyncCompletionHandlerImpl(CanSILFunctionType BlockType,
173173
CanType ResultType,
174+
CanGenericSignature Sig,
174175
bool predefined);
175176

176-
/// Mangle the derivative function (JVP/VJP) for the given:
177+
/// Mangle the derivative function (JVP/VJP), or optionally its vtable entry
178+
/// thunk, for the given:
177179
/// - Mangled original function declaration.
178180
/// - Derivative function kind.
179181
/// - Derivative function configuration: parameter/result indices and
180182
/// derivative generic signature.
181183
std::string
182184
mangleAutoDiffDerivativeFunction(const AbstractFunctionDecl *originalAFD,
183185
AutoDiffDerivativeFunctionKind kind,
184-
AutoDiffConfig config);
186+
AutoDiffConfig config,
187+
bool isVTableThunk = false);
185188

186189
/// Mangle the linear map (differential/pullback) for the given:
187190
/// - Mangled original function declaration.
@@ -201,6 +204,11 @@ class ASTMangler : public Mangler {
201204
CanType fromType, CanType toType, GenericSignature signature,
202205
AutoDiffLinearMapKind linearMapKind);
203206

207+
/// Mangle a SIL differentiability witness.
208+
std::string mangleSILDifferentiabilityWitness(StringRef originalName,
209+
DifferentiabilityKind kind,
210+
AutoDiffConfig config);
211+
204212
/// Mangle the AutoDiff generated declaration for the given:
205213
/// - Generated declaration kind: linear map struct or branching trace enum.
206214
/// - Mangled original function name.
@@ -214,14 +222,6 @@ class ASTMangler : public Mangler {
214222
AutoDiffLinearMapKind linearMapKind,
215223
AutoDiffConfig config);
216224

217-
/// Mangle a SIL differentiability witness key:
218-
/// - Mangled original function name.
219-
/// - Parameter indices.
220-
/// - Result indices.
221-
/// - Derivative generic signature (optional).
222-
std::string
223-
mangleSILDifferentiabilityWitnessKey(SILDifferentiabilityWitnessKey key);
224-
225225
std::string mangleKeyPathGetterThunkHelper(const AbstractStorageDecl *property,
226226
GenericSignature signature,
227227
CanType baseType,
@@ -447,7 +447,8 @@ class ASTMangler : public Mangler {
447447

448448
void beginManglingWithAutoDiffOriginalFunction(
449449
const AbstractFunctionDecl *afd);
450-
void appendAutoDiffFunctionParts(char functionKindCode,
450+
void appendAutoDiffFunctionParts(StringRef op,
451+
Demangle::AutoDiffFunctionKind kind,
451452
AutoDiffConfig config);
452453
void appendIndexSubset(IndexSubset *indexSubset);
453454
};

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ SWIFT_TYPEID(PropertyWrapperTypeInfo)
3131
SWIFT_TYPEID(Requirement)
3232
SWIFT_TYPEID(ResilienceExpansion)
3333
SWIFT_TYPEID(FragileFunctionKind)
34-
SWIFT_TYPEID(FunctionRethrowingKind)
35-
SWIFT_TYPEID(ProtocolRethrowsRequirementList)
34+
SWIFT_TYPEID(PolymorphicEffectKind)
35+
SWIFT_TYPEID(PolymorphicEffectRequirementList)
3636
SWIFT_TYPEID(TangentPropertyInfo)
3737
SWIFT_TYPEID(SymbolSourceMap)
3838
SWIFT_TYPEID(Type)

include/swift/AST/ASTTypeIDs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class ProtocolDecl;
6464
class Requirement;
6565
enum class ResilienceExpansion : unsigned;
6666
struct FragileFunctionKind;
67-
enum class FunctionRethrowingKind : uint8_t;
68-
class ProtocolRethrowsRequirementList;
67+
enum class PolymorphicEffectKind : uint8_t;
68+
class PolymorphicEffectRequirementList;
6969
class SourceFile;
7070
class SymbolSourceMap;
7171
struct TangentPropertyInfo;

include/swift/AST/Attr.def

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,25 +353,25 @@ SIMPLE_DECL_ATTR(testable, Testable,
353353
DECL_ATTR(_alignment, Alignment,
354354
OnStruct | OnEnum |
355355
UserInaccessible |
356-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
356+
ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
357357
56)
358358
SIMPLE_DECL_ATTR(rethrows, Rethrows,
359-
OnFunc | OnAccessor | OnConstructor |
359+
OnFunc | OnConstructor |
360360
RejectByParser |
361-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
361+
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
362362
57)
363363
SIMPLE_DECL_ATTR(rethrows, AtRethrows,
364364
OnProtocol |
365-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
365+
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
366366
58)
367367
DECL_ATTR(_swift_native_objc_runtime_base, SwiftNativeObjCRuntimeBase,
368368
OnClass |
369369
UserInaccessible |
370-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
370+
ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
371371
59)
372372
CONTEXTUAL_SIMPLE_DECL_ATTR(indirect, Indirect, DeclModifier |
373373
OnEnum | OnEnumElement |
374-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
374+
ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
375375
60)
376376
SIMPLE_DECL_ATTR(warn_unqualified_access, WarnUnqualifiedAccess,
377377
OnFunc | OnAccessor /*| OnVar*/ |
@@ -469,7 +469,7 @@ DECL_ATTR(_dynamicReplacement, DynamicReplacement,
469469
SIMPLE_DECL_ATTR(_borrowed, Borrowed,
470470
OnVar | OnSubscript | UserInaccessible |
471471
NotSerialized |
472-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
472+
ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
473473
81)
474474
DECL_ATTR(_private, PrivateImport,
475475
OnImport |
@@ -479,7 +479,7 @@ DECL_ATTR(_private, PrivateImport,
479479
82)
480480
SIMPLE_DECL_ATTR(_alwaysEmitIntoClient, AlwaysEmitIntoClient,
481481
OnVar | OnSubscript | OnAbstractFunction | UserInaccessible |
482-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
482+
ABIBreakingToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
483483
83)
484484

485485
SIMPLE_DECL_ATTR(_implementationOnly, ImplementationOnly,
@@ -613,6 +613,17 @@ SIMPLE_DECL_ATTR(_marker, Marker,
613613
APIBreakingToAdd | APIBreakingToRemove,
614614
108)
615615

616+
SIMPLE_DECL_ATTR(reasync, Reasync,
617+
OnFunc | OnConstructor |
618+
RejectByParser |
619+
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
620+
109)
621+
622+
SIMPLE_DECL_ATTR(reasync, AtReasync,
623+
OnProtocol |
624+
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
625+
110)
626+
616627
#undef TYPE_ATTR
617628
#undef DECL_ATTR_ALIAS
618629
#undef CONTEXTUAL_DECL_ATTR_ALIAS

0 commit comments

Comments
 (0)