Skip to content

Commit 8a4137a

Browse files
authored
Merge pull request #72342 from apple/elsh/add-features
Map package optimization flags to features
2 parents 683e94f + 45126a8 commit 8a4137a

File tree

7 files changed

+86
-64
lines changed

7 files changed

+86
-64
lines changed

include/swift/Basic/Features.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ EXPERIMENTAL_FEATURE(LayoutPrespecialization, true)
219219

220220
EXPERIMENTAL_FEATURE(AccessLevelOnImport, true)
221221

222+
/// Enables a module to allow non resilient access from other
223+
/// modules within a package if built from source.
224+
EXPERIMENTAL_FEATURE(AllowNonResilientAccessInPackage, false)
225+
226+
/// Enables a client module within a package to bypass resilient
227+
/// access (at use site) to decls defined in another module within
228+
/// the same package.
229+
EXPERIMENTAL_FEATURE(ClientBypassResilientAccessInPackage, false)
230+
231+
/// Enables serialization of package decls and bodies and performs
232+
/// CMO within a package.
233+
EXPERIMENTAL_FEATURE(PackageCMO, false)
234+
222235
/// Whether to enable experimental layout string value witnesses
223236
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(LayoutStringValueWitnesses, true)
224237
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(LayoutStringValueWitnessesInstantiation, true)

