Skip to content

Commit f943a88

Browse files
committed
[SourceKit] Don't use clang build sessions when validation is disabled
Don't use '-fbuild-session-timestamp' if '-disable-modules-validate-system-headers' is specified. Since system header validation happens under *OR* condition of 'ValidateSystemInputs' and 'ModulesValidateOncePerBuildSession', using build sessions effectively overrides it. rdar://problem/61075677
1 parent 36667b9 commit f943a88

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

test/SourceKit/Sema/sema_build_session.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ func test() {
1515
// UNSUPPORTED: OS=windows-msvc
1616

1717
// -----------------------------------------------------------------------------
18-
// Test that modifications for frameworks in '-Fsystem' doesn't affect the result.
18+
// Test that modifications for frameworks in '-Fsystem' doesn't affect the result
19+
// within a session, and that they are propagated after restarting SourceKit.
1920

2021
// RUN: %empty-directory(%t/ModuleCache)
2122
// RUN: %empty-directory(%t/System/Frameworks)
@@ -69,7 +70,7 @@ func test() {
6970
// RUN: -shell -- cp -R %S/../Inputs/build_session/Frameworks_modified/FooHelper.framework %t/System/Frameworks/ == \
7071
// RUN: -shell -- echo '## TWO' == \
7172
// RUN: -req=sema %s -- %s -D TWO -F %t/Frameworks -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache \
72-
// RUN: | tee %t.reponse | %FileCheck %s --check-prefix=CHECK_USER
73+
// RUN: | %FileCheck %s --check-prefix=CHECK_USER
7374

7475
// CHECK_USER-LABEL: ## ONE
7576
// CHECK_USER-NOT: key.description
@@ -81,3 +82,35 @@ func test() {
8182
// CHECK_USER: key.severity: source.diagnostic.severity.error,
8283
// CHECK_USER-NEXT: key.description: "use of unresolved identifier 'fooSubFunc'",
8384
// CHECK_USER-NOT: key.severity:
85+
86+
// -----------------------------------------------------------------------------
87+
// Test that modifications for frameworks in '-Fsystem' doesn't affect the result
88+
// across SourceKit sessions *if* '-disable-modules-validate-system-headers' is
89+
// passed.
90+
91+
// RUN: %empty-directory(%t/ModuleCache)
92+
// RUN: %empty-directory(%t/System/Frameworks)
93+
// RUN: cp -R %S/../Inputs/build_session/Frameworks/Foo.framework %t/System/Frameworks/
94+
// RUN: cp -R %S/../Inputs/build_session/Frameworks/FooHelper.framework %t/System/Frameworks/
95+
// RUN: %sourcekitd-test \
96+
// RUN: -shell -- echo '## ONE' == \
97+
// RUN: -req=sema %s -- %s -D ONE -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache -Xfrontend -disable-modules-validate-system-headers == \
98+
// RUN: -shell -- cp -R %S/../Inputs/build_session/Frameworks_modified/Foo.framework %t/System/Frameworks/ == \
99+
// RUN: -shell -- cp -R %S/../Inputs/build_session/Frameworks_modified/FooHelper.framework %t/System/Frameworks/ == \
100+
// RUN: -shell -- echo '## TWO' == \
101+
// RUN: -req=sema %s -- %s -D TWO -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache -Xfrontend -disable-modules-validate-system-headers \
102+
// RUN: | %FileCheck %s --check-prefix=CHECK_DISABLED
103+
// RUN: sleep 2
104+
// RUN: %sourcekitd-test \
105+
// RUN: -shell -- echo '## THREE' == \
106+
// RUN: -req=sema %s -- %s -D THREE -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache -Xfrontend -disable-modules-validate-system-headers \
107+
// RUN: | %FileCheck %s --check-prefix=CHECK_DISABLED_2
108+
109+
// CHECK_DISABLED-LABEL: ## ONE
110+
// CHECK_DISABLED-NOT: key.description
111+
112+
// CHECK_DISABLED-LABEL: ## TWO
113+
// CHECK_DISABLED-NOT: key.description
114+
115+
// CHECK_DISABLED_2-LABEL: ## THREE
116+
// CHECK_DISABLED_2-NOT: key.description

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,20 @@ bool SwiftASTManager::initCompilerInvocation(
554554

555555
// To save the time for module validation, consider the lifetime of ASTManager
556556
// as a single build session.
557-
// NOTE: 'SessionTimestamp - 1' because clang compares it with '<=' that may
558-
// cause unnecessary validations if they happens within one second from
559-
// the SourceKit startup.
560-
ImporterOpts.ExtraArgs.push_back("-fbuild-session-timestamp=" +
561-
std::to_string(Impl.SessionTimestamp - 1));
562-
ImporterOpts.ExtraArgs.push_back("-fmodules-validate-once-per-build-session");
563-
557+
// NOTE: Do this only if '-disable-modules-validate-system-headers' is *not*
558+
// explicitly enabled.
564559
auto &SearchPathOpts = Invocation.getSearchPathOptions();
565-
SearchPathOpts.DisableModulesValidateSystemDependencies = true;
560+
if (!SearchPathOpts.DisableModulesValidateSystemDependencies) {
561+
// NOTE: 'SessionTimestamp - 1' because clang compares it with '<=' that may
562+
// cause unnecessary validations if they happens within one second
563+
// from the SourceKit startup.
564+
ImporterOpts.ExtraArgs.push_back("-fbuild-session-timestamp=" +
565+
std::to_string(Impl.SessionTimestamp - 1));
566+
ImporterOpts.ExtraArgs.push_back(
567+
"-fmodules-validate-once-per-build-session");
568+
569+
SearchPathOpts.DisableModulesValidateSystemDependencies = true;
570+
}
566571

567572
// Disable expensive SIL options to reduce time spent in SILGen.
568573
disableExpensiveSILOptions(Invocation.getSILOptions());

0 commit comments

Comments
 (0)