Skip to content

Commit bffba72

Browse files
authored
Merge pull request #38034 from artemcm/ShortCircuitSerializedGlobalActorAttrQuery
Short-circuit `GlobalActorAttributeRequest` attempting to get the Source Location of a serialized decl.
2 parents d3d87e8 + 6dc6adb commit bffba72

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,18 @@ GlobalActorAttributeRequest::evaluate(
207207
if (auto decl = subject.dyn_cast<Decl *>()) {
208208
dc = decl->getDeclContext();
209209
declAttrs = &decl->getAttrs();
210-
loc = decl->getLoc();
210+
// HACK: `getLoc`, when querying the attr from a serialized decl,
211+
// dependning on deserialization order, may launch into arbitrary
212+
// type-checking when querying interface types of such decls. Which,
213+
// in turn, may do things like query (to print) USRs. This ends up being
214+
// prone to request evaluator cycles.
215+
//
216+
// Because this only applies to serialized decls, we can be confident
217+
// that they already went through this type-checking as primaries, so,
218+
// for now, to avoid cycles, we simply ignore the locs on serialized decls
219+
// only.
220+
// This is a workaround for rdar://79563942
221+
loc = decl->getLoc(/* SerializedOK */ false);
211222
} else {
212223
auto closure = subject.get<ClosureExpr *>();
213224
dc = closure;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public actor Bar {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module -o %t/a.swiftmodule -emit-module-source-info-path %t/a.swiftsourceinfo -primary-file %s %S/Inputs/actor_bar.swift -module-name Foo
4+
// RUN: %target-swift-frontend -emit-module -o %t/b.swiftmodule -emit-module-source-info-path %t/b.swiftsourceinfo -primary-file %S/Inputs/actor_bar.swift %s -module-name Foo
5+
// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/Foo.swiftmodule -emit-module-source-info-path %t/Foo.swiftsourceinfo %t/a.swiftmodule %t/b.swiftmodule -module-name Foo
6+
7+
extension Bar {
8+
@MainActor
9+
func bar() async throws -> Int {
10+
return 42
11+
}
12+
}

0 commit comments

Comments
 (0)