Skip to content

Commit da3cfae

Browse files
authored
Merge pull request swiftlang#73057 from apple/minor-isolation-checking-fixes
Minor isolation checking fixes
2 parents 7b8f76e + 5a39369 commit da3cfae

12 files changed

+71
-31
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5875,7 +5875,7 @@ ASTContext::getOpenedExistentialSignature(Type type, GenericSignature parentSig)
58755875
return found->second;
58765876

58775877
auto genericParam = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5878-
canParentSig, type->getASTContext())
5878+
canParentSig, *this)
58795879
->castTo<GenericTypeParamType>();
58805880
Requirement requirement(RequirementKind::Conformance, genericParam,
58815881
constraint);

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ namespace {
14021402
printField(PD->getDefaultArgumentKind(), "default_arg");
14031403
}
14041404
if (PD->hasDefaultExpr() &&
1405+
PD->getDefaultArgumentCaptureInfo().hasBeenComputed() &&
14051406
!PD->getDefaultArgumentCaptureInfo().isTrivial()) {
14061407
printFieldRaw([&](raw_ostream &OS) {
14071408
PD->getDefaultArgumentCaptureInfo().print(OS);
@@ -1488,7 +1489,8 @@ namespace {
14881489

14891490
void printCommonAFD(AbstractFunctionDecl *D, const char *Type, StringRef Label) {
14901491
printCommon(D, Type, Label, FuncColor);
1491-
if (!D->getCaptureInfo().isTrivial()) {
1492+
if (D->getCaptureInfo().hasBeenComputed() &&
1493+
!D->getCaptureInfo().isTrivial()) {
14921494
printFlagRaw([&](raw_ostream &OS) {
14931495
D->getCaptureInfo().print(OS);
14941496
});
@@ -2826,7 +2828,8 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
28262828
break;
28272829
}
28282830

2829-
if (!E->getCaptureInfo().isTrivial()) {
2831+
if (E->getCaptureInfo().hasBeenComputed() &&
2832+
!E->getCaptureInfo().isTrivial()) {
28302833
printFieldRaw([&](raw_ostream &OS) {
28312834
E->getCaptureInfo().print(OS);
28322835
}, "", CapturesColor);

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,14 +1683,11 @@ void PrintAST::printGenericSignature(GenericSignature genericSig,
16831683
static void eraseInvertibleProtocolConformances(
16841684
SmallVectorImpl<Requirement> &requirements) {
16851685
llvm::erase_if(requirements, [&](Requirement req) {
1686-
if (req.getKind() == RequirementKind::Conformance) {
1687-
if (auto protoType = req.getSecondType()->getAs<ProtocolType>()) {
1688-
auto proto = protoType->getDecl();
1689-
return proto->getInvertibleProtocolKind().has_value();
1690-
}
1691-
}
1686+
if (req.getKind() != RequirementKind::Conformance)
1687+
return false;
16921688

1693-
return false;
1689+
return req.getProtocolDecl()
1690+
->getInvertibleProtocolKind().has_value();
16941691
});
16951692
}
16961693

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {
954954
// If it's a Sendable requirement, skip it.
955955
const auto &req = requirements[reqIdx];
956956
if (req.getKind() == RequirementKind::Conformance &&
957-
req.getSecondType()->castTo<ProtocolType>()->getDecl()
957+
req.getProtocolDecl()
958958
->isSpecificProtocol(KnownProtocolKind::Sendable))
959959
continue;
960960

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10256,13 +10256,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
1025610256
if (req.getKind() != RequirementKind::Conformance)
1025710257
return false;
1025810258

10259-
if (auto protocolTy =
10260-
req.getSecondType()->template getAs<ProtocolType>()) {
10261-
return req.getFirstType()->hasTypeVariable() &&
10262-
protocolTy->getDecl()->isSpecificProtocol(
10263-
KnownProtocolKind::Sendable);
10264-
}
10265-
return false;
10259+
return (req.getFirstType()->hasTypeVariable() &&
10260+
req.getProtocolDecl()->isSpecificProtocol(
10261+
KnownProtocolKind::Sendable));
1026610262
})) {
1026710263
result.OverallResult = MemberLookupResult::Unsolved;
1026810264
return result;

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,9 +2624,23 @@ namespace {
26242624
return MacroWalking::Expansion;
26252625
}
26262626

2627+
PreWalkResult<Pattern *> walkToPatternPre(Pattern *pattern) override {
2628+
// Walking into patterns leads to nothing good because then we
2629+
// end up visiting the AccessorDecls of a top-level
2630+
// PatternBindingDecl twice.
2631+
return Action::SkipNode(pattern);
2632+
}
2633+
26272634
PreWalkAction walkToDeclPre(Decl *decl) override {
2635+
// Don't walk into local types because nothing in them can
2636+
// change the outcome of our analysis, and we don't want to
2637+
// assume things there have been type checked yet.
2638+
if (isa<TypeDecl>(decl)) {
2639+
return Action::SkipChildren();
2640+
}
2641+
26282642
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2629-
if (func->isLocalContext()) {
2643+
if (func->getDeclContext()->isLocalContext()) {
26302644
checkLocalCaptures(func);
26312645
}
26322646

@@ -4249,7 +4263,9 @@ void swift::checkFunctionActorIsolation(AbstractFunctionDecl *decl) {
42494263
ActorIsolationChecker checker(decl);
42504264
if (auto body = decl->getBody()) {
42514265
body->walk(checker);
4252-
if(ctx.LangOpts.hasFeature(Feature::GroupActorErrors)){ checker.diagnoseIsolationErrors(); }
4266+
if (ctx.LangOpts.hasFeature(Feature::GroupActorErrors)) {
4267+
checker.diagnoseIsolationErrors();
4268+
}
42534269
}
42544270
if (auto ctor = dyn_cast<ConstructorDecl>(decl)) {
42554271
if (auto superInit = ctor->getSuperInitCall())
@@ -5375,11 +5391,9 @@ DefaultInitializerIsolation::evaluate(Evaluator &evaluator,
53755391
return ActorIsolation::forUnspecified();
53765392

53775393
auto i = pbd->getPatternEntryIndexForVarDecl(var);
5378-
if (!pbd->isInitializerChecked(i))
5379-
TypeChecker::typeCheckPatternBinding(pbd, i);
53805394

53815395
dc = cast<Initializer>(pbd->getInitContext(i));
5382-
initExpr = pbd->getInit(i);
5396+
initExpr = pbd->getCheckedAndContextualizedInit(i);
53835397
enclosingIsolation = getActorIsolation(var);
53845398
} else if (auto *param = dyn_cast<ParamDecl>(var)) {
53855399
// If this parameter corresponds to a stored property for a

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,16 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27222722

27232723
// Trigger a request that will complete typechecking for the
27242724
// initializer.
2725-
(void)PBD->getCheckedAndContextualizedInit(i);
2725+
(void) PBD->getCheckedAndContextualizedInit(i);
2726+
2727+
if (auto *var = PBD->getSingleVar()) {
2728+
if (var->hasAttachedPropertyWrapper())
2729+
return;
2730+
}
2731+
2732+
if (!PBD->getDeclContext()->isLocalContext()) {
2733+
(void) PBD->getInitializerIsolation(i);
2734+
}
27262735
}
27272736
}
27282737

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,12 +2994,10 @@ bool TypeChecker::typeCheckTapBody(TapExpr *expr, DeclContext *DC) {
29942994
}
29952995

29962996
void TypeChecker::typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {
2997-
// We intentionally use typeCheckStmt instead of typeCheckBody here
2998-
// because we want to contextualize all the TopLevelCode
2999-
// declarations simultaneously.
30002997
BraceStmt *Body = TLCD->getBody();
3001-
StmtChecker(TLCD).typeCheckStmt(Body);
2998+
StmtChecker(TLCD).typeCheckBody(Body);
30022999
TLCD->setBody(Body);
3000+
30033001
checkTopLevelActorIsolation(TLCD);
30043002
checkTopLevelEffects(TLCD);
30053003
performTopLevelDeclDiagnostics(TLCD);

lib/Sema/TypeCheckStorage.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,6 @@ static void checkAndContextualizePatternBindingInit(PatternBindingDecl *binding,
617617
if (auto *initContext = binding->getInitContext(i)) {
618618
auto *init = binding->getInit(i);
619619
TypeChecker::contextualizeInitializer(initContext, init);
620-
(void)binding->getInitializerIsolation(i);
621620
TypeChecker::checkInitializerEffects(initContext, init);
622621
}
623622
}

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
284284
for (auto D : SF->getTopLevelDecls()) {
285285
if (auto *TLCD = dyn_cast<TopLevelCodeDecl>(D)) {
286286
TypeChecker::typeCheckTopLevelCodeDecl(TLCD);
287-
TypeChecker::contextualizeTopLevelCode(TLCD);
288287
} else {
289288
TypeChecker::typeCheckDecl(D);
290289
}

0 commit comments

Comments
 (0)