Skip to content

[5.5] Short-circuit GlobalActorAttributeRequest attempting to get the Source Location of a serialized decl. #38035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,18 @@ GlobalActorAttributeRequest::evaluate(
if (auto decl = subject.dyn_cast<Decl *>()) {
dc = decl->getDeclContext();
declAttrs = &decl->getAttrs();
loc = decl->getLoc();
// HACK: `getLoc`, when querying the attr from a serialized decl,
// dependning on deserialization order, may launch into arbitrary
// type-checking when querying interface types of such decls. Which,
// in turn, may do things like query (to print) USRs. This ends up being
// prone to request evaluator cycles.
//
// Because this only applies to serialized decls, we can be confident
// that they already went through this type-checking as primaries, so,
// for now, to avoid cycles, we simply ignore the locs on serialized decls
// only.
// This is a workaround for rdar://79563942
loc = decl->getLoc(/* SerializedOK */ false);
} else {
auto closure = subject.get<ClosureExpr *>();
dc = closure;
Expand Down
1 change: 1 addition & 0 deletions test/Serialization/Inputs/actor_bar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public actor Bar {}
12 changes: 12 additions & 0 deletions test/Serialization/actor-attr-query-cycle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %empty-directory(%t)

// 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
// 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
// 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

extension Bar {
@MainActor
func bar() async throws -> Int {
return 42
}
}