@@ -914,23 +914,14 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
914914
915915 B.setInsertionPoint (entryBlock);
916916
917- // / Generates a reinterpret_cast for converting
918- // / Builtin.Job -> UnownedJob
919- // / Builtin.Executor -> UnownedSerialExecutor
920- // / These are used by _swiftJobRun, which, ABI-wise, could take
921- // / Builtin.Job or Builtin.Executor, but doesn't.
922- auto createExplodyCastForCall =
923- [this , &moduleLoc](SILValue originalValue, FuncDecl *jobRunFuncDecl,
924- uint32_t paramIndex) -> SILValue {
925- // The type coming from the _swiftJobRun function
926- Type apiType = jobRunFuncDecl->getParameters ()->get (paramIndex)->getType ();
927- SILType apiSILType =
928- SILType::getPrimitiveObjectType (apiType->getCanonicalType ());
917+ auto wrapCallArgs = [this , &moduleLoc](SILValue originalValue, FuncDecl *fd,
918+ uint32_t paramIndex) -> SILValue {
919+ Type parameterType = fd->getParameters ()->get (paramIndex)->getType ();
920+ SILType paramSILType = SILType::getPrimitiveObjectType (parameterType->getCanonicalType ());
929921 // If the types are the same, we don't need to do anything!
930- if (apiSILType == originalValue->getType ())
922+ if (paramSILType == originalValue->getType ())
931923 return originalValue;
932- return this ->B .createUncheckedReinterpretCast (moduleLoc, originalValue,
933- apiSILType);
924+ return this ->B .createStruct (moduleLoc, paramSILType, originalValue);
934925 };
935926
936927 // Call CreateAsyncTask
@@ -975,7 +966,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
975966 moduleLoc,
976967 ctx.getIdentifier (getBuiltinName (BuiltinValueKind::ConvertTaskToJob)),
977968 JobType, {}, {task});
978- jobResult = createExplodyCastForCall (jobResult, swiftJobRunFuncDecl, 0 );
969+ jobResult = wrapCallArgs (jobResult, swiftJobRunFuncDecl, 0 );
979970
980971 // Get main executor
981972 FuncDecl *getMainExecutorFuncDecl = SGM.getGetMainExecutor ();
@@ -985,7 +976,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
985976 SILValue getMainExeutorFunc =
986977 B.createFunctionRefFor (moduleLoc, getMainExeutorSILFunc);
987978 SILValue mainExecutor = B.createApply (moduleLoc, getMainExeutorFunc, {}, {});
988- mainExecutor = createExplodyCastForCall (mainExecutor, swiftJobRunFuncDecl, 1 );
979+ mainExecutor = wrapCallArgs (mainExecutor, swiftJobRunFuncDecl, 1 );
989980
990981 // Run first part synchronously
991982 B.createApply (moduleLoc, swiftJobRunFunc, {}, {jobResult, mainExecutor});
0 commit comments