From e839d864097e3430f2e8cc91eeed71bbd9604a9c Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 8 Sep 2025 14:20:06 -0700 Subject: [PATCH 1/2] Fix Swift 6.0 support Support regressed when the macro started introducing `nonisolated` requirements for default main actor isolation in #128. --- .../StructuredQueriesMacros/TableMacro.swift | 20 +- .../StructuredQueriesTests/SelectTests.swift | 172 +++++++++--------- 2 files changed, 100 insertions(+), 92 deletions(-) diff --git a/Sources/StructuredQueriesMacros/TableMacro.swift b/Sources/StructuredQueriesMacros/TableMacro.swift index c30cabe9..99bfb9e9 100644 --- a/Sources/StructuredQueriesMacros/TableMacro.swift +++ b/Sources/StructuredQueriesMacros/TableMacro.swift @@ -4,6 +4,12 @@ import SwiftSyntax import SwiftSyntaxBuilder import SwiftSyntaxMacros +#if compiler(>=6.1) + let nonisolated: TokenSyntax? = .keyword(.nonisolated, trailingTrivia: .space) +#else + let nonisolated: TokenSyntax? = nil +#endif + public enum TableMacro {} extension TableMacro: ExtensionMacro { @@ -416,7 +422,7 @@ extension TableMacro: ExtensionMacro { if let draftTableType { initFromOther = """ - public nonisolated init(_ other: \(draftTableType)) { + public \(nonisolated)init(_ other: \(draftTableType)) { \(allColumns.map { "self.\($0) = other.\($0)" as ExprSyntax }, separator: "\n") } """ @@ -571,7 +577,7 @@ extension TableMacro: ExtensionMacro { if let schemaName { letSchemaName = """ - public nonisolated static let schemaName: Swift.String? = \(schemaName) + public \(nonisolated)static let schemaName: Swift.String? = \(schemaName) """ } var initDecoder: DeclSyntax? @@ -589,7 +595,7 @@ extension TableMacro: ExtensionMacro { } else { initDecoder = """ - public nonisolated init(decoder: inout some \(moduleName).QueryDecoder) throws { + public \(nonisolated)init(decoder: inout some \(moduleName).QueryDecoder) throws { \(raw: (decodings + decodingUnwrappings + decodingAssignments).joined(separator: "\n")) } """ @@ -598,11 +604,11 @@ extension TableMacro: ExtensionMacro { return [ DeclSyntax( """ - \(declaration.attributes.availability)nonisolated extension \(type)\ + \(declaration.attributes.availability)\(nonisolated)extension \(type)\ \(conformances.isEmpty ? "" : ": \(conformances, separator: ", ")") {\ \(statics, separator: "\n") - public nonisolated static var columns: TableColumns { TableColumns() } - public nonisolated static var tableName: String { \(tableName) }\(letSchemaName)\(initDecoder)\(initFromOther) + public \(nonisolated)static var columns: TableColumns { TableColumns() } + public \(nonisolated)static var tableName: String { \(tableName) }\(letSchemaName)\(initDecoder)\(initFromOther) } """ ) @@ -1029,7 +1035,7 @@ extension TableMacro: MemberMacro { return [ """ - public nonisolated struct TableColumns: \(schemaConformances, separator: ", ") { + public \(nonisolated)struct TableColumns: \(schemaConformances, separator: ", ") { public typealias QueryValue = \(type.trimmed) \(columnsProperties, separator: "\n") public static var allColumns: [any \(moduleName).TableColumnExpression] { \ diff --git a/Tests/StructuredQueriesTests/SelectTests.swift b/Tests/StructuredQueriesTests/SelectTests.swift index 7fff7733..639a53ea 100644 --- a/Tests/StructuredQueriesTests/SelectTests.swift +++ b/Tests/StructuredQueriesTests/SelectTests.swift @@ -1247,92 +1247,94 @@ extension SnapshotTests { } } - @Test func reusableStaticHelperOnDraft() { - assertQuery( - Reminder.Draft.incomplete.select(\.id) - ) { - """ - SELECT "reminders"."id" - FROM "reminders" - WHERE NOT ("reminders"."isCompleted") - """ - } results: { - """ - ┌───┐ - │ 1 │ - │ 2 │ - │ 3 │ - │ 5 │ - │ 6 │ - │ 8 │ - │ 9 │ - └───┘ - """ - } - assertQuery( - Reminder.Draft.where { _ in true }.incomplete.select(\.id) - ) { - """ - SELECT "reminders"."id" - FROM "reminders" - WHERE 1 AND NOT ("reminders"."isCompleted") - """ - } results: { - """ - ┌───┐ - │ 1 │ - │ 2 │ - │ 3 │ - │ 5 │ - │ 6 │ - │ 8 │ - │ 9 │ - └───┘ - """ - } - assertQuery( - Reminder.Draft.select(\.id).incomplete - ) { - """ - SELECT "reminders"."id" - FROM "reminders" - WHERE NOT ("reminders"."isCompleted") - """ - } results: { - """ - ┌───┐ - │ 1 │ - │ 2 │ - │ 3 │ - │ 5 │ - │ 6 │ - │ 8 │ - │ 9 │ - └───┘ - """ - } - assertQuery( - Reminder.Draft.all.incomplete.select(\.id) - ) { - """ - SELECT "reminders"."id" - FROM "reminders" - WHERE NOT ("reminders"."isCompleted") - """ - } results: { - """ - ┌───┐ - │ 1 │ - │ 2 │ - │ 3 │ - │ 5 │ - │ 6 │ - │ 8 │ - │ 9 │ - └───┘ - """ + #if swift(>=6.1) + @Test func reusableStaticHelperOnDraft() { + assertQuery( + Reminder.Draft.incomplete.select(\.id) + ) { + """ + SELECT "reminders"."id" + FROM "reminders" + WHERE NOT ("reminders"."isCompleted") + """ + } results: { + """ + ┌───┐ + │ 1 │ + │ 2 │ + │ 3 │ + │ 5 │ + │ 6 │ + │ 8 │ + │ 9 │ + └───┘ + """ + } + assertQuery( + Reminder.Draft.where { _ in true }.incomplete.select(\.id) + ) { + """ + SELECT "reminders"."id" + FROM "reminders" + WHERE 1 AND NOT ("reminders"."isCompleted") + """ + } results: { + """ + ┌───┐ + │ 1 │ + │ 2 │ + │ 3 │ + │ 5 │ + │ 6 │ + │ 8 │ + │ 9 │ + └───┘ + """ + } + assertQuery( + Reminder.Draft.select(\.id).incomplete + ) { + """ + SELECT "reminders"."id" + FROM "reminders" + WHERE NOT ("reminders"."isCompleted") + """ + } results: { + """ + ┌───┐ + │ 1 │ + │ 2 │ + │ 3 │ + │ 5 │ + │ 6 │ + │ 8 │ + │ 9 │ + └───┘ + """ + } + assertQuery( + Reminder.Draft.all.incomplete.select(\.id) + ) { + """ + SELECT "reminders"."id" + FROM "reminders" + WHERE NOT ("reminders"."isCompleted") + """ + } results: { + """ + ┌───┐ + │ 1 │ + │ 2 │ + │ 3 │ + │ 5 │ + │ 6 │ + │ 8 │ + │ 9 │ + └───┘ + """ + } } - } + #endif @Test func reusableColumnHelperOnDraft() { assertQuery( From f194ce2be10e34a761baf64b8652f96b7b80366d Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 8 Sep 2025 14:23:03 -0700 Subject: [PATCH 2/2] wip --- Sources/StructuredQueriesMacros/Internal/Nonisolated.swift | 7 +++++++ Sources/StructuredQueriesMacros/TableMacro.swift | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 Sources/StructuredQueriesMacros/Internal/Nonisolated.swift diff --git a/Sources/StructuredQueriesMacros/Internal/Nonisolated.swift b/Sources/StructuredQueriesMacros/Internal/Nonisolated.swift new file mode 100644 index 00000000..34418215 --- /dev/null +++ b/Sources/StructuredQueriesMacros/Internal/Nonisolated.swift @@ -0,0 +1,7 @@ +import SwiftSyntax + +#if compiler(>=6.1) + let nonisolated: TokenSyntax? = .keyword(.nonisolated, trailingTrivia: .space) +#else + let nonisolated: TokenSyntax? = nil +#endif diff --git a/Sources/StructuredQueriesMacros/TableMacro.swift b/Sources/StructuredQueriesMacros/TableMacro.swift index 99bfb9e9..60cd021d 100644 --- a/Sources/StructuredQueriesMacros/TableMacro.swift +++ b/Sources/StructuredQueriesMacros/TableMacro.swift @@ -4,12 +4,6 @@ import SwiftSyntax import SwiftSyntaxBuilder import SwiftSyntaxMacros -#if compiler(>=6.1) - let nonisolated: TokenSyntax? = .keyword(.nonisolated, trailingTrivia: .space) -#else - let nonisolated: TokenSyntax? = nil -#endif - public enum TableMacro {} extension TableMacro: ExtensionMacro {