Skip to content

Map package optimization flags to features #72342

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 2 commits into from
Mar 16, 2024
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
13 changes: 13 additions & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ EXPERIMENTAL_FEATURE(LayoutPrespecialization, true)

EXPERIMENTAL_FEATURE(AccessLevelOnImport, true)

/// Enables a module to allow non resilient access from other
/// modules within a package if built from source.
EXPERIMENTAL_FEATURE(AllowNonResilientAccessInPackage, false)

/// Enables a client module within a package to bypass resilient
/// access (at use site) to decls defined in another module within
/// the same package.
EXPERIMENTAL_FEATURE(ClientBypassResilientAccessInPackage, false)

/// Enables serialization of package decls and bodies and performs
/// CMO within a package.
EXPERIMENTAL_FEATURE(PackageCMO, false)

/// Whether to enable experimental layout string value witnesses
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(LayoutStringValueWitnesses, true)
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(LayoutStringValueWitnessesInstantiation, true)
Expand Down
7 changes: 7 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,13 @@ namespace swift {
/// Enable implicit lifetime dependence for ~Escapable return types.
bool EnableExperimentalLifetimeDependenceInference = true;

/// Skips decls that cannot be referenced externally.
bool SkipNonExportableDecls = false;

/// True if -experimental-allow-non-resilient-access is passed and built
/// from source.
bool AllowNonResilientAccess = false;

/// Enables dumping type witness systems from associated type inference.
bool DumpTypeWitnessSystems = false;

Expand Down
7 changes: 0 additions & 7 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,6 @@ class FrontendOptions {
/// times) when compiling a module interface?
bool SerializeModuleInterfaceDependencyHashes = false;

/// Should we skip decls that cannot be referenced externally?
bool SkipNonExportableDecls = false;

/// True if -experimental-allow-non-resilient-access is passed and built
/// from source.
bool AllowNonResilientAccess = false;

/// Should we warn if an imported module needed to be rebuilt from a
/// module interface file?
bool RemarkOnRebuildFromModuleInterface = false;
Expand Down
3 changes: 3 additions & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,16 @@ static bool usesFeatureLayoutPrespecialization(Decl *decl) {
}

UNINTERESTING_FEATURE(AccessLevelOnImport)
UNINTERESTING_FEATURE(AllowNonResilientAccessInPackage)
UNINTERESTING_FEATURE(ClientBypassResilientAccessInPackage)
UNINTERESTING_FEATURE(LayoutStringValueWitnesses)
UNINTERESTING_FEATURE(LayoutStringValueWitnessesInstantiation)
UNINTERESTING_FEATURE(DifferentiableProgramming)
UNINTERESTING_FEATURE(ForwardModeDifferentiation)
UNINTERESTING_FEATURE(AdditiveArithmeticDerivedConformances)
UNINTERESTING_FEATURE(SendableCompletionHandlers)
UNINTERESTING_FEATURE(OpaqueTypeErasure)
UNINTERESTING_FEATURE(PackageCMO)
UNINTERESTING_FEATURE(ParserRoundTrip)
UNINTERESTING_FEATURE(ParserValidation)
UNINTERESTING_FEATURE(ParserDiagnostics)
Expand Down
42 changes: 0 additions & 42 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,48 +301,6 @@ bool ArgsToFrontendOptionsConverter::convert(
A->getOption().matches(OPT_serialize_debugging_options);
}

if (Args.hasArg(OPT_enable_library_evolution)) {
Opts.SkipNonExportableDecls |=
Args.hasArg(OPT_experimental_skip_non_exportable_decls);

Opts.SkipNonExportableDecls |=
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
Args.hasArg(
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
} else {
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
"-experimental-skip-non-exportable-decls",
"-enable-library-evolution");
}

Opts.AllowNonResilientAccess = Args.hasArg(OPT_experimental_allow_non_resilient_access);
if (Opts.AllowNonResilientAccess) {
// Override the option to skip non-exportable decls.
if (Opts.SkipNonExportableDecls) {
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-skip-non-exportable-decls",
"-experimental-allow-non-resilient-access");
Opts.SkipNonExportableDecls = false;
}
// If built from interface, non-resilient access should not be allowed.
if (Opts.AllowNonResilientAccess &&
(Opts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface ||
Opts.RequestedAction == FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-allow-non-resilient-access",
"-compile-module-from-interface or -typecheck-module-from-interface");
Opts.AllowNonResilientAccess = false;
}
}

// HACK: The driver currently erroneously passes all flags to module interface
// verification jobs. -experimental-skip-non-exportable-decls is not
// appropriate for verification tasks and should be ignored, though.
if (Opts.RequestedAction ==
FrontendOptions::ActionType::TypecheckModuleFromInterface)
Opts.SkipNonExportableDecls = false;

Opts.DebugPrefixSerializedDebuggingOptions |=
Args.hasArg(OPT_prefix_serialized_debugging_options);
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);
Expand Down
73 changes: 60 additions & 13 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnablePackageInterfaceLoad = Args.hasArg(OPT_experimental_package_interface_load) ||
::getenv("SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD");

