Skip to content

Commit 20ebf6c

Browse files
committed
Renamed coder to adapter
1 parent fd465c4 commit 20ebf6c

12 files changed

Lines changed: 177 additions & 163 deletions

Sources/Compiler/Gen/Language.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public protocol Language {
1414

1515
var boolName: String { get }
1616

17-
var builtinCoders: Set<String> { get }
17+
var builtinAdapters: Set<String> { get }
1818

1919
func queryTypeName(input: String, output: String) -> String
2020

@@ -27,7 +27,7 @@ public protocol Language {
2727
migrations: [String],
2828
tables: [GeneratedModel],
2929
queries: [(String?, [GeneratedQuery])],
30-
coders: [String]
30+
adapters: [String]
3131
) throws -> String
3232

3333
/// Function to generate a interpolation segment in a string
@@ -49,20 +49,20 @@ extension Language {
4949
) throws -> String {
5050
let values = try assemble(queries: queries, schema: schema)
5151

52-
// Get a list of all coders used. Right now we only have to look at the
52+
// Get a list of all adapters used. Right now we only have to look at the
5353
// tables since any output would inhereit the encoding of the source table.
54-
let coders: Set<String> = values.tables.reduce(into: []) { coders, table in
54+
let adapters: Set<String> = values.tables.reduce(into: []) { adapters, table in
5555
for field in table.fields.values {
56-
guard let coder = field.type.coder else { continue }
57-
coders.insert(coder)
56+
guard let adapter = field.type.adapter else { continue }
57+
adapters.insert(adapter)
5858
}
5959
}
6060

6161
return try file(
6262
migrations: migrations,
6363
tables: values.tables,
6464
queries: values.queries,
65-
coders: coders.subtracting(builtinCoders).sorted()
65+
adapters: adapters.subtracting(builtinAdapters).sorted()
6666
)
6767
}
6868

@@ -145,8 +145,8 @@ extension Language {
145145
result.append(.arrayStart(name: "input", elementName: "element"))
146146
result.append(contentsOf: bindings(for: values, index: &index, owner: "element"))
147147
result.append(.arrayEnd)
148-
case .encoded(_, _, let coder):
149-
result.append(.value(index: index, name: "input", owner: owner, coder: coder))
148+
case .encoded(_, _, let adapter):
149+
result.append(.value(index: index, name: "input", owner: owner, adapter: adapter))
150150
index += 1
151151
}
152152

@@ -174,7 +174,7 @@ extension Language {
174174
switch type {
175175
case let .nominal(name):
176176
return .builtin(builtinType(named: name))
177-
case let .alias(root, alias, coder):
177+
case let .alias(root, alias, adapter):
178178
let alias = switch alias {
179179
case .explicit(let e): e.description
180180
case .hint(let hint):
@@ -186,7 +186,7 @@ extension Language {
186186
return .encoded(
187187
generationType(for: root),
188188
alias: alias,
189-
coder: "\(coder?.description ?? alias)DatabaseValueCoder"
189+
adapter: "\(adapter?.description ?? alias)DatabaseValueAdapter"
190190
)
191191
case let .optional(type):
192192
return .optional(generationType(for: type))
@@ -342,7 +342,7 @@ public struct GeneratedQuery {
342342
let bindings: [Binding]
343343

344344
public enum Binding {
345-
case value(index: Int, name: String, owner: String? = nil, coder: String? = nil)
345+
case value(index: Int, name: String, owner: String? = nil, adapter: String? = nil)
346346
case arrayStart(name: String, elementName: String)
347347
case arrayEnd
348348
}
@@ -354,7 +354,7 @@ public enum GenerationType: Equatable {
354354
case model(GeneratedModel)
355355
indirect case optional(Self)
356356
indirect case array(Self)
357-
indirect case encoded(Self, alias: String, coder: String)
357+
indirect case encoded(Self, alias: String, adapter: String)
358358

359359
var model: GeneratedModel? {
360360
switch self {
@@ -366,12 +366,12 @@ public enum GenerationType: Equatable {
366366
}
367367
}
368368

369-
var coder: String? {
369+
var adapter: String? {
370370
switch self {
371371
case .void, .builtin, .model: nil
372-
case .optional(let optional): optional.coder
373-
case .array(let array): array.coder
374-
case .encoded(_, _, let coder): coder
372+
case .optional(let optional): optional.adapter
373+
case .array(let array): array.adapter
374+
case .encoded(_, _, let adapter): adapter
375375
}
376376
}
377377
}

Sources/Compiler/Gen/SwiftLanguage.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ public struct SwiftLanguage: Language {
1515

1616
public var boolName: String { "Bool" }
1717

18-
public var builtinCoders: Set<String> {
18+
public var builtinAdapters: Set<String> {
1919
[
20-
"BoolDatabaseValueCoder",
21-
"Int8DatabaseValueCoder",
22-
"Int16DatabaseValueCoder",
23-
"Int32DatabaseValueCoder",
24-
"Int64DatabaseValueCoder",
25-
"UInt8DatabaseValueCoder",
26-
"UInt16DatabaseValueCoder",
27-
"UInt32DatabaseValueCoder",
28-
"UInt64DatabaseValueCoder",
29-
"UIntDatabaseValueCoder",
30-
"FloatDatabaseValueCoder",
31-
"Float16DatabaseValueCoder",
32-
"UUIDDatabaseValueCoder",
33-
"DecimalDatabaseValueCoder",
34-
"DateDatabaseValueCoder",
20+
"BoolDatabaseValueAdapter",
21+
"Int8DatabaseValueAdapter",
22+
"Int16DatabaseValueAdapter",
23+
"Int32DatabaseValueAdapter",
24+
"Int64DatabaseValueAdapter",
25+
"UInt8DatabaseValueAdapter",
26+
"UInt16DatabaseValueAdapter",
27+
"UInt32DatabaseValueAdapter",
28+
"UInt64DatabaseValueAdapter",
29+
"UIntDatabaseValueAdapter",
30+
"FloatDatabaseValueAdapter",
31+
"Float16DatabaseValueAdapter",
32+
"UUIDDatabaseValueAdapter",
33+
"DecimalDatabaseValueAdapter",
34+
"DateDatabaseValueAdapter",
3535
]
3636
}
3737

@@ -72,9 +72,9 @@ public struct SwiftLanguage: Language {
7272
migrations: [String],
7373
tables: [GeneratedModel],
7474
queries: [(String?, [GeneratedQuery])],
75-
coders: [String]
75+
adapters: [String]
7676
) throws -> String {
77-
// Note: For now just going to ignore the `coders`
77+
// Note: For now just going to ignore the `adapters`
7878
// Kotlin will need that info which is why it exists.
7979
// Swift having less finegrained namespaces makes it
8080
// so it can just do module level lookups for the type.
@@ -496,10 +496,10 @@ public struct SwiftLanguage: Language {
496496
writer.write("row.embedded(at: start + ", index.description, ")")
497497
case .optional(.model):
498498
writer.write("row.optionallyEmbedded(at: start + ", index.description, ")")
499-
case let .encoded(_, _, coder):
500-
writer.write("row.value(at: start + ", index.description, ", using: ", coder, ".self)")
501-
case let .optional(.encoded(_, _, coder)):
502-
writer.write("row.optionalValue(at: start + ", index.description, ", using: ", coder, ".self)")
499+
case let .encoded(_, _, adapter):
500+
writer.write("row.value(at: start + ", index.description, ", using: ", adapter, ".self)")
501+
case let .optional(.encoded(_, _, adapter)):
502+
writer.write("row.optionalValue(at: start + ", index.description, ", using: ", adapter, ".self)")
503503
default:
504504
fatalError("Invalid field type \(field.typeName) \(field.type)")
505505
}
@@ -639,7 +639,7 @@ public struct SwiftLanguage: Language {
639639

640640
private func bind(binding: GeneratedQuery.Binding) {
641641
switch binding {
642-
case let .value(index, name, owner, coder):
642+
case let .value(index, name, owner, adapter):
643643
writer.write(line: "try statement.bind(value: ")
644644

645645
if let owner {
@@ -648,8 +648,8 @@ public struct SwiftLanguage: Language {
648648

649649
writer.write(name, ", to: ", index.description)
650650

651-
if let coder {
652-
writer.write(", using: ", coder, ".self")
651+
if let adapter {
652+
writer.write(", using: ", adapter, ".self")
653653
}
654654

655655
writer.write(")")

Sources/Compiler/Sema/InferenceState.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct InferenceState {
123123
for type: Type,
124124
at location: SourceLocation
125125
) {
126-
unify(type, with: .alias(type, .hint(hint), coder: nil), at: location)
126+
unify(type, with: .alias(type, .hint(hint), adapter: nil), at: location)
127127
}
128128

129129
/// Gets the final type from the solution for the type if its a ty var.
@@ -141,8 +141,8 @@ struct InferenceState {
141141
return tv.defaultType
142142
case let .optional(ty):
143143
return .optional(solution(for: ty, defaultIfTyVar: true))
144-
case let .alias(ty, alias, coder):
145-
return .alias(solution(for: ty, defaultIfTyVar: true), alias, coder: coder)
144+
case let .alias(ty, alias, adapter):
145+
return .alias(solution(for: ty, defaultIfTyVar: true), alias, adapter: adapter)
146146
case let .row(row):
147147
if let type = row.first, row.count == 1, !row.isUnknown {
148148
return solution(for: type, defaultIfTyVar: true)

Sources/Compiler/Sema/StmtTypeChecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ extension StmtTypeChecker {
13041304
let nominal: Type = .nominal(column.type.name.value)
13051305

13061306
let type: Type = if let alias = column.type.alias {
1307-
.alias(nominal, .explicit(alias.name.identifier.value), coder: alias.using?.value)
1307+
.alias(nominal, .explicit(alias.name.identifier.value), adapter: alias.using?.value)
13081308
} else {
13091309
nominal
13101310
}

Sources/Compiler/Sema/Type.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum Type: Equatable, CustomStringConvertible, Sendable {
2424
/// A type that has been aliased. These are not in SQL by default
2525
/// but are from the layer on top that we are adding so a user
2626
/// can replace a `INTEGER` with a `Bool`
27-
indirect case alias(Type, Alias, coder: Substring?)
27+
indirect case alias(Type, Alias, adapter: Substring?)
2828
/// There was an error somewhere in the analysis. We can just return
2929
/// an `error` type and continue the analysis. So if the user makes up
3030
/// 3 columns, they can get all 3 errors at once.
@@ -43,7 +43,7 @@ public enum Type: Equatable, CustomStringConvertible, Sendable {
4343
static let real: Type = .nominal("REAL")
4444
static let blob: Type = .nominal("BLOB")
4545
static let any: Type = .nominal("ANY")
46-
static let boolean: Type = .alias(.integer, .hint(.bool), coder: nil)
46+
static let boolean: Type = .alias(.integer, .hint(.bool), adapter: nil)
4747

4848
static let validTypeNames: Set<Substring> = [
4949
"TEXT", "INT", "INTEGER", "REAL", "BLOB", "ANY",
@@ -166,7 +166,7 @@ public enum Type: Equatable, CustomStringConvertible, Sendable {
166166
case let .optional(ty):
167167
return .optional(ty.apply(s))
168168
case let .alias(t, a, c):
169-
return .alias(t.apply(s), a, coder: c)
169+
return .alias(t.apply(s), a, adapter: c)
170170
case .nominal, .error:
171171
// Literals can't be substituted for.
172172
return self

Sources/Otter/Cursor.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ public struct Row: ~Copyable {
3737
}
3838

3939
/// Decodes the column at the index as the `Storage.Value` type
40-
@inlinable public func value<Storage: DatabasePrimitive, Coder: DatabaseValueCoder>(
40+
@inlinable public func value<Storage: DatabasePrimitive, Coder: DatabaseValueAdapter>(
4141
at column: Int32,
42-
using coder: Coder.Type,
42+
using adapter: Coder.Type,
4343
storage: Storage
4444
) throws(OtterError) -> Coder.Value {
4545
let storage = try Storage(from: sqliteStatement, at: column)
46-
return try storage.decode(from: coder)
46+
return try storage.decode(from: adapter)
4747
}
4848

4949
/// Decodes the column at the index as the `Storage.Value` type
5050
/// if it has a value.
51-
@inlinable public func optionalValue<Storage: DatabasePrimitive, Coder: DatabaseValueCoder>(
51+
@inlinable public func optionalValue<Storage: DatabasePrimitive, Coder: DatabaseValueAdapter>(
5252
at column: Int32,
53-
using coder: Coder.Type,
53+
using adapter: Coder.Type,
5454
storage: Storage
5555
) throws(OtterError) -> Coder.Value? {
5656
guard let storage = try Storage?(from: sqliteStatement, at: column) else { return nil}
57-
return try storage.decode(from: coder)
57+
return try storage.decode(from: adapter)
5858
}
5959

6060
/// Decodes the struct embeeded at the start index as the `Value` type.

0 commit comments

Comments
 (0)