Skip to content

Commit 6f98e9a

Browse files
committed
trifurcate the MoveOnly feature
I want to reserve Feature::MoveOnly only for move-only types and other things that are part of SE-390. Other prototyped features like noimplicitcopy and some older names for consume were left behind as guarded by this Feature. That's really not the right way to do it, as people will expect that the feature is enabled all the time, which would put those unofficial features into on-by-default. So this change introduces two new Features to guard those unofficial features.
1 parent df35da4 commit 6f98e9a

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

include/swift/Basic/Features.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ EXPERIMENTAL_FEATURE(FreestandingMacros, true)
115115
// but our tests currently rely on it, and we want to run those
116116
// tests in non-asserts builds too.
117117
EXPERIMENTAL_FEATURE(MoveOnlyClasses, true)
118+
EXPERIMENTAL_FEATURE(NoImplicitCopy, true)
119+
EXPERIMENTAL_FEATURE(OldOwnershipOperatorSpellings, true)
118120

119121
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
120122
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,6 +3212,14 @@ static bool usesFeatureMoveOnlyClasses(Decl *decl) {
32123212
return isa<ClassDecl>(decl) && usesFeatureMoveOnly(decl);
32133213
}
32143214

3215+
static bool usesFeatureNoImplicitCopy(Decl *decl) {
3216+
return decl->isNoImplicitCopy();
3217+
}
3218+
3219+
static bool usesFeatureOldOwnershipOperatorSpellings(Decl *decl) {
3220+
return false;
3221+
}
3222+
32153223
static bool usesFeatureOneWayClosureParameters(Decl *decl) {
32163224
return false;
32173225
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
721721
Opts.Features.insert(Feature::NamedOpaqueTypes);
722722
if (Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures))
723723
Opts.Features.insert(Feature::FlowSensitiveConcurrencyCaptures);
724-
if (Args.hasArg(OPT_enable_experimental_move_only))
724+
if (Args.hasArg(OPT_enable_experimental_move_only)) {
725+
// FIXME: drop addition of Feature::MoveOnly once its queries are gone.
725726
Opts.Features.insert(Feature::MoveOnly);
727+
Opts.Features.insert(Feature::NoImplicitCopy);
728+
Opts.Features.insert(Feature::OldOwnershipOperatorSpellings);
729+
}
726730
if (Args.hasArg(OPT_experimental_one_way_closure_params))
727731
Opts.Features.insert(Feature::OneWayClosureParameters);
728732
if (Args.hasArg(OPT_enable_experimental_associated_type_inference))

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
422422
return sub;
423423
}
424424

425-
if (Context.LangOpts.hasFeature(Feature::MoveOnly)) {
425+
if (Context.LangOpts.hasFeature(Feature::OldOwnershipOperatorSpellings)) {
426426
if (Tok.isContextualKeyword("_move")) {
427427
Tok.setKind(tok::contextual_keyword);
428428
SourceLoc awaitLoc = consumeToken();

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
349349
void AttributeChecker::visitNoImplicitCopyAttr(NoImplicitCopyAttr *attr) {
350350
// Only allow for this attribute to be used when experimental move only is
351351
// enabled.
352-
if (!D->getASTContext().LangOpts.hasFeature(Feature::MoveOnly)) {
352+
if (!D->getASTContext().LangOpts.hasFeature(Feature::NoImplicitCopy)) {
353353
auto error =
354354
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;
355355
diagnoseAndRemoveAttr(attr, error);

tools/sil-opt/SILOpt.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,13 @@ int main(int argc, char **argv) {
581581
EnableExperimentalConcurrency;
582582
Optional<bool> enableExperimentalMoveOnly =
583583
toOptionalBool(EnableExperimentalMoveOnly);
584-
if (enableExperimentalMoveOnly && *enableExperimentalMoveOnly)
584+
if (enableExperimentalMoveOnly && *enableExperimentalMoveOnly) {
585+
// FIXME: drop addition of Feature::MoveOnly once its queries are gone.
585586
Invocation.getLangOptions().Features.insert(Feature::MoveOnly);
587+
Invocation.getLangOptions().Features.insert(Feature::NoImplicitCopy);
588+
Invocation.getLangOptions().Features.insert(
589+
Feature::OldOwnershipOperatorSpellings);
590+
}
586591
for (auto &featureName : ExperimentalFeatures) {
587592
if (auto feature = getExperimentalFeature(featureName)) {
588593
Invocation.getLangOptions().Features.insert(*feature);

0 commit comments

Comments
 (0)