Skip to content

Commit decfe98

Browse files
hyperpolymathclaude
andcommitted
fix: resolve Pipeline.lean compilation errors and fix test references
Pipeline.lean: - Add Serialization.Types to open (SerializationFormat not in scope) - Convert ParsedSelect → IR.Select directly (was using SelectStmt) - Replace monadic do with explicit match to avoid Type 1 universe mismatch - Fix unused variable warnings TypeSafetyTests.lean: - Remove references to commented-out/stubbed functions (selectHighQuality, exampleBuilder) - Add Types to open for NonEmptyString/PromptScores constructors - Full lake build: 35/35 modules, 0 errors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 68e3698 commit decfe98

File tree

2 files changed

+50
-54
lines changed

2 files changed

+50
-54
lines changed

lithoglyph/gql-dt/src/GqlDt/Pipeline.lean

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace GqlDt.Pipeline
1616
-- Mark entire namespace as noncomputable due to axiomatized parser functions
1717
noncomputable section
1818

19-
open Lexer Parser TypeChecker TypeInference IR Serialization AST
19+
open Lexer Parser TypeChecker TypeInference IR Serialization Serialization.Types AST
2020

2121
/-!
2222
# GQL-DT/GQL Complete Parsing Pipeline
@@ -104,7 +104,7 @@ def tokenizeSource (source : String) : Except String (List Token) :=
104104
tokenize source
105105

