Skip to content

Commit 1a93808

Browse files
committed
[Macros] Gate closure body macros behind an experimental feature flag.
1 parent 69656b0 commit 1a93808

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
@@ -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

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

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

lib/AST/FeatureSet.cpp

+4
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

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