Skip to content

Commit 0d8e3e1

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 8724a01 + a8f3634 commit 0d8e3e1

File tree

80 files changed

+698
-175
lines changed

Some content is hidden

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

80 files changed

+698
-175
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,14 @@ Types
527527
FUNCTION-KIND ::= 'H' // @differentiable(linear) function type
528528
FUNCTION-KIND ::= 'I' // @differentiable(linear) function type (escaping)
529529

530-
function-signature ::= params-type params-type throws? // results and parameters
530+
function-signature ::= params-type params-type async? throws? // results and parameters
531531

532532
params-type ::= type 'z'? 'h'? // tuple in case of multiple parameters or a single parameter with a single tuple type
533533
// with optional inout convention, shared convention. parameters don't have labels,
534534
// they are mangled separately as part of the entity.
535535
params-type ::= empty-list // shortcut for no parameters
536536

537+
async ::= 'Y' // 'async' annotation on function types
537538
throws ::= 'K' // 'throws' annotation on function types
538539

539540
type-list ::= list-type '_' list-type* // list of types

include/swift/ABI/Metadata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,7 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
16341634
FunctionMetadataConvention getConvention() const {
16351635
return Flags.getConvention();
16361636
}
1637+
bool async() const { return Flags.async(); }
16371638
bool throws() const { return Flags.throws(); }
16381639
bool hasParameterFlags() const { return Flags.hasParameterFlags(); }
16391640
bool isEscaping() const { return Flags.isEscaping(); }

include/swift/ABI/MetadataValues.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,9 @@ class TargetFunctionTypeFlags {
794794
ThrowsMask = 0x01000000U,
795795
ParamFlagsMask = 0x02000000U,
796796
EscapingMask = 0x04000000U,
797-
DifferentiableMask = 0x08000000U,
798-
LinearMask = 0x10000000U
797+
DifferentiableMask = 0x08000000U,
798+
LinearMask = 0x10000000U,
799+
AsyncMask = 0x20000000U,
799800
};
800801
int_type Data;
801802

