Skip to content

Commit 0737723

Browse files
authored
Merge pull request #84465 from DougGregor/has-feature-library-evolution
Add an optional language feature for Library Evolution
2 parents e5a9b64 + bab1a9c commit 0737723

13 files changed

+30
-29
lines changed

include/swift/Basic/Features.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ UPCOMING_FEATURE(ImmutableWeakCaptures, 481, 7)
308308
/// safety.
309309
MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(StrictMemorySafety, 458, "Strict memory safety")
310310

311+
OPTIONAL_LANGUAGE_FEATURE(LibraryEvolution, 0, "Library evolution")
312+
311313
// Experimental features
312314

313315
EXPERIMENTAL_FEATURE(StaticAssert, false)

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,6 @@ class FrontendOptions {
298298
/// \see ModuleDecl::isImplicitDynamicEnabled
299299
bool EnableImplicitDynamic = false;
300300

301-
/// Enables the "fully resilient" resilience strategy.
302-
///
303-
/// \see ResilienceStrategy::Resilient
304-
bool EnableLibraryEvolution = false;
305-
306301
/// If set, this module is part of a mixed Objective-C/Swift framework, and
307302
/// the Objective-C half should implicitly be visible to the Swift sources.
308303
bool ImportUnderlyingModule = false;

include/swift/Sema/SourceLoader.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ class SourceLoader : public ModuleLoader {
2525
private:
2626
ASTContext &Ctx;
2727
std::vector<ModuleDecl *> ModulesToBindExtensions;
28-
bool EnableLibraryEvolution;
2928

3029
explicit SourceLoader(ASTContext &ctx,
31-
bool enableResilience,
3230
DependencyTracker *tracker)
33-
: ModuleLoader(tracker), Ctx(ctx),
34-
EnableLibraryEvolution(enableResilience) {}
31+
: ModuleLoader(tracker), Ctx(ctx) {}
3532

3633
public:
3734
static std::unique_ptr<SourceLoader>
38-
create(ASTContext &ctx, bool enableResilience,
39-
DependencyTracker *tracker = nullptr) {
35+
create(ASTContext &ctx, DependencyTracker *tracker = nullptr) {
4036
return std::unique_ptr<SourceLoader>{
41-
new SourceLoader(ctx, enableResilience, tracker)
37+
new SourceLoader(ctx, tracker)
4238
};
4339
}
4440

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ static bool usesFeatureCDecl(Decl *decl) {
327327
}
328328

329329
UNINTERESTING_FEATURE(StrictMemorySafety)
330+
UNINTERESTING_FEATURE(LibraryEvolution)
330331
UNINTERESTING_FEATURE(SafeInteropWrappers)
331332
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
332333
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)

lib/Basic/SupportedFeatures.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ static std::optional<std::string_view> optionalFlagName(Feature feature) {
5959
case Feature::StrictMemorySafety:
6060
return "-strict-memory-safety";
6161

62+
case Feature::LibraryEvolution:
63+
return "-enable-library-evolution";
64+
6265
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) case Feature::FeatureName:
6366
#define OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, Description)
6467
#include "swift/Basic/Features.def"

lib/DriverTool/sil_opt_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
710710
Invocation.setTargetTriple(options.Target);
711711
if (!options.ResourceDir.empty())
712712
Invocation.setRuntimeResourcePath(options.ResourceDir);
713-
Invocation.getFrontendOptions().EnableLibraryEvolution
714-
= options.EnableLibraryEvolution;
713+
if (options.EnableLibraryEvolution)
714+
Invocation.getLangOptions().enableFeature(Feature::LibraryEvolution);
715715
Invocation.getFrontendOptions().StrictImplicitModuleContext
716716
= options.StrictImplicitModuleContext;
717717

lib/DriverTool/swift_symbolgraph_extract_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
140140
Invocation.getLangOptions().EnableObjCInterop = Target.isOSDarwin();
141141
Invocation.getLangOptions().DebuggerSupport = true;
142142

143-
Invocation.getFrontendOptions().EnableLibraryEvolution = true;
143+
Invocation.getLangOptions().enableFeature(Feature::LibraryEvolution);
144144

145145
std::string ModuleCachePath = "";
146146
if (auto *A = ParsedArgs.getLastArg(OPT_module_cache_path)) {

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,12 @@ bool ArgsToFrontendOptionsConverter::convert(
107107

108108
Opts.EnableTesting |= Args.hasArg(OPT_enable_testing);
109109
Opts.EnablePrivateImports |= Args.hasArg(OPT_enable_private_imports);
110-
Opts.EnableLibraryEvolution |= Args.hasArg(OPT_enable_library_evolution);
111110
Opts.FrontendParseableOutput |= Args.hasArg(OPT_frontend_parseable_output);
112111
Opts.ExplicitInterfaceBuild |= Args.hasArg(OPT_explicit_interface_module_build);
113112

114113
Opts.EmitClangHeaderWithNonModularIncludes |=
115114
Args.hasArg(OPT_emit_clang_header_nonmodular_includes);
116115

117-
// FIXME: Remove this flag
118-
Opts.EnableLibraryEvolution |= Args.hasArg(OPT_enable_resilience);
119-
120116
Opts.EnableImplicitDynamic |= Args.hasArg(OPT_enable_implicit_dynamic);
121117

122118
if (Args.hasArg(OPT_track_system_dependencies)) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,9 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
10111011
else if (Args.hasArg(OPT_strict_memory_safety_migrate))
10121012
Opts.enableFeature(Feature::StrictMemorySafety, /*forMigration=*/true);
10131013

1014+
if (Args.hasArg(OPT_enable_library_evolution, OPT_enable_resilience))
1015+
Opts.enableFeature(Feature::LibraryEvolution);
1016+
10141017
return HadError;
10151018
}
10161019

@@ -1802,7 +1805,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
18021805
HadError = true;
18031806
}
18041807

1805-
if (FrontendOpts.EnableLibraryEvolution) {
1808+
if (Opts.hasFeature(Feature::LibraryEvolution)) {
18061809
Diags.diagnose(SourceLoc(), diag::evolution_with_embedded);
18071810
HadError = true;
18081811
}
@@ -2138,7 +2141,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args,
21382141

21392142
// Until we have some checking in place, internal bridging headers are a
21402143
// bit unsafe without library evolution.
2141-
if (Opts.BridgingHeaderIsInternal && !FrontendOpts.EnableLibraryEvolution) {
2144+
if (Opts.BridgingHeaderIsInternal &&
2145+
!LangOpts.hasFeature(Feature::LibraryEvolution)) {
21422146
Diags.diagnose(SourceLoc(),
21432147
diag::internal_bridging_header_without_library_evolution);
21442148
}
@@ -3064,7 +3068,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
30643068
FrontendOptions::ActionType::TypecheckModuleFromInterface)
30653069
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
30663070
"-package-cmo", "-allow-non-resilient-access");
3067-
} else if (!FEOpts.EnableLibraryEvolution) {
3071+
} else if (!LangOpts.hasFeature(Feature::LibraryEvolution)) {
30683072
Diags.diagnose(SourceLoc(), diag::package_cmo_requires_library_evolution);
30693073
} else {
30703074
Opts.EnableSerializePackage = true;

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,7 @@ bool CompilerInstance::setUpModuleLoaders() {
813813
}
814814

815815
if (hasSourceImport()) {
816-
bool enableLibraryEvolution =
817-
Invocation.getFrontendOptions().EnableLibraryEvolution;
818816
Context->addModuleLoader(SourceLoader::create(*Context,
819-
enableLibraryEvolution,
820817
getDependencyTracker()));
821818
}
822819

@@ -1173,7 +1170,7 @@ bool CompilerInvocation::shouldImportCxx() const {
11731170
if (getFrontendOptions().ModuleName == CXX_MODULE_NAME)
11741171
return false;
11751172
// Cxx cannot be imported when Library evolution is enabled
1176-
if (getFrontendOptions().EnableLibraryEvolution)
1173+
if (getLangOptions().hasFeature(Feature::LibraryEvolution))
11771174
return false;
11781175
// Implicit import of Cxx is disabled
11791176
if (getLangOptions().DisableImplicitCxxModuleImport)
@@ -1507,7 +1504,7 @@ ModuleDecl *CompilerInstance::getMainModule() const {
15071504
MainModule->setPublicModuleName(getASTContext().getIdentifier(
15081505
Invocation.getFrontendOptions().PublicModuleName));
15091506
}
1510-
if (Invocation.getFrontendOptions().EnableLibraryEvolution)
1507+
if (Invocation.getLangOptions().hasFeature(Feature::LibraryEvolution))
15111508
MainModule->setResilienceStrategy(ResilienceStrategy::Resilient);
15121509
if (Invocation.getLangOptions().isSwiftVersionAtLeast(6))
15131510
MainModule->setIsConcurrencyChecked(true);

0 commit comments

Comments
 (0)