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