@@ -2161,18 +2161,35 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
21612161 if (funcTy->hasErrorResult ()) {
21622162 auto errorType =
21632163 fnConv.getSILErrorType (IGF.IGM .getMaximalTypeExpansionContext ());
2164- auto &errorTI = cast<FixedTypeInfo>(IGF.getTypeInfo (errorType));
2164+ auto inContextErrorType =
2165+ IGF.CurSILFn ->mapTypeIntoContext (errorType);
21652166 bool isTypedError = fnConv.isTypedError ();
2166- if (isTypedError) {
2167+ bool isIndirectError = fnConv.hasIndirectSILErrorResults ();
2168+
2169+ if (isTypedError && !isIndirectError) {
2170+ auto &errorTI = cast<FixedTypeInfo>(IGF.getTypeInfo (errorType));
21672171 IGF.setCallerTypedErrorResultSlot (Address (
21682172 emission->getCallerTypedErrorResultArgument (),
21692173 errorTI.getStorageType (),
21702174 errorTI.getFixedAlignment ()));
2175+
2176+ } else if (isTypedError && isIndirectError) {
2177+
2178+ auto &errorTI = IGF.getTypeInfo (inContextErrorType);
2179+ auto ptr = emission->getCallerTypedErrorResultArgument ();
2180+ auto addr = errorTI.getAddressForPointer (ptr);
2181+ auto indirectErrorArgIdx = fnConv.getNumIndirectSILResults ();
2182+ auto errorArg = entry->getArguments ()[indirectErrorArgIdx];
2183+ IGF.setLoweredAddress (errorArg, addr);
2184+ params = params.slice (1 );
21712185 }
2186+
21722187 if (!funcTy->isAsync ()) {
2188+ auto &errorTI = IGF.getTypeInfo (inContextErrorType);
21732189 IGF.setCallerErrorResultSlot (
21742190 Address (emission->getCallerErrorResultArgument (),
2175- isTypedError ? IGF.IGM .Int8PtrTy : errorTI.getStorageType (),
2191+ isTypedError ? IGF.IGM .Int8PtrTy :
2192+ cast<FixedTypeInfo>(errorTI).getStorageType (),
21762193 IGF.IGM .getPointerAlignment ()));
21772194 }
21782195 }
@@ -3685,6 +3702,12 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
36853702
36863703 // Turn the formal SIL parameters into IR-gen things.
36873704 for (auto index : indices (args)) {
3705+ if (origConv.hasIndirectSILErrorResults () &&
3706+ index == origConv.getNumIndirectSILResults ()) {
3707+ auto addr = getLoweredAddress (args[index]);
3708+ emission->setIndirectTypedErrorResultSlot (addr.getAddress ());
3709+ continue ;
3710+ }
36883711 emitApplyArgument (*this , args[index], emission->getParameterType (index),
36893712 llArgs);
36903713 }
@@ -3752,9 +3775,10 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
37523775 // See below.
37533776 Builder.CreateStore (nullError, calleeErrorSlot);
37543777 }
3755- auto hasTypedError = substConv.isTypedError ();
3778+ auto hasTypedDirectError = substConv.isTypedError () &&
3779+ !substConv.hasIndirectSILErrorResults ();
37563780 llvm::BasicBlock *typedErrorLoadBB = nullptr ;
3757- if (hasTypedError ) {
3781+ if (hasTypedDirectError ) {
37583782 typedErrorLoadBB = createBasicBlock (" typed.error.load" );
37593783 }
37603784
@@ -3771,8 +3795,11 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
37713795
37723796 // Set up the PHI nodes on the error edge.
37733797 if (!typedErrorLoadBB) {
3774- assert (errorDest.phis .size () == 1 );
3775- errorDest.phis [0 ]->addIncoming (errorValue, Builder.GetInsertBlock ());
3798+ assert (errorDest.phis .size () == 1 ||
3799+ (substConv.hasIndirectSILErrorResults () &&
3800+ errorDest.phis .empty ()));
3801+ if (errorDest.phis .size () == 1 )
3802+ errorDest.phis [0 ]->addIncoming (errorValue, Builder.GetInsertBlock ());
37763803 } else {
37773804 Builder.emitBlock (typedErrorLoadBB);
37783805
@@ -4226,16 +4253,18 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
42264253 SILFunctionConventions conv (CurSILFn->getLoweredFunctionType (),
42274254 getSILModule ());
42284255 if (!isAsync ()) {
4229- Explosion errorResult = getLoweredExplosion (i->getOperand ());
42304256 if (conv.isTypedError ()) {
4231- auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4232- IGM.getMaximalTypeExpansionContext ())));
42334257 llvm::Constant *flag = llvm::ConstantInt::get (IGM.IntPtrTy , 1 );
42344258 flag = llvm::ConstantExpr::getIntToPtr (flag, IGM.Int8PtrTy );
4235- Builder.CreateStore (flag,
4236- getCallerErrorResultSlot ());
4237- ti.initialize (*this , errorResult, getCallerTypedErrorResultSlot (), false );
4259+ if (!conv.hasIndirectSILErrorResults ()) {
4260+ Explosion errorResult = getLoweredExplosion (i->getOperand ());
4261+ auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4262+ IGM.getMaximalTypeExpansionContext ())));
4263+ ti.initialize (*this , errorResult, getCallerTypedErrorResultSlot (), false );
4264+ }
4265+ Builder.CreateStore (flag, getCallerErrorResultSlot ());
42384266 } else {
4267+ Explosion errorResult = getLoweredExplosion (i->getOperand ());
42394268 Builder.CreateStore (errorResult.claimNext (), getCallerErrorResultSlot ());
42404269 }
42414270 // Async functions just return to the continuation.
@@ -4248,9 +4277,13 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
42484277 conv.getSILResultType (IGM.getMaximalTypeExpansionContext ()));
42494278
42504279 if (conv.isTypedError ()) {
4251- auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4252- IGM.getMaximalTypeExpansionContext ())));
4253- ti.initialize (*this , exn, getCallerTypedErrorResultSlot (), false );
4280+ if (conv.hasIndirectSILErrorResults ()) {
4281+ (void )exn.claimAll ();
4282+ } else {
4283+ auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4284+ IGM.getMaximalTypeExpansionContext ())));
4285+ ti.initialize (*this , exn, getCallerTypedErrorResultSlot (), false );
4286+ }
42544287 llvm::Constant *flag = llvm::ConstantInt::get (IGM.IntPtrTy , 1 );
42554288 flag = llvm::ConstantExpr::getIntToPtr (flag, IGM.Int8PtrTy );
42564289 assert (exn.empty () && " Unclaimed typed error results" );
0 commit comments