@@ -178,14 +178,24 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType) {
178
178
return FD;
179
179
}
180
180
181
+ namespace {
182
+
183
+ enum class BuiltinThrowsKind : uint8_t {
184
+ None,
185
+ Throws,
186
+ Rethrows
187
+ };
188
+
189
+ }
190
+
181
191
// / Build a builtin function declaration.
182
192
static FuncDecl *
183
193
getBuiltinGenericFunction (Identifier Id,
184
194
ArrayRef<AnyFunctionType::Param> ArgParamTypes,
185
195
Type ResType,
186
196
GenericParamList *GenericParams,
187
197
GenericSignature Sig,
188
- bool Rethrows = false ) {
198
+ bool Async, BuiltinThrowsKind Throws ) {
189
199
assert (GenericParams && " Missing generic parameters" );
190
200
auto &Context = ResType->getASTContext ();
191
201
@@ -211,13 +221,15 @@ getBuiltinGenericFunction(Identifier Id,
211
221
212
222
DeclName Name (Context, Id, paramList);
213
223
auto *const func = FuncDecl::createImplicit (
214
- Context, StaticSpellingKind::None, Name, /* NameLoc=*/ SourceLoc (),
215
- /* Async=*/ false ,
216
- /* Throws=*/ Rethrows, GenericParams, paramList, ResType, DC);
224
+ Context, StaticSpellingKind::None, Name,
225
+ /* NameLoc=*/ SourceLoc (),
226
+ Async,
227
+ Throws != BuiltinThrowsKind::None,
228
+ GenericParams, paramList, ResType, DC);
217
229
218
230
func->setAccess (AccessLevel::Public);
219
231
func->setGenericSignature (Sig);
220
- if (Rethrows)
232
+ if (Throws == BuiltinThrowsKind:: Rethrows)
221
233
func->getAttrs ().add (new (Context) RethrowsAttr (/* ThrowsLoc*/ SourceLoc ()));
222
234
223
235
return func;
@@ -445,7 +457,8 @@ namespace {
445
457
GenericParamList *TheGenericParamList;
446
458
SmallVector<AnyFunctionType::Param, 4 > InterfaceParams;
447
459
Type InterfaceResult;
448
- bool Rethrows = false ;
460
+ bool Async = false ;
461
+ BuiltinThrowsKind Throws = BuiltinThrowsKind::None;
449
462
450
463
// Accumulate params and requirements here, so that we can make the
451
464
// appropriate `AbstractGenericSignatureRequest` when `build()` is called.
@@ -490,8 +503,16 @@ namespace {
490
503
addedRequirements.push_back (req);
491
504
}
492
505
493
- void setRethrows (bool rethrows = true ) {
494
- Rethrows = rethrows;
506
+ void setAsync () {
507
+ Async = true ;
508
+ }
509
+
510
+ void setThrows () {
511
+ Throws = BuiltinThrowsKind::Throws;
512
+ }
513
+
514
+ void setRethrows () {
515
+ Throws = BuiltinThrowsKind::Rethrows;
495
516
}
496
517
497
518
FuncDecl *build (Identifier name) {
@@ -502,7 +523,8 @@ namespace {
502
523
nullptr );
503
524
return getBuiltinGenericFunction (name, InterfaceParams,
504
525
InterfaceResult,
505
- TheGenericParamList, GenericSig);
526
+ TheGenericParamList, GenericSig,
527
+ Async, Throws);
506
528
}
507
529
508
530
// Don't use these generator classes directly; call the make{...}
0 commit comments