MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / push_func

Method push_func

crates/environ/src/module_artifacts.rs:125–231  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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.

Callers 3

link_and_append_codeMethod · 0.80
make_test_tableFunction · 0.80
runFunction · 0.80

Calls 15

panic_on_oomMethod · 0.80
last_func_locMethod · 0.80
repeatFunction · 0.50
into_partsMethod · 0.45
lastMethod · 0.45
next_keyMethod · 0.45
pushMethod · 0.45
kindMethod · 0.45
as_u32Method · 0.45
into_rawMethod · 0.45
mapMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected