Skip to content

Commit 9b9aaae

Browse files
authored
Fix Swift 6.0 support (#165)
* Fix Swift 6.0 support Support regressed when the macro started introducing `nonisolated` requirements for default main actor isolation in #128. * wip
1 parent 243b7c9 commit 9b9aaae

File tree

3 files changed

+101
-92
lines changed

3 files changed

+101
-92
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import SwiftSyntax
2+
3+
#if compiler(>=6.1)
4+
let nonisolated: TokenSyntax? = .keyword(.nonisolated, trailingTrivia: .space)
5+
#else
6+
let nonisolated: TokenSyntax? = nil
7+
#endif

Sources/StructuredQueriesMacros/TableMacro.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ extension TableMacro: ExtensionMacro {
416416
if let draftTableType {
417417
initFromOther = """
418418
419-
public nonisolated init(_ other: \(draftTableType)) {
419+
public \(nonisolated)init(_ other: \(draftTableType)) {
420420
\(allColumns.map { "self.\($0) = other.\($0)" as ExprSyntax }, separator: "\n")
421421
}
422422
"""
@@ -571,7 +571,7 @@ extension TableMacro: ExtensionMacro {
571571
if let schemaName {
572572
letSchemaName = """
573573
574-
public nonisolated static let schemaName: Swift.String? = \(schemaName)
574+
public \(nonisolated)static let schemaName: Swift.String? = \(schemaName)
575575
"""
576576
}
577577
var initDecoder: DeclSyntax?
@@ -589,7 +589,7 @@ extension TableMacro: ExtensionMacro {
589589
} else {
590590
initDecoder = """
591591
592-
public nonisolated init(decoder: inout some \(moduleName).QueryDecoder) throws {
592+
public \(nonisolated)init(decoder: inout some \(moduleName).QueryDecoder) throws {
593593
\(raw: (decodings + decodingUnwrappings + decodingAssignments).joined(separator: "\n"))
594594
}
595595
"""
@@ -598,11 +598,11 @@ extension TableMacro: ExtensionMacro {
598598
return [
599599
DeclSyntax(
600600
"""
601-
\(declaration.attributes.availability)nonisolated extension \(type)\
601+
\(declaration.attributes.availability)\(nonisolated)extension \(type)\
602602
\(conformances.isEmpty ? "" : ": \(conformances, separator: ", ")") {\
603603
\(statics, separator: "\n")
604-
public nonisolated static var columns: TableColumns { TableColumns() }
605-
public nonisolated static var tableName: String { \(tableName) }\(letSchemaName)\(initDecoder)\(initFromOther)
604+
public \(nonisolated)static var columns: TableColumns { TableColumns() }
605+
public \(nonisolated)static var tableName: String { \(tableName) }\(letSchemaName)\(initDecoder)\(initFromOther)
606606
}
607607
"""
608608
)
@@ -1029,7 +1029,7 @@ extension TableMacro: MemberMacro {
10291029

10301030
return [
10311031
"""
1032-
public nonisolated struct TableColumns: \(schemaConformances, separator: ", ") {
1032+
public \(nonisolated)struct TableColumns: \(schemaConformances, separator: ", ") {
10331033
public typealias QueryValue = \(type.trimmed)
10341034
\(columnsProperties, separator: "\n")
10351035
public static var allColumns: [any \(moduleName).TableColumnExpression] { \

Tests/StructuredQueriesTests/SelectTests.swift

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,92 +1247,94 @@ extension SnapshotTests {
12471247
}
12481248
}
12491249

1250-
@Test func reusableStaticHelperOnDraft() {
1251-
assertQuery(
1252-
Reminder.Draft.incomplete.select(\.id)
1253-
) {
1254-
"""
1255-
SELECT "reminders"."id"
1256-
FROM "reminders"
1257-
WHERE NOT ("reminders"."isCompleted")
1258-
"""
1259-
} results: {
1260-
"""
1261-
┌───┐
1262-
│ 1 │
1263-
│ 2 │
1264-
│ 3 │
1265-
│ 5 │
1266-
│ 6 │
1267-
│ 8 │
1268-
│ 9 │
1269-
└───┘
1270-
"""
1271-
}
1272-
assertQuery(
1273-
Reminder.Draft.where { _ in true }.incomplete.select(\.id)
1274-
) {
1275-
"""
1276-
SELECT "reminders"."id"
1277-
FROM "reminders"
1278-
WHERE 1 AND NOT ("reminders"."isCompleted")
1279-
"""
1280-
} results: {
1281-
"""
1282-
┌───┐
1283-
│ 1 │
1284-
│ 2 │
1285-
│ 3 │
1286-
│ 5 │
1287-
│ 6 │
1288-
│ 8 │
1289-
│ 9 │
1290-
└───┘
1291-
"""
1292-
}
1293-
assertQuery(
1294-
Reminder.Draft.select(\.id).incomplete
1295-
) {
1296-
"""
1297-
SELECT "reminders"."id"
1298-
FROM "reminders"
1299-
WHERE NOT ("reminders"."isCompleted")
1300-
"""
1301-
} results: {
1302-
"""
1303-
┌───┐
1304-
│ 1 │
1305-
│ 2 │
1306-
│ 3 │
1307-
│ 5 │
1308-
│ 6 │
1309-
│ 8 │
1310-
│ 9 │
1311-
└───┘
1312-
"""
1313-
}
1314-
assertQuery(
1315-
Reminder.Draft.all.incomplete.select(\.id)
1316-
) {
1317-
"""
1318-
SELECT "reminders"."id"
1319-
FROM "reminders"
1320-
WHERE NOT ("reminders"."isCompleted")
1321-
"""
1322-
} results: {
1323-
"""
1324-
┌───┐
1325-
│ 1 │
1326-
│ 2 │
1327-
│ 3 │
1328-
│ 5 │
1329-
│ 6 │
1330-
│ 8 │
1331-
│ 9 │
1332-
└───┘
1333-
"""
1250+
#if swift(>=6.1)
1251+
@Test func reusableStaticHelperOnDraft() {
1252+
assertQuery(
1253+
Reminder.Draft.incomplete.select(\.id)
1254+
) {
1255+
"""
1256+
SELECT "reminders"."id"
1257+
FROM "reminders"
1258+
WHERE NOT ("reminders"."isCompleted")
1259+
"""
1260+
} results: {
1261+
"""
1262+
┌───┐
1263+
│ 1 │
1264+
│ 2 │
1265+
│ 3 │
1266+
│ 5 │
1267+
│ 6 │
1268+
│ 8 │
1269+
│ 9 │
1270+
└───┘
1271+
"""
1272+
}
1273+
assertQuery(
1274+
Reminder.Draft.where { _ in true }.incomplete.select(\.id)
1275+
) {
1276+
"""
1277+
SELECT "reminders"."id"
1278+
FROM "reminders"
1279+
WHERE 1 AND NOT ("reminders"."isCompleted")
1280+
"""
1281+
} results: {
1282+
"""
1283+
┌───┐
1284+
│ 1 │
1285+
│ 2 │
1286+
│ 3 │
1287+
│ 5 │
1288+
│ 6 │
1289+
│ 8 │
1290+
│ 9 │
1291+
└───┘
1292+
"""
1293+
}
1294+
assertQuery(
1295+
Reminder.Draft.select(\.id).incomplete
1296+
) {
1297+
"""
1298+
SELECT "reminders"."id"
1299+
FROM "reminders"
1300+
WHERE NOT ("reminders"."isCompleted")
1301+
"""
1302+
} results: {
1303+
"""
1304+
┌───┐
1305+
│ 1 │
1306+
│ 2 │
1307+
│ 3 │
1308+
│ 5 │
1309+
│ 6 │
1310+
│ 8 │
1311+
│ 9 │
1312+
└───┘
1313+
"""
1314+
}
1315+
assertQuery(
1316+
Reminder.Draft.all.incomplete.select(\.id)
1317+
) {
1318+
"""
1319+
SELECT "reminders"."id"
1320+
FROM "reminders"
1321+
WHERE NOT ("reminders"."isCompleted")
1322+
"""
1323+
} results: {
1324+
"""
1325+
┌───┐
1326+
│ 1 │
1327+
│ 2 │
1328+
│ 3 │
1329+
│ 5 │
1330+
│ 6 │
1331+
│ 8 │
1332+
│ 9 │
1333+
└───┘
1334+
"""
1335+
}
13341336
}
1335-
}
1337+
#endif
13361338

13371339
@Test func reusableColumnHelperOnDraft() {
13381340
assertQuery(

0 commit comments

Comments
 (0)