Skip to content

Commit cf46074

Browse files
committed
[Distributed] Harden typechecker against completely empty DAS types
1 parent cb109dc commit cf46074

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/AST/ASTContext.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,9 @@ FuncDecl *ASTContext::getMakeInvocationEncoderOnDistributedActorSystem(
13831383
FuncDecl *
13841384
ASTContext::getRecordGenericSubstitutionOnDistributedInvocationEncoder(
13851385
NominalTypeDecl *nominal) const {
1386+
if (!nominal)
1387+
return nullptr;
1388+
13861389
for (auto result : nominal->lookupDirect(Id_recordGenericSubstitution)) {
13871390
auto *func = dyn_cast<FuncDecl>(result);
13881391
if (func &&
@@ -1396,6 +1399,9 @@ ASTContext::getRecordGenericSubstitutionOnDistributedInvocationEncoder(
13961399

13971400
AbstractFunctionDecl *ASTContext::getRecordArgumentOnDistributedInvocationEncoder(
13981401
NominalTypeDecl *nominal) const {
1402+
if (!nominal)
1403+
return nullptr;
1404+
13991405
return evaluateOrDefault(
14001406
nominal->getASTContext().evaluator,
14011407
GetDistributedTargetInvocationEncoderRecordArgumentFunctionRequest{nominal},
@@ -1404,6 +1410,9 @@ AbstractFunctionDecl *ASTContext::getRecordArgumentOnDistributedInvocationEncode
14041410

14051411
AbstractFunctionDecl *ASTContext::getRecordReturnTypeOnDistributedInvocationEncoder(
14061412
NominalTypeDecl *nominal) const {
1413+
if (!nominal)
1414+
return nullptr;
1415+
14071416
return evaluateOrDefault(
14081417
nominal->getASTContext().evaluator,
14091418
GetDistributedTargetInvocationEncoderRecordReturnTypeFunctionRequest{nominal},
@@ -1412,6 +1421,9 @@ AbstractFunctionDecl *ASTContext::getRecordReturnTypeOnDistributedInvocationEnco
14121421

14131422
AbstractFunctionDecl *ASTContext::getRecordErrorTypeOnDistributedInvocationEncoder(
14141423
NominalTypeDecl *nominal) const {
1424+
if (!nominal)
1425+
return nullptr;
1426+
14151427
return evaluateOrDefault(
14161428
nominal->getASTContext().evaluator,
14171429
GetDistributedTargetInvocationEncoderRecordErrorTypeFunctionRequest{nominal},
@@ -1420,6 +1432,9 @@ AbstractFunctionDecl *ASTContext::getRecordErrorTypeOnDistributedInvocationEncod
14201432

14211433
AbstractFunctionDecl *ASTContext::getDecodeNextArgumentOnDistributedInvocationDecoder(
14221434
NominalTypeDecl *nominal) const {
1435+
if (!nominal)
1436+
return nullptr;
1437+
14231438
return evaluateOrDefault(
14241439
nominal->getASTContext().evaluator,
14251440
GetDistributedTargetInvocationDecoderDecodeNextArgumentFunctionRequest{nominal},
@@ -1428,6 +1443,9 @@ AbstractFunctionDecl *ASTContext::getDecodeNextArgumentOnDistributedInvocationDe
14281443

14291444
AbstractFunctionDecl *ASTContext::getOnReturnOnDistributedTargetInvocationResultHandler(
14301445
NominalTypeDecl *nominal) const {
1446+
if (!nominal)
1447+
return nullptr;
1448+
14311449
return evaluateOrDefault(
14321450
nominal->getASTContext().evaluator,
14331451
GetDistributedTargetInvocationResultHandlerOnReturnFunctionRequest{nominal},

test/Distributed/distributed_imcomplete_system_dont_crash.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ public final class CompletelyHollowActorSystem: DistributedActorSystem {
3636
// expected-error@-1{{type 'CompletelyHollowActorSystem.ResultHandler' does not conform to protocol 'DistributedTargetInvocationResultHandler'}}
3737
}
3838

39+
}
40+
41+
public final class CompletelyHollowActorSystem_NotEvenTypes: DistributedActorSystem {
42+
// expected-error@-1{{type 'CompletelyHollowActorSystem_NotEvenTypes' does not conform to protocol 'DistributedActorSystem'}}
43+
// expected-error@-2{{class 'CompletelyHollowActorSystem_NotEvenTypes' is missing witness for protocol requirement 'remoteCallVoid'}}
44+
// expected-error@-3{{class 'CompletelyHollowActorSystem_NotEvenTypes' is missing witness for protocol requirement 'remoteCall'}}
45+
// expected-note@-4{{protocol 'DistributedActorSystem' requires function 'remoteCall' with signature:}}
46+
// expected-note@-5{{protocol 'DistributedActorSystem' requires function 'remoteCallVoid' with signature:}}
3947
}

0 commit comments

Comments
 (0)