Skip to content

Commit 4d8dab0

Browse files
Merge pull request #65845 from nate-chandler/eagermove_language_feature
[AST] Added language feature for @_eagerMove.
2 parents 8a611bf + b723958 commit 4d8dab0

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ LANGUAGE_FEATURE(
101101
LANGUAGE_FEATURE(AttachedMacros, 389, "Attached macros", hasSwiftSwiftParser)
102102
LANGUAGE_FEATURE(MoveOnly, 390, "noncopyable types", true)
103103
LANGUAGE_FEATURE(ParameterPacks, 393, "Value and type parameter packs", true)
104+
SUPPRESSIBLE_LANGUAGE_FEATURE(LexicalLifetimes, 0, "@_eagerMove/@_noEagerMove/@_lexicalLifetimes annotations", true)
104105

105106
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
106107
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)

lib/AST/ASTPrinter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,6 +3340,23 @@ static bool usesFeatureFreestandingExpressionMacros(Decl *decl) {
33403340
return macro->getMacroRoles().contains(MacroRole::Expression);
33413341
}
33423342

3343+
static bool usesFeatureLexicalLifetimes(Decl *decl) {
3344+
return decl->getAttrs().hasAttribute<EagerMoveAttr>()
3345+
|| decl->getAttrs().hasAttribute<NoEagerMoveAttr>()
3346+
|| decl->getAttrs().hasAttribute<LexicalLifetimesAttr>();
3347+
}
3348+
3349+
static void
3350+
suppressingFeatureLexicalLifetimes(PrintOptions &options,
3351+
llvm::function_ref<void()> action) {
3352+
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3353+
options.ExcludeAttrList.push_back(DAK_EagerMove);
3354+
options.ExcludeAttrList.push_back(DAK_NoEagerMove);
3355+
options.ExcludeAttrList.push_back(DAK_LexicalLifetimes);
3356+
action();
3357+
options.ExcludeAttrList.resize(originalExcludeAttrCount);
3358+
}
3359+
33433360
static void
33443361
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
33453362
llvm::function_ref<void()> action) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-emit-module-interface(%t/FeatureTest.swiftinterface) %s -module-name FeatureTest -disable-availability-checking
4+
// RUN: %target-swift-typecheck-module-from-interface(%t/FeatureTest.swiftinterface) -module-name FeatureTest -disable-availability-checking
5+
// RUN: %FileCheck %s < %t/FeatureTest.swiftinterface
6+
7+
// CHECK: #if compiler(>=5.3) && $LexicalLifetimes
8+
// CHECK-NEXT: @_noEagerMove public struct Permanent {
9+
// CHECK-NEXT: }
10+
// CHECK-NEXT: #else
11+
// CHECK-NEXT: public struct Permanent {
12+
// CHECK-NEXT: }
13+
// CHECK-NEXT: #endif
14+
@_noEagerMove
15+
public struct Permanent {}
16+
17+
// CHECK: #if compiler(>=5.3) && $LexicalLifetimes
18+
// CHECK-NEXT: @_hasMissingDesignatedInitializers @_eagerMove public class Transient {
19+
// CHECK-NEXT: deinit
20+
// CHECK-NEXT: }
21+
// CHECK-NEXT: #else
22+
// CHECK-NEXT: @_hasMissingDesignatedInitializers public class Transient {
23+
// CHECK-NEXT: deinit
24+
// CHECK-NEXT: }
25+
// CHECK-NEXT: #endif
26+
@_eagerMove
27+
public class Transient {}
28+
29+
// CHECK: #if compiler(>=5.3) && $LexicalLifetimes
30+
// CHECK-NEXT: @_lexicalLifetimes public func lexicalInAModuleWithoutLexicalLifetimes(_ t: FeatureTest.Transient)
31+
// CHECK-NEXT: #else
32+
// CHECK-NEXT: public func lexicalInAModuleWithoutLexicalLifetimes(_ t: FeatureTest.Transient)
33+
// CHECK-NEXT: #endif
34+
@_lexicalLifetimes
35+
public func lexicalInAModuleWithoutLexicalLifetimes(_ t: Transient) {}

0 commit comments

Comments
 (0)