Push a new entry into this builder. Panics if the key or function location is out of order.
(
&mut self,
key: FuncKey,
func_loc: FunctionLoc,
src_loc: FilePos,
)
| 123 | /// |
| 124 | /// Panics if the key or function location is out of order. |
| 125 | pub fn push_func( |
| 126 | &mut self, |
| 127 | key: FuncKey, |
| 128 | func_loc: FunctionLoc, |
| 129 | src_loc: FilePos, |
| 130 | ) -> &mut Self { |
| 131 | let (key_ns, key_index) = key.into_parts(); |
| 132 | |
| 133 | assert!( |
| 134 | self.last_namespace().is_none_or(|ns| ns <= key_ns), |
| 135 | "`FuncKey`s pushed out of order" |
| 136 | ); |
| 137 | assert!( |
| 138 | self.last_key_index().is_none_or( |
| 139 | |i| i <= key_index || self.last_namespace().is_some_and(|ns| ns != key_ns) |
| 140 | ), |
| 141 | "`FuncKey`s pushed out of order" |
| 142 | ); |
| 143 | assert!( |
| 144 | self.last_func_loc() |
| 145 | .is_none_or(|l| l.start + l.length <= func_loc.start), |
| 146 | "`FunctionLoc`s pushed out of order" |
| 147 | ); |
| 148 | |
| 149 | // Make sure that there is a `kind` entry for this key's kind. |
| 150 | let kind_start_index = self |
| 151 | .inner |
| 152 | .namespaces |
| 153 | .last() |
| 154 | .and_then(|(ns_idx, ns)| { |
| 155 | if *ns == key_ns { |
| 156 | Some(self.inner.func_loc_starts[ns_idx]) |
| 157 | } else { |
| 158 | None |
| 159 | } |
| 160 | }) |
| 161 | .unwrap_or_else(|| { |
| 162 | let start = self.inner.func_locs.next_key(); |
| 163 | let ns_idx = self.inner.namespaces.push(key_ns).panic_on_oom(); |
| 164 | let ns_idx2 = self.inner.func_loc_starts.push(start).panic_on_oom(); |
| 165 | let ns_idx3 = self |
| 166 | .inner |
| 167 | .sparse_starts |
| 168 | .push(self.inner.sparse_indices.next_key()) |
| 169 | .panic_on_oom(); |
| 170 | let ns_idx4 = self |
| 171 | .inner |
| 172 | .src_loc_starts |
| 173 | .push(self.inner.src_locs.next_key()) |
| 174 | .panic_on_oom(); |
| 175 | debug_assert_eq!(ns_idx, ns_idx2); |
| 176 | debug_assert_eq!(ns_idx, ns_idx3); |
| 177 | debug_assert_eq!(ns_idx, ns_idx4); |
| 178 | start |
| 179 | }); |
| 180 | |
| 181 | if CompiledFunctionsTable::is_dense(key.kind()) { |
| 182 | // Figure out the index within `func_locs` for this key's entry. |
no test coverage detected