MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / needs_deallocate

Function needs_deallocate

crates/core/src/abi.rs:890–935  ·  view source on GitHub ↗
(resolve: &Resolve, ty: &Type, what: Deallocate)

Source from the content-addressed store, hash-verified

888}
889
890fn needs_deallocate(resolve: &Resolve, ty: &Type, what: Deallocate) -> bool {
891 match ty {
892 Type::String => true,
893 Type::ErrorContext => true,
894 Type::Id(id) => match &resolve.types[*id].kind {
895 TypeDefKind::List(_) => true,
896 TypeDefKind::Type(t) => needs_deallocate(resolve, t, what),
897 TypeDefKind::Handle(Handle::Own(_)) => what.handles(),
898 TypeDefKind::Handle(Handle::Borrow(_)) => false,
899 TypeDefKind::Resource => false,
900 TypeDefKind::Record(r) => r
901 .fields
902 .iter()
903 .any(|f| needs_deallocate(resolve, &f.ty, what)),
904 TypeDefKind::Tuple(t) => t.types.iter().any(|t| needs_deallocate(resolve, t, what)),
905 TypeDefKind::Variant(t) => t
906 .cases
907 .iter()
908 .filter_map(|t| t.ty.as_ref())
909 .any(|t| needs_deallocate(resolve, t, what)),
910 TypeDefKind::Option(t) => needs_deallocate(resolve, t, what),
911 TypeDefKind::Result(t) => [&t.ok, &t.err]
912 .iter()
913 .filter_map(|t| t.as_ref())
914 .any(|t| needs_deallocate(resolve, t, what)),
915 TypeDefKind::Flags(_) | TypeDefKind::Enum(_) => false,
916 TypeDefKind::Future(_) | TypeDefKind::Stream(_) => what.handles(),
917 TypeDefKind::Unknown => unreachable!(),
918 TypeDefKind::FixedLengthList(t, _) => needs_deallocate(resolve, t, what),
919 TypeDefKind::Map(_, _) => true,
920 },
921
922 Type::Bool
923 | Type::U8
924 | Type::S8
925 | Type::U16
926 | Type::S16
927 | Type::U32
928 | Type::S32
929 | Type::U64
930 | Type::S64
931 | Type::F32
932 | Type::F64
933 | Type::Char => false,
934 }
935}
936
937/// Generate instructions in `bindgen` to deallocate all lists in `ptr` where
938/// that's a pointer to a sequence of `types` stored in linear memory.

Calls 2

handlesMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected