Skip to content

Commit 71937e0

Browse files
committed
[region-isolation] Fix verifier check.
After following up with @slavapestov and @xedin, I was right to be suspicious of my changes here. Instead of attempting to hard code this, I do the right thing and I map the relevant type into the function's generic context and then do the check. This ensures that when isAnyActorType() performs the conformance check, ModuleDecl::lookupConformance() has a generic signature to work with. (cherry picked from commit 4412fff)
1 parent b6f51a5 commit 71937e0

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6578,36 +6578,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
65786578
})),
65796579
"transferring result means all results are transferring");
65806580

6581-
// We should only ever have a single sil_isolated parameter.
6582-
bool foundIsolatedParameter = false;
6583-
for (const auto &parameterInfo : FTy->getParameters()) {
6584-
if (parameterInfo.hasOption(SILParameterInfo::Isolated)) {
6585-
auto argType = parameterInfo.getArgumentType(F.getModule(),
6586-
FTy,
6587-
F.getTypeExpansionContext());
6588-
if (argType->isOptional())
6589-
argType = argType->lookThroughAllOptionalTypes()->getCanonicalType();
6590-
6591-
auto genericSig = FTy->getInvocationGenericSignature();
6592-
auto &ctx = F.getASTContext();
6593-
auto *actorProtocol = ctx.getProtocol(KnownProtocolKind::Actor);
6594-
auto *anyActorProtocol = ctx.getProtocol(KnownProtocolKind::AnyActor);
6595-
bool genericTypeWithActorRequirement = llvm::any_of(
6596-
genericSig.getRequirements(), [&](const Requirement &other) {
6597-
if (other.getKind() != RequirementKind::Conformance)
6598-
return false;
6599-
if (other.getFirstType()->getCanonicalType() != argType)
6600-
return false;
6601-
auto *otherProtocol = other.getProtocolDecl();
6602-
return otherProtocol->inheritsFrom(actorProtocol) ||
6603-
otherProtocol->inheritsFrom(anyActorProtocol);
6604-
});
6605-
require(argType->isAnyActorType() || genericTypeWithActorRequirement,
6606-
"Only any actor types can be isolated");
6607-
require(!foundIsolatedParameter, "Two isolated parameters");
6608-
foundIsolatedParameter = true;
6609-
}
6610-
}
66116581
require(1 >= std::count_if(FTy->getParameters().begin(), FTy->getParameters().end(),
66126582
[](const SILParameterInfo &parameterInfo) {
66136583
return parameterInfo.hasOption(SILParameterInfo::Isolated);
@@ -7015,11 +6985,37 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
70156985
}
70166986
}
70176987

6988+
void verifyParentFunctionSILFunctionType(CanSILFunctionType FTy) {
6989+
bool foundIsolatedParameter = false;
6990+
for (const auto &parameterInfo : FTy->getParameters()) {
6991+
if (parameterInfo.hasOption(SILParameterInfo::Isolated)) {
6992+
auto argType = parameterInfo.getArgumentType(F.getModule(),
6993+
FTy,
6994+
F.getTypeExpansionContext());
6995+
6996+
if (argType->isOptional())
6997+
argType = argType->lookThroughAllOptionalTypes()->getCanonicalType();
6998+
6999+
auto genericSig = FTy->getInvocationGenericSignature();
7000+
auto &ctx = F.getASTContext();
7001+
auto *actorProtocol = ctx.getProtocol(KnownProtocolKind::Actor);
7002+
auto *anyActorProtocol = ctx.getProtocol(KnownProtocolKind::AnyActor);
7003+
require(argType->isAnyActorType() ||
7004+
genericSig->requiresProtocol(argType, actorProtocol) ||
7005+
genericSig->requiresProtocol(argType, anyActorProtocol),
7006+
"Only any actor types can be isolated");
7007+
require(!foundIsolatedParameter, "Two isolated parameters");
7008+
foundIsolatedParameter = true;
7009+
}
7010+
}
7011+
}
7012+
70187013
void visitSILFunction(SILFunction *F) {
70197014
PrettyStackTraceSILFunction stackTrace("verifying", F);
70207015

70217016
CanSILFunctionType FTy = F->getLoweredFunctionType();
70227017
verifySILFunctionType(FTy);
7018+
verifyParentFunctionSILFunctionType(FTy);
70237019

70247020
SILModule &mod = F->getModule();
70257021
bool embedded = mod.getASTContext().LangOpts.hasFeature(Feature::Embedded);

0 commit comments

Comments
 (0)