Skip to content

Commit 1ddc793

Browse files
authored
Merge pull request #65168 from xymus/display-public-only
[IDE] Inject Sendable conformance on public types only in `getTopLevelDeclsForDisplay`
2 parents 273a400 + 7f32a9e commit 1ddc793

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@ swift::getTopLevelDeclsForDisplay(ModuleDecl *M,
4040
auto startingSize = Results.size();
4141
M->getDisplayDecls(Results, Recursive);
4242

43-
// Force Sendable on all types, which might synthesize some extensions.
43+
// Force Sendable on all public types, which might synthesize some extensions.
4444
// FIXME: We can remove this if @_nonSendable stops creating extensions.
4545
for (auto result : Results) {
46-
if (auto NTD = dyn_cast<NominalTypeDecl>(result))
46+
if (auto NTD = dyn_cast<NominalTypeDecl>(result)) {
47+
48+
// Restrict this logic to public and package types. Non-public types
49+
// may refer to implementation details and fail at deserialization.
50+
auto accessScope = NTD->getFormalAccessScope();
51+
if (!M->isMainModule() &&
52+
!accessScope.isPublic() && !accessScope.isPackage())
53+
continue;
54+
4755
(void)swift::isSendableType(M, NTD->getDeclaredInterfaceType());
56+
}
4857
}
4958

5059
// Remove what we fetched and fetch again, possibly now with additional

test/IDE/print_stdlib.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@
7272
// CHECK-GROUPS1-DAG: Collection/Type-erased
7373
// CHECK-GROUPS1-NOT: <NULL>
7474
// CHECK-GROUPS1: Module groups end.
75+
76+
/// Check that we can still print the interface of the stdlib with
77+
/// deserialization safety enabled.
78+
// RUN: %target-swift-ide-test -print-module-groups -module-to-print=Swift -source-filename %s -print-interface -enable-deserialization-safety > %t-group.txt
79+
// RUN: %FileCheck -check-prefix=CHECK-GROUPS1 %s < %t-group.txt

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ DisableAccessControl("disable-access-control",
397397
llvm::cl::desc("Disables access control, like a debugger"),
398398
llvm::cl::cat(Category));
399399

400+
static llvm::cl::opt<bool>
401+
EnableDeserializationSafety("enable-deserialization-safety",
402+
llvm::cl::desc("Avoid reading potentially unsafe decls from swiftmodules"),
403+
llvm::cl::cat(Category));
404+
400405
static llvm::cl::opt<bool> CodeCompleteInitsInPostfixExpr(
401406
"code-complete-inits-in-postfix-expr",
402407
llvm::cl::desc(
@@ -4464,6 +4469,8 @@ int main(int argc, char *argv[]) {
44644469
options::ImportObjCHeader;
44654470
InitInvok.getLangOptions().EnableAccessControl =
44664471
!options::DisableAccessControl;
4472+
InitInvok.getLangOptions().EnableDeserializationSafety =
4473+
options::EnableDeserializationSafety;
44674474
InitInvok.getLangOptions().EnableSwift3ObjCInference =
44684475
options::EnableSwift3ObjCInference;
44694476
InitInvok.getClangImporterOptions().ImportForwardDeclarations |=

0 commit comments

Comments
 (0)