Skip to content

Commit 2290a86

Browse files
authored
Merge pull request #2920 from swiftwasm/katei/merge-main-2021-04-01
Merge main 2021-04-01
2 parents 6e61d01 + 81e1ede commit 2290a86

File tree

288 files changed

+6290
-1989
lines changed

Some content is hidden

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

288 files changed

+6290
-1989
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@ CHANGELOG
2929
Swift 5.5
3030
---------
3131

32+
* [SE-0293][]:
33+
34+
Property wrappers can now be applied to function and closure parameters:
35+
36+
```swift
37+
@propertyWrapper
38+
struct Wrapper<Value> {
39+
var wrappedValue: Value
40+
41+
var projectedValue: Self { return self }
42+
43+
init(wrappedValue: Value) { ... }
44+
45+
init(projectedValue: Self) { ... }
46+
}
47+
48+
func test(@Wrapper value: Int) {
49+
print(value)
50+
print($value)
51+
print(_value)
52+
}
53+
54+
test(value: 10)
55+
56+
let projection = Wrapper(wrappedValue: 10)
57+
test($value: projection)
58+
```
59+
60+
The call-site can pass a wrapped value or a projected value, and the property wrapper will be initialized using `init(wrappedValue:)` or `init(projectedValue:)`, respectively.
61+
3262
* [SE-0299][]:
3363