include/swift/Basic/LangOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ namespace swift {
570570
/// Enable implicit lifetime dependence for ~Escapable return types.
571571
bool EnableExperimentalLifetimeDependenceInference = true;
572572

573+
/// Skips decls that cannot be referenced externally.
574+
bool SkipNonExportableDecls = false;
575+
576+
/// True if -experimental-allow-non-resilient-access is passed and built
577+
/// from source.
578+
bool AllowNonResilientAccess = false;
579+
573580
/// Enables dumping type witness systems from associated type inference.
574581
bool DumpTypeWitnessSystems = false;
575582

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,6 @@ class FrontendOptions {
312312
/// times) when compiling a module interface?
313313
bool SerializeModuleInterfaceDependencyHashes = false;
314314

315-
/// Should we skip decls that cannot be referenced externally?
316-
bool SkipNonExportableDecls = false;
317-
318-
/// True if -experimental-allow-non-resilient-access is passed and built
319-
/// from source.
320-
bool AllowNonResilientAccess = false;
321-
322315
/// Should we warn if an imported module needed to be rebuilt from a
323316
/// module interface file?
324317
bool RemarkOnRebuildFromModuleInterface = false;

lib/AST/FeatureSet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,16 @@ static bool usesFeatureLayoutPrespecialization(Decl *decl) {
468468
}
469469

470470
UNINTERESTING_FEATURE(AccessLevelOnImport)
471+
UNINTERESTING_FEATURE(AllowNonResilientAccessInPackage)
472+
UNINTERESTING_FEATURE(ClientBypassResilientAccessInPackage)
471473
UNINTERESTING_FEATURE(LayoutStringValueWitnesses)
472474
UNINTERESTING_FEATURE(LayoutStringValueWitnessesInstantiation)
473475
UNINTERESTING_FEATURE(DifferentiableProgramming)
474476
UNINTERESTING_FEATURE(ForwardModeDifferentiation)
475477
UNINTERESTING_FEATURE(AdditiveArithmeticDerivedConformances)
476478
UNINTERESTING_FEATURE(SendableCompletionHandlers)
477479
UNINTERESTING_FEATURE(OpaqueTypeErasure)
480+
UNINTERESTING_FEATURE(PackageCMO)
478481
UNINTERESTING_FEATURE(ParserRoundTrip)
479482
UNINTERESTING_FEATURE(ParserValidation)
480483
UNINTERESTING_FEATURE(ParserDiagnostics)

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -301,48 +301,6 @@ bool ArgsToFrontendOptionsConverter::convert(
301301
A->getOption().matches(OPT_serialize_debugging_options);
302302
}
303303

304-
if (Args.hasArg(OPT_enable_library_evolution)) {
305-
Opts.SkipNonExportableDecls |=
306-
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
307-
308-
Opts.SkipNonExportableDecls |=
309-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
310-
Args.hasArg(
311-
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
312-
} else {
313-
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
314-
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
315-
"-experimental-skip-non-exportable-decls",
316-
"-enable-library-evolution");
317-
}
318-
319-
Opts.AllowNonResilientAccess = Args.hasArg(OPT_experimental_allow_non_resilient_access);
320-
if (Opts.AllowNonResilientAccess) {
321-
// Override the option to skip non-exportable decls.
322-
if (Opts.SkipNonExportableDecls) {
323-
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
324-
"-experimental-skip-non-exportable-decls",
325-
"-experimental-allow-non-resilient-access");
326-
Opts.SkipNonExportableDecls = false;
327-
}
328-
// If built from interface, non-resilient access should not be allowed.
329-
if (Opts.AllowNonResilientAccess &&
330-
(Opts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface ||
331-
Opts.RequestedAction == FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
332-
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
333-
"-experimental-allow-non-resilient-access",
334-
"-compile-module-from-interface or -typecheck-module-from-interface");
335-
Opts.AllowNonResilientAccess = false;
336-
}
337-
}
338-
339-
// HACK: The driver currently erroneously passes all flags to module interface
340-
// verification jobs. -experimental-skip-non-exportable-decls is not
341-
// appropriate for verification tasks and should be ignored, though.
342-
if (Opts.RequestedAction ==
343-
FrontendOptions::ActionType::TypecheckModuleFromInterface)
344-
Opts.SkipNonExportableDecls = false;
345-
346304
Opts.DebugPrefixSerializedDebuggingOptions |=
347305
Args.hasArg(OPT_prefix_serialized_debugging_options);
348306
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
681681
Opts.EnablePackageInterfaceLoad = Args.hasArg(OPT_experimental_package_interface_load) ||
682682
::getenv("SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD");
683683

684-
Opts.EnableBypassResilienceInPackage = Args.hasArg(OPT_experimental_package_bypass_resilience);
684+
Opts.EnableBypassResilienceInPackage =
685+
Args.hasArg(OPT_experimental_package_bypass_resilience) ||
686+
Opts.hasFeature(Feature::ClientBypassResilientAccessInPackage);
685687

686688
Opts.DisableAvailabilityChecking |=
687689
Args.hasArg(OPT_disable_availability_checking);
@@ -1111,7 +1113,54 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11111113
Opts.EnableIndexingSystemModuleRemarks = Args.hasArg(OPT_remark_indexing_system_module);
11121114

11131115
Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);
1114-
1116+
1117+
if (Args.hasArg(OPT_enable_library_evolution)) {
1118+
Opts.SkipNonExportableDecls |=
1119+
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
1120+
1121+
Opts.SkipNonExportableDecls |=
1122+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1123+
Args.hasArg(
1124+
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1125+
} else {
1126+
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
1127+
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
1128+
"-experimental-skip-non-exportable-decls",
1129+
"-enable-library-evolution");
1130+
}
1131+
1132+
Opts.AllowNonResilientAccess =
1133+
Args.hasArg(OPT_experimental_allow_non_resilient_access) ||
1134+
Opts.hasFeature(Feature::AllowNonResilientAccessInPackage);
1135+
if (Opts.AllowNonResilientAccess) {
1136+
// Override the option to skip non-exportable decls.
1137+
if (Opts.SkipNonExportableDecls) {
1138+
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
1139+
"-experimental-skip-non-exportable-decls",
1140+
"-experimental-allow-non-resilient-access");
1141+
Opts.SkipNonExportableDecls = false;
1142+
}
1143+
// If built from interface, non-resilient access should not be allowed.
1144+
if (Opts.AllowNonResilientAccess &&
1145+
(FrontendOpts.RequestedAction ==
1146+
FrontendOptions::ActionType::CompileModuleFromInterface ||
1147+
FrontendOpts.RequestedAction ==
1148+
FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
1149+
Diags.diagnose(
1150+
SourceLoc(), diag::warn_ignore_option_overriden_by,
1151+
"-experimental-allow-non-resilient-access",
1152+
"-compile-module-from-interface or -typecheck-module-from-interface");
1153+
Opts.AllowNonResilientAccess = false;
1154+
}
1155+
}
1156+
1157+
// HACK: The driver currently erroneously passes all flags to module interface
1158+
// verification jobs. -experimental-skip-non-exportable-decls is not
1159+
// appropriate for verification tasks and should be ignored, though.
1160+
if (FrontendOpts.RequestedAction ==
1161+
FrontendOptions::ActionType::TypecheckModuleFromInterface)
1162+
Opts.SkipNonExportableDecls = false;
1163+
11151164
llvm::Triple Target = Opts.Target;
11161165
StringRef TargetArg;
11171166
std::string TargetArgScratch;
@@ -2097,11 +2146,9 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
20972146
}
20982147

