Skip to content

Commit b7f64f8

Browse files
committed
comments
1 parent 9cd0daa commit b7f64f8

5 files changed

Lines changed: 31 additions & 22 deletions

File tree

Sources/Compiler/Diagnostics.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,6 @@ public struct Diagnostics {
3636
copy.merge(diagnostics)
3737
return copy
3838
}
39-
40-
public mutating func throwing(_ diagnostic: Diagnostic) throws {
41-
elements.append(diagnostic)
42-
throw diagnostic
43-
}
44-
45-
public mutating func trying<Output>(
46-
_ action: () throws -> Output,
47-
at location: SourceLocation
48-
) -> Output? {
49-
do {
50-
return try action()
51-
} catch {
52-
add(.init("\(error)", at: location))
53-
return nil
54-
}
55-
}
5639
}
5740

5841
extension Diagnostics: Sequence {

Sources/Compiler/Schema.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ extension Columns {
4242
}
4343
}
4444

45+
/// A table within the database schema
4546
public struct Table: Sendable {
47+
/// The name of the table
4648
public var name: Substring
49+
/// The columns of the table
4750
public var columns: Columns
51+
/// The columns that make up the primary key
4852
public let primaryKey: [Substring]
53+
/// What kind of table it is (FTS/CTE...)
4954
public let kind: Kind
5055

5156
public enum Kind: Sendable {
@@ -60,6 +65,7 @@ public struct Table: Sendable {
6065
}
6166
}
6267

68+
/// A trigger to be run on certain SQL operations
6369
public struct Trigger {
6470
/// The name of the trigger
6571
public let name: Substring
@@ -69,7 +75,10 @@ public struct Trigger {
6975
public let usedTables: Set<Substring>
7076
}
7177

78+
/// An index created within the schema
7279
public struct Index {
80+
/// The name given too the index
7381
public let name: Substring
82+
/// The name of the table the index was created for.
7483
public let table: Substring
7584
}

Sources/Compiler/Sema/ExprTypeChecker.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ extension ExprTypeChecker: ExprSyntaxVisitor {
9898
return inferenceState.errorType(for: expr)
9999
}
100100

101-
// TODO: Maybe put this in the scheme instantiation?
102101
if result.isAmbiguous {
103102
diagnostics.add(.ambiguous(tableName.value, at: tableName.location))
104103
}
@@ -146,7 +145,6 @@ extension ExprTypeChecker: ExprSyntaxVisitor {
146145
return inferenceState.errorType(for: expr)
147146
}
148147

149-
// TODO: Maybe put this in the scheme instantiation?
150148
if result.isAmbiguous {
151149
diagnostics.add(.ambiguous(column.value, at: column.location))
152150
}
@@ -192,7 +190,11 @@ extension ExprTypeChecker: ExprSyntaxVisitor {
192190

193191
let tv = inferenceState.freshTyVar(for: expr)
194192
let fnType = inferenceState.instantiate(scheme)
195-
inferenceState.unify(fnType, with: .fn(params: [inferenceState.solution(for: lTy), rTy], ret: tv), at: expr.location)
193+
inferenceState.unify(
194+
fnType,
195+
with: .fn(params: [inferenceState.solution(for: lTy), rTy], ret: tv),
196+
at: expr.location
197+
)
196198
return inferenceState.solution(for: tv)
197199
}
198200

Sources/Compiler/Sema/StmtTypeChecker.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,16 +708,28 @@ extension StmtTypeChecker {
708708
}
709709
}
710710

711+
/// Type checks a `WHERE` expression
711712
private mutating func typeCheck(where expr: ExpressionSyntax) {
712713
let (type, _) = typeCheck(expr)
714+
// Needs to return an `INTEGER` e.g. boolean
713715
inferenceState.unify(type, with: .integer, at: expr.location)
714716
}
715717

718+
/// Type checks and calculates the returned columns from a `SELECT` stmt.
719+
///
720+
/// Note: This is going to do a little extra than just infer the column names
721+
/// and types. It will try to chunk them out by table. So if the user does
722+
/// a query like `SELECT foo.*, bar.*` we can embed the fact that they
723+
/// selected all columns from foo and bar so the table structs can be embded
724+
/// within the output type.
716725
private mutating func typeCheck(resultColumns: [ResultColumnSyntax]) -> ResultColumns {
717726
var columns: OrderedDictionary<Substring, Type> = [:]
718727
var table: Substring?
728+
// Each chunk is either a list of specifically listed columns
729+
// or a select all of a table.
719730
var chunks: [ResultColumns.Chunk] = []
720731

732+
// Breaks off the current columns into a chunk then starts a new one.
721733
func breakOffCurrentChunkIfNeeded() {
722734
guard !columns.isEmpty else { return }
723735

Sources/Compiler/Sema/Type.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ public struct TypeVariable: Hashable, CustomStringConvertible, ExpressibleByInte
187187
/// What kind or group this type variable belongs too.
188188
let kind: Kind
189189

190-
/// There are different type of type variables.
190+
/// There are different types of type variables.
191191
/// Each are spawned from different usages.
192+
///
193+
/// Having a kind with a type variable allows us to delay unification
194+
/// with a concrete type till we have more info.
192195
enum Kind: Int, Equatable, Comparable {
193-
/// `general` is any type variable that does not fall into the above
196+
/// `general` is any type variable that does not fall into the below
194197
case general = 0
195198
/// `integer` is any type variable from an integer literal e.g. `0`
196199
case integer = 1

0 commit comments

Comments
 (0)