Skip to content

Commit 4412fff

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.
1 parent 4789cc7 commit 4412fff

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
@@ -6574,36 +6574,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
65746574
})),
65756575
"transferring result means all results are transferring");
65766576

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

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

70207015
CanSILFunctionType FTy = F->getLoweredFunctionType();
70217016
verifySILFunctionType(FTy);
7017+
verifyParentFunctionSILFunctionType(FTy);
70227018

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

0 commit comments

Comments
 (0)