Skip to content

Commit 896b56e

Browse files
committed
Create features mapped to package optimization flags to
allow a more standard way to pass experimental features from build systems. Also moved other flags relevant to diagnostics from Frontend options to Lang options. Ref: rdar://124648653
1 parent 3deb5d4 commit 896b56e

File tree

8 files changed

+77
-58
lines changed

8 files changed

+77
-58
lines changed

include/swift/AST/SILOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class SILOptions {
132132
/// to be built in the same project. To enable this optimization, the
133133
/// module also needs to opt in to allow non-resilient access with
134134
/// -experimental-allow-non-resilient-access.
135-
bool EnableSerializePackage = true;
135+
bool EnableSerializePackage = false;
136136

137137
/// Enables the emission of stack protectors in functions.
138138
bool EnableStackProtection = true;

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+
/// True if -experimental-allow-non-resilient-access is passed and built
574+
/// from source.
575+
bool AllowNonResilientAccess = false;
576+
577+
/// Skips decls that cannot be referenced externally.
578+
bool SkipNonExportableDecls = 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: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ 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 = Args.hasArg(OPT_experimental_package_bypass_resilience) ||
685+
Opts.hasFeature(Feature::ClientBypassResilientAccessInPackage);
685686

686687
Opts.DisableAvailabilityChecking |=
687688
Args.hasArg(OPT_disable_availability_checking);
@@ -1111,7 +1112,50 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11111112
Opts.EnableIndexingSystemModuleRemarks = Args.hasArg(OPT_remark_indexing_system_module);
11121113

11131114
Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);
1114-
1115+
1116+
if (Args.hasArg(OPT_enable_library_evolution)) {
1117+
Opts.SkipNonExportableDecls |=
1118+
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
1119+
1120+
Opts.SkipNonExportableDecls |=
1121+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1122+
Args.hasArg(
1123+
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1124+
} else {
1125+
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
1126+
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
1127+
"-experimental-skip-non-exportable-decls",
1128+
"-enable-library-evolution");
1129+
}
1130+
1131+
Opts.AllowNonResilientAccess = Args.hasArg(OPT_experimental_allow_non_resilient_access) ||
1132+
Opts.hasFeature(Feature::AllowNonResilientAccessInPackage);
1133+
if (Opts.AllowNonResilientAccess) {
1134+
// Override the option to skip non-exportable decls.
1135+
if (Opts.SkipNonExportableDecls) {
1136+
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
1137+
"-experimental-skip-non-exportable-decls",
1138+
"-experimental-allow-non-resilient-access");
1139+
Opts.SkipNonExportableDecls = false;
1140+
}
1141+
// If built from interface, non-resilient access should not be allowed.
1142+
if (Opts.AllowNonResilientAccess &&
1143+
(FrontendOpts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface ||
1144+
FrontendOpts.RequestedAction == FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
1145+
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
1146+
"-experimental-allow-non-resilient-access",
1147+
"-compile-module-from-interface or -typecheck-module-from-interface");
1148+
Opts.AllowNonResilientAccess = false;
1149+
}
1150+
}
1151+
1152+
// HACK: The driver currently erroneously passes all flags to module interface
1153+
// verification jobs. -experimental-skip-non-exportable-decls is not
1154+
// appropriate for verification tasks and should be ignored, though.
1155+
if (FrontendOpts.RequestedAction ==
1156+
FrontendOptions::ActionType::TypecheckModuleFromInterface)
1157+
Opts.SkipNonExportableDecls = false;
1158+
11151159
llvm::Triple Target = Opts.Target;
11161160
StringRef TargetArg;
11171161
std::string TargetArgScratch;
@@ -2101,7 +2145,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
21012145
const FrontendOptions &FEOpts,
21022146
const TypeCheckerOptions &TCOpts,
21032147
DiagnosticEngine &Diags,
2104-
const llvm::Triple &Triple,
2148+
LangOptions &LangOpts,
21052149
ClangImporterOptions &ClangOpts) {
21062150
using namespace options;
21072151

@@ -2346,8 +2390,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
23462390
Opts.CMOMode = CrossModuleOptimizationMode::Everything;
23472391
}
23482392

2349-
if (Args.hasArg(OPT_ExperimentalPackageCMO)) {
2350-
if (!FEOpts.AllowNonResilientAccess) {
2393+
if (Args.hasArg(OPT_ExperimentalPackageCMO) ||
2394+
LangOpts.hasFeature(Feature::PackageCMO)) {
2395+
if (!LangOpts.AllowNonResilientAccess) {
23512396
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
23522397
"-experimental-package-cmo",
23532398
"-experimental-allow-non-resilient-access");
@@ -2439,7 +2484,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
24392484

24402485
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_EQ)) {
24412486
Opts.Sanitizers = parseSanitizerArgValues(
2442-
Args, A, Triple, Diags,
2487+
Args, A, LangOpts.Target, Diags,
24432488
/* sanitizerRuntimeLibExists= */[](StringRef libName, bool shared) {
24442489

24452490
// The driver has checked the existence of the library
@@ -3289,7 +3334,7 @@ bool CompilerInvocation::parseArgs(
32893334

32903335
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts,
32913336
TypeCheckerOpts, Diags,
3292-
LangOpts.Target, ClangImporterOpts)) {
3337+
LangOpts, ClangImporterOpts)) {
32933338
return true;
32943339
}
32953340

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ ModuleDecl *CompilerInstance::getMainModule() const {
14021402
if (Invocation.getLangOptions().EnableCXXInterop &&
14031403
Invocation.getLangOptions().RequireCxxInteropToImportCxxInteropModule)
14041404
MainModule->setHasCxxInteroperability();
1405-
if (Invocation.getFrontendOptions().AllowNonResilientAccess)
1405+
if (Invocation.getLangOptions().AllowNonResilientAccess)
14061406
MainModule->setAllowNonResilientAccess();
14071407

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

0 commit comments

Comments
 (0)