@@ -986,7 +986,8 @@ ManagedValue Transform::transformTuple(ManagedValue inputTuple,
986
986
void SILGenFunction::collectThunkParams (
987
987
SILLocation loc, SmallVectorImpl<ManagedValue> ¶ms,
988
988
SmallVectorImpl<ManagedValue> *indirectResults,
989
- SmallVectorImpl<ManagedValue> *indirectErrors) {
989
+ SmallVectorImpl<ManagedValue> *indirectErrors,
990
+ ManagedValue *implicitIsolation) {
990
991
// Add the indirect results.
991
992
for (auto resultTy : F.getConventions ().getIndirectSILResultTypes (
992
993
getTypeExpansionContext ())) {
@@ -1028,8 +1029,12 @@ void SILGenFunction::collectThunkParams(
1028
1029
// If our thunk has an implicit param and we are being asked to forward it,
1029
1030
// to the callee, skip it. We are going to handle it especially later.
1030
1031
if (param.hasOption (SILParameterInfo::ImplicitLeading) &&
1031
- param.hasOption (SILParameterInfo::Isolated))
1032
+ param.hasOption (SILParameterInfo::Isolated)) {
1033
+ if (implicitIsolation)
1034
+ *implicitIsolation = functionArgument;
1032
1035
continue ;
1036
+ }
1037
+
1033
1038
params.push_back (functionArgument);
1034
1039
}
1035
1040
}
@@ -5462,9 +5467,18 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
5462
5467
options |= ThunkGenFlag::CalleeHasImplicitIsolatedParam;
5463
5468
}
5464
5469
5470
+ // Collect the thunk parameters. We don't need to collect the indirect
5471
+ // error parameter because it'll be stored as IndirectErrorResult, which
5472
+ // gets used implicitly by emitApplyWithRethrow.
5465
5473
SmallVector<ManagedValue, 8 > params;
5466
5474
SmallVector<ManagedValue, 4 > indirectResultParams;
5467
- SGF.collectThunkParams (loc, params, &indirectResultParams);
5475
+ ManagedValue implicitIsolationParam;
5476
+ SGF.collectThunkParams (loc, params, &indirectResultParams,
5477
+ /* indirect error params*/ nullptr ,
5478
+ &implicitIsolationParam);
5479
+
5480
+ assert (bool (options & ThunkGenFlag::ThunkHasImplicitIsolatedParam)
5481
+ == implicitIsolationParam.isValid ());
5468
5482
5469
5483
// Ignore the self parameter at the SIL level. IRGen will use it to
5470
5484
// recover type metadata.
@@ -5510,9 +5524,11 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
5510
5524
case FunctionTypeIsolation::Kind::NonIsolated:
5511
5525
break ;
5512
5526
5527
+ // For a function for caller isolation, we'll have to figure out what the
5528
+ // output function's formal isolation is. This is quite doable, but we don't
5529
+ // have to do it yet.
5513
5530
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
5514
- hopToIsolatedParameter = true ;
5515
- break ;
5531
+ llvm_unreachable (" synchronous function has caller isolation?" );
5516
5532
5517
5533
// For a function with parameter isolation, we'll have to dig the
5518
5534
// argument out after translation but before making the call.
@@ -5594,12 +5610,15 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
5594
5610
/* mandatory*/ false );
5595
5611
}
5596
5612
5597
- // If we are thunking a nonisolated caller to nonisolated or global actor, we
5598
- // need to load the actor .
5613
+ // If the input function has caller isolation, we need to fill in that
5614
+ // argument with the formal isolation of the output function .
5599
5615
if (options.contains (ThunkGenFlag::CalleeHasImplicitIsolatedParam)) {
5600
5616
auto outputIsolation = outputSubstType->getIsolation ();
5601
5617
switch (outputIsolation.getKind ()) {
5602
5618
case FunctionTypeIsolation::Kind::NonIsolated:
5619
+ case FunctionTypeIsolation::Kind::Erased:
5620
+ // Converting a caller-isolated function to @isolated(any) makes
5621
+ // it @concurrent. In either case, emit a nil actor reference.
5603
5622
argValues.push_back (SGF.emitNonIsolatedIsolation (loc).getValue ());
5604
5623
break ;
5605
5624
case FunctionTypeIsolation::Kind::GlobalActor: {
@@ -5609,11 +5628,17 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
5609
5628
SGF.emitGlobalActorIsolation (loc, globalActor).getValue ());
5610
5629
break ;
5611
5630
}
5631
+ case FunctionTypeIsolation::Kind::NonIsolatedCaller: {
5632
+ argValues.push_back (implicitIsolationParam.getValue ());
5633
+ break ;
5634
+ }
5612
5635
case FunctionTypeIsolation::Kind::Parameter:
5613
- case FunctionTypeIsolation::Kind::Erased:
5614
- case FunctionTypeIsolation::Kind::NonIsolatedCaller:
5636
+ // This would require a conversion from a type with caller
5637
+ // isolation to a type with parameter isolation, which is not
5638
+ // currently allowed and probably won't ever be. Anyway, to
5639
+ // implement it, we'd need to borrow the isolated parameter
5640
+ // and wrap it up as an `Optional<any Actor>`.
5615
5641
llvm_unreachable (" Should never see this" );
5616
- break ;
5617
5642
}
5618
5643
}
5619
5644
@@ -5964,7 +5989,9 @@ static void buildWithoutActuallyEscapingThunkBody(SILGenFunction &SGF,
5964
5989
SmallVector<ManagedValue, 8 > params;
5965
5990
SmallVector<ManagedValue, 8 > indirectResults;
5966
5991
SmallVector<ManagedValue, 1 > indirectErrorResults;
5967
- SGF.collectThunkParams (loc, params, &indirectResults, &indirectErrorResults);
5992
+ ManagedValue implicitIsolationParam;
5993
+ SGF.collectThunkParams (loc, params, &indirectResults, &indirectErrorResults,
5994
+ &implicitIsolationParam);
5968
5995
5969
5996
// Ignore the self parameter at the SIL level. IRGen will use it to
5970
5997
// recover type metadata.
@@ -5985,6 +6012,11 @@ static void buildWithoutActuallyEscapingThunkBody(SILGenFunction &SGF,
5985
6012
for (auto indirectError : indirectErrorResults)
5986
6013
argValues.push_back (indirectError.getLValueAddress ());
5987
6014
6015
+ // Forward the implicit isolation parameter.
6016
+ if (implicitIsolationParam.isValid ()) {
6017
+ argValues.push_back (implicitIsolationParam.getValue ());
6018
+ }
6019
+
5988
6020
// Add the rest of the arguments.
5989
6021
forwardFunctionArguments (SGF, loc, fnType, params, argValues);
5990
6022
@@ -6174,6 +6206,7 @@ ManagedValue SILGenFunction::getThunkedAutoDiffLinearMap(
6174
6206
return getThunkedResult ();
6175
6207
thunk->setGenericEnvironment (genericEnv);
6176
6208
6209
+ // FIXME: handle implicit isolation parameter here
6177
6210
SILGenFunction thunkSGF (SGM, *thunk, FunctionDC);
6178
6211
SmallVector<ManagedValue, 4 > params;
6179
6212
SmallVector<ManagedValue, 4 > thunkIndirectResults;
@@ -6516,6 +6549,7 @@ SILFunction *SILGenModule::getOrCreateCustomDerivativeThunk(
6516
6549
thunk->setGenericEnvironment (thunkGenericEnv);
6517
6550
6518
6551
SILGenFunction thunkSGF (*this , *thunk, customDerivativeFn->getDeclContext ());
6552
+ // FIXME: handle implicit isolation parameter here
6519
6553
SmallVector<ManagedValue, 4 > params;
6520
6554
SmallVector<ManagedValue, 4 > indirectResults;
6521
6555
SmallVector<ManagedValue, 1 > indirectErrorResults;
0 commit comments