20992148
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
2100-
IRGenOptions &IRGenOpts,
2101-
const FrontendOptions &FEOpts,
2149+
IRGenOptions &IRGenOpts, const FrontendOptions &FEOpts,
21022150
const TypeCheckerOptions &TCOpts,
2103-
DiagnosticEngine &Diags,
2104-
const llvm::Triple &Triple,
2151+
DiagnosticEngine &Diags, LangOptions &LangOpts,
21052152
ClangImporterOptions &ClangOpts) {
21062153
using namespace options;
21072154

@@ -2139,7 +2186,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
21392186
Opts.SkipFunctionBodies = TCOpts.SkipFunctionBodies;
21402187

21412188
// Propagate -experimental-skip-non-exportable-decls to SIL.
2142-
Opts.SkipNonExportableDecls = FEOpts.SkipNonExportableDecls;
2189+
Opts.SkipNonExportableDecls = LangOpts.SkipNonExportableDecls;
21432190

21442191
// Parse the optimization level.
21452192
// Default to Onone settings if no option is passed.
@@ -2346,8 +2393,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
23462393
Opts.CMOMode = CrossModuleOptimizationMode::Everything;
23472394
}
23482395

2349-
if (Args.hasArg(OPT_ExperimentalPackageCMO)) {
2350-
if (!FEOpts.AllowNonResilientAccess) {
2396+
if (Args.hasArg(OPT_ExperimentalPackageCMO) ||
2397+
LangOpts.hasFeature(Feature::PackageCMO)) {
2398+
if (!LangOpts.AllowNonResilientAccess) {
23512399
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
23522400
"-experimental-package-cmo",
23532401
"-experimental-allow-non-resilient-access");
@@ -2439,8 +2487,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
24392487

24402488
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_EQ)) {
24412489
Opts.Sanitizers = parseSanitizerArgValues(
2442-
Args, A, Triple, Diags,
2443-
/* sanitizerRuntimeLibExists= */[](StringRef libName, bool shared) {
2490+
Args, A, LangOpts.Target, Diags,
2491+
/* sanitizerRuntimeLibExists= */ [](StringRef libName, bool shared) {
24442492

24452493
// The driver has checked the existence of the library
24462494
// already.
@@ -3288,8 +3336,7 @@ bool CompilerInvocation::parseArgs(
32883336
}
32893337

32903338
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts,
3291-
TypeCheckerOpts, Diags,
3292-
LangOpts.Target, ClangImporterOpts)) {
3339+
TypeCheckerOpts, Diags, LangOpts, ClangImporterOpts)) {
32933340
return true;
32943341
}
32953342

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
249249

250250
serializationOpts.IsOSSA = getSILOptions().EnableOSSAModules;
251251

252-
serializationOpts.SkipNonExportableDecls = opts.SkipNonExportableDecls;
252+
serializationOpts.SkipNonExportableDecls =
253+
getLangOptions().SkipNonExportableDecls;
253254

254255
serializationOpts.ExplicitModuleBuild = FrontendOpts.DisableImplicitModules;
255256

@@ -1402,7 +1403,7 @@ ModuleDecl *CompilerInstance::getMainModule() const {
14021403
if (Invocation.getLangOptions().EnableCXXInterop &&
14031404
Invocation.getLangOptions().RequireCxxInteropToImportCxxInteropModule)
14041405
MainModule->setHasCxxInteroperability();
1405-
if (Invocation.getFrontendOptions().AllowNonResilientAccess)
1406+
if (Invocation.getLangOptions().AllowNonResilientAccess)
14061407
MainModule->setAllowNonResilientAccess();
14071408

14081409
// Register the main module with the AST context.

0 commit comments

Comments
 (0)