Skip to content

Commit f54d1b3

Browse files
committed
Reorder for top-to-bottom reading
1 parent 574aadf commit f54d1b3

1 file changed

Lines changed: 25 additions & 26 deletions

File tree

crates/oak_index/src/use_def_map.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ use crate::semantic_index::UseId;
125125
// {} | true | no local def, parent scope reference
126126
// {A, B} | true | some paths define, some don't
127127

128+
/// The immutable use-def map for a single scope. For each use site, stores the
129+
/// set of definitions that can reach it through control flow.
130+
#[derive(Debug)]
131+
pub struct UseDefMap {
132+
bindings_by_use: IndexVec<UseId, Bindings>,
133+
}
134+
135+
impl UseDefMap {
136+
pub(crate) fn empty() -> Self {
137+
Self {
138+
bindings_by_use: IndexVec::new(),
139+
}
140+
}
141+
142+
pub fn bindings_at_use(&self, use_id: UseId) -> &Bindings {
143+
&self.bindings_by_use[use_id]
144+
}
145+
}
146+
128147
/// The set of definitions that can reach a particular point in control flow,
129148
/// plus whether the symbol may be unbound (no definition on some path).
130149
///
@@ -198,32 +217,6 @@ fn sorted_union(a: &[DefinitionId], b: &[DefinitionId]) -> SmallVec<[DefinitionI
198217
.collect()
199218
}
200219

201-
/// A snapshot of all symbol states at a particular point in control flow.
202-
#[derive(Clone, Debug)]
203-
pub(crate) struct FlowSnapshot {
204-
symbol_states: IndexVec<SymbolId, Bindings>,
205-
}
206-
207-
/// The immutable use-def map for a single scope, produced by finalizing the
208-
/// builder. For each use site, stores the set of definitions that can reach
209-
/// it through control flow.
210-
#[derive(Debug)]
211-
pub struct UseDefMap {
212-
bindings_by_use: IndexVec<UseId, Bindings>,
213-
}
214-
215-
impl UseDefMap {
216-
pub(crate) fn empty() -> Self {
217-
Self {
218-
bindings_by_use: IndexVec::new(),
219-
}
220-
}
221-
222-
pub fn bindings_at_use(&self, use_id: UseId) -> &Bindings {
223-
&self.bindings_by_use[use_id]
224-
}
225-
}
226-
227220
/// Mutable builder for constructing a [`UseDefMap`] during the tree walk.
228221
/// One builder exists per scope. When entering a nested scope the current
229222
/// builder is pushed onto a stack and a fresh one takes over.
@@ -392,3 +385,9 @@ impl UseDefMapBuilder {
392385
}
393386
}
394387
}
388+
389+
/// A snapshot of all symbol states at a particular point in control flow.
390+
#[derive(Clone, Debug)]
391+
pub(crate) struct FlowSnapshot {
392+
symbol_states: IndexVec<SymbolId, Bindings>,
393+
}

0 commit comments

Comments
 (0)