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
//! Types for the indexed environment layer.
//!
//! Provides bidirectional Name ↔ compact u32 id mapping and multi-dimensional
//! indices over declaration attributes (sort level, Pi arity, namespace prefix)
//! for sub-linear declaration lookup in large kernel environments.
use HashMap;
// ---------------------------------------------------------------------------
// NameIndex
// ---------------------------------------------------------------------------
/// Bidirectional mapping between declaration names and compact `u32` identifiers.
///
/// Assigning a dense integer id to each name enables O(1) lookup by id and
/// compact storage in downstream indices.
// ---------------------------------------------------------------------------
// TypeIndex
// ---------------------------------------------------------------------------
/// Index over declaration type attributes: sort level and Pi-type arity.
///
/// Enables efficient retrieval of all declarations with a given sort level or
/// a given number of explicit arguments.
// ---------------------------------------------------------------------------
// ModuleIndex
// ---------------------------------------------------------------------------
/// Groups declarations by their namespace prefix.
///
/// The namespace is the dot-separated prefix of a name: the namespace of
/// `"Nat.add"` is `"Nat"`, and top-level names (no dot) live in the `""`
/// (empty) namespace.
// ---------------------------------------------------------------------------
// EnvIndex
// ---------------------------------------------------------------------------
/// Composite index combining name, type, and module indices.
///
/// Provides a single entry point for all indexed lookups over a kernel
/// `Environment`. The index is append-only: names are inserted as
/// declarations are added, and ids are never recycled.
// ---------------------------------------------------------------------------
// IndexStats
// ---------------------------------------------------------------------------
/// A snapshot of index statistics.
// ---------------------------------------------------------------------------
// LookupResult
// ---------------------------------------------------------------------------
/// The result of a successful indexed lookup.
///
/// Borrows the name string from the owning `NameIndex` to avoid allocation.