@@ -442,7 +442,7 @@ enum class BuiltinThrowsKind : uint8_t {
442
442
static FuncDecl *getBuiltinGenericFunction (
443
443
Identifier Id, ArrayRef<AnyFunctionType::Param> ArgParamTypes, Type ResType,
444
444
GenericParamList *GenericParams, GenericSignature Sig, bool Async,
445
- BuiltinThrowsKind Throws, bool SendingResult) {
445
+ BuiltinThrowsKind Throws, Type ThrownError, bool SendingResult) {
446
446
assert (GenericParams && " Missing generic parameters" );
447
447
auto &Context = ResType->getASTContext ();
448
448
@@ -471,7 +471,7 @@ static FuncDecl *getBuiltinGenericFunction(
471
471
Context, StaticSpellingKind::None, Name,
472
472
/* NameLoc=*/ SourceLoc (),
473
473
Async,
474
- Throws != BuiltinThrowsKind::None, /* thrownType= */ Type () ,
474
+ Throws != BuiltinThrowsKind::None, ThrownError ,
475
475
GenericParams, paramList, ResType, DC);
476
476
477
477
func->setSendingResult (SendingResult);
@@ -696,6 +696,7 @@ namespace {
696
696
Type InterfaceResult;
697
697
bool Async = false ;
698
698
BuiltinThrowsKind Throws = BuiltinThrowsKind::None;
699
+ Type ThrownError;
699
700
bool SendingResult = false ;
700
701
701
702
// Accumulate params and requirements here, so that we can call
@@ -740,6 +741,11 @@ namespace {
740
741
InterfaceResult = generator.build (*this );
741
742
}
742
743
744
+ template <class G >
745
+ void setThrownError (const G &generator) {
746
+ ThrownError = generator.build (*this );
747
+ }
748
+
743
749
template <class G >
744
750
void addConformanceRequirement (const G &generator, KnownProtocolKind kp) {
745
751
addConformanceRequirement (generator, Context.getProtocol (kp));
@@ -776,7 +782,7 @@ namespace {
776
782
/* allowInverses=*/ false );
777
783
return getBuiltinGenericFunction (name, InterfaceParams, InterfaceResult,
778
784
TheGenericParamList, GenericSig, Async,
779
- Throws, SendingResult);
785
+ Throws, ThrownError, SendingResult);
780
786
}
781
787
782
788
// Don't use these generator classes directly; call the make{...}
@@ -2231,17 +2237,31 @@ static ValueDecl *getAddressOfRawLayout(ASTContext &ctx, Identifier id) {
2231
2237
}
2232
2238
2233
2239
static ValueDecl *getEmplace (ASTContext &ctx, Identifier id) {
2234
- BuiltinFunctionBuilder builder (ctx, /* genericParamCount */ 1 );
2240
+ BuiltinFunctionBuilder builder (ctx, /* genericParamCount */ 2 );
2235
2241
2236
- auto T = makeGenericParam ();
2242
+ // <T: ~Copyable, E: Error>(
2243
+ // _: (Builtin.RawPointer) throws(E) -> ()
2244
+ // ) throws(E) -> T
2245
+
2246
+ auto T = makeGenericParam (0 );
2237
2247
builder.addConformanceRequirement (T, KnownProtocolKind::Escapable);
2238
2248
2249
+ auto E = makeGenericParam (1 );
2250
+ builder.addConformanceRequirement (E, KnownProtocolKind::Error);
2251
+
2252
+ auto extInfo = ASTExtInfoBuilder ()
2253
+ .withNoEscape ()
2254
+ .withThrows (/* throws */ true , E.build (builder))
2255
+ .build ();
2256
+
2239
2257
auto fnParamTy = FunctionType::get (FunctionType::Param (ctx.TheRawPointerType ),
2240
2258
ctx.TheEmptyTupleType ,
2241
- ASTExtInfo (). withNoEscape () );
2259
+ extInfo );
2242
2260
2243
2261
builder.addParameter (makeConcrete (fnParamTy), ParamSpecifier::Borrowing);
2244
2262
builder.setResult (T);
2263
+ builder.setThrows ();
2264
+ builder.setThrownError (E);
2245
2265
2246
2266
return builder.build (id);
2247
2267
}
0 commit comments