Skip to content

Commit

Permalink
Update to Swift-Syntax 6
Browse files Browse the repository at this point in the history
  • Loading branch information
rauhul committed Sep 24, 2024
1 parent ccf9a40 commit 930c52f
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 102 deletions.
7 changes: 4 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "3cf0366a7e5a934f83dca0775b705ecd50d61bd0dde967aa0e5a789be7683282",
"pins" : [
{
"identity" : "swift-argument-parser",
Expand All @@ -14,10 +15,10 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
"version" : "600.0.0"
}
}
],
"version" : 2
"version" : 3
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let package = Package(
from: "1.4.0"),
.package(
url: "https://github.com/swiftlang/swift-syntax.git",
from: "509.0.2"),
from: "600.0.0"),
],
targets: [
// MMIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

struct BitFieldTypeProjection {
Expand Down
1 change: 0 additions & 1 deletion Sources/MMIOMacros/Macros/BitFieldMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

// @BaseName(bits: 3..<4, 0..<1, as: Swift.Bool.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension BitFieldDescription {
leftOperand: IntegerLiteralExprSyntax(clampedRange.lowerBound),
operator: BinaryOperatorExprSyntax(operator: .binaryOperator("..<")),
rightOperand: IntegerLiteralExprSyntax(clampedRange.upperBound + 1))
guard let expression = infix.as(ExprSyntax.self) else {
guard let expression = ExprSyntax(infix) else {
preconditionFailure("InfixOperatorExprSyntax must be an ExprSyntax")
}
return expression
Expand Down
4 changes: 0 additions & 4 deletions Sources/MMIOMacros/Macros/RegisterBlockMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

public struct RegisterBlockMacro {}
Expand All @@ -35,9 +34,6 @@ extension RegisterBlockMacro: MMIOMemberMacro {
providingMembersOf declaration: some DeclGroupSyntax,
in context: MacroContext<Self, some MacroExpansionContext>
) throws -> [DeclSyntax] {
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2366
// swift-format-ignore: NeverForceUnwrap
let declaration = declaration as! DeclSyntaxProtocol
// Can only applied to structs.
let structDecl = try declaration.requireAs(StructDeclSyntax.self, context)

Expand Down
1 change: 0 additions & 1 deletion Sources/MMIOMacros/Macros/RegisterBlockMemberMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

protocol RegisterBlockMemberMacro: ParsableMacro {}
Expand Down
4 changes: 0 additions & 4 deletions Sources/MMIOMacros/Macros/RegisterMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

public struct RegisterMacro {
Expand Down Expand Up @@ -43,9 +42,6 @@ extension RegisterMacro: MMIOMemberMacro {
providingMembersOf declaration: some DeclGroupSyntax,
in context: MacroContext<Self, some MacroExpansionContext>
) throws -> [DeclSyntax] {
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2366
// swift-format-ignore: NeverForceUnwrap
let declaration = declaration as! DeclSyntaxProtocol
// Can only applied to structs.
let structDecl = try declaration.requireAs(StructDeclSyntax.self, context)
let accessLevel = structDecl.accessLevel?.trimmed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

extension PatternBindingSyntax {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

extension VariableDeclSyntax {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros

struct MatchingAttributeAndMacro {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ final class ExpressibleByExprSyntaxTests: XCTestCase {

func test_bitRange() throws {
// UnboundedRange_
let unboundedRange = DeclReferenceExprSyntax(
let unboundedRange = ExprSyntax(DeclReferenceExprSyntax(
baseName: .binaryOperator("...")
).as(ExprSyntax.self)!
))!
XCTAssertParse(expression: unboundedRange, expected: "(-∞, +∞)" as BitRange)
// PartialRangeThrough
XCTAssertParse(expression: "...0", expected: "(-∞, 0]" as BitRange)
Expand Down
31 changes: 12 additions & 19 deletions Tests/MMIOMacrosTests/Macros/BitFieldMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

#if canImport(MMIOMacros)
@preconcurrency import SwiftSyntax
import SwiftSyntax
import SwiftSyntaxMacros
import SwiftSyntaxMacrosTestSupport
import XCTest
Expand Down Expand Up @@ -86,17 +86,15 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.expectedBindingSpecifier(.var).message,
line: 1,
column: 20,
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2213
highlight: "inout ",
highlights: ["inout"],
fixIts: [
.init(message: "Replace 'inout' with 'var'")
]),
.init(
message: ErrorDiagnostic.expectedBindingSpecifier(.var).message,
line: 2,
column: 20,
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2213
highlight: "let ",
highlights: ["let"],
fixIts: [
.init(message: "Replace 'let' with 'var'")
]),
Expand All @@ -106,12 +104,7 @@ final class BitFieldMacroTests: XCTestCase {
}

func test_binding_noMultiple() {
let message = """
swift-syntax applies macros syntactically and there is no way to \
represent a variable declaration with multiple bindings that have \
accessors syntactically. While the compiler allows this expansion, \
swift-syntax cannot represent it and thus disallows it.
"""
let message = "accessor macro can only be applied to a single variable"
assertMacroExpansion(
"""
@Test(bits: 0..<1) var a, b: Int
Expand Down Expand Up @@ -142,7 +135,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingIdentifier().message,
line: 1,
column: 24,
highlight: "_")
highlights: ["_"])
],
macros: Self.macros,
indentationWidth: Self.indentationWidth)
Expand All @@ -161,7 +154,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingIdentifier().message,
line: 1,
column: 24,
highlight: "(a, b)")
highlights: ["(a, b)"])
],
macros: Self.macros,
indentationWidth: Self.indentationWidth)
Expand All @@ -180,7 +173,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingType().message,
line: 1,
column: 24,
highlight: "v",
highlights: ["v"],
fixIts: [
.init(message: "Insert explicit type annotation")
])
Expand All @@ -202,7 +195,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingType().message,
line: 1,
column: 27,
highlight: "_",
highlights: ["_"],
fixIts: [
.init(message: "Insert explicit type annotation")
])
Expand All @@ -225,7 +218,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingType().message,
line: 1,
column: 27,
highlight: "Int?")
highlights: ["Int?"])
],
macros: Self.macros,
indentationWidth: Self.indentationWidth)
Expand All @@ -244,7 +237,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingType().message,
line: 1,
column: 27,
highlight: "[Int]")
highlights: ["[Int]"])
],
macros: Self.macros,
indentationWidth: Self.indentationWidth)
Expand All @@ -263,7 +256,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.unexpectedBindingType().message,
line: 1,
column: 27,
highlight: "(Int, Int)")
highlights: ["(Int, Int)"])
],
macros: Self.macros,
indentationWidth: Self.indentationWidth)
Expand Down Expand Up @@ -314,7 +307,7 @@ final class BitFieldMacroTests: XCTestCase {
message: ErrorDiagnostic.expectedStoredProperty().message,
line: 1,
column: 31,
highlight: "{}",
highlights: ["{}"],
fixIts: [
.init(message: "Remove accessor block")
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

#if canImport(MMIOMacros)
@preconcurrency import SwiftSyntax
import SwiftSyntax
import SwiftSyntaxMacros
import SwiftSyntaxMacrosTestSupport
import XCTest
Expand Down
17 changes: 7 additions & 10 deletions Tests/MMIOMacrosTests/Macros/RegisterBlockMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

#if canImport(MMIOMacros)
@preconcurrency import SwiftSyntax
import SwiftSyntax
import SwiftSyntaxMacros
import SwiftSyntaxMacrosTestSupport
import XCTest
Expand Down Expand Up @@ -42,20 +42,17 @@ final class RegisterBlockMacroTests: XCTestCase {
message: ErrorDiagnostic.expectedDecl(StructDeclSyntax.self).message,
line: 1,
column: 16,
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2213
highlight: "actor "),
highlights: ["actor"]),
.init(
message: ErrorDiagnostic.expectedDecl(StructDeclSyntax.self).message,
line: 2,
column: 16,
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2213
highlight: "class "),
highlights: ["class"]),
.init(
message: ErrorDiagnostic.expectedDecl(StructDeclSyntax.self).message,
line: 3,
column: 16,
// FIXME: https://github.com/swiftlang/swift-syntax/pull/2213
highlight: "enum "),
highlights: ["enum"]),
],
macros: Self.macros,
indentationWidth: Self.indentationWidth)
Expand Down Expand Up @@ -101,7 +98,7 @@ final class RegisterBlockMacroTests: XCTestCase {
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(registerBlockMemberMacros).message,
line: 3,
column: 3,
highlight: "var v1: Int",
highlights: ["var v1: Int"],
fixIts: [
.init(message: "Insert '@RegisterBlock(offset:)' macro"),
.init(message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
Expand All @@ -111,7 +108,7 @@ final class RegisterBlockMacroTests: XCTestCase {
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(registerBlockMemberMacros).message,
line: 4,
column: 3,
highlight: "@OtherAttribute var v2: Int",
highlights: ["@OtherAttribute var v2: Int"],
fixIts: [
.init(message: "Insert '@RegisterBlock(offset:)' macro"),
.init(message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
Expand All @@ -121,7 +118,7 @@ final class RegisterBlockMacroTests: XCTestCase {
ErrorDiagnostic.expectedMemberAnnotatedWithMacro(registerBlockMemberMacros).message,
line: 5,
column: 3,
highlight: "var v3: Int { willSet {} }",
highlights: ["var v3: Int { willSet {} }"],
fixIts: [
.init(message: "Insert '@RegisterBlock(offset:)' macro"),
.init(message: "Insert '@RegisterBlock(offset:stride:count:)' macro"),
Expand Down
Loading

0 comments on commit 930c52f

Please sign in to comment.