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

Method compile

crates/wasmtime/src/compile.rs:594–665  ·  view source on GitHub ↗

Compile these `CompileInput`s (maybe in parallel) and return the resulting `UnlinkedCompileOutput`s.

(
        self,
        engine: &Engine,
        types: &'a ModuleTypesBuilder,
    )

Source from the content-addressed store, hash-verified

592 /// Compile these `CompileInput`s (maybe in parallel) and return the
593 /// resulting `UnlinkedCompileOutput`s.
594 fn compile(
595 self,
596 engine: &Engine,
597 types: &'a ModuleTypesBuilder,
598 ) -> Result<UnlinkedCompileOutputs<'a>> {
599 let compiler = engine.try_compiler()?;
600
601 if self.inputs.len() > 0 && cfg!(miri) {
602 bail!(
603 "\
604You are attempting to compile a WebAssembly module or component that contains
605functions in Miri. Running Cranelift through Miri is known to take quite a long
606time and isn't what we want in CI at least. If this is a mistake then you should
607ignore this test in Miri with:
608
609 #[cfg_attr(miri, ignore)]
610
611If this is not a mistake then try to edit the `pulley_provenance_test` test
612which runs Cranelift outside of Miri. If you still feel this is a mistake then
613please open an issue or a topic on Zulip to talk about how best to accommodate
614the use case.
615"
616 );
617 }
618
619 let mut raw_outputs = if let Some(inlining_compiler) = compiler.inlining_compiler() {
620 if engine.tunables().inlining != Inlining::No {
621 self.compile_with_inlining(engine, compiler, inlining_compiler)?
622 } else {
623 // Inlining compiler but inlining is disabled: compile each
624 // input and immediately finish its output in parallel, skipping
625 // call graph computation and all that.
626 engine.run_maybe_parallel::<_, _, Error, _>(self.inputs, |f| {
627 let mut compiled = f(compiler)?;
628 inlining_compiler.finish_compiling(
629 &mut compiled.function,
630 compiled.func_body.take(),
631 &compiled.symbol,
632 )?;
633 Ok(compiled)
634 })?
635 }
636 } else {
637 // No inlining: just compile each individual input in parallel.
638 engine.run_maybe_parallel(self.inputs, |f| f(compiler))?
639 };
640
641 if cfg!(debug_assertions) {
642 let mut symbols: Vec<_> = raw_outputs.iter().map(|i| &i.symbol).collect();
643 symbols.sort();
644 for [a, b] in symbols.array_windows() {
645 assert_ne!(
646 a, b,
647 "should never have duplicate symbols, but found two functions with the symbol `{a}`",
648 );
649 }
650 }
651

Callers 3

build_c_helpersFunction · 0.45
build_module_artifactsFunction · 0.45

Calls 15

OkFunction · 0.85
try_compilerMethod · 0.80
compile_with_inliningMethod · 0.80
finish_compilingMethod · 0.80
run_maybe_parallelMethod · 0.80
collectMethod · 0.80
sortMethod · 0.80
fFunction · 0.50
newFunction · 0.50
lenMethod · 0.45
inlining_compilerMethod · 0.45

Tested by

no test coverage detected