3464
It is now possible to use leading-dot syntax in generic contexts to access static members of protocol extensions where `Self` is constrained to a fully concrete type:

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ function(_add_host_variant_link_flags target)
301301
target_link_libraries(${target} PRIVATE
302302
pthread
303303
dl)
304+
if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv6|armv7|i686")
305+
target_link_libraries(${target} PRIVATE atomic)
306+
endif()
304307
elseif(SWIFT_HOST_VARIANT_SDK STREQUAL FREEBSD)
305308
target_link_libraries(${target} PRIVATE
306309
pthread)

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ function(add_swift_unittest test_dirname)
5656
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
5757
target_compile_options(${test_dirname} PRIVATE
5858
-march=core2)
59+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv6|armv7|i686")
60+
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES
61+
"atomic")
5962
endif()
6063
elseif("${SWIFT_HOST_VARIANT}" STREQUAL "windows")
6164
target_compile_definitions("${test_dirname}" PRIVATE

docs/ABI/Mangling.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,24 +560,24 @@ Types
560560
FUNCTION-KIND ::= 'zC' C-TYPE // C function pointer type with with non-canonical C type
561561
FUNCTION-KIND ::= 'A' // @auto_closure function type (escaping)
562562
FUNCTION-KIND ::= 'E' // function type (noescape)
563-
FUNCTION-KIND ::= 'F' // @differentiable function type
564-
FUNCTION-KIND ::= 'G' // @differentiable function type (escaping)
565-
FUNCTION-KIND ::= 'H' // @differentiable(_linear) function type
566-
FUNCTION-KIND ::= 'I' // @differentiable(_linear) function type (escaping)
567563

568564
C-TYPE is mangled according to the Itanium ABI, and prefixed with the length.
569565
Non-ASCII identifiers are preserved as-is; we do not use Punycode.
570566

571-
function-signature ::= params-type params-type async? sendable? throws? // results and parameters
567+
function-signature ::= params-type params-type async? sendable? throws? differentiable? // results and parameters
572568

573-
params-type ::= type 'z'? 'h'? // tuple in case of multiple parameters or a single parameter with a single tuple type
569+
params-type ::= type 'z'? 'h'? // tuple in case of multiple parameters or a single parameter with a single tuple type
574570
// with optional inout convention, shared convention. parameters don't have labels,
575571
// they are mangled separately as part of the entity.
576-
params-type ::= empty-list // shortcut for no parameters
572+
params-type ::= empty-list // shortcut for no parameters
577573

578-
sendable ::= 'J' // @Sendable on function types
574+
sendable ::= 'J' // @Sendable on function types
579575
async ::= 'Y' // 'async' annotation on function types
580576
throws ::= 'K' // 'throws' annotation on function types
577+
differentiable ::= 'jf' // @differentiable(_forward) on function type
578+
differentiable ::= 'jr' // @differentiable(reverse) on function type
579+
differentiable ::= 'jd' // @differentiable on function type
580+
differentiable ::= 'jl' // @differentiable(_linear) on function type
581581

582582
type-list ::= list-type '_' list-type* // list of types
583583
type-list ::= empty-list

docs/SIL.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3302,7 +3302,7 @@ hop_to_executor
33023302

33033303
hop_to_executor %0 : $T
33043304

3305-
// $T must conform to the Actor protocol
3305+
// $T must be Builtin.Executor or conform to the Actor protocol
33063306

33073307
Ensures that all instructions, which need to run on the actor's executor
33083308
actually run on that executor.
@@ -3312,6 +3312,11 @@ Checks if the current executor is the one which is bound to the operand actor.
33123312
If not, begins a suspension point and enqueues the continuation to the executor
33133313
which is bound to the operand actor.
33143314

3315+
SIL generation emits this instruction with operands of actor type as
3316+
well as of type ``Builtin.Executor``. The former are expected to be
3317+
lowered by the SIL pipeline, so that IR generation only operands of type
3318+
``Builtin.Executor`` remain.
3319+
33153320
The operand is a guaranteed operand, i.e. not consumed.
33163321

33173322
dealloc_stack

include/swift/ABI/Metadata.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,18 +1338,20 @@ using ClassMetadata = TargetClassMetadata<InProcess>;
13381338
/// dispatch expects to see, with padding to place them at the expected offsets.
13391339
template <typename Runtime>
13401340
struct TargetDispatchClassMetadata : public TargetHeapMetadata<Runtime> {
1341-
using DummyVTableCall = void (*)(void);
1341+
using InvokeCall = void (*)(void *, void *, uint32_t);
13421342

1343-
TargetDispatchClassMetadata(MetadataKind Kind,
1344-
DummyVTableCall DummyVTableEntry)
1345-
: TargetHeapMetadata<Runtime>(Kind), DummyVTableEntry(DummyVTableEntry) {}
1343+
TargetDispatchClassMetadata(MetadataKind Kind, unsigned long VTableType,
1344+
InvokeCall Invoke)
1345+
: TargetHeapMetadata<Runtime>(Kind), VTableType(VTableType),
1346+
VTableInvoke(Invoke) {}
13461347

13471348
TargetPointer<Runtime, void> Opaque;
13481349
#if SWIFT_OBJC_INTEROP
13491350
TargetPointer<Runtime, void> OpaqueObjC[3];
13501351
#endif
13511352

1352-
TargetSignedPointer<Runtime, DummyVTableCall> DummyVTableEntry;
1353+
unsigned long VTableType;
1354+
TargetSignedPointer<Runtime, InvokeCall __ptrauth_swift_dispatch_invoke_function> VTableInvoke;
13531355
};
13541356
using DispatchClassMetadata = TargetDispatchClassMetadata<InProcess>;
13551357

@@ -1658,6 +1660,7 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
16581660
bool isAsync() const { return Flags.isAsync(); }
16591661
bool isThrowing() const { return Flags.isThrowing(); }
16601662
bool isSendable() const { return Flags.isSendable(); }
1663+
bool isDifferentiable() const { return Flags.isDifferentiable(); }
16611664
bool hasParameterFlags() const { return Flags.hasParameterFlags(); }
16621665
bool isEscaping() const { return Flags.isEscaping(); }
16631666

@@ -1675,6 +1678,28 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
16751678
return reinterpret_cast<const uint32_t *>(getParameters() +
16761679
getNumParameters());
16771680
}
1681+
1682+
TargetFunctionMetadataDifferentiabilityKind<StoredSize> *
1683+
getDifferentiabilityKindAddress() {
1684+
assert(isDifferentiable());
1685+
void *previousEndAddr = hasParameterFlags()
1686+
? reinterpret_cast<void *>(getParameterFlags() + getNumParameters())
1687+
: reinterpret_cast<void *>(getParameters() + getNumParameters());
1688+
return reinterpret_cast<
1689+
TargetFunctionMetadataDifferentiabilityKind<StoredSize> *>(
1690+
llvm::alignAddr(previousEndAddr,
1691+
llvm::Align(alignof(typename Runtime::StoredPointer))));
1692+
}
1693+
1694+
TargetFunctionMetadataDifferentiabilityKind<StoredSize>
1695+
getDifferentiabilityKind() const {
1696+
if (isDifferentiable()) {
1697+
return *const_cast<TargetFunctionTypeMetadata<Runtime> *>(this)
1698+
->getDifferentiabilityKindAddress();
1699+
}
1700+
return TargetFunctionMetadataDifferentiabilityKind<StoredSize>
1701+
::NonDifferentiable;
1702+
}
16781703
};
16791704
using FunctionTypeMetadata = TargetFunctionTypeMetadata<InProcess>;
16801705

