mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Revert "[Macros] Enable composition of member attribute macros and accessor macros."
It causes crashes in some Sema/SwiftUI tests in some configurations.
rdar://104297642
This reverts commit b8d65e1ed9.
This commit is contained in:
@@ -500,17 +500,6 @@ public:
|
||||
/// the \c SourceFileKind is \c MacroExpansion.
|
||||
ASTNode getMacroExpansion() const;
|
||||
|
||||
/// For source files created to hold the source code created by expanding
|
||||
/// an attached macro, this is the custom attribute that describes the macro
|
||||
/// expansion.
|
||||
///
|
||||
/// The source location of this attribute is the place in the source that
|
||||
/// triggered the creation of the macro expansion whose resulting source
|
||||
/// code is in this source file. This will only produce a non-null value when
|
||||
/// the \c SourceFileKind is \c MacroExpansion , and the macro is an attached
|
||||
/// macro.
|
||||
CustomAttr *getAttachedMacroAttribute() const;
|
||||
|
||||
/// When this source file is enclosed within another source file, for example
|
||||
/// because it describes a macro expansion, return the source file it was
|
||||
/// enclosed in.
|
||||
|
||||
@@ -887,15 +887,6 @@ ASTNode SourceFile::getMacroExpansion() const {
|
||||
return ASTNode::getFromOpaqueValue(genInfo.astNode);
|
||||
}
|
||||
|
||||
CustomAttr *SourceFile::getAttachedMacroAttribute() const {
|
||||
if (Kind != SourceFileKind::MacroExpansion)
|
||||
return nullptr;
|
||||
|
||||
auto genInfo =
|
||||
*getASTContext().SourceMgr.getGeneratedSourceInfo(*getBufferID());
|
||||
return genInfo.attachedMacroCustomAttr;
|
||||
}
|
||||
|
||||
SourceFile *SourceFile::getEnclosingSourceFile() const {
|
||||
auto macroExpansion = getMacroExpansion();
|
||||
if (!macroExpansion)
|
||||
|
||||
@@ -326,17 +326,6 @@ static bool isFromExpansionOfMacro(SourceFile *sourceFile, MacroDecl *macro) {
|
||||
// in it.
|
||||
if (expansionDecl->getMacro().getFullName() == macro->getName())
|
||||
return true;
|
||||
} else if (auto *macroAttr = sourceFile->getAttachedMacroAttribute()) {
|
||||
auto *decl = expansion.dyn_cast<Decl *>();
|
||||
auto &ctx = decl->getASTContext();
|
||||
auto attrDecl = evaluateOrDefault(ctx.evaluator,
|
||||
CustomAttrDeclRequest{macroAttr, decl->getDeclContext()},
|
||||
nullptr);
|
||||
auto *macroDecl = attrDecl.dyn_cast<MacroDecl *>();
|
||||
if (!macroDecl)
|
||||
return false;
|
||||
|
||||
return macroDecl == macro;
|
||||
} else {
|
||||
llvm_unreachable("Unknown macro expansion node kind");
|
||||
}
|
||||
|
||||
@@ -3441,7 +3441,7 @@ StorageImplInfoRequest::evaluate(Evaluator &evaluator,
|
||||
}
|
||||
|
||||
// Check for an accessor macro.
|
||||
for (auto customAttrConst : storage->getSemanticAttrs().getAttributes<CustomAttr>()) {
|
||||
for (auto customAttrConst : storage->getAttrs().getAttributes<CustomAttr>()) {
|
||||
auto customAttr = const_cast<CustomAttr *>(customAttrConst);
|
||||
auto decl = evaluateOrDefault(
|
||||
evaluator,
|
||||
@@ -3457,8 +3457,8 @@ StorageImplInfoRequest::evaluate(Evaluator &evaluator,
|
||||
if (!macro)
|
||||
continue;
|
||||
|
||||
if (!macro->getMacroRoles().contains(MacroRole::Accessor))
|
||||
continue;
|
||||
// FIXME: Make sure it's an accessors macro. We're not currently parsing
|
||||
// this information in the @declaration attribute.
|
||||
|
||||
// Expand the accessors.
|
||||
expandAccessors(storage, customAttr, macro);
|
||||
|
||||
@@ -273,57 +273,3 @@ public struct WrapAllProperties: MemberAttributeMacro {
|
||||
return [propertyWrapperAttr]
|
||||
}
|
||||
}
|
||||
|
||||
public struct TypeWrapperMacro: MemberAttributeMacro {
|
||||
public static func expansion(
|
||||
of node: AttributeSyntax,
|
||||
attachedTo decl: DeclSyntax,
|
||||
annotating member: DeclSyntax,
|
||||
in context: inout MacroExpansionContext
|
||||
) throws -> [AttributeSyntax] {
|
||||
guard let varDecl = member.as(VariableDeclSyntax.self),
|
||||
let binding = varDecl.bindings.first,
|
||||
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier,
|
||||
binding.accessor == nil
|
||||
else {
|
||||
return []
|
||||
}
|
||||
|
||||
if identifier.text == "_storage" {
|
||||
return []
|
||||
}
|
||||
|
||||
let customAttr = AttributeSyntax(
|
||||
attributeName: SimpleTypeIdentifierSyntax(
|
||||
name: .identifier("accessViaStorage")
|
||||
)
|
||||
)
|
||||
|
||||
return [customAttr]
|
||||
}
|
||||
}
|
||||
|
||||
public struct AccessViaStorageMacro: AccessorDeclarationMacro {
|
||||
public static func expansion(
|
||||
of node: AttributeSyntax,
|
||||
attachedTo declaration: DeclSyntax,
|
||||
in context: inout MacroExpansionContext
|
||||
) throws -> [AccessorDeclSyntax] {
|
||||
guard let varDecl = declaration.as(VariableDeclSyntax.self),
|
||||
let binding = varDecl.bindings.first,
|
||||
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier,
|
||||
binding.accessor == nil
|
||||
else {
|
||||
return []
|
||||
}
|
||||
|
||||
if identifier.text == "_storage" {
|
||||
return []
|
||||
}
|
||||
|
||||
return [
|
||||
"get { _storage.\(identifier) }",
|
||||
"set { _storage.\(identifier) = newValue }",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
|
||||
// RUNx: %target-swift-frontend -dump-ast -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser 2>&1 | %FileCheck --check-prefix CHECK-AST %s
|
||||
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5
|
||||
// RUN: %target-build-swift -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser -swift-version 5
|
||||
// RUN: %target-run %t/main | %FileCheck %s
|
||||
// REQUIRES: executable_test
|
||||
|
||||
// FIXME: Swift parser is not enabled on Linux CI yet.
|
||||
// REQUIRES: OS=macosx
|
||||
|
||||
@attached(memberAttributes) macro myTypeWrapper() = #externalMacro(module: "MacroDefinition", type: "TypeWrapperMacro")
|
||||
@attached(accessor) macro accessViaStorage() = #externalMacro(module: "MacroDefinition", type: "AccessViaStorageMacro")
|
||||
|
||||
struct _Storage {
|
||||
var x: Int = 0 {
|
||||
willSet { print("setting \(newValue)") }
|
||||
}
|
||||
var y: Int = 0 {
|
||||
willSet { print("setting \(newValue)") }
|
||||
}
|
||||
}
|
||||
|
||||
@myTypeWrapper
|
||||
struct S {
|
||||
var _storage = _Storage()
|
||||
|
||||
var x: Int
|
||||
var y: Int
|
||||
}
|
||||
|
||||
var s = S()
|
||||
|
||||
// CHECK: setting 10
|
||||
s.x = 10
|
||||
|
||||
// CHECK: setting 100
|
||||
s.y = 100
|
||||
Reference in New Issue
Block a user