Skip to content

Commit a926b05

Browse files
committed
[Sema] Accept and store the IPI library-level
Prepare to accept the `ipi` argument to the `-library-level` flag. IPI stands for Internal Programming Interface and would describe a module that's not to be distributed outside of its project. In the future, the compiler could use that information to report when a distributed module (api or spi) imports publicly a module that's not distributed. rdar://102435183
1 parent f184504 commit a926b05

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ERROR(error_upcoming_feature_on_by_default, none,
4646

4747
ERROR(error_unknown_library_level, none,
4848
"unknown library level '%0', "
49-
"expected one of 'api', 'spi' or 'other'", (StringRef))
49+
"expected one of 'api', 'spi', 'ipi', or 'other'", (StringRef))
5050

5151
ERROR(error_unknown_require_explicit_availability, none,
5252
"unknown argument '%0', passed to -require-explicit-availability, "

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ namespace swift {
8585
/// all decls in the module are considered to be SPI including public ones.
8686
SPI,
8787

88+
/// Internal Programming Interface that is not distributed and only usable
89+
/// from within a project.
90+
IPI,
91+
8892
/// The library has some other undefined distribution.
8993
Other
9094
};

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -704,17 +704,15 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
704704
Opts.LibraryLevel = LibraryLevel::API;
705705
} else if (contents == "spi") {
706706
Opts.LibraryLevel = LibraryLevel::SPI;
707+
} else if (contents == "ipi") {
708+
Opts.LibraryLevel = LibraryLevel::IPI;
707709
} else {
708710
Opts.LibraryLevel = LibraryLevel::Other;
709711
if (contents != "other") {
710712
// Error on unknown library levels.
711-
auto inFlight = Diags.diagnose(SourceLoc(),
712-
diag::error_unknown_library_level,
713-
contents);
714-
715-
// Only warn for "ipi" as we may use it in the future.
716-
if (contents == "ipi")
717-
inFlight.limitBehavior(DiagnosticBehavior::Warning);
713+
Diags.diagnose(SourceLoc(),
714+
diag::error_unknown_library_level,
715+
contents);
718716
}
719717
}
720718
}

test/Sema/implementation-only-import-suggestion.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/PublicImports.swift \
3535
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
3636
// RUN: -library-level other -module-name MainLib
37+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/PublicImports.swift \
38+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
39+
// RUN: -library-level ipi -module-name MainLib
3740
//--- PublicImports.swift
3841
import PublicSwift
3942
import PrivateSwift // expected-error{{private module 'PrivateSwift' is imported publicly from the public module 'MainLib'}}
@@ -70,7 +73,7 @@ import LocalClang // expected-error{{private module 'LocalClang' is imported pub
7073
/// Test error message on an unknown library level name.
7174
// RUN: not %target-swift-frontend -typecheck %s -library-level ThatsNotALibraryLevel 2>&1 \
7275
// RUN: | %FileCheck %s --check-prefix CHECK-ARG
73-
// CHECK-ARG: error: unknown library level 'ThatsNotALibraryLevel', expected one of 'api', 'spi' or 'other'
76+
// CHECK-ARG: error: unknown library level 'ThatsNotALibraryLevel', expected one of 'api', 'spi', 'ipi', or 'other'
7477

7578
/// Expect no errors in swiftinterfaces.
7679
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) \

0 commit comments

Comments
 (0)