Skip to content

Commit 2b13eca

Browse files
authored
Merge pull request swiftlang#63510 from DougGregor/freestanding-expr-ast-printer
Introduce a separate feature to cover `@freestanding(expression)`
2 parents fbca92c + 85ba74b commit 2b13eca

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes2, 346, "Primary associated
9292
SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync", true)
9393
SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)", true)
9494
LANGUAGE_FEATURE(BuiltinIntLiteralAccessors, 368, "Builtin.IntLiteral accessors", true)
95+
LANGUAGE_FEATURE(
96+
FreestandingExpressionMacros, 0, "@freestanding(expression) macros",
97+
langOpts.hasFeature(Feature::Macros))
9598

9699
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
97100
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,6 +3171,14 @@ static bool usesFeatureBuiltinMacros(Decl *decl) {
31713171

31723172
static bool usesFeatureImportSymbolicCXXDecls(Decl *decl) { return false; }
31733173

3174+
static bool usesFeatureFreestandingExpressionMacros(Decl *decl) {
3175+
auto macro = dyn_cast<MacroDecl>(decl);
3176+
if (!macro)
3177+
return false;
3178+
3179+
return macro->getMacroRoles().contains(MacroRole::Expression);
3180+
}
3181+
31743182
static void
31753183
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
31763184
llvm::function_ref<void()> action) {

test/ModuleInterface/macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// RUN: %FileCheck %s < %t/Macros.swiftinterface --check-prefix CHECK
77
// RUN: %target-swift-frontend -compile-module-from-interface %t/Macros.swiftinterface -o %t/Macros.swiftmodule
88

9-
// CHECK: #if compiler(>=5.3) && $Macros
9+
// CHECK: #if compiler(>=5.3) && $FreestandingExpressionMacros && $Macros
1010
// CHECK-NEXT: @freestanding(expression) public macro publicStringify<T>(_ value: T) -> (T, Swift.String) = #externalMacro(module: "SomeModule", type: "StringifyMacro")
1111
// CHECK-NEXT: #endif
1212
@freestanding(expression) public macro publicStringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "SomeModule", type: "StringifyMacro")
1313

14-
// CHECK: #if compiler(>=5.3) && $Macros
14+
// CHECK: #if compiler(>=5.3) && $FreestandingExpressionMacros && $Macros
1515
// CHECK: @freestanding(expression) public macro publicLine<T>: T = #externalMacro(module: "SomeModule", type: "Line") where T : Swift.ExpressibleByIntegerLiteral
1616
// CHECK-NEXT: #endif
1717
@freestanding(expression) public macro publicLine<T: ExpressibleByIntegerLiteral>: T = #externalMacro(module: "SomeModule", type: "Line")

0 commit comments

Comments
 (0)