wasmtime/runtime/externals/
tag.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::runtime::types::TagType;
use crate::{
    store::{StoreData, StoreOpaque, Stored},
    AsContext,
};
use wasmtime_environ::VMSharedTypeIndex;

/// A WebAssembly `tag`.
#[derive(Copy, Clone, Debug)]
#[repr(transparent)] // here for the C API
pub struct Tag(pub(super) Stored<crate::runtime::vm::ExportTag>);

impl Tag {
    pub(crate) unsafe fn from_wasmtime_tag(
        wasmtime_export: crate::runtime::vm::ExportTag,
        store: &mut StoreOpaque,
    ) -> Self {
        debug_assert!(
            wasmtime_export.tag.signature.unwrap_engine_type_index()
                != VMSharedTypeIndex::default()
        );
        Tag(store.store_data_mut().insert(wasmtime_export))
    }

    /// Returns the underlying type of this `tag`.
    ///
    /// # Panics
    ///
    /// Panics if `store` does not own this tag.
    pub fn ty(&self, store: impl AsContext) -> TagType {
        self._ty(store.as_context().0)
    }

    pub(crate) fn _ty(&self, store: &StoreOpaque) -> TagType {
        let ty = &store[self.0].tag;
        TagType::from_wasmtime_tag(store.engine(), &ty)
    }

    pub(crate) fn wasmtime_ty<'a>(&self, data: &'a StoreData) -> &'a wasmtime_environ::Tag {
        &data[self.0].tag
    }

    pub(crate) fn vmimport(&self, store: &StoreOpaque) -> crate::runtime::vm::VMTagImport {
        let export = &store[self.0];
        crate::runtime::vm::VMTagImport {
            from: export.definition.into(),
        }
    }

    /// Determines whether this tag is reference equal to the other
    /// given tag in the given store.
    ///
    /// # Panics
    ///
    /// Panics if either tag do not belong to the given `store`.
    pub fn eq(a: &Tag, b: &Tag, store: impl AsContext) -> bool {
        let store = store.as_context().0;
        let a = &store[a.0];
        let b = &store[b.0];
        a.definition.eq(&b.definition)
    }
}