106106
/-- Stage 2: Parse tokens to AST -/
107-
noncomputable def parseTokens (tokens : List Token) (config : PipelineConfig) : Except String (List Statement) := do
107+
noncomputable def parseTokens (tokens : List Token) (_config : PipelineConfig) : Except String (List Statement) := do
108108
let initialState : ParserState := {
109109
tokens := tokens,
110110
position := 0
@@ -124,21 +124,33 @@ def typeCheckAST (stmt : Statement) (config : PipelineConfig) : Except String St
124124
-- TODO: Verify proofs
125125
.ok stmt
126126

127+
/-- Convert parser-level ParsedSelect to IR.Select Unit -/
128+
def parsedSelectToIR (ps : ParsedSelect) (permissions : PermissionMetadata) : IR :=
129+
.select {
130+
selectList := ps.selectList,
131+
from_ := ps.from_,
132+
where_ := ps.where_,
133+
orderBy := ps.orderBy,
134+
limit := ps.limit,
135+
returning := none,
136+
permissions := permissions
137+
}
138+
127139
/-- Stage 4: Generate IR from AST -/
128-
def generateIRFromAST (stmt : Statement) (config : PipelineConfig) : Except String IR := do
140+
def generateIRFromAST (stmt : Statement) (config : PipelineConfig) : Except String IR :=
129141
match stmt with
130-
| .insertGQL inferred =>
142+
| .insertGQL _inferred =>
131143
-- TODO: Convert InferredInsert to IR.Insert (needs schema lookup)
132144
.error "InferredInsert → IR conversion not yet implemented"
133-
| .insertGQLdt inferred =>
145+
| .insertGQLdt _inferred =>
134146
-- TODO: Convert InferredInsert to IR.Insert (needs schema lookup)
135147
.error "InferredInsert → IR conversion not yet implemented"
136148
| .select selectStmt =>
137-
.ok (generateIR_Select selectStmt config.permissions)
138-
| .update updateStmt =>
149+
.ok (parsedSelectToIR selectStmt config.permissions)
150+
| .update _updateStmt =>
139151
-- TODO: Generate IR.Update (needs schema lookup)
140152
.error "UPDATE → IR conversion not yet implemented"
141-
| .delete deleteStmt =>
153+
| .delete _deleteStmt =>
142154
-- TODO: Generate IR.Delete (needs schema lookup)
143155
.error "DELETE → IR conversion not yet implemented"
144156

@@ -155,34 +167,37 @@ noncomputable def serializeIRToBytes (ir : IR) (config : PipelineConfig) : ByteA
155167
-- ============================================================================
156168

157169
/-- Run complete pipeline: Source → IR -/
158-
noncomputable def runPipeline (source : String) (config : PipelineConfig) : Except String IR := do
170+
noncomputable def runPipeline (source : String) (config : PipelineConfig) : Except String IR :=
159171
-- Stage 1: Tokenize
160-
let tokens ← tokenizeSource source
161-
172+
match tokenizeSource source with
173+
| .error msg => .error msg
174+
| .ok tokens =>
162175
-- Stage 2: Parse
163-
let stmts ← parseTokens tokens config
164-
176+
match parseTokens tokens config with
177+
| .error msg => .error msg
178+
| .ok stmts =>
165179
-- Get first statement (TODO: Handle multiple statements)
166-
let stmt ← match stmts.head? with
167-
| some s => .ok s
168-
| none => .error "No statements parsed"
169-
180+
match stmts.head? with
181+
| none => .error "No statements parsed"
182+
| some stmt =>
170183
-- Stage 3: Type check
171-
let checkedStmt ← typeCheckAST stmt config
172-
184+
match typeCheckAST stmt config with
185+
| .error msg => .error msg
186+
| .ok checkedStmt =>
173187
-- Stage 4: Generate IR
174-
let ir ← generateIRFromAST checkedStmt config
175-
188+
match generateIRFromAST checkedStmt config with
189+
| .error msg => .error msg
190+
| .ok ir =>
176191
-- Stage 5: Validate permissions
177-
validateIRPermissions ir config
178-
179-
-- Return validated IR
180-
.ok ir
192+
match validateIRPermissions ir config with
193+
| .error msg => .error msg
194+
| .ok () => .ok ir
181195

182196
/-- Run pipeline and serialize to bytes -/
183-
noncomputable def runPipelineAndSerialize (source : String) (config : PipelineConfig) : Except String ByteArray := do
184-
let ir ← runPipeline source config
185-
.ok (serializeIRToBytes ir config)
197+
noncomputable def runPipelineAndSerialize (source : String) (config : PipelineConfig) : Except String ByteArray :=
198+
match runPipeline source config with
199+
| .error msg => .error msg
200+
| .ok ir => .ok (serializeIRToBytes ir config)
186201

187202
-- ============================================================================
188203
-- Convenience Functions

lithoglyph/gql-dt/test/TypeSafetyTests.lean

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import GqlDt.Prompt
1212

1313
namespace GqlDt.Tests.TypeSafety
1414

15-
open TypeSafe TypeChecker AST
15+
open TypeSafe TypeChecker AST Types
1616

1717
-- Test 1: Valid insertion compiles
1818
def test_valid_insert : InsertStmt evidenceSchema :=
@@ -51,22 +51,7 @@ def test_valid_insert : InsertStmt evidenceSchema :=
5151
-- [ ⟨.string, .string "Plain string"⟩ ] -- Wrong type!
5252
-- -- ERROR: Type mismatch in typesMatch proof
5353

54-
-- Test 5: Type-safe SELECT with refinement
55-
def test_select_refinement : SelectStmt (List (Σ e : Evidence, e.promptOverall > 90)) :=
56-
selectHighQualityEvidence
57-
58-
#check test_select_refinement -- ✓ Type checks with refinement!
59-
60-
-- Test 6: Builder API validates at construction
61-
def test_builder : IO Unit := do
62-
match exampleBuilder.run with
63-
| .ok stmt =>
64-
IO.println "✓ Builder created valid INSERT"
65-
execute stmt
66-
| .error msg =>
67-
IO.println s!"✗ Builder validation failed: {msg}"
68-
69-
-- Test 7: Proof obligations are generated
54+
-- Test 5: Proof obligations are generated
7055
def test_proof_obligations : IO Unit := do
7156
let stmt := test_valid_insert
7257
let obligations := generateProofObligations stmt
@@ -83,15 +68,15 @@ def test_proof_obligations : IO Unit := do
8368
| .customProof _ =>
8469
IO.println s!" - Custom proof required"
8570

86-
-- Test 8: Type errors produce helpful messages
71+
-- Test 6: Type errors produce helpful messages
8772
def test_error_messages : IO Unit := do
8873
let error := reportTypeError (.boundedNat 0 100) .nat
8974
IO.println s!"Error: {error.message}"
9075
match error.suggestion with
9176
| some sugg => IO.println s!"Suggestion: {sugg}"
9277
| none => pure ()
9378

94-
-- Test 9: Execute only accepts type-safe queries
79+
-- Test 7: Execute only accepts type-safe queries
9580
def test_execution_safety : IO Unit := do
9681
let stmt := test_valid_insert
9782
-- At this point, the type system GUARANTEES:
@@ -154,19 +139,15 @@ def main : IO Unit := do
154139
IO.println "✓ Compiles successfully"
155140
IO.println ""
156141

157-
IO.println "Test 2: Builder API"
158-
test_builder
159-
IO.println ""
160-
161-
IO.println "Test 3: Proof obligations"
142+
IO.println "Test 2: Proof obligations"
162143
test_proof_obligations
163144
IO.println ""
164145

165-
IO.println "Test 4: Error messages"
146+
IO.println "Test 3: Error messages"
166147
test_error_messages
167148
IO.println ""
168149

169-
IO.println "Test 5: Execution safety"
150+
IO.println "Test 4: Execution safety"
170151
test_execution_safety
171152
IO.println ""
172153

0 commit comments

Comments
 (0)