Skip to content

Revert #64269 #65568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ struct PrintOptions {
/// for class layout
bool PrintClassLayoutName = false;

/// Replace @freestanding(expression) with @expression.
bool SuppressingFreestandingExpression = false;

/// Suppress emitting @available(*, noasync)
bool SuppressNoAsyncAvailabilityAttr = false;

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync",
SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)", true)
LANGUAGE_FEATURE(BuiltinIntLiteralAccessors, 368, "Builtin.IntLiteral accessors", true)
LANGUAGE_FEATURE(Macros, 0, "Macros", hasSwiftSwiftParser)
SUPPRESSIBLE_LANGUAGE_FEATURE(
LANGUAGE_FEATURE(
FreestandingExpressionMacros, 382, "Expression macros",
hasSwiftSwiftParser)
LANGUAGE_FEATURE(AttachedMacros, 389, "Attached macros", hasSwiftSwiftParser)
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3340,14 +3340,6 @@ static bool usesFeatureFreestandingExpressionMacros(Decl *decl) {
return macro->getMacroRoles().contains(MacroRole::Expression);
}

static void
suppressingFeatureFreestandingExpressionMacros(PrintOptions &options,
llvm::function_ref<void()> action) {
llvm::SaveAndRestore<PrintOptions> originalOptions(options);
options.SuppressingFreestandingExpression = true;
action();
}

static void
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
llvm::function_ref<void()> action) {
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,14 +1356,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,

case DAK_MacroRole: {
auto Attr = cast<MacroRoleAttr>(this);

if (Options.SuppressingFreestandingExpression &&
Attr->getMacroSyntax() == MacroSyntax::Freestanding &&
Attr->getMacroRole() == MacroRole::Expression) {
Printer.printAttrName("@expression");
break;
}

switch (Attr->getMacroSyntax()) {
case MacroSyntax::Freestanding:
Printer.printAttrName("@freestanding");
Expand Down
19 changes: 8 additions & 11 deletions test/ModuleInterface/macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@

// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -typecheck -module-name Macros -emit-module-interface-path %t/Macros.swiftinterface %s
// RUN: %target-swift-emit-module-interface(%t/Macros.swiftinterface) -module-name Macros %s
// RUN: %FileCheck %s < %t/Macros.swiftinterface --check-prefix CHECK
// RUN: %target-swift-frontend -compile-module-from-interface %t/Macros.swiftinterface -o %t/Macros.swiftmodule

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

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

// CHECK: #if compiler(>=5.3) && $Macros && $FreestandingExpressionMacros
// CHECK: @freestanding(expression) public macro unlabeledStringify<T>(_ value: T, label: Swift.String) -> (T, Swift.String) = #labeledStringify(value, label: "default label")
// CHECK-NEXT: #endif
@freestanding(expression) public macro unlabeledStringify<T>(_ value: T, label: String) -> (T, String) = #labeledStringify(value, label: "default label")

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

Expand Down