Skip to content

[SourceKit] Don't use clang build sessions when validation is disabled #31013

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
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
37 changes: 35 additions & 2 deletions test/SourceKit/Sema/sema_build_session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func test() {
// UNSUPPORTED: OS=windows-msvc

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

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

// CHECK_USER-LABEL: ## ONE
// CHECK_USER-NOT: key.description
Expand All @@ -81,3 +82,35 @@ func test() {
// CHECK_USER: key.severity: source.diagnostic.severity.error,
// CHECK_USER-NEXT: key.description: "use of unresolved identifier 'fooSubFunc'",
// CHECK_USER-NOT: key.severity:

// -----------------------------------------------------------------------------
// Test that modifications for frameworks in '-Fsystem' doesn't affect the result
// across SourceKit sessions *if* '-disable-modules-validate-system-headers' is
// passed.

// RUN: %empty-directory(%t/ModuleCache)
// RUN: %empty-directory(%t/System/Frameworks)
// RUN: cp -R %S/../Inputs/build_session/Frameworks/Foo.framework %t/System/Frameworks/
// RUN: cp -R %S/../Inputs/build_session/Frameworks/FooHelper.framework %t/System/Frameworks/
// RUN: %sourcekitd-test \
// RUN: -shell -- echo '## ONE' == \
// RUN: -req=sema %s -- %s -D ONE -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache -Xfrontend -disable-modules-validate-system-headers == \
// RUN: -shell -- cp -R %S/../Inputs/build_session/Frameworks_modified/Foo.framework %t/System/Frameworks/ == \
// RUN: -shell -- cp -R %S/../Inputs/build_session/Frameworks_modified/FooHelper.framework %t/System/Frameworks/ == \
// RUN: -shell -- echo '## TWO' == \
// RUN: -req=sema %s -- %s -D TWO -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache -Xfrontend -disable-modules-validate-system-headers \
// RUN: | %FileCheck %s --check-prefix=CHECK_DISABLED
// RUN: sleep 2
// RUN: %sourcekitd-test \
// RUN: -shell -- echo '## THREE' == \
// RUN: -req=sema %s -- %s -D THREE -Fsystem %t/System/Frameworks -module-cache-path %t/ModuleCache -Xfrontend -disable-modules-validate-system-headers \
// RUN: | %FileCheck %s --check-prefix=CHECK_DISABLED_2

// CHECK_DISABLED-LABEL: ## ONE
// CHECK_DISABLED-NOT: key.description

// CHECK_DISABLED-LABEL: ## TWO
// CHECK_DISABLED-NOT: key.description

// CHECK_DISABLED_2-LABEL: ## THREE
// CHECK_DISABLED_2-NOT: key.description
21 changes: 13 additions & 8 deletions tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,20 @@ bool SwiftASTManager::initCompilerInvocation(

// To save the time for module validation, consider the lifetime of ASTManager
// as a single build session.
// NOTE: 'SessionTimestamp - 1' because clang compares it with '<=' that may
// cause unnecessary validations if they happens within one second from
// the SourceKit startup.
ImporterOpts.ExtraArgs.push_back("-fbuild-session-timestamp=" +
std::to_string(Impl.SessionTimestamp - 1));
ImporterOpts.ExtraArgs.push_back("-fmodules-validate-once-per-build-session");

// NOTE: Do this only if '-disable-modules-validate-system-headers' is *not*
// explicitly enabled.
auto &SearchPathOpts = Invocation.getSearchPathOptions();
SearchPathOpts.DisableModulesValidateSystemDependencies = true;
if (!SearchPathOpts.DisableModulesValidateSystemDependencies) {
// NOTE: 'SessionTimestamp - 1' because clang compares it with '<=' that may
// cause unnecessary validations if they happens within one second
// from the SourceKit startup.
ImporterOpts.ExtraArgs.push_back("-fbuild-session-timestamp=" +
std::to_string(Impl.SessionTimestamp - 1));
ImporterOpts.ExtraArgs.push_back(
"-fmodules-validate-once-per-build-session");

SearchPathOpts.DisableModulesValidateSystemDependencies = true;
}

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