Skip to content

Commit 8ec70e2

Browse files
committed
[Macros] Gate closure body macros behind an experimental feature flag.
1 parent 9cd3c8d commit 8ec70e2

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7833,6 +7833,9 @@ ERROR(conformance_macro,none,
78337833
ERROR(experimental_macro,none,
78347834
"macro %0 is experimental",
78357835
(DeclName))
7836+
ERROR(experimental_closure_body_macro,none,
7837+
"function body macros on closures is experimental",
7838+
())
78367839

78377840
ERROR(macro_resolve_circular_reference, none,
78387841
"circular reference resolving %select{freestanding|attached}0 macro %1",

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ EXPERIMENTAL_FEATURE(ConcurrencySyntaxSugar, true)
511511
/// Allow declaration of compile-time values
512512
EXPERIMENTAL_FEATURE(CompileTimeValues, true)
513513

514+
/// Allow function body macros applied to closures.
515+
EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
516+
514517
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
515518
#undef EXPERIMENTAL_FEATURE
516519
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ static bool usesFeatureCompileTimeValues(Decl *decl) {
359359
return decl->getAttrs().hasAttribute<ConstValAttr>();
360360
}
361361

362+
static bool usesFeatureClosureBodyMacro(Decl *decl) {
363+
return false;
364+
}
365+
362366
static bool usesFeatureMemorySafetyAttributes(Decl *decl) {
363367
if (decl->getAttrs().hasAttribute<SafeAttr>() ||
364368
decl->getAttrs().hasAttribute<UnsafeAttr>())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8319,6 +8319,12 @@ class ClosureAttributeChecker
83198319
auto *decl = declRef.getDecl();
83208320
if (auto *macro = dyn_cast_or_null<MacroDecl>(decl)) {
83218321
if (macro->getMacroRoles().contains(MacroRole::Body)) {
8322+
if (!ctx.LangOpts.hasFeature(Feature::ClosureBodyMacro)) {
8323+
ctx.Diags.diagnose(
8324+
attr->getLocation(),
8325+
diag::experimental_closure_body_macro);
8326+
}
8327+
83228328
// Function body macros are allowed on closures.
83238329
return;
83248330
}

test/Macros/start_task.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// REQUIRES: swift_swift_parser, swift_feature_ConcurrencySyntaxSugar
1+
// REQUIRES: swift_swift_parser, swift_feature_ConcurrencySyntaxSugar, swift_feature_ClosureBodyMacro
22

3-
// RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -enable-experimental-feature ConcurrencySyntaxSugar -language-mode 6 %s -dump-macro-expansions 2>&1 | %FileCheck %s
3+
// RUN: %target-swift-frontend -typecheck -plugin-path %swift-plugin-dir -enable-experimental-feature ConcurrencySyntaxSugar -enable-experimental-feature ClosureBodyMacro -language-mode 6 %s -dump-macro-expansions 2>&1 | %FileCheck %s
44

55
func f() async {}
66

0 commit comments

Comments
 (0)