Skip to content

Commit 1357e54

Browse files
committed
[AST] Added language feature for @_eagerMove.
The new LexicalLifetimes suppressible language feature results in declarations annotated with @_eagerMove, @_noEagerMove, and @_lexicalLifetimes to be printed with that attribute when it's available and without it when it's not.
1 parent 53e5723 commit 1357e54

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

.clang-format

Lines changed: 0 additions & 2 deletions
This file was deleted.

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) {

test/ModuleInterface/features.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,33 @@ public func unavailableFromAsyncFunc() { }
189189
public func noAsyncFunc() { }
190190

191191
// CHECK-NOT: extension FeatureTest.MyActor : Swift.Sendable
192+
193+
// CHECK: #if compiler(>=5.3) && $LexicalLifetimes
194+
// CHECK-NEXT: @_noEagerMove public struct Permanent {
195+
// CHECK-NEXT: }
196+
// CHECK-NEXT: #else
197+
// CHECK-NEXT: public struct Permanent {
198+
// CHECK-NEXT: }
199+
// CHECK-NEXT: #endif
200+
@_noEagerMove
201+
public struct Permanent {}
202+
203+
// CHECK: #if compiler(>=5.3) && $LexicalLifetimes
204+
// CHECK-NEXT: @_hasMissingDesignatedInitializers @_eagerMove public class Transient {
205+
// CHECK-NEXT: @objc deinit
206+
// CHECK-NEXT: }
207+
// CHECK-NEXT: #else
208+
// CHECK-NEXT: @_hasMissingDesignatedInitializers public class Transient {
209+
// CHECK-NEXT: @objc deinit
210+
// CHECK-NEXT: }
211+
#endif
212+
@_eagerMove
213+
public class Transient {}
214+
215+
// CHECK: #if compiler(>=5.3) && $LexicalLifetimes
216+
// CHECK-NEXT: @_lexicalLifetimes public func lexicalInAModuleWithoutLexicalLifetimes(_ t: FeatureTest.Transient)
217+
// CHECK-NEXT: #else
218+
// CHECK-NEXT: public func lexicalInAModuleWithoutLexicalLifetimes(_ t: FeatureTest.Transient)
219+
// CHECK-NEXT: #endif
220+
@_lexicalLifetimes
221+
public func lexicalInAModuleWithoutLexicalLifetimes(_ t: Transient) {}

0 commit comments

Comments
 (0)