Skip to content

Commit e8d4343

Browse files
authored
Merge pull request #69733 from apple/es-pkg-intf
Introduce a package interface
2 parents b693cce + 82eef75 commit e8d4343

32 files changed

+580
-73
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,9 @@ ERROR(module_not_testable,Fatal,
11071107
ERROR(module_not_compiled_for_private_import,none,
11081108
"module %0 was not compiled for private import", (Identifier))
11091109

1110-
ERROR(in_package_module_not_compiled_from_source,none,
1111-
"module %0 is in package '%1' but was built from interface; "
1112-
"modules of the same package can only be loaded if built from source: %2",
1110+
ERROR(in_package_module_not_compiled_from_source_or_package_interface,none,
1111+
"module %0 is in package '%1' but was built from a non-package interface; "
1112+
"modules of the same package can only be loaded if built from source or package interface: %2",
11131113
(Identifier, StringRef, StringRef))
11141114

11151115
WARNING(in_package_module_not_compiled_locally,none,

include/swift/AST/PrintOptions.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,25 @@ struct PrintOptions {
183183
/// Whether to print enum raw value expressions.
184184
EnumRawValueMode EnumRawValues = EnumRawValueMode::Skip;
185185

186+
enum class InterfaceMode : uint8_t {
187+
Public, // prints public/inlinable decls
188+
Private, // prints SPI and public/inlinable decls
189+
Package // prints package, SPI, and public/inlinable decls
190+
};
191+
192+
InterfaceMode InterfaceContentKind;
193+
194+
bool printPublicInterface() const {
195+
return InterfaceContentKind == InterfaceMode::Public;
196+
}
197+
bool printPackageInterface() const {
198+
return InterfaceContentKind == InterfaceMode::Package;
199+
}
200+
201+
void setInterfaceMode(InterfaceMode mode) {
202+
InterfaceContentKind = mode;
203+
}
204+
186205
/// Whether to prefer printing TypeReprs instead of Types,
187206
/// if a TypeRepr is available. This allows us to print the original
188207
/// spelling of the type name.
@@ -299,9 +318,6 @@ struct PrintOptions {
299318
/// Whether to skip keywords with a prefix of underscore such as __consuming.
300319
bool SkipUnderscoredKeywords = false;
301320

302-
// Print SPI attributes and decls that are visible only as SPI.
303-
bool PrintSPIs = true;
304-
305321
/// Prints type variables and unresolved types in an expanded notation suitable
306322
/// for debugging.
307323
bool PrintTypesForDebugging = false;
@@ -684,7 +700,7 @@ struct PrintOptions {
684700
static PrintOptions printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
685701
bool preferTypeRepr,
686702
bool printFullConvention,
687-
bool printSPIs,
703+
InterfaceMode interfaceMode,
688704
bool useExportedModuleNames,
689705
bool aliasModuleNames,
690706
llvm::SmallSet<StringRef, 4>

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ TYPE("swiftmodule", SwiftModuleFile, "swiftmodule", "")
5151
TYPE("swiftdoc", SwiftModuleDocFile, "swiftdoc", "")
5252
TYPE("swiftinterface", SwiftModuleInterfaceFile, "swiftinterface", "")
5353
TYPE("private-swiftinterface", PrivateSwiftModuleInterfaceFile, "private.swiftinterface", "")
54+
TYPE("package-swiftinterface", PackageSwiftModuleInterfaceFile, "package.swiftinterface", "")
5455
TYPE("swiftmodulesummary", SwiftModuleSummaryFile, "swiftmodulesummary", "")
5556
TYPE("swiftsourceinfo", SwiftSourceInfoFile, "swiftsourceinfo", "")
5657
TYPE("assembly", Assembly, "s", "")

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ namespace swift {
216216
/// Should access control be respected?
217217
bool EnableAccessControl = true;
218218

219+
/// Enable loading a package interface if both client and depdency module are in the
220+
/// same package determined by `package-name` flag.
221+
bool EnablePackageInterfaceLoad = false;
222+
219223
/// Enable 'availability' restrictions for App Extensions.
220224
bool EnableAppExtensionRestrictions = false;
221225

include/swift/Basic/SupplementaryOutputPaths.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ OUTPUT(ModuleInterfaceOutputPath, TY_SwiftModuleInterfaceFile)
137137
OUTPUT(PrivateModuleInterfaceOutputPath,
138138
TY_PrivateSwiftModuleInterfaceFile)
139139

140+
/// The path to which we should emit a package module interface.
141+
///
142+
/// The package interface contains package decls, SPIs, and public/inlinable decls.
143+
///
144+
/// \sa ModuleInterfaceOutputPath
145+
OUTPUT(PackageModuleInterfaceOutputPath,
146+
TY_PackageSwiftModuleInterfaceFile)
147+
140148
/// The path to which we should emit module summary file.
141149
OUTPUT(ModuleSummaryOutputPath, TY_SwiftModuleSummaryFile)
142150

include/swift/Driver/Action.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ class VerifyModuleInterfaceJobAction : public JobAction {
408408
: JobAction(Action::Kind::VerifyModuleInterfaceJob, { ModuleEmitter },
409409
file_types::TY_Nothing), inputType(inputType) {
410410
assert(inputType == file_types::TY_SwiftModuleInterfaceFile ||
411-
inputType == file_types::TY_PrivateSwiftModuleInterfaceFile);
411+
inputType == file_types::TY_PrivateSwiftModuleInterfaceFile ||
412+
inputType == file_types::TY_PackageSwiftModuleInterfaceFile);
412413
}
413414

414415
file_types::ID getInputType() const { return inputType; }

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ class CompilerInvocation {
432432
/// fail an assert if not in that mode.
433433
std::string getModuleInterfaceOutputPathForWholeModule() const;
434434
std::string getPrivateModuleInterfaceOutputPathForWholeModule() const;
435+
std::string getPackageModuleInterfaceOutputPathForWholeModule() const;
435436

436437
/// APIDescriptorPath only makes sense in whole module compilation mode,
437438
/// so return the APIDescriptorPath when in that mode and fail an assert

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class FrontendInputsAndOutputs {
266266
bool hasModuleSourceInfoOutputPath() const;
267267
bool hasModuleInterfaceOutputPath() const;
268268
bool hasPrivateModuleInterfaceOutputPath() const;
269+
bool hasPackageModuleInterfaceOutputPath() const;
269270
bool hasABIDescriptorOutputPath() const;
270271
bool hasAPIDescriptorOutputPath() const;
271272
bool hasConstValuesOutputPath() const;

include/swift/Frontend/ModuleInterfaceSupport.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ struct ModuleInterfaceOptions {
5555
/// e.g. -package-name PACKAGE_ID
5656
std::string IgnorablePrivateFlags;
5757

58-
/// Print for a private swiftinterface file, SPI decls and attributes.
59-
bool PrintPrivateInterfaceContent = false;
60-
6158
/// Print imports with both @_implementationOnly and @_spi, only applies
6259
/// when PrintSPIs is true.
6360
bool ExperimentalSPIImports = false;
@@ -70,6 +67,18 @@ struct ModuleInterfaceOptions {
7067

7168
/// A list of modules we shouldn't import in the public interfaces.
7269
std::vector<std::string> ModulesToSkipInPublicInterface;
70+
71+
/// A mode which decides whether the printed interface contains package, SPIs, or public/inlinable declarations.
72+
PrintOptions::InterfaceMode InterfaceContentMode = PrintOptions::InterfaceMode::Public;
73+
bool printPublicInterface() const {
74+
return InterfaceContentMode == PrintOptions::InterfaceMode::Public;
75+
}
76+
bool printPackageInterface() const {
77+
return InterfaceContentMode == PrintOptions::InterfaceMode::Package;
78+
}
79+
void setInterfaceMode(PrintOptions::InterfaceMode mode) {
80+
InterfaceContentMode = mode;
81+
}
7382
};
7483

7584
extern version::Version InterfaceFormatVersion;

include/swift/Option/Options.td

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ def ModuleInterfaceOption : OptionFlag;
5656
// The option can be safely ignored by the older compiler.
5757
def ModuleInterfaceOptionIgnorable : OptionFlag;
5858

59-
// The option should be written into a .private.swiftinterface module interface file,
60-
// and read/parsed from there when reconstituting a .swiftmodule from it.
59+
// The option should be written into a .private.swiftinterface or
60+
// .package.swiftinterface module interface file, and read/parsed from
61+
// there when reconstituting a .swiftmodule from it.
6162
// The option can be safely ignored by the older compiler.
6263
def ModuleInterfaceOptionIgnorablePrivate : OptionFlag;
6364

@@ -593,6 +594,12 @@ def emit_private_module_interface_path :
593594
ArgumentIsPath, SupplementaryOutput, CacheInvariant]>,
594595
MetaVarName<"<path>">, HelpText<"Output private module interface file to <path>">;
595596

597+
def emit_package_module_interface_path :
598+
Separate<["-"], "emit-package-module-interface-path">,
599+
Flags<[FrontendOption, NoInteractiveOption, HelpHidden,
600+
ArgumentIsPath, SupplementaryOutput, CacheInvariant]>,
601+
MetaVarName<"<path>">, HelpText<"Output package module interface file to <path>">;
602+
596603
def verify_emitted_module_interface :
597604
Flag<["-"], "verify-emitted-module-interface">,
598605
Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
@@ -751,6 +758,11 @@ def experimental_hermetic_seal_at_link:
751758
Flags<[FrontendOption, HelpHidden]>,
752759
HelpText<"Library code can assume that all clients are visible at linktime, and aggressively strip unused code">;
753760

761+
def experimental_package_interface_load:
762+
Flag<["-"], "experimental-package-interface-load">,
763+
Flags<[FrontendOption, HelpHidden]>,
764+
HelpText<"Enables loading a package interface if in the same package specified with package-name">;
765+
754766
// Diagnostic control options
755767
def suppress_warnings : Flag<["-"], "suppress-warnings">,
756768
Flags<[FrontendOption]>,

0 commit comments

Comments
 (0)