-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEnvironment.lean
More file actions
629 lines (535 loc) · 18.2 KB
/
Environment.lean
File metadata and controls
629 lines (535 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/-
Canonical Lean types with embedded content-addressed hashes.
Ix types mirror Lean's core types but include a Blake3 hash at each node,
enabling O(1) equality checks and content-addressed storage.
-/
module
public import Blake3.Rust
public import Std.Data.HashMap
public import Batteries.Data.RBMap
public import Ix.Address
public section
namespace Ix
open Std (HashMap)
open Blake3.Rust (Hasher)
/-! ## LEON (Lean Objective Notation) Tags (must match Rust env.rs) -/
def TAG_NANON : UInt8 := 0x00
def TAG_NSTR : UInt8 := 0x01
def TAG_NNUM : UInt8 := 0x02
def TAG_UZERO : UInt8 := 0x03
def TAG_USUCC : UInt8 := 0x04
def TAG_UMAX : UInt8 := 0x05
def TAG_UIMAX : UInt8 := 0x06
def TAG_UPARAM : UInt8 := 0x10
def TAG_UMVAR : UInt8 := 0x70
def TAG_EVAR : UInt8 := 0x20
def TAG_ESORT : UInt8 := 0x80
def TAG_EREF : UInt8 := 0x30
def TAG_EPRJ : UInt8 := 0x50
def TAG_ESTR : UInt8 := 0x81
def TAG_ENAT : UInt8 := 0x82
def TAG_EAPP : UInt8 := 0x83
def TAG_ELAM : UInt8 := 0x84
def TAG_EALL : UInt8 := 0x85
def TAG_ELET : UInt8 := 0x86
def TAG_EFVAR : UInt8 := 0x72
def TAG_EMVAR : UInt8 := 0x73
def TAG_EMDATA : UInt8 := 0x74
def TAG_DEFN : UInt8 := 0xA0
def TAG_RECR : UInt8 := 0xA1
def TAG_AXIO : UInt8 := 0xA2
def TAG_QUOT : UInt8 := 0xA3
def TAG_INDC : UInt8 := 0xA6
def TAG_CTOR : UInt8 := 0xC0
def TAG_THEO : UInt8 := 0xC1
def TAG_OPAQ : UInt8 := 0xC2
def TAG_MINT : UInt8 := 0xF1
def TAG_MSSTR : UInt8 := 0xF2
def TAG_MSINFO : UInt8 := 0xF3
def TAG_MSPRE : UInt8 := 0xF4
def TAG_MSYN : UInt8 := 0xF5
def TAG_MDVAL : UInt8 := 0xF6
/-! ## Name -/
/-- Content-addressed hierarchical name. Mirrors `Lean.Name` but carries a Blake3 hash at each node for O(1) equality. -/
inductive Name where
| anonymous (hash : Address)
| str (parent : Name) (s : String) (hash : Address)
| num (parent : Name) (i : Nat) (hash : Address)
deriving Repr, Nonempty
namespace Name
/-- Extract the Blake3 hash stored at the root of a `Name`. -/
def getHash : Name → Address
| anonymous h => h
| str _ _ h => h
| num _ _ h => h
instance : BEq Name where
beq a b := a.getHash == b.getHash
instance : Hashable Name where
hash n := hash n.getHash -- Uses Address's Hashable (first 8 bytes as LE u64)
/-- The anonymous (root) name with its canonical hash. -/
def mkAnon : Name := .anonymous <| Address.blake3 (ByteArray.mk #[TAG_NANON])
instance : Inhabited Name where
default := mkAnon
/-- Construct a string name component, hashing the tag, parent hash, and string bytes. -/
def mkStr (pre: Name) (s: String): Name := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_NSTR])
h := h.update pre.getHash.hash
h := h.update s.toUTF8
.str pre s ⟨(h.finalizeWithLength 32).val⟩
/-- Construct a numeric name component, hashing the tag, parent hash, and little-endian nat bytes. -/
def mkNat (pre: Name) (i: Nat): Name := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_NNUM])
h := h.update pre.getHash.hash
h := h.update ⟨i.toBytesLE⟩
.num pre i ⟨(h.finalizeWithLength 32).val⟩
partial def toStringAux : Name → String
| .anonymous _ => ""
| .str (.anonymous _) s _ => s
| .str parent s _ => s!"{toStringAux parent}.{s}"
| .num (.anonymous _) n _ => s!"«{n}»"
| .num parent n _ => s!"{toStringAux parent}.«{n}»"
instance : ToString Name where
toString := toStringAux
def fromLeanName : Lean.Name → Name
| .anonymous => .mkAnon
| .str pre s => .mkStr (.fromLeanName pre) s
| .num pre n => .mkNat (.fromLeanName pre) n
end Name
/-- Compare Ix.Name by hash for ordered collections. -/
def nameCompare (a b : Name) : Ordering :=
compare a.getHash b.getHash
instance : Ord Name where
compare := nameCompare
/-! ## Level -/
/-- Content-addressed universe level. Mirrors `Lean.Level` with a Blake3 hash at each node. -/
inductive Level where
| zero (hash : Address)
| succ (x : Level) (hash : Address)
| max (x y : Level) (hash : Address)
| imax (x y : Level) (hash : Address)
| param (n : Name) (hash : Address)
| mvar (n : Name) (hash : Address)
deriving Repr, Nonempty
namespace Level
/-- Extract the Blake3 hash stored at the root of a `Level`. -/
def getHash : Level → Address
| zero h => h
| succ _ h => h
| max _ _ h => h
| imax _ _ h => h
| param _ h => h
| mvar _ h => h
def mkZero : Level := .zero <| Address.blake3 (ByteArray.mk #[TAG_UZERO])
def mkSucc (x: Level) : Level := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_USUCC])
h := h.update x.getHash.hash
.succ x ⟨(h.finalizeWithLength 32).val⟩
def mkMax (x y : Level) : Level := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_UMAX])
h := h.update x.getHash.hash
h := h.update y.getHash.hash
.max x y ⟨(h.finalizeWithLength 32).val⟩
def mkIMax (x y : Level) : Level := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_UIMAX])
h := h.update x.getHash.hash
h := h.update y.getHash.hash
.imax x y ⟨(h.finalizeWithLength 32).val⟩
def mkParam (n: Name) : Level := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_UPARAM])
h := h.update n.getHash.hash
.param n ⟨(h.finalizeWithLength 32).val⟩
def mkMvar (n: Name) : Level := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_UMVAR])
h := h.update n.getHash.hash
.mvar n ⟨(h.finalizeWithLength 32).val⟩
instance : BEq Level where
beq a b := a.getHash == b.getHash
instance : Hashable Level where
hash l := hash l.getHash -- Uses Address's Hashable (first 8 bytes as LE u64)
instance : Inhabited Level where
default := mkZero
end Level
/-! ## Auxiliary types for MData -/
/-- Ix-local integer type used within `MData` values (mirrors `Int` for serialization). -/
inductive Int where
| ofNat (n : Nat)
| negSucc (n : Nat)
deriving BEq, Repr, Inhabited
structure Substring where
str : String
startPos : Nat
stopPos : Nat
deriving BEq, Repr, Inhabited
inductive SourceInfo where
| original (leading : Substring) (leadingPos : Nat)
(trailing : Substring) (trailingPos : Nat)
| synthetic (start : Nat) (stop : Nat) (canonical : Bool)
| none
deriving BEq, Repr, Inhabited
inductive SyntaxPreresolved where
| namespace (name : Name)
| decl (name : Name) (aliases : Array String)
deriving BEq, Repr, Inhabited
inductive Syntax where
| missing
| node (info : SourceInfo) (kind : Name) (args : Array Syntax)
| atom (info : SourceInfo) (val : String)
| ident (info : SourceInfo) (rawVal : Substring) (val : Name)
(preresolved : Array SyntaxPreresolved)
deriving BEq, Repr, Inhabited, Nonempty
/-- A metadata value carried in an `mdata` expression node. -/
inductive DataValue where
| ofString (s : String)
| ofBool (b : Bool)
| ofName (n : Name)
| ofNat (n : Nat)
| ofInt (i : Int)
| ofSyntax (s : Syntax)
deriving BEq, Repr, Inhabited
/-! ## Expr -/
/-- Content-addressed expression. Mirrors `Lean.Expr` with a Blake3 hash at each node,
enabling O(1) structural equality and content-addressed storage. -/
inductive Expr where
| bvar (idx : Nat) (hash : Address)
| fvar (name : Name) (hash : Address)
| mvar (name : Name) (hash : Address)
| sort (level : Level) (hash : Address)
| const (name : Name) (levels : Array Level) (hash : Address)
| app (fn arg : Expr) (hash : Address)
| lam (name : Name) (ty body : Expr) (bi : Lean.BinderInfo) (hash : Address)
| forallE (name : Name) (ty body : Expr) (bi : Lean.BinderInfo) (hash : Address)
| letE (name : Name) (ty val body : Expr) (nonDep : Bool) (hash : Address)
| lit (l : Lean.Literal) (hash : Address)
| mdata (data : Array (Name × DataValue)) (expr : Expr) (hash : Address)
| proj (typeName : Name) (idx : Nat) (struct : Expr) (hash : Address)
deriving Repr, Nonempty
namespace Expr
def binderInfoTag : Lean.BinderInfo → UInt8
| .default => 0
| .implicit => 1
| .strictImplicit => 2
| .instImplicit => 3
/-- Extract the Blake3 hash stored at the root of an `Expr`. -/
def getHash : Expr → Address
| bvar _ h => h
| fvar _ h => h
| mvar _ h => h
| sort _ h => h
| const _ _ h => h
| app _ _ h => h
| lam _ _ _ _ h => h
| forallE _ _ _ _ h => h
| letE _ _ _ _ _ h => h
| lit _ h => h
| mdata _ _ h => h
| proj _ _ _ h => h
instance : BEq Expr where
beq a b := a.getHash == b.getHash
instance : Hashable Expr where
hash e := hash e.getHash -- Uses Address's Hashable (first 8 bytes as LE u64)
def mkBVar (x: Nat) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EVAR])
h := h.update ⟨x.toBytesLE⟩
.bvar x ⟨(h.finalizeWithLength 32).val⟩
def mkFVar (x: Name) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EFVAR])
h := h.update x.getHash.hash
.fvar x ⟨(h.finalizeWithLength 32).val⟩
def mkMVar (x: Name) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EMVAR])
h := h.update x.getHash.hash
.mvar x ⟨(h.finalizeWithLength 32).val⟩
def mkSort (x: Level) : Expr := Id.run <| do
let h := Hasher.init ()
let h := h.update (ByteArray.mk #[TAG_ESORT])
let h := h.update x.getHash.hash
.sort x ⟨(h.finalizeWithLength 32).val⟩
def mkConst (x: Name) (us: Array Level): Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EREF])
h := h.update x.getHash.hash
for u in us do
h := h.update u.getHash.hash
.const x us ⟨(h.finalizeWithLength 32).val⟩
def mkApp (f a : Expr) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EAPP])
h := h.update f.getHash.hash
h := h.update a.getHash.hash
.app f a ⟨(h.finalizeWithLength 32).val⟩
def mkLam (n : Name) (t b : Expr) (bi : Lean.BinderInfo) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_ELAM])
h := h.update n.getHash.hash
h := h.update t.getHash.hash
h := h.update b.getHash.hash
h := h.update (ByteArray.mk #[binderInfoTag bi])
.lam n t b bi ⟨(h.finalizeWithLength 32).val⟩
def mkForallE (n : Name) (t b : Expr) (bi : Lean.BinderInfo) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EALL])
h := h.update n.getHash.hash
h := h.update t.getHash.hash
h := h.update b.getHash.hash
h := h.update (ByteArray.mk #[binderInfoTag bi])
.forallE n t b bi ⟨(h.finalizeWithLength 32).val⟩
def mkLetE (n : Name) (t v b : Expr) (nd : Bool) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_ELET])
h := h.update n.getHash.hash
h := h.update t.getHash.hash
h := h.update v.getHash.hash
h := h.update b.getHash.hash
h := h.update (ByteArray.mk #[if nd then 1 else 0])
.letE n t v b nd ⟨(h.finalizeWithLength 32).val⟩
def mkLit (l : Lean.Literal) : Expr := Id.run <| do
let mut h := Hasher.init ()
match l with
| .natVal n =>
h := h.update (ByteArray.mk #[TAG_ENAT])
h := h.update ⟨n.toBytesLE⟩
| .strVal s =>
h := h.update (ByteArray.mk #[TAG_ESTR])
h := h.update s.toUTF8
.lit l ⟨(h.finalizeWithLength 32).val⟩
def mkProj (n : Name) (i : Nat) (e : Expr) : Expr := Id.run <| do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EPRJ])
h := h.update n.getHash.hash
h := h.update ⟨i.toBytesLE⟩
h := h.update e.getHash.hash
.proj n i e ⟨(h.finalizeWithLength 32).val⟩
def hashInt (h : Hasher) (i : Int) : Hasher := Id.run do
let mut h := h.update (ByteArray.mk #[TAG_MINT])
match i with
| .ofNat n =>
h := h.update (ByteArray.mk #[0])
h := h.update ⟨n.toBytesLE⟩
| .negSucc n =>
h := h.update (ByteArray.mk #[1])
h := h.update ⟨n.toBytesLE⟩
h
def hashSubstring (h : Hasher) (ss : Substring) : Hasher :=
Id.run do
let mut h := h.update (ByteArray.mk #[TAG_MSSTR])
h := h.update ss.str.toUTF8
h := h.update ⟨ss.startPos.toBytesLE⟩
h := h.update ⟨ss.stopPos.toBytesLE⟩
h
def hashSourceInfo (h : Hasher) (si : SourceInfo) : Hasher :=
Id.run do
let mut h := h.update (ByteArray.mk #[TAG_MSINFO])
match si with
| .original leading leadingPos trailing trailingPos =>
h := h.update (ByteArray.mk #[0])
h := hashSubstring h leading
h := h.update ⟨leadingPos.toBytesLE⟩
h := hashSubstring h trailing
h := h.update ⟨trailingPos.toBytesLE⟩
| .synthetic start stop canonical =>
h := h.update (ByteArray.mk #[1])
h := h.update ⟨start.toBytesLE⟩
h := h.update ⟨stop.toBytesLE⟩
h := h.update (ByteArray.mk #[if canonical then 1 else 0])
| .none =>
h := h.update (ByteArray.mk #[2])
h
def hashSyntaxPreresolved (h : Hasher) (sp : SyntaxPreresolved)
: Hasher := Id.run do
let mut h := h.update (ByteArray.mk #[TAG_MSPRE])
match sp with
| .namespace name =>
h := h.update (ByteArray.mk #[0])
h := h.update name.getHash.hash
| .decl name aliases =>
h := h.update (ByteArray.mk #[1])
h := h.update name.getHash.hash
for a in aliases do
h := h.update a.toUTF8
h := h.update (ByteArray.mk #[0])
h
private partial def hashSyntax (h : Hasher) (syn : Syntax)
: Hasher := Id.run do
let mut h := h.update (ByteArray.mk #[TAG_MSYN])
match syn with
| .missing =>
h := h.update (ByteArray.mk #[0])
| .node info kind args =>
h := h.update (ByteArray.mk #[1])
h := hashSourceInfo h info
h := h.update kind.getHash.hash
h := h.update ⟨args.size.toBytesLE⟩
for arg in args do
h := hashSyntax h arg
| .atom info val =>
h := h.update (ByteArray.mk #[2])
h := hashSourceInfo h info
h := h.update val.toUTF8
| .ident info rawVal val preresolved =>
h := h.update (ByteArray.mk #[3])
h := hashSourceInfo h info
h := hashSubstring h rawVal
h := h.update val.getHash.hash
h := h.update ⟨preresolved.size.toBytesLE⟩
for pr in preresolved do
h := hashSyntaxPreresolved h pr
h
def hashDataValue (h : Hasher) (dv : DataValue)
: Hasher := Id.run do
let mut h := h.update (ByteArray.mk #[TAG_MDVAL])
match dv with
| .ofString s =>
h := h.update (ByteArray.mk #[0])
h := h.update s.toUTF8
| .ofBool b =>
h := h.update (ByteArray.mk #[1])
h := h.update (ByteArray.mk #[if b then 1 else 0])
| .ofName name =>
h := h.update (ByteArray.mk #[2])
h := h.update name.getHash.hash
| .ofNat n =>
h := h.update (ByteArray.mk #[3])
h := h.update ⟨n.toBytesLE⟩
| .ofInt i =>
h := h.update (ByteArray.mk #[4])
h := hashInt h i
| .ofSyntax syn =>
h := h.update (ByteArray.mk #[5])
h := hashSyntax h syn
h
def mkMData (data : Array (Name × DataValue)) (e : Expr) : Expr := Id.run do
let mut h := Hasher.init ()
h := h.update (ByteArray.mk #[TAG_EMDATA])
h := h.update ⟨data.size.toBytesLE⟩
for (name, dv) in data do
h := h.update name.getHash.hash
h := hashDataValue h dv
h := h.update e.getHash.hash
.mdata data e ⟨(h.finalizeWithLength 32).val⟩
instance : Inhabited Expr where
default := mkBVar 0
end Expr
/-! ## Constant Types -/
/-- Common fields shared by all constant declarations: name, universe parameters, and type. -/
structure ConstantVal where
name : Name
levelParams : Array Name
type : Expr
deriving Repr, BEq
structure AxiomVal where
cnst : ConstantVal
isUnsafe : Bool
deriving Repr, BEq
structure DefinitionVal where
cnst : ConstantVal
value : Expr
hints : Lean.ReducibilityHints
safety : Lean.DefinitionSafety
all : Array Name
deriving Repr, BEq
structure TheoremVal where
cnst : ConstantVal
value : Expr
all : Array Name
deriving Repr, BEq
structure OpaqueVal where
cnst : ConstantVal
value : Expr
isUnsafe : Bool
all : Array Name
deriving Repr, BEq
structure QuotVal where
cnst : ConstantVal
kind : Lean.QuotKind
deriving Repr, BEq
structure InductiveVal where
cnst : ConstantVal
numParams : Nat
numIndices : Nat
all : Array Name
ctors : Array Name
numNested : Nat
isRec : Bool
isUnsafe : Bool
isReflexive : Bool
deriving Repr, BEq
structure ConstructorVal where
cnst : ConstantVal
induct : Name
cidx : Nat
numParams : Nat
numFields : Nat
isUnsafe : Bool
deriving Repr, BEq
structure RecursorRule where
ctor : Name
nfields : Nat
rhs : Expr
deriving Repr, BEq
structure RecursorVal where
cnst : ConstantVal
all : Array Name
numParams : Nat
numIndices : Nat
numMotives : Nat
numMinors : Nat
rules : Array RecursorRule
k : Bool
isUnsafe : Bool
deriving Repr, BEq
/-- Sum type of all Lean constant declarations (axioms, definitions, theorems, inductives, etc.). -/
inductive ConstantInfo where
| axiomInfo (v : AxiomVal)
| defnInfo (v : DefinitionVal)
| thmInfo (v : TheoremVal)
| opaqueInfo (v : OpaqueVal)
| quotInfo (v : QuotVal)
| inductInfo (v : InductiveVal)
| ctorInfo (v : ConstructorVal)
| recInfo (v : RecursorVal)
deriving Repr, BEq
/-- Extract the `ConstantVal` common fields from any `ConstantInfo` variant. -/
def ConstantInfo.getCnst : ConstantInfo → ConstantVal
| .axiomInfo v => v.cnst
| .defnInfo v => v.cnst
| .thmInfo v => v.cnst
| .opaqueInfo v => v.cnst
| .quotInfo v => v.cnst
| .inductInfo v => v.cnst
| .ctorInfo v => v.cnst
| .recInfo v => v.cnst
/-! ## Environment -/
/-- A content-addressed Lean environment: a map from `Ix.Name` to `ConstantInfo`. -/
structure Environment where
consts : HashMap Name ConstantInfo
/-- Raw environment data as arrays (returned from Rust FFI).
Use `toEnvironment` to convert to Environment with HashMaps. -/
structure RawEnvironment where
consts : Array (Name × ConstantInfo)
deriving Repr, Inhabited
/-- Convert raw arrays to Environment with HashMaps.
This is done on the Lean side for correct hash function usage. -/
def RawEnvironment.toEnvironment (raw : RawEnvironment) : Environment :=
{ consts := raw.consts.foldl (init := {}) fun m (k, v) => m.insert k v }
/-- Convert Environment to raw arrays for FFI usage. -/
def Environment.toRaw (env : Environment) : RawEnvironment :=
{ consts := env.consts.toArray }
/-! ## Context Types for Compilation -/
/-- Mutual context mapping Name to index within block. -/
abbrev MutCtx := Batteries.RBMap Name Nat nameCompare
instance : Ord MutCtx where
compare a b := compare a.toList b.toList
/-- Set of Names (for tracking constants in a block). -/
abbrev NameSet := Batteries.RBSet Name nameCompare
end Ix
end