Skip to content

Commit 0ed5cff

Browse files
authored
Merge pull request #81744 from DougGregor/more-migratable-features-6.2
[6.2] Make `InferIsolatedConformances` and `StrictMemorySafety` migratable features
2 parents 17d8955 + 60024c3 commit 0ed5cff

24 files changed

+188
-40
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8545,6 +8545,9 @@ GROUPED_ERROR(isolated_conformance_with_sendable_simple,IsolatedConformances,
85458545
GROUPED_ERROR(isolated_conformance_wrong_domain,IsolatedConformances,none,
85468546
"%0 conformance of %1 to %2 cannot be used in %3 context",
85478547
(ActorIsolation, Type, DeclName, ActorIsolation))
8548+
GROUPED_WARNING(isolated_conformance_will_become_nonisolated,IsolatedConformances,none,
8549+
"conformance of %0 to %1 should be marked 'nonisolated' to retain its behavior with upcoming feature 'InferIsolatedConformances'",
8550+
(const ValueDecl *, const ValueDecl *))
85488551
85498552
//===----------------------------------------------------------------------===//
85508553
// MARK: @_inheritActorContext

include/swift/Basic/Features.def

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@
155155
#endif
156156
#endif
157157

158+
#ifndef MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE
159+
#define MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, Name) \
160+
OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, #Name)
161+
#endif
162+
158163
#ifndef UPCOMING_FEATURE
159164
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \
160165
LANGUAGE_FEATURE(FeatureName, SENumber, #FeatureName)
@@ -283,14 +288,14 @@ UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
283288
MIGRATABLE_UPCOMING_FEATURE(ExistentialAny, 335, 7)
284289
UPCOMING_FEATURE(InternalImportsByDefault, 409, 7)
285290
UPCOMING_FEATURE(MemberImportVisibility, 444, 7)
286-
UPCOMING_FEATURE(InferIsolatedConformances, 470, 7)
291+
MIGRATABLE_UPCOMING_FEATURE(InferIsolatedConformances, 470, 7)
287292
MIGRATABLE_UPCOMING_FEATURE(NonisolatedNonsendingByDefault, 461, 7)
288293

289294
// Optional language features / modes
290295

291296
/// Diagnose uses of language constructs and APIs that can violate memory
292297
/// safety.
293-
OPTIONAL_LANGUAGE_FEATURE(StrictMemorySafety, 458, "Strict memory safety")
298+
MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(StrictMemorySafety, 458, "Strict memory safety")
294299

295300
// Experimental features
296301

@@ -522,6 +527,7 @@ EXPERIMENTAL_FEATURE(CopyBlockOptimization, true)
522527
#undef UPCOMING_FEATURE
523528
#undef MIGRATABLE_UPCOMING_FEATURE
524529
#undef MIGRATABLE_EXPERIMENTAL_FEATURE
530+
#undef MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE
525531
#undef BASELINE_LANGUAGE_FEATURE
526532
#undef OPTIONAL_LANGUAGE_FEATURE
527533
#undef CONDITIONALLY_SUPPRESSIBLE_EXPERIMENTAL_FEATURE

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,9 @@ namespace swift {
872872
FeatureState getFeatureState(Feature feature) const;
873873

874874
/// Returns whether the given feature is enabled.
875-
bool hasFeature(Feature feature) const;
875+
///
876+
/// If allowMigration is set, also returns true when the feature has been enabled for migration.
877+
bool hasFeature(Feature feature, bool allowMigration = false) const;
876878

877879
/// Returns whether a feature with the given name is enabled. Returns
878880
/// `false` if a feature by this name is not known.

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,10 @@ def strict_memory_safety : Flag<["-"], "strict-memory-safety">,
10181018
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable,
10191019
SwiftAPIDigesterOption, SwiftSynthesizeInterfaceOption]>,
10201020
HelpText<"Enable strict memory safety checking">;
1021+
def strict_memory_safety_migrate : Flag<["-"], "strict-memory-safety:migrate">,
1022+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable,
1023+
SwiftAPIDigesterOption, SwiftSynthesizeInterfaceOption]>,
1024+
HelpText<"Enable migration to strict memory safety checking">;
10211025

10221026
def Rpass_EQ : Joined<["-"], "Rpass=">,
10231027
Flags<[FrontendOption]>,

lib/Basic/Feature.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ bool Feature::isMigratable() const {
7373
switch (kind) {
7474
#define MIGRATABLE_UPCOMING_FEATURE(FeatureName, SENumber, Version)
7575
#define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)
76+
#define MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, Name)
7677
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
7778
case Feature::FeatureName:
7879
#include "swift/Basic/Features.def"
@@ -82,6 +83,8 @@ bool Feature::isMigratable() const {
8283
case Feature::FeatureName:
8384
#define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
8485
case Feature::FeatureName:
86+
#define MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, Name) \
87+
case Feature::FeatureName:
8588
#include "swift/Basic/Features.def"
8689
return true;
8790
}

lib/Basic/LangOptions.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,17 @@ LangOptions::FeatureState LangOptions::getFeatureState(Feature feature) const {
335335
return state;
336336
}
337337

338-
bool LangOptions::hasFeature(Feature feature) const {
339-
if (featureStates.getState(feature).isEnabled())
338+
bool LangOptions::hasFeature(Feature feature, bool allowMigration) const {
339+
auto state = featureStates.getState(feature);
340+
if (state.isEnabled())
340341
return true;
341342

342343
if (auto version = feature.getLanguageVersion())
343344
return isSwiftVersionAtLeast(*version);
344345

346+
if (allowMigration && state.isEnabledForMigration())
347+
return true;
348+
345349
return false;
346350
}
347351

lib/Basic/SupportedFeatures.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <array>
1414
#include <vector>
1515

16+
#include "swift/AST/DiagnosticGroups.h"
1617
#include "swift/Basic/Feature.h"
1718
#include "swift/Frontend/Frontend.h"
1819

@@ -22,6 +23,33 @@ using namespace swift;
2223

2324
namespace swift {
2425
namespace features {
26+
27+
/// The subset of diagnostic groups (called categories by the diagnostic machinery) whose diagnostics should be
28+
/// considered to be part of the migration for this feature.
29+
///
30+
/// When making a feature migratable, ensure that all of the warnings that are used to drive the migration are
31+
/// part of a diagnostic group, and put that diagnostic group into the list for that feature here.
32+
static std::vector<DiagGroupID> migratableCategories(Feature feature) {
33+
switch (feature) {
34+
case Feature::InnerKind::ExistentialAny:
35+
return { DiagGroupID::ExistentialAny };
36+
case Feature::InnerKind::InferIsolatedConformances:
37+
return { DiagGroupID::IsolatedConformances };
38+
case Feature::InnerKind::NonisolatedNonsendingByDefault:
39+
return { DiagGroupID::NonisolatedNonsendingByDefault };
40+
case Feature::InnerKind::StrictMemorySafety:
41+
return { DiagGroupID::StrictMemorySafety };
42+
43+
// Provide unreachable cases for all of the non-migratable features.
44+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) case Feature::FeatureName:
45+
#define MIGRATABLE_UPCOMING_FEATURE(FeatureName, SENumber, Version)
46+
#define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)
47+
#define MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, Name)
48+
#include "swift/Basic/Features.def"
49+
llvm_unreachable("Not a migratable feature");
50+
}
51+
}
52+
2553
/// Print information about what features upcoming/experimental are
2654
/// supported by the compiler.
2755
/// The information includes whether a feature is adoptable and for
@@ -50,9 +78,18 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
5078
out << "{ \"name\": \"" << feature.getName() << "\"";
5179
if (feature.isMigratable()) {
5280
out << ", \"migratable\": true";
81+
82+
auto categories = migratableCategories(feature);
83+
out << ", \"categories\": [";
84+
llvm::interleave(categories, [&out](DiagGroupID diagGroupID) {
85+
out << "\"" << getDiagGroupInfoByID(diagGroupID).name << "\"";
86+
}, [&out] {
87+
out << ", ";
88+
});
89+
out << "]";
5390
}
5491
if (auto version = feature.getLanguageVersion()) {
55-
out << ", \"enabled_in\": " << *version;
92+
out << ", \"enabled_in\": \"" << *version << "\"";
5693
}
5794
out << " }";
5895
};
@@ -71,4 +108,4 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
71108
}
72109

73110
} // end namespace features
74-
} // end namespace swift
111+
} // end namespace swift

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
284284
options::OPT_disable_experimental_feature,
285285
options::OPT_enable_upcoming_feature,
286286
options::OPT_disable_upcoming_feature});
287-
inputArgs.AddLastArg(arguments, options::OPT_strict_memory_safety);
287+
inputArgs.AddLastArg(arguments, options::OPT_strict_memory_safety,
288+
options::OPT_strict_memory_safety_migrate);
288289
inputArgs.AddLastArg(arguments, options::OPT_warn_implicit_overrides);
289290
inputArgs.AddLastArg(arguments, options::OPT_typo_correction_limit);
290291
inputArgs.AddLastArg(arguments, options::OPT_enable_app_extension);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
996996

997997
if (Args.hasArg(OPT_strict_memory_safety))
998998
Opts.enableFeature(Feature::StrictMemorySafety);
999+
else if (Args.hasArg(OPT_strict_memory_safety_migrate))
1000+
Opts.enableFeature(Feature::StrictMemorySafety, /*forMigration=*/true);
9991001

10001002
return HadError;
10011003
}

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8172,7 +8172,7 @@ Expr *ExprRewriter::convertLiteralInPlace(
81728172
Diag<> brokenProtocolDiag, Diag<> brokenBuiltinProtocolDiag) {
81738173
// If coercing a literal to an unresolved type, we don't try to look up the
81748174
// witness members, just do it.
8175-
if (type->is<UnresolvedType>()) {
8175+
if (type->is<UnresolvedType>() || type->is<ErrorType>()) {
81768176
cs.setType(literal, type);
81778177
return literal;
81788178
}

0 commit comments

Comments
 (0)