Skip to content

[5.9] Companion of cherry-picking multiple SwiftSyntax PRs to release/5.9 #65239

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 3 commits into from
Apr 22, 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
4 changes: 2 additions & 2 deletions lib/ASTGen/Sources/ASTGen/Decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension ASTGenVisitor {
declContext = out.declContext
defer { declContext = oldDeclContext }

node.members.members
node.memberBlock.members
.map { self.visit($0).rawValue }
.withBridgedArrayRef { ref in
NominalTypeDecl_setMembers(out.nominalDecl, ref)
Expand All @@ -60,7 +60,7 @@ extension ASTGenVisitor {
declContext = out.declContext
defer { declContext = oldDeclContext }

node.members.members
node.memberBlock.members
.map { self.visit($0).rawValue }
.withBridgedArrayRef { ref in
NominalTypeDecl_setMembers(out.nominalDecl, ref)
Expand Down
13 changes: 12 additions & 1 deletion lib/ASTGen/Sources/ASTGen/Generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@ extension ASTGenVisitor {
let nameLoc = self.base.advanced(by: node.name.position.utf8Offset).raw
let eachLoc = node.each.map { self.base.advanced(by: $0.position.utf8Offset).raw }

var genericParameterIndex: Int?
for (index, sibling) in (node.parent?.as(GenericParameterListSyntax.self) ?? []).enumerated() {
if sibling == node {
genericParameterIndex = index
break
}
}
guard let genericParameterIndex = genericParameterIndex else {
preconditionFailure("Node not part of the parent?")
}

return .decl(
GenericTypeParamDecl_create(
self.ctx, self.declContext, name, nameLoc, eachLoc, node.indexInParent / 2,
self.ctx, self.declContext, name, nameLoc, eachLoc, genericParameterIndex,
eachLoc != nil))
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ASTGen/Sources/ASTGen/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func expandFreestandingMacroInProcess(
guard let parentExpansion = macroSyntax.asProtocol(
FreestandingMacroExpansionSyntax.self
) else {
print("not on a macro expansion node: \(macroSyntax.recursiveDescription)")
print("not on a macro expansion node: \(macroSyntax.debugDescription)")
return nil
}

Expand Down Expand Up @@ -671,7 +671,7 @@ private func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
currentSyntax = parentSyntax
}

print("unable to find node: \(token.recursiveDescription)")
print("unable to find node: \(token.debugDescription)")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Macros/Sources/ObservationMacros/ObservableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct ObservableMacro: MemberMacro, MemberAttributeMacro, ConformanceMac
"""

let memberList = MemberDeclListSyntax(
declaration.members.members.filter {
declaration.memberBlock.members.filter {
$0.decl.isObservableStoredProperty
}
)
Expand Down
4 changes: 2 additions & 2 deletions lib/Macros/Sources/SwiftMacros/OptionSetMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public struct OptionSetMacro {
}

// Find the option enum within the struct.
let optionsEnums: [EnumDeclSyntax] = decl.members.members.compactMap({ member in
let optionsEnums: [EnumDeclSyntax] = decl.memberBlock.members.compactMap({ member in
if let enumDecl = member.decl.as(EnumDeclSyntax.self),
enumDecl.identifier.text == optionsEnumName {
return enumDecl
Expand Down Expand Up @@ -163,7 +163,7 @@ extension OptionSetMacro: MemberMacro {

// Find all of the case elements.
var caseElements: [EnumCaseElementSyntax] = []
for member in optionsEnum.members.members {
for member in optionsEnum.memberBlock.members {
if let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) {
caseElements.append(contentsOf: caseDecl.elements)
}
Expand Down
6 changes: 3 additions & 3 deletions test/Macros/Inputs/syntax_macro_definitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public enum AddBlocker: ExpressionMacro {
ExprSyntax(
binOp.with(
\.operatorToken,
binOp.operatorToken.withKind(.binaryOperator("-"))
binOp.operatorToken.with(\.tokenKind, .binaryOperator("-"))
)
)
)
Expand Down Expand Up @@ -681,7 +681,7 @@ extension DeclGroupSyntax {
/// Enumerate the stored properties that syntactically occur in this
/// declaration.
func storedProperties() -> [VariableDeclSyntax] {
return members.members.compactMap { member in
return memberBlock.members.compactMap { member in
guard let variable = member.decl.as(VariableDeclSyntax.self),
variable.isStoredProperty else {
return nil
Expand Down Expand Up @@ -1020,7 +1020,7 @@ public struct ObservableMacro: MemberMacro, MemberAttributeMacro {
"""

let memberList = MemberDeclListSyntax(
declaration.members.members.filter {
declaration.memberBlock.members.filter {
$0.decl.isObservableStoredProperty
}
)
Expand Down