Skip to main content

wasmtime_environ/component/
compiler.rs

1use crate::component::{
2    ComponentTranslation, ComponentTypesBuilder, RuntimeComponentInstanceIndex,
3    TypeResourceTableIndex, UnsafeIntrinsic,
4};
5use crate::error::Result;
6use crate::{Abi, CompiledFunctionBody, FactInlineIntrinsic, FuncKey, Tunables};
7
8/// The component-model-specific `FactInlineIntrinsic`s.
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
10pub enum FactComponentIntrinsic {
11    /// `resource.transfer-borrow-to-owner`: lazily lend a `borrow` to its
12    /// resource's owning instance, or fall back to the libcall.
13    ResourceTransferBorrowToOwner {
14        /// The resource type of the handle being lent.
15        ty: TypeResourceTableIndex,
16        /// The component instance owning `ty`'s handle table.
17        instance: RuntimeComponentInstanceIndex,
18    },
19}
20
21impl From<FactComponentIntrinsic> for FactInlineIntrinsic {
22    #[inline]
23    fn from(intrinsic: FactComponentIntrinsic) -> Self {
24        Self::Component(intrinsic)
25    }
26}
27
28/// Compilation support necessary for components.
29pub trait ComponentCompiler: Send + Sync {
30    /// Compiles the pieces necessary to create a `VMFuncRef` for the
31    /// `trampoline` specified.
32    ///
33    /// Each trampoline is a member of the `Trampoline` enumeration and has a
34    /// unique purpose and is translated differently. See the implementation of
35    /// this trait for Cranelift for more information.
36    fn compile_component_trampoline(
37        &self,
38        component: &ComponentTranslation,
39        types: &ComponentTypesBuilder,
40        key: FuncKey,
41        abi: Abi,
42        tunables: &Tunables,
43        symbol: &str,
44    ) -> Result<CompiledFunctionBody>;
45
46    /// Compile the given Wasmtime intrinsic.
47    fn compile_intrinsic(
48        &self,
49        tunables: &Tunables,
50        component: &ComponentTranslation,
51        types: &ComponentTypesBuilder,
52        intrinsic: UnsafeIntrinsic,
53        abi: Abi,
54        symbol: &str,
55    ) -> Result<CompiledFunctionBody>;
56}