@@ -813,7 +814,13 @@ class TargetFunctionTypeFlags {
813814
return TargetFunctionTypeFlags((Data & ~ConventionMask)
814815
| (int_type(c) << ConventionShift));
815816
}
816-
817+
818+
constexpr TargetFunctionTypeFlags<int_type>
819+
withAsync(bool async) const {
820+
return TargetFunctionTypeFlags<int_type>((Data & ~AsyncMask) |
821+
(async ? AsyncMask : 0));
822+
}
823+
817824
constexpr TargetFunctionTypeFlags<int_type>
818825
withThrows(bool throws) const {
819826
return TargetFunctionTypeFlags<int_type>((Data & ~ThrowsMask) |
@@ -847,7 +854,11 @@ class TargetFunctionTypeFlags {
847854
FunctionMetadataConvention getConvention() const {
848855
return FunctionMetadataConvention((Data&ConventionMask) >> ConventionShift);
849856
}
850-
857+
858+
bool async() const {
859+
return bool(Data & AsyncMask);
860+
}
861+
851862
bool throws() const {
852863
return bool(Data & ThrowsMask);
853864
}

include/swift/AST/Decl.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class alignas(1 << DeclAlignInBits) Decl {
385385
SWIFT_INLINE_BITFIELD(SubscriptDecl, VarDecl, 2,
386386
StaticSpelling : 2
387387
);
388-
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1,
388+
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1+1,
389389
/// \see AbstractFunctionDecl::BodyKind
390390
BodyKind : 3,
391391

@@ -398,6 +398,9 @@ class alignas(1 << DeclAlignInBits) Decl {
398398
/// Whether we are overridden later.
399399
Overridden : 1,
400400

401+
/// Whether the function is async.
402+
Async : 1,
403+
401404
/// Whether the function body throws.
402405
Throws : 1,
403406

@@ -5792,6 +5795,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57925795

57935796
CaptureInfo Captures;
57945797

5798+
/// Location of the 'async' token.
5799+
SourceLoc AsyncLoc;
5800+
57955801
/// Location of the 'throws' token.
57965802
SourceLoc ThrowsLoc;
57975803

@@ -5801,15 +5807,17 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
58015807
} LazySemanticInfo = { };
58025808

58035809
AbstractFunctionDecl(DeclKind Kind, DeclContext *Parent, DeclName Name,
5804-
SourceLoc NameLoc, bool Throws, SourceLoc ThrowsLoc,
5810+
SourceLoc NameLoc, bool Async, SourceLoc AsyncLoc,
5811+
bool Throws, SourceLoc ThrowsLoc,
58055812
bool HasImplicitSelfDecl,
58065813
GenericParamList *GenericParams)
58075814
: GenericContext(DeclContextKind::AbstractFunctionDecl, Parent, GenericParams),
58085815
ValueDecl(Kind, Parent, Name, NameLoc),
5809-
Body(nullptr), ThrowsLoc(ThrowsLoc) {
5816+
Body(nullptr), AsyncLoc(AsyncLoc), ThrowsLoc(ThrowsLoc) {
58105817
setBodyKind(BodyKind::None);
58115818
Bits.AbstractFunctionDecl.HasImplicitSelfDecl = HasImplicitSelfDecl;
58125819
Bits.AbstractFunctionDecl.Overridden = false;
5820+
Bits.AbstractFunctionDecl.Async = Async;
58135821
Bits.AbstractFunctionDecl.Throws = Throws;
58145822
Bits.AbstractFunctionDecl.Synthesized = false;
58155823
Bits.AbstractFunctionDecl.HasSingleExpressionBody = false;
@@ -5869,9 +5877,16 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
58695877
Bits.AbstractFunctionDecl.IAMStatus = newValue.getRawValue();
58705878
}
58715879

5880+
/// Retrieve the location of the 'async' keyword, if present.
5881+
SourceLoc getAsyncLoc() const { return AsyncLoc; }
5882+
58725883
/// Retrieve the location of the 'throws' keyword, if present.
58735884
SourceLoc getThrowsLoc() const { return ThrowsLoc; }
58745885

5886+
/// Returns true if the function is marked as `async`. The
5887+
/// type of the function will be `async` as well.
5888+
bool hasAsync() const { return Bits.AbstractFunctionDecl.Async; }
5889+
58755890
/// Returns true if the function body throws.
58765891
bool hasThrows() const { return Bits.AbstractFunctionDecl.Throws; }
58775892

@@ -6117,11 +6132,13 @@ class FuncDecl : public AbstractFunctionDecl {
61176132
SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
61186133
SourceLoc FuncLoc,
61196134
DeclName Name, SourceLoc NameLoc,
6135+
bool Async, SourceLoc AsyncLoc,
61206136
bool Throws, SourceLoc ThrowsLoc,
61216137
bool HasImplicitSelfDecl,
61226138
GenericParamList *GenericParams, DeclContext *Parent)
61236139
: AbstractFunctionDecl(Kind, Parent,
61246140
Name, NameLoc,
6141+
Async, AsyncLoc,
61256142
Throws, ThrowsLoc,
61266143
HasImplicitSelfDecl, GenericParams),
61276144
StaticLoc(StaticLoc), FuncLoc(FuncLoc) {
@@ -6143,6 +6160,7 @@ class FuncDecl : public AbstractFunctionDecl {
61436160
StaticSpellingKind StaticSpelling,
61446161
SourceLoc FuncLoc,
61456162
DeclName Name, SourceLoc NameLoc,
6163+
bool Async, SourceLoc AsyncLoc,
61466164
bool Throws, SourceLoc ThrowsLoc,
61476165
GenericParamList *GenericParams,
61486166
DeclContext *Parent,
@@ -6168,6 +6186,7 @@ class FuncDecl : public AbstractFunctionDecl {
61686186
StaticSpellingKind StaticSpelling,
61696187
SourceLoc FuncLoc,
61706188
DeclName Name, SourceLoc NameLoc,
6189+
bool Async, SourceLoc AsyncLoc,
61716190
bool Throws, SourceLoc ThrowsLoc,
61726191
GenericParamList *GenericParams,
61736192
DeclContext *Parent);
@@ -6176,6 +6195,7 @@ class FuncDecl : public AbstractFunctionDecl {
61766195
StaticSpellingKind StaticSpelling,
61776196
SourceLoc FuncLoc,
61786197
DeclName Name, SourceLoc NameLoc,
6198+
bool Async, SourceLoc AsyncLoc,
61796199
bool Throws, SourceLoc ThrowsLoc,
61806200
GenericParamList *GenericParams,
61816201
ParameterList *ParameterList,
@@ -6317,7 +6337,8 @@ class AccessorDecl final : public FuncDecl {
63176337
: FuncDecl(DeclKind::Accessor,
63186338
staticLoc, staticSpelling, /*func loc*/ declLoc,
63196339
/*name*/ Identifier(), /*name loc*/ declLoc,
6320-
throws, throwsLoc, hasImplicitSelfDecl, genericParams, parent),
6340+
/*Async=*/false, SourceLoc(), throws, throwsLoc,
6341+
hasImplicitSelfDecl, genericParams, parent),
63216342
AccessorKeywordLoc(accessorKeywordLoc),
63226343
Storage(storage) {
63236344
Bits.AccessorDecl.AccessorKind = unsigned(accessorKind);

include/swift/AST/DiagnosticsParse.def

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,9 @@ ERROR(generic_non_function,PointsToFirstBadToken,
727727
ERROR(rethrowing_function_type,none,
728728
"only function declarations may be marked 'rethrows'; "
729729
"did you mean 'throws'?", ())
730-
ERROR(throws_in_wrong_position,none,
731-
"'throws' may only occur before '->'", ())
732-
ERROR(rethrows_in_wrong_position,none,
733-
"'rethrows' may only occur before '->'", ())
730+
ERROR(async_or_throws_in_wrong_position,none,
731+
"%select{'throws'|'rethrows'|'async'}0 may only occur before '->'",
732+
(unsigned))
734733
ERROR(throw_in_function_type,none,
735734
"expected throwing specifier; did you mean 'throws'?", ())
736735
ERROR(expected_type_before_arrow,none,
@@ -742,6 +741,9 @@ ERROR(function_type_argument_label,none,
742741
(Identifier))
743742
ERROR(expected_dynamic_func_attr,none,
744743
"expected a dynamically_replaceable function", ())
744+
ERROR(async_after_throws,none,
745+
"'async' must precede %select{'throws'|'rethrows'}0", (bool))
746+
ERROR(async_init,none, "initializer cannot be marked 'async'", ())
745747

746748
// Enum Types
747749
ERROR(expected_expr_enum_case_raw_value,PointsToFirstBadToken,

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,9 @@ NOTE(protocol_witness_settable_conflict,none,
21672167
"candidate is not settable, but protocol requires it", ())
21682168
NOTE(protocol_witness_rethrows_conflict,none,
21692169
"candidate is not 'rethrows', but protocol requires it", ())
2170+
NOTE(protocol_witness_async_conflict,none,
2171+
"candidate is %select{not |}0'async', but protocol requirement is%select{| not}0",
2172+
(bool))
21702173
NOTE(protocol_witness_throws_conflict,none,
21712174
"candidate throws, but protocol does not allow it", ())
21722175
NOTE(protocol_witness_not_objc,none,
@@ -4377,6 +4380,10 @@ NOTE(not_objc_generic_type_param,none,
43774380
NOTE(not_objc_function_type_param,none,
43784381
"function types cannot be represented in Objective-C unless their "
43794382
"parameters and returns can be", ())
4383+
ERROR(not_objc_function_async,none,
4384+
"'async' function cannot be represented in Objective-C", ())
4385+
NOTE(not_objc_function_type_async,none,
4386+
"'async' function types cannot be represented in Objective-C", ())
43804387
NOTE(not_objc_function_type_throwing,none,
43814388
"throwing function types cannot be represented in Objective-C", ())
43824389
NOTE(objc_inferring_on_objc_protocol_member,none,

include/swift/AST/Expr.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,32 +4812,38 @@ class CoerceExpr final : public ExplicitCastExpr {
48124812
/// may be preceded by the 'throws' keyword. Currently this only exists to be
48134813
/// transformed into a FunctionTypeRepr by simplifyTypeExpr() in Sema.
48144814
class ArrowExpr : public Expr {
4815+
SourceLoc AsyncLoc;
48154816
SourceLoc ThrowsLoc;
48164817
SourceLoc ArrowLoc;
48174818
Expr *Args;
48184819
Expr *Result;
48194820
public:
4820-
ArrowExpr(Expr *Args, SourceLoc ThrowsLoc, SourceLoc ArrowLoc, Expr *Result)
4821+
ArrowExpr(Expr *Args, SourceLoc AsyncLoc, SourceLoc ThrowsLoc,
4822+
SourceLoc ArrowLoc, Expr *Result)
48214823
: Expr(ExprKind::Arrow, /*implicit=*/false, Type()),
4822-
ThrowsLoc(ThrowsLoc), ArrowLoc(ArrowLoc), Args(Args), Result(Result)
4824+
AsyncLoc(AsyncLoc), ThrowsLoc(ThrowsLoc), ArrowLoc(ArrowLoc), Args(Args),
4825+
Result(Result)
48234826
{ }
48244827

4825-
ArrowExpr(SourceLoc ThrowsLoc, SourceLoc ArrowLoc)
4828+
ArrowExpr(SourceLoc AsyncLoc, SourceLoc ThrowsLoc, SourceLoc ArrowLoc)
48264829
: Expr(ExprKind::Arrow, /*implicit=*/false, Type()),
4827-
ThrowsLoc(ThrowsLoc), ArrowLoc(ArrowLoc), Args(nullptr), Result(nullptr)
4830+
AsyncLoc(AsyncLoc), ThrowsLoc(ThrowsLoc), ArrowLoc(ArrowLoc),
4831+
Args(nullptr), Result(nullptr)
48284832
{ }
48294833

48304834
Expr *getArgsExpr() const { return Args; }
48314835
void setArgsExpr(Expr *E) { Args = E; }
48324836
Expr *getResultExpr() const { return Result; }
48334837
void setResultExpr(Expr *E) { Result = E; }
4838+
SourceLoc getAsyncLoc() const { return AsyncLoc; }
48344839
SourceLoc getThrowsLoc() const { return ThrowsLoc; }
48354840
SourceLoc getArrowLoc() const { return ArrowLoc; }
48364841
bool isFolded() const { return Args != nullptr && Result != nullptr; }
48374842

48384843
SourceLoc getSourceLoc() const { return ArrowLoc; }
48394844
SourceLoc getStartLoc() const {
48404845
return isFolded() ? Args->getStartLoc() :
4846+
AsyncLoc.isValid() ? AsyncLoc :
48414847
ThrowsLoc.isValid() ? ThrowsLoc : ArrowLoc;
48424848
}
48434849
SourceLoc getEndLoc() const {

include/swift/AST/TypeRepr.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,14 @@ class FunctionTypeRepr : public TypeRepr {
482482

483483
TupleTypeRepr *ArgsTy;
484484
TypeRepr *RetTy;
485-
SourceLoc ArrowLoc;
485+
SourceLoc AsyncLoc;
486486
SourceLoc ThrowsLoc;
487+
SourceLoc ArrowLoc;
487488

488489
public:
489490
FunctionTypeRepr(GenericParamList *genericParams, TupleTypeRepr *argsTy,
490-
SourceLoc throwsLoc, SourceLoc arrowLoc, TypeRepr *retTy,
491+
SourceLoc asyncLoc, SourceLoc throwsLoc, SourceLoc arrowLoc,
492+
TypeRepr *retTy,
491493
GenericParamList *patternGenericParams = nullptr,
492494
ArrayRef<TypeRepr *> patternSubs = {},
493495
ArrayRef<TypeRepr *> invocationSubs = {})
@@ -497,7 +499,7 @@ class FunctionTypeRepr : public TypeRepr {
497499
PatternGenericParams(patternGenericParams), PatternGenericEnv(nullptr),
498500
PatternSubs(patternSubs),
499501
ArgsTy(argsTy), RetTy(retTy),
500-
ArrowLoc(arrowLoc), ThrowsLoc(throwsLoc) {
502+
AsyncLoc(asyncLoc), ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc) {
501503
}
502504

503505
GenericParamList *getGenericParams() const { return GenericParams; }
@@ -527,10 +529,12 @@ class FunctionTypeRepr : public TypeRepr {
527529

528530
TupleTypeRepr *getArgsTypeRepr() const { return ArgsTy; }
529531
TypeRepr *getResultTypeRepr() const { return RetTy; }
532+
bool async() const { return AsyncLoc.isValid(); }
530533
bool throws() const { return ThrowsLoc.isValid(); }
531534

532-
SourceLoc getArrowLoc() const { return ArrowLoc; }
535+
SourceLoc getAsyncLoc() const { return AsyncLoc; }
533536
SourceLoc getThrowsLoc() const { return ThrowsLoc; }
537+
SourceLoc getArrowLoc() const { return ArrowLoc; }
534538

535539
static bool classof(const TypeRepr *T) {
536540
return T->getKind() == TypeReprKind::Function;

include/swift/AST/Types.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
311311
}
312312

313313
protected:
314-
enum { NumAFTExtInfoBits = 8 };
314+
enum { NumAFTExtInfoBits = 9 };
315315
enum { NumSILExtInfoBits = 8 };
316316
union { uint64_t OpaqueBits;
317317

@@ -2972,7 +2972,7 @@ class AnyFunctionType : public TypeBase {
29722972
/// A class which abstracts out some details necessary for
29732973
/// making a call.
29742974
class ExtInfo {
2975-
// If bits are added or removed, then TypeBase::AnyFunctionTypeBits
2975+
// If bits are added or removed, then TypeBase::NumAFTExtInfoBits
29762976
// and NumMaskBits must be updated, and they must match.
29772977
//
29782978
// |representation|noEscape|throws|differentiability|
@@ -2981,10 +2981,11 @@ class AnyFunctionType : public TypeBase {
29812981
enum : unsigned {
29822982
RepresentationMask = 0xF << 0,
29832983
NoEscapeMask = 1 << 4,
2984-
ThrowsMask = 1 << 5,
2985-
DifferentiabilityMaskOffset = 6,
2984+
AsyncMask = 1 << 5,
2985+
ThrowsMask = 1 << 6,
2986+
DifferentiabilityMaskOffset = 7,
29862987
DifferentiabilityMask = 0x3 << DifferentiabilityMaskOffset,
2987-
NumMaskBits = 8
2988+
NumMaskBits = 9
29882989
};
29892990

29902991
unsigned Bits; // Naturally sized for speed.
@@ -3051,6 +3052,7 @@ class AnyFunctionType : public TypeBase {
30513052
}
30523053

30533054
bool isNoEscape() const { return Bits & NoEscapeMask; }
3055+
bool async() const { return Bits & AsyncMask; }
30543056
bool throws() const { return Bits & ThrowsMask; }
30553057
bool isDifferentiable() const {
30563058
return getDifferentiabilityKind() >
@@ -3120,6 +3122,11 @@ class AnyFunctionType : public TypeBase {
31203122
Other);
31213123
}
31223124
LLVM_NODISCARD
3125+
ExtInfo withAsync(bool Async = true) const {
3126+
return ExtInfo(Async ? (Bits | AsyncMask) : (Bits & ~AsyncMask),
3127+
Other);
3128+
}
3129+
LLVM_NODISCARD
31233130
ExtInfo withThrows(bool Throws = true) const {
31243131
return ExtInfo(Throws ? (Bits | ThrowsMask) : (Bits & ~ThrowsMask),
31253132
Other);
@@ -3378,6 +3385,10 @@ class AnyFunctionType : public TypeBase {
33783385
return getExtInfo().isNoEscape();
33793386
}
33803387

3388+
bool async() const {
3389+
return getExtInfo().async();
3390+
}
3391+
33813392
bool throws() const {
33823393
return getExtInfo().throws();
33833394
}

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ namespace swift {
235235
/// Enable experimental #assert feature.
236236
bool EnableExperimentalStaticAssert = false;
237237

238+
/// Enable experimental concurrency model.
239+
bool EnableExperimentalConcurrency = false;
240+
238241
/// Should we check the target OSs of serialized modules to see that they're
239242
/// new enough?
240243
bool EnableTargetOSChecking = true;

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ NODE(AssociatedConformanceDescriptor)
249249
NODE(DefaultAssociatedConformanceAccessor)
250250
NODE(BaseConformanceDescriptor)
251251
NODE(AssociatedTypeDescriptor)
252+
NODE(AsyncAnnotation)
252253
NODE(ThrowsAnnotation)
253254
NODE(EmptyList)
254255
NODE(FirstElementMarker)

0 commit comments

Comments
 (0)