Merge pull request #76815 from allevato/index-closure-attrs

[Index] Record references to global actors in closures and function types.
This commit is contained in:
Tony Allevato
2024-10-04 07:43:51 -04:00
committed by GitHub
2 changed files with 80 additions and 0 deletions

View File

@@ -89,6 +89,9 @@ private:
bool handleImports(ImportDecl *Import);
bool handleCustomAttributes(Decl *D);
bool handleCustomTypeAttribute(const CustomAttr *customAttr);
bool handleClosureAttributes(ClosureExpr *E);
bool handleTypeAttributes(AttributedTypeRepr *T);
bool passModulePathElements(ImportPath::Module Path,
const clang::Module *ClangMod);
@@ -603,6 +606,10 @@ ASTWalker::PreWalkResult<Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
return Action::Stop();
}
}
} else if (auto CE = dyn_cast<ClosureExpr>(E)) {
if (!handleClosureAttributes(CE))
return Action::Stop();
return Action::Continue(E);
}
return Action::Continue(E);
@@ -655,6 +662,9 @@ ASTWalker::PreWalkAction SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
ST->getSourceRange(), Data);
return Action::StopIf(!Continue);
}
} else if (auto AT = dyn_cast<AttributedTypeRepr>(T)) {
auto Continue = handleTypeAttributes(AT);
return Action::StopIf(!Continue);
}
return Action::Continue();
@@ -762,6 +772,39 @@ bool SemaAnnotator::handleCustomAttributes(Decl *D) {
return true;
}
bool SemaAnnotator::handleCustomTypeAttribute(const CustomAttr *customAttr) {
if (auto *Repr = customAttr->getTypeRepr())
if (!Repr->walk(*this))
return false;
if (auto *Args = customAttr->getArgs())
if (!Args->walk(*this))
return false;
return true;
}
bool SemaAnnotator::handleClosureAttributes(ClosureExpr *E) {
for (auto *customAttr : E->getAttrs().getAttributes<CustomAttr, true>())
if (!handleCustomTypeAttribute(customAttr))
return false;
return true;
}
bool SemaAnnotator::handleTypeAttributes(AttributedTypeRepr *T) {
for (auto attr : T->getAttrs()) {
if (!attr.is<CustomAttr *>())
continue;
CustomAttr *customAttr = attr.get<CustomAttr *>();
if (!handleCustomTypeAttribute(customAttr))
return false;
}
return true;
}
bool SemaAnnotator::handleImports(ImportDecl *Import) {
auto Mod = Import->getModule();
if (!Mod)

View File

@@ -0,0 +1,37 @@
// RUN: %target-swift-ide-test -print-indexed-symbols -include-locals -source-filename %s | %FileCheck %s
// REQUIRES: concurrency
@globalActor
actor CustomActor {
static let shared = CustomActor()
}
// Closure attributes
func f() {
_ = { @MainActor in }
// CHECK: [[@LINE-1]]:10 | class/Swift | MainActor | s:ScM | Ref,RelCont | rel: 1
// CHECK-NEXT: RelCont | function/Swift | f() | s:14swift_ide_test1fyyF
_ = { @CustomActor in }
// CHECK: [[@LINE-1]]:10 | class/Swift | CustomActor | s:14swift_ide_test11CustomActorC | Ref,RelCont | rel: 1
// CHECK-NEXT: RelCont | function/Swift | f() | s:14swift_ide_test1fyyF
}
// Function type attributes
typealias MAIsolated = @MainActor (Int) -> ()
// CHECK: [[@LINE-1]]:25 | class/Swift | MainActor | s:ScM | Ref | rel: 0
// CHECK: [[@LINE-2]]:36 | struct/Swift | Int | s:Si | Ref | rel: 0
typealias CAIsolated = @CustomActor () -> Int
// CHECK: [[@LINE-1]]:25 | class/Swift | CustomActor | s:14swift_ide_test11CustomActorC | Ref | rel: 0
// CHECK: [[@LINE-2]]:43 | struct/Swift | Int | s:Si | Ref | rel: 0
// Declaration attributes
@CustomActor
// CHECK: [[@LINE-1]]:2 | class/Swift | CustomActor | s:14swift_ide_test11CustomActorC | Ref | rel: 0
class CustomIsolated {
@CustomActor func customIsolated() {}
// CHECK: [[@LINE-1]]:4 | class/Swift | CustomActor | s:14swift_ide_test11CustomActorC | Ref,RelCont | rel: 1
// CHECK-NEXT: RelCont | instance-method/Swift | customIsolated() | s:14swift_ide_test14CustomIsolatedC06customE0yyF
}