Skip to content

Commit c06eccc

Browse files
authored
Merge pull request #63062 from eeckstein/revert-sema-change
Revert "[Macros] Enable composition of member attribute macros and accessor macros."
2 parents e405b50 + bfa14e6 commit c06eccc

File tree

6 files changed

+3
-126
lines changed

6 files changed

+3
-126
lines changed

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,6 @@ class SourceFile final : public FileUnit {
500500
/// the \c SourceFileKind is \c MacroExpansion.
501501
ASTNode getMacroExpansion() const;
502502

503-
/// For source files created to hold the source code created by expanding
504-
/// an attached macro, this is the custom attribute that describes the macro
505-
/// expansion.
506-
///
507-
/// The source location of this attribute is the place in the source that
508-
/// triggered the creation of the macro expansion whose resulting source
509-
/// code is in this source file. This will only produce a non-null value when
510-
/// the \c SourceFileKind is \c MacroExpansion , and the macro is an attached
511-
/// macro.
512-
CustomAttr *getAttachedMacroAttribute() const;
513-
514503
/// When this source file is enclosed within another source file, for example
515504
/// because it describes a macro expansion, return the source file it was
516505
/// enclosed in.

lib/AST/Module.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -887,15 +887,6 @@ ASTNode SourceFile::getMacroExpansion() const {
887887
return ASTNode::getFromOpaqueValue(genInfo.astNode);
888888
}
889889

890-
CustomAttr *SourceFile::getAttachedMacroAttribute() const {
891-
if (Kind != SourceFileKind::MacroExpansion)
892-
return nullptr;
893-
894-
auto genInfo =
895-
*getASTContext().SourceMgr.getGeneratedSourceInfo(*getBufferID());
896-
return genInfo.attachedMacroCustomAttr;
897-
}
898-
899890
SourceFile *SourceFile::getEnclosingSourceFile() const {
900891
auto macroExpansion = getMacroExpansion();
901892
if (!macroExpansion)

lib/Sema/TypeCheckMacros.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,6 @@ static bool isFromExpansionOfMacro(SourceFile *sourceFile, MacroDecl *macro) {
326326
// in it.
327327
if (expansionDecl->getMacro().getFullName() == macro->getName())
328328
return true;
329-
} else if (auto *macroAttr = sourceFile->getAttachedMacroAttribute()) {
330-
auto *decl = expansion.dyn_cast<Decl *>();
331-
auto &ctx = decl->getASTContext();
332-
auto attrDecl = evaluateOrDefault(ctx.evaluator,
333-
CustomAttrDeclRequest{macroAttr, decl->getDeclContext()},
334-
nullptr);
335-
auto *macroDecl = attrDecl.dyn_cast<MacroDecl *>();
336-
if (!macroDecl)
337-
return false;
338-
339-
return macroDecl == macro;
340329
} else {
341330
llvm_unreachable("Unknown macro expansion node kind");
342331
}

lib/Sema/TypeCheckStorage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,7 +3441,7 @@ StorageImplInfoRequest::evaluate(Evaluator &evaluator,
34413441
}
34423442

34433443
// Check for an accessor macro.
3444-
for (auto customAttrConst : storage->getSemanticAttrs().getAttributes<CustomAttr>()) {
3444+
for (auto customAttrConst : storage->getAttrs().getAttributes<CustomAttr>()) {
34453445
auto customAttr = const_cast<CustomAttr *>(customAttrConst);
34463446
auto decl = evaluateOrDefault(
34473447
evaluator,
@@ -3457,8 +3457,8 @@ StorageImplInfoRequest::evaluate(Evaluator &evaluator,
34573457
if (!macro)
34583458
continue;
34593459

3460-
if (!macro->getMacroRoles().contains(MacroRole::Accessor))
3461-
continue;
3460+
// FIXME: Make sure it's an accessors macro. We're not currently parsing
3461+
// this information in the @declaration attribute.
34623462

34633463
// Expand the accessors.
34643464
expandAccessors(storage, customAttr, macro);

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -273,57 +273,3 @@ public struct WrapAllProperties: MemberAttributeMacro {
273273
return [propertyWrapperAttr]
274274
}
275275
}
276-
277-
public struct TypeWrapperMacro: MemberAttributeMacro {
278-
public static func expansion(
279-
of node: AttributeSyntax,
280-
attachedTo decl: DeclSyntax,
281-
annotating member: DeclSyntax,
282-
in context: inout MacroExpansionContext
283-
) throws -> [AttributeSyntax] {
284-
guard let varDecl = member.as(VariableDeclSyntax.self),
285-
let binding = varDecl.bindings.first,
286-
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier,
287-
binding.accessor == nil
288-
else {
289-
return []
290-
}
291-
292-
if identifier.text == "_storage" {
293-
return []
294-
}
295-
296-
let customAttr = AttributeSyntax(
297-
attributeName: SimpleTypeIdentifierSyntax(
298-
name: .identifier("accessViaStorage")
299-
)
300-
)
301-
302-
return [customAttr]
303-
}
304-
}
305-
306-
public struct AccessViaStorageMacro: AccessorDeclarationMacro {
307-
public static func expansion(
308-
of node: AttributeSyntax,
309-
attachedTo declaration: DeclSyntax,
310-
in context: inout MacroExpansionContext
311-
) throws -> [AccessorDeclSyntax] {
312-
guard let varDecl = declaration.as(VariableDeclSyntax.self),
313-
let binding = varDecl.bindings.first,
314-
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier,
315-
binding.accessor == nil
316-
else {
317-
return []
318-
}
319-
320-
if identifier.text == "_storage" {
321-
return []
322-
}
323-
324-
return [
325-
"get { _storage.\(identifier) }",
326-
"set { _storage.\(identifier) = newValue }",
327-
]
328-
}
329-
}

test/Macros/composed_macro.swift

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)