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

Method apply_func_rename

cranelift/filetests/src/function_runner.rs:211–252  ·  view source on GitHub ↗

Renames the function to its new [UserExternalName], as well as any other function that it may reference. We have to do this since the JIT cannot link Testcase functions.

(
        &self,
        mut func: Function,
        defined_func: &DefinedFunction,
    )

Source from the content-addressed store, hash-verified

209 ///
210 /// We have to do this since the JIT cannot link Testcase functions.
211 fn apply_func_rename(
212 &self,
213 mut func: Function,
214 defined_func: &DefinedFunction,
215 ) -> Result<Function> {
216 // First, rename the function
217 let func_original_name = func.name;
218 func.name = UserFuncName::User(defined_func.new_name.clone());
219
220 // Rename any functions that it references
221 // Do this in stages to appease the borrow checker
222 let mut redefines = Vec::with_capacity(func.dfg.ext_funcs.len());
223 for (ext_ref, ext_func) in &func.dfg.ext_funcs {
224 let old_name = match &ext_func.name {
225 ExternalName::TestCase(tc) => UserFuncName::Testcase(tc.clone()),
226 ExternalName::User(username) => {
227 UserFuncName::User(func.params.user_named_funcs()[*username].clone())
228 }
229 // The other cases don't need renaming, so lets just continue...
230 _ => continue,
231 };
232
233 let target_df = self.defined_functions.get(&old_name).ok_or(anyhow!(
234 "Undeclared function {} is referenced by {}!",
235 &old_name,
236 &func_original_name
237 ))?;
238
239 redefines.push((ext_ref, target_df.new_name.clone()));
240 }
241
242 // Now register the redefines
243 for (ext_ref, new_name) in redefines.into_iter() {
244 // Register the new name in the func, so that we can get a reference to it.
245 let new_name_ref = func.params.ensure_user_func_name(new_name);
246
247 // Finally rename the ExtFunc
248 func.dfg.ext_funcs[ext_ref].name = ExternalName::User(new_name_ref);
249 }
250
251 Ok(func)
252 }
253
254 /// Defines the body of a function
255 pub fn define_function(

Callers 1

define_functionMethod · 0.80

Calls 8

OkFunction · 0.85
user_named_funcsMethod · 0.80
ensure_user_func_nameMethod · 0.80
cloneMethod · 0.45
lenMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected