@@ -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);
0 commit comments