include/swift/ABI/MetadataValues.h

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,29 @@ enum class FunctionMetadataConvention: uint8_t {
787787

788788
/// Differentiability kind for function type metadata.
789789
/// Duplicates `DifferentiabilityKind` in AST/AutoDiff.h.
790-
enum class FunctionMetadataDifferentiabilityKind: uint8_t {
791-
NonDifferentiable = 0b00000,
792-
Forward = 0b00001,
793-
Reverse = 0b00010,
794-
Normal = 0b00011,
795-
Linear = 0b10000,
790+
template <typename int_type>
791+
struct TargetFunctionMetadataDifferentiabilityKind {
792+
enum Value : int_type {
793+
NonDifferentiable = 0,
794+
Forward = 1,
795+
Reverse = 2,
796+
Normal = 3,
797+
Linear = 4,
798+
} Value;
799+
800+
constexpr TargetFunctionMetadataDifferentiabilityKind(
801+
enum Value value = NonDifferentiable) : Value(value) {}
802+
803+
int_type getIntValue() const {
804+
return (int_type)Value;
805+
}
806+
807+
bool isDifferentiable() const {
808+
return Value != NonDifferentiable;
809+
}
796810
};
811+
using FunctionMetadataDifferentiabilityKind =
812+
TargetFunctionMetadataDifferentiabilityKind<size_t>;
797813

798814
/// Flags in a function type metadata record.
799815
template <typename int_type>
@@ -808,8 +824,7 @@ class TargetFunctionTypeFlags {
808824
ThrowsMask = 0x01000000U,
809825
ParamFlagsMask = 0x02000000U,
810826
EscapingMask = 0x04000000U,
811-
DifferentiabilityMask = 0x98000000U,
812-
DifferentiabilityShift = 27U,
827+
DifferentiableMask = 0x08000000U,
813828
AsyncMask = 0x20000000U,
814829
SendableMask = 0x40000000U,
815830
};
@@ -842,10 +857,10 @@ class TargetFunctionTypeFlags {
842857
(throws ? ThrowsMask : 0));
843858
}
844859

845-
constexpr TargetFunctionTypeFlags<int_type> withDifferentiabilityKind(
846-
FunctionMetadataDifferentiabilityKind differentiabilityKind) const {
847-
return TargetFunctionTypeFlags((Data & ~DifferentiabilityMask)
848-
| (int_type(differentiabilityKind) << DifferentiabilityShift));
860+
constexpr TargetFunctionTypeFlags<int_type>
861+
withDifferentiable(bool differentiable) const {
862+
return TargetFunctionTypeFlags<int_type>((Data & ~DifferentiableMask) |
863+
(differentiable ? DifferentiableMask : 0));
849864
}
850865

851866
constexpr TargetFunctionTypeFlags<int_type>
@@ -888,13 +903,7 @@ class TargetFunctionTypeFlags {
888903
bool hasParameterFlags() const { return bool(Data & ParamFlagsMask); }
889904

890905
bool isDifferentiable() const {
891-
return getDifferentiabilityKind() !=
892-
FunctionMetadataDifferentiabilityKind::NonDifferentiable;
893-
}
894-
895-
FunctionMetadataDifferentiabilityKind getDifferentiabilityKind() const {
896-
return FunctionMetadataDifferentiabilityKind(
897-
(Data & DifferentiabilityMask) >> DifferentiabilityShift);
906+
return bool (Data & DifferentiableMask);
898907
}
899908

900909
int_type getIntValue() const {
@@ -947,6 +956,12 @@ class TargetParameterTypeFlags {
947956
(Data & ~AutoClosureMask) | (isAutoClosure ? AutoClosureMask : 0));
948957
}
949958

959+
constexpr TargetParameterTypeFlags<int_type>
960+
withNoDerivative(bool isNoDerivative) const {
961+
return TargetParameterTypeFlags<int_type>(
962+
(Data & ~NoDerivativeMask) | (isNoDerivative ? NoDerivativeMask : 0));
963+
}
964+
950965
bool isNone() const { return Data == 0; }
951966
bool isVariadic() const { return Data & VariadicMask; }
952967
bool isAutoClosure() const { return Data & AutoClosureMask; }
@@ -1212,6 +1227,9 @@ namespace SpecialPointerAuthDiscriminators {
12121227

12131228
/// Swift async context parameter stored in the extended frame info.
12141229
const uint16_t SwiftAsyncContextExtendedFrameEntry = 0xc31a; // = 49946
1230+
1231+
/// Dispatch integration.
1232+
const uint16_t DispatchInvokeFunction = 0xf493; // = 62611
12151233
}
12161234

12171235
/// The number of arguments that will be passed directly to a generic

include/swift/ABI/Task.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@ extern FullMetadata<DispatchClassMetadata> jobHeapMetadata;
4040

4141
/// A schedulable job.
4242
class alignas(2 * alignof(void*)) Job : public HeapObject {
43-
protected:
43+
public:
4444
// Indices into SchedulerPrivate, for use by the runtime.
4545
enum {
4646
/// The next waiting task link, an AsyncTask that is waiting on a future.
4747
NextWaitingTaskIndex = 0,
48+
49+
/// An opaque field used by Dispatch when enqueueing Jobs directly.
50+
DispatchLinkageIndex = 0,
51+
52+
/// The dispatch queue being used when enqueueing a Job directly with
53+
/// Dispatch.
54+
DispatchQueueIndex = 1,
4855
};
4956

50-
public:
5157
// Reserved for the use of the scheduler.
5258
void *SchedulerPrivate[2];
5359

include/swift/AST/ASTDemangler.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ class ASTBuilder {
9797

9898
Type createTupleType(ArrayRef<Type> eltTypes, StringRef labels);
9999

100-
Type createFunctionType(ArrayRef<Demangle::FunctionParam<Type>> params,
101-
Type output, FunctionTypeFlags flags);
100+
Type createFunctionType(
101+
ArrayRef<Demangle::FunctionParam<Type>> params,
102+
Type output, FunctionTypeFlags flags,
103+
FunctionMetadataDifferentiabilityKind diffKind);
102104

103105
Type createImplFunctionType(
104106
Demangle::ImplParameterConvention calleeConvention,

include/swift/AST/ASTSynthesis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct VariadicSynthesizerStorage<> {
135135
constexpr VariadicSynthesizerStorage() {}
136136

137137
template <class Fn>
138-
void visit(const Fn &fn) const {}
138+
void visit(Fn &&fn) const {}
139139
};
140140
template <class Head, class... Tail>
141141
struct VariadicSynthesizerStorage<Head, Tail...> {
@@ -145,7 +145,7 @@ struct VariadicSynthesizerStorage<Head, Tail...> {
145145
: head(head), tail(tail...) {}
146146

147147
template <class Fn>
148-
void visit(const Fn &fn) const {
148+
void visit(Fn &&fn) const {
149149
fn(head);
150150
tail.visit(fn);
151151
}

include/swift/AST/AnyFunctionRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ class AnyFunctionRef {
110110
return TheFunction.get<AbstractClosureExpr *>()->getParameters();
111111
}
112112

113-
bool hasPropertyWrapperParameters() const {
113+
bool hasExternalPropertyWrapperParameters() const {
114114
return llvm::any_of(*getParameters(), [](const ParamDecl *param) {
115-
return param->hasAttachedPropertyWrapper();
115+
return param->hasExternalPropertyWrapper();
116116
});
117117
}
118118

include/swift/AST/Attr.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ SIMPLE_DECL_ATTR(reasync, AtReasync,
625625
110)
626626

627627
DECL_ATTR(completionHandlerAsync, CompletionHandlerAsync,
628-
OnAbstractFunction | ConcurrencyOnly |
628+
OnAbstractFunction | ConcurrencyOnly | LongAttribute |
629629
ABIStableToAdd | ABIStableToRemove |
630630
APIStableToAdd | APIStableToRemove,
631631
111)
@@ -637,6 +637,15 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(nonisolated, Nonisolated,
637637
APIBreakingToAdd | APIStableToRemove,
638638
112)
639639

640+
CONTEXTUAL_SIMPLE_DECL_ATTR(_unsafeSendable, UnsafeSendable,
641+
OnParam | UserInaccessible |
642+
ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
643+
113)
644+
645+
CONTEXTUAL_SIMPLE_DECL_ATTR(_unsafeMainActor, UnsafeMainActor,
646+
OnParam | UserInaccessible |
647+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIBreakingToRemove,
648+
114)
640649

641650
#undef TYPE_ATTR
642651
#undef DECL_ATTR_ALIAS

0 commit comments

Comments
 (0)