Skip to content

[5.1 EARLY] Rename -enable-resilience to -enable-library-evolution and make it a driver flag #24095

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
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
4 changes: 2 additions & 2 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ function(_compile_swift_files
list(APPEND swift_flags "-Xfrontend" "-sil-verify-all")
endif()

# The standard library and overlays are always built with resilience.
# The standard library and overlays are always built resiliently.
if(SWIFTFILE_IS_STDLIB)
list(APPEND swift_flags "-Xfrontend" "-enable-resilience")
list(APPEND swift_flags "-enable-library-evolution")
endif()

if(SWIFT_STDLIB_USE_NONATOMIC_RC)
Expand Down
2 changes: 1 addition & 1 deletion docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3958,7 +3958,7 @@ unless the enum can be exhaustively switched in the current function, i.e. when
the compiler can be sure that it knows all possible present and future values
of the enum in question. This is generally true for enums defined in Swift, but
there are two exceptions: *non-frozen enums* declared in libraries compiled
with the ``-enable-resilience`` flag, which may grow new cases in the future in
with the ``-enable-library-evolution`` flag, which may grow new cases in the future in
an ABI-compatible way; and enums marked with the ``objc`` attribute, for which
other bit patterns are permitted for compatibility with C. All enums imported
from C are treated as "non-exhaustive" for the same reason, regardless of the
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ ERROR(indirect_case_without_payload,none,
ERROR(indirect_case_in_indirect_enum,none,
"enum case in 'indirect' enum cannot also be 'indirect'", ())
WARNING(enum_frozen_nonresilient,none,
"%0 has no effect without -enable-resilience", (DeclAttribute))
"%0 has no effect without -enable-library-evolution", (DeclAttribute))
WARNING(enum_frozen_nonpublic,none,
"%0 has no effect on non-public enums", (DeclAttribute))

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ enum class ResilienceStrategy : unsigned {
/// Public nominal types: resilient
/// Non-inlinable function bodies: resilient
///
/// This is the behavior with -enable-resilience.
/// This is the behavior with -enable-library-evolution.
Resilient
};

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class FrontendOptions {
/// Enables the "fully resilient" resilience strategy.
///
/// \see ResilienceStrategy::Resilient
bool EnableResilience = false;
bool EnableLibraryEvolution = false;

/// Indicates that the frontend should emit "verbose" SIL
/// (if asked to emit SIL).
Expand Down
3 changes: 1 addition & 2 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def disable_objc_attr_requires_foundation_module :
"Foundation module">;

def enable_resilience : Flag<["-"], "enable-resilience">,
HelpText<"Compile the module to export resilient interfaces for all "
"public declarations by default">;
HelpText<"Deprecated, use -enable-library-evolution instead">;

def enable_class_resilience : Flag<["-"], "enable-class-resilience">,
HelpText<"Enable resilient layout for classes containing resilient value types">;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ def module_cache_path : Separate<["-"], "module-cache-path">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
HelpText<"Specifies the Clang module cache path">;

def enable_library_evolution : Flag<["-"], "enable-library-evolution">,
Flags<[FrontendOption, ParseableInterfaceOption]>,
HelpText<"Build the module to allow binary-compatible library evolution">;

def module_name : Separate<["-"], "module-name">,
Flags<[FrontendOption, ParseableInterfaceOption]>,
HelpText<"Name of the module to build">;
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Sema/SourceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class SourceLoader : public ModuleLoader {
private:
ASTContext &Ctx;
bool SkipBodies;
bool EnableResilience;
bool EnableLibraryEvolution;

explicit SourceLoader(ASTContext &ctx,
bool skipBodies,
bool enableResilience,
DependencyTracker *tracker)
: ModuleLoader(tracker), Ctx(ctx),
SkipBodies(skipBodies), EnableResilience(enableResilience) {}
SkipBodies(skipBodies), EnableLibraryEvolution(enableResilience) {}

public:
static std::unique_ptr<SourceLoader>
Expand Down
1 change: 1 addition & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
inputArgs.AddLastArg(arguments, options::OPT_warn_implicit_overrides);
inputArgs.AddLastArg(arguments, options::OPT_typo_correction_limit);
inputArgs.AddLastArg(arguments, options::OPT_enable_app_extension);
inputArgs.AddLastArg(arguments, options::OPT_enable_library_evolution);
inputArgs.AddLastArg(arguments, options::OPT_enable_testing);
inputArgs.AddLastArg(arguments, options::OPT_enable_private_imports);
inputArgs.AddLastArg(arguments, options::OPT_g_Group);
Expand Down
6 changes: 5 additions & 1 deletion lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ bool ArgsToFrontendOptionsConverter::convert(

Opts.EnableTesting |= Args.hasArg(OPT_enable_testing);
Opts.EnablePrivateImports |= Args.hasArg(OPT_enable_private_imports);
Opts.EnableResilience |= Args.hasArg(OPT_enable_resilience);
Opts.EnableLibraryEvolution |= Args.hasArg(OPT_enable_library_evolution);

// FIXME: Remove this flag
Opts.EnableLibraryEvolution |= Args.hasArg(OPT_enable_resilience);

Opts.EnableImplicitDynamic |= Args.hasArg(OPT_enable_implicit_dynamic);

Opts.TrackSystemDeps |= Args.hasArg(OPT_track_system_dependencies);
Expand Down
7 changes: 4 additions & 3 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ bool CompilerInstance::setUpModuleLoaders() {
if (hasSourceImport()) {
bool immediate = FrontendOptions::isActionImmediate(
Invocation.getFrontendOptions().RequestedAction);
bool enableResilience = Invocation.getFrontendOptions().EnableResilience;
bool enableLibraryEvolution =
Invocation.getFrontendOptions().EnableLibraryEvolution;
Context->addModuleLoader(SourceLoader::create(*Context,
!immediate,
enableResilience,
enableLibraryEvolution,
getDependencyTracker()));
}
auto MLM = ModuleLoadingMode::PreferSerialized;
Expand Down Expand Up @@ -528,7 +529,7 @@ ModuleDecl *CompilerInstance::getMainModule() {
if (Invocation.getFrontendOptions().EnableImplicitDynamic)
MainModule->setImplicitDynamicEnabled();

if (Invocation.getFrontendOptions().EnableResilience)
if (Invocation.getFrontendOptions().EnableLibraryEvolution)
MainModule->setResilienceStrategy(ResilienceStrategy::Resilient);
}
return MainModule;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/SourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ModuleDecl *SourceLoader::loadModule(SourceLoc importLoc,
bufferID = Ctx.SourceMgr.addNewSourceBuffer(std::move(inputFile));

auto *importMod = ModuleDecl::create(moduleID.first, Ctx);
if (EnableResilience)
if (EnableLibraryEvolution)
importMod->setResilienceStrategy(ResilienceStrategy::Resilient);
Ctx.LoadedModules[moduleID.first] = importMod;

Expand Down
2 changes: 1 addition & 1 deletion test/Serialization/attr-invalid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// CHECK-RESILIENT: Frozen_DECL_ATTR
// CHECK-NON-RESILIENT-NOT: Frozen_DECL_ATTR

@_frozen // expected-warning {{@_frozen has no effect without -enable-resilience}}
@_frozen // expected-warning {{@_frozen has no effect without -enable-library-evolution}}
public enum SomeEnum {
case x
}
14 changes: 8 additions & 6 deletions test/Serialization/resilience.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// RUN: %empty-directory(%t)

// This test checks that we serialize the -enable-resilience and -sil-serialize-all
// flags correctly.
// This test checks that we serialize the -enable-library-evolution
// flag.

// RUN: %target-swift-frontend -emit-module -o %t %s
// RUN: llvm-bcanalyzer -dump %t/resilience.swiftmodule > %t/resilience.dump.txt
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=DEFAULT %s < %t/resilience.dump.txt

// RUN: %target-swift-frontend -emit-module -o %t -enable-resilience %s
// RUN: %target-swift-frontend -emit-module -o %t -enable-library-evolution %s
// RUN: llvm-bcanalyzer -dump %t/resilience.swiftmodule > %t/resilience2.dump.txt
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=RESILIENCE %s < %t/resilience2.dump.txt
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t/resilience2.dump.txt

// RUN: %target-swift-frontend -emit-module -o %t %s
// RUN: llvm-bcanalyzer -dump %t/resilience.swiftmodule > %t/resilience3.dump.txt
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=FRAGILE %s < %t/resilience3.dump.txt
// FIXME: The alternate -enable-resilience flag is going away soon.

// RUN: %target-swift-frontend -emit-module -o %t -enable-resilience %s
// RUN: llvm-bcanalyzer -dump %t/resilience.swiftmodule > %t/resilience2.dump.txt
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=RESILIENCE %s < %t/resilience2.dump.txt
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t/resilience2.dump.txt

// CHECK: <MODULE_BLOCK {{.*}}>
Expand Down
4 changes: 2 additions & 2 deletions test/decl/enum/frozen-nonresilient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-typecheck-verify-swift

@_frozen public enum Exhaustive {} // expected-warning {{@_frozen has no effect without -enable-resilience}} {{1-10=}}
@_frozen public enum Exhaustive {} // expected-warning {{@_frozen has no effect without -enable-library-evolution}} {{1-10=}}

@_frozen enum NotPublic {} // expected-warning {{@_frozen has no effect without -enable-resilience}} {{1-10=}}
@_frozen enum NotPublic {} // expected-warning {{@_frozen has no effect without -enable-library-evolution}} {{1-10=}}
2 changes: 1 addition & 1 deletion tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int main(int argc, char **argv) {
Invocation.setTargetTriple(Target);
if (!ResourceDir.empty())
Invocation.setRuntimeResourcePath(ResourceDir);
Invocation.getFrontendOptions().EnableResilience = EnableResilience;
Invocation.getFrontendOptions().EnableLibraryEvolution = EnableResilience;
// Set the module cache path. If not passed in we use the default swift module
// cache.
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
Expand Down