Opts.EnableBypassResilienceInPackage = Args.hasArg(OPT_experimental_package_bypass_resilience);
Opts.EnableBypassResilienceInPackage =
Args.hasArg(OPT_experimental_package_bypass_resilience) ||
Opts.hasFeature(Feature::ClientBypassResilientAccessInPackage);

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);
Expand Down Expand Up @@ -1111,7 +1113,54 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableIndexingSystemModuleRemarks = Args.hasArg(OPT_remark_indexing_system_module);

Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);


if (Args.hasArg(OPT_enable_library_evolution)) {
Opts.SkipNonExportableDecls |=
Args.hasArg(OPT_experimental_skip_non_exportable_decls);

Opts.SkipNonExportableDecls |=
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
Args.hasArg(
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
} else {
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
"-experimental-skip-non-exportable-decls",
"-enable-library-evolution");
}

Opts.AllowNonResilientAccess =
Args.hasArg(OPT_experimental_allow_non_resilient_access) ||
Opts.hasFeature(Feature::AllowNonResilientAccessInPackage);
if (Opts.AllowNonResilientAccess) {
// Override the option to skip non-exportable decls.
if (Opts.SkipNonExportableDecls) {
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-skip-non-exportable-decls",
"-experimental-allow-non-resilient-access");
Opts.SkipNonExportableDecls = false;
}
// If built from interface, non-resilient access should not be allowed.
if (Opts.AllowNonResilientAccess &&
(FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::CompileModuleFromInterface ||
FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
Diags.diagnose(
SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-allow-non-resilient-access",
"-compile-module-from-interface or -typecheck-module-from-interface");
Opts.AllowNonResilientAccess = false;
}
}

// HACK: The driver currently erroneously passes all flags to module interface
// verification jobs. -experimental-skip-non-exportable-decls is not
// appropriate for verification tasks and should be ignored, though.
if (FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::TypecheckModuleFromInterface)
Opts.SkipNonExportableDecls = false;

llvm::Triple Target = Opts.Target;
StringRef TargetArg;
std::string TargetArgScratch;
Expand Down Expand Up @@ -2097,11 +2146,9 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
}

static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
IRGenOptions &IRGenOpts,
const FrontendOptions &FEOpts,
IRGenOptions &IRGenOpts, const FrontendOptions &FEOpts,
const TypeCheckerOptions &TCOpts,
DiagnosticEngine &Diags,
const llvm::Triple &Triple,
DiagnosticEngine &Diags, LangOptions &LangOpts,
ClangImporterOptions &ClangOpts) {
using namespace options;

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

// Propagate -experimental-skip-non-exportable-decls to SIL.
Opts.SkipNonExportableDecls = FEOpts.SkipNonExportableDecls;
Opts.SkipNonExportableDecls = LangOpts.SkipNonExportableDecls;

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

if (Args.hasArg(OPT_ExperimentalPackageCMO)) {
if (!FEOpts.AllowNonResilientAccess) {
if (Args.hasArg(OPT_ExperimentalPackageCMO) ||
LangOpts.hasFeature(Feature::PackageCMO)) {
if (!LangOpts.AllowNonResilientAccess) {
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
"-experimental-package-cmo",
"-experimental-allow-non-resilient-access");
Expand Down Expand Up @@ -2439,8 +2487,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,

if (const Arg *A = Args.getLastArg(options::OPT_sanitize_EQ)) {
Opts.Sanitizers = parseSanitizerArgValues(
Args, A, Triple, Diags,
/* sanitizerRuntimeLibExists= */[](StringRef libName, bool shared) {
Args, A, LangOpts.Target, Diags,
/* sanitizerRuntimeLibExists= */ [](StringRef libName, bool shared) {

// The driver has checked the existence of the library
// already.
Expand Down Expand Up @@ -3288,8 +3336,7 @@ bool CompilerInvocation::parseArgs(
}

if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts,
TypeCheckerOpts, Diags,
LangOpts.Target, ClangImporterOpts)) {
TypeCheckerOpts, Diags, LangOpts, ClangImporterOpts)) {
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(

serializationOpts.IsOSSA = getSILOptions().EnableOSSAModules;

serializationOpts.SkipNonExportableDecls = opts.SkipNonExportableDecls;
serializationOpts.SkipNonExportableDecls =
getLangOptions().SkipNonExportableDecls;

serializationOpts.ExplicitModuleBuild = FrontendOpts.DisableImplicitModules;

Expand Down Expand Up @@ -1402,7 +1403,7 @@ ModuleDecl *CompilerInstance::getMainModule() const {
if (Invocation.getLangOptions().EnableCXXInterop &&
Invocation.getLangOptions().RequireCxxInteropToImportCxxInteropModule)
MainModule->setHasCxxInteroperability();
if (Invocation.getFrontendOptions().AllowNonResilientAccess)
if (Invocation.getLangOptions().AllowNonResilientAccess)
MainModule->setAllowNonResilientAccess();

// Register the main module with the AST context.
Expand Down