|
15 | 15 | #include "DIMemoryUseCollector.h"
|
16 | 16 | #include "swift/AST/DiagnosticEngine.h"
|
17 | 17 | #include "swift/AST/DiagnosticsSIL.h"
|
| 18 | +#include "swift/AST/DistributedDecl.h" |
18 | 19 | #include "swift/AST/Expr.h"
|
19 | 20 | #include "swift/AST/Stmt.h"
|
20 | 21 | #include "swift/ClangImporter/ClangModule.h"
|
@@ -1361,25 +1362,51 @@ void LifetimeChecker::handleFlowSensitiveActorIsolationUse(
|
1361 | 1362 | SILType optExistentialType = builtinInst->getType();
|
1362 | 1363 | SILLocation loc = builtinInst->getLoc();
|
1363 | 1364 | if (isInitializedAtUse(Use, &IsSuperInitComplete, &FailedSelfUse)) {
|
1364 |
| - // 'self' is initialized, so replace this builtin with an injection of the |
1365 |
| - // argument into (any Actor)?. |
1366 |
| - |
1367 |
| - // Create a copy of the actor argument, which we intentionally did not |
1368 |
| - // copy in SILGen. |
1369 |
| - SILValue actor = B.createCopyValue(loc, builtinInst->getArguments()[0]); |
1370 |
| - |
1371 |
| - // Inject 'self' into 'any Actor'. |
1372 |
| - ProtocolConformanceRef conformances[1] = { |
1373 |
| - builtinInst->getSubstitutions().getConformances()[0] |
1374 |
| - }; |
1375 |
| - SILType existentialType = optExistentialType.getOptionalObjectType(); |
1376 |
| - SILValue existentialBox = B.createInitExistentialRef( |
1377 |
| - loc, existentialType, actor->getType().getASTType(), actor, |
1378 |
| - ctx.AllocateCopy(conformances)); |
| 1365 | + // 'self' is initialized, so replace this builtin with the appropriate |
| 1366 | + // operation to produce `any Actor. |
| 1367 | + |
| 1368 | + SILValue anyActorValue; |
| 1369 | + auto conformance = builtinInst->getSubstitutions().getConformances()[0]; |
| 1370 | + if (builtinInst->getBuiltinKind() == BuiltinValueKind::FlowSensitiveSelfIsolation) { |
| 1371 | + // Create a copy of the actor argument, which we intentionally did not |
| 1372 | + // copy in SILGen. |
| 1373 | + SILValue actor = B.createCopyValue(loc, builtinInst->getArguments()[0]); |
| 1374 | + |
| 1375 | + // Inject 'self' into 'any Actor'. |
| 1376 | + ProtocolConformanceRef conformances[1] = { conformance }; |
| 1377 | + SILType existentialType = optExistentialType.getOptionalObjectType(); |
| 1378 | + anyActorValue = B.createInitExistentialRef( |
| 1379 | + loc, existentialType, actor->getType().getASTType(), actor, |
| 1380 | + ctx.AllocateCopy(conformances)); |
| 1381 | + } else { |
| 1382 | + // Borrow the actor argument, which we need to form the appropriate |
| 1383 | + // call to the asLocalActor getter. |
| 1384 | + SILValue actor = B.createBeginBorrow(loc, builtinInst->getArguments()[0]); |
| 1385 | + |
| 1386 | + // Dig out the getter for asLocalActor. |
| 1387 | + auto asLocalActorDecl = getDistributedActorAsLocalActorComputedProperty( |
| 1388 | + F.getDeclContext()->getParentModule()); |
| 1389 | + auto asLocalActorGetter = asLocalActorDecl->getAccessor(AccessorKind::Get); |
| 1390 | + SILDeclRef asLocalActorRef = SILDeclRef( |
| 1391 | + asLocalActorGetter, SILDeclRef::Kind::Func); |
| 1392 | + SILFunction *asLocalActorFunc = F.getModule() |
| 1393 | + .lookUpFunction(asLocalActorRef); |
| 1394 | + SILValue asLocalActorValue = B.createFunctionRef(loc, asLocalActorFunc); |
| 1395 | + |
| 1396 | + // Call asLocalActor. It produces an 'any Actor'. |
| 1397 | + anyActorValue = B.createApply( |
| 1398 | + loc, |
| 1399 | + asLocalActorValue, |
| 1400 | + SubstitutionMap::get(asLocalActorGetter->getGenericSignature(), |
| 1401 | + { actor->getType().getASTType() }, |
| 1402 | + { conformance }), |
| 1403 | + { actor }); |
| 1404 | + B.createEndBorrow(loc, actor); |
| 1405 | + } |
1379 | 1406 |
|
1380 | 1407 | // Then, wrap it in an optional.
|
1381 | 1408 | replacement = B.createEnum(
|
1382 |
| - loc, existentialBox, ctx.getOptionalSomeDecl(), optExistentialType); |
| 1409 | + loc, anyActorValue, ctx.getOptionalSomeDecl(), optExistentialType); |
1383 | 1410 | } else {
|
1384 | 1411 | // 'self' is not initialized yet, so use 'nil'.
|
1385 | 1412 | replacement = B.createEnum(
|
|
0 commit comments