Skip to content

Commit 34715fe

Browse files
committed
[Macros] Gate closure body macros behind an experimental feature flag.
1 parent 4ed275f commit 34715fe

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

include/swift/AST/DiagnosticsSema.def

+3
Original file line numberDiff line numberDiff line change
@@ -7813,6 +7813,9 @@ ERROR(conformance_macro,none,
78137813
ERROR(experimental_macro,none,
78147814
"macro %0 is experimental",
78157815
(DeclName))
7816+
ERROR(experimental_closure_body_macro,none,
7817+
"function body macros on closures is experimental",
7818+
())
78167819

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

include/swift/Basic/Features.def

+3
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ EXPERIMENTAL_FEATURE(ConcurrencySyntaxSugar, true)
515515
/// Allow declaration of compile-time values
516516
EXPERIMENTAL_FEATURE(CompileTimeValues, true)
517517

518+
/// Allow function body macros applied to closures.
519+
EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
520+
518521
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
519522
#undef EXPERIMENTAL_FEATURE
520523
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ static bool usesFeatureCompileTimeValues(Decl *decl) {
358358
return decl->getAttrs().hasAttribute<ConstValAttr>();
359359
}
360360

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

lib/Sema/TypeCheckAttr.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -8281,6 +8281,12 @@ class ClosureAttributeChecker
82818281
auto *decl = declRef.getDecl();
82828282
if (auto *macro = dyn_cast_or_null<MacroDecl>(decl)) {
82838283
if (macro->getMacroRoles().contains(MacroRole::Body)) {
8284+
if (!ctx.LangOpts.hasFeature(Feature::ClosureBodyMacro)) {
8285+
ctx.Diags.diagnose(
8286+
attr->getLocation(),
8287+
diag::experimental_closure_body_macro);
8288+
}
8289+
82848290
// Function body macros are allowed on closures.
82858291
return;
82868292
}

test/Macros/start_task.swift

+2-2
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)