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

Method deallocate

crates/core/src/abi.rs:2370–2489  ·  view source on GitHub ↗

Runs the deallocation of `ty` for the operands currently on `self.stack`. This will pop the ABI items of `ty` from `self.stack`.

(&mut self, ty: &Type, what: Deallocate)

Source from the content-addressed store, hash-verified

2368 ///
2369 /// This will pop the ABI items of `ty` from `self.stack`.
2370 fn deallocate(&mut self, ty: &Type, what: Deallocate) {
2371 use Instruction::*;
2372
2373 match *ty {
2374 Type::String => {
2375 self.emit(&Instruction::GuestDeallocateString);
2376 }
2377
2378 Type::Bool
2379 | Type::U8
2380 | Type::S8
2381 | Type::U16
2382 | Type::S16
2383 | Type::U32
2384 | Type::S32
2385 | Type::Char
2386 | Type::U64
2387 | Type::S64
2388 | Type::F32
2389 | Type::F64
2390 | Type::ErrorContext => {
2391 // No deallocation necessary, just discard the operand on the
2392 // stack.
2393 self.stack.pop().unwrap();
2394 }
2395
2396 Type::Id(id) => match &self.resolve.types[id].kind {
2397 TypeDefKind::Type(t) => self.deallocate(t, what),
2398
2399 TypeDefKind::List(element) => {
2400 self.push_block();
2401 self.emit(&IterBasePointer);
2402 let elemaddr = self.stack.pop().unwrap();
2403 self.deallocate_indirect(element, elemaddr, Default::default(), what);
2404 self.finish_block(0);
2405
2406 self.emit(&Instruction::GuestDeallocateList { element });
2407 }
2408
2409 TypeDefKind::Map(key, value) => {
2410 let value_offset = self.bindgen.sizes().field_offsets([key, value])[1].0;
2411 self.push_block();
2412 self.emit(&IterBasePointer);
2413 let entry_addr = self.stack.pop().unwrap();
2414 self.deallocate_indirect(key, entry_addr.clone(), Default::default(), what);
2415 self.deallocate_indirect(value, entry_addr, value_offset, what);
2416 self.finish_block(0);
2417
2418 self.emit(&Instruction::GuestDeallocateMap { key, value });
2419 }
2420
2421 TypeDefKind::Handle(Handle::Own(_))
2422 | TypeDefKind::Future(_)
2423 | TypeDefKind::Stream(_)
2424 if what.handles() =>
2425 {
2426 self.lift(ty);
2427 self.emit(&DropHandle { ty });

Callers 2

deallocate_in_typesMethod · 0.80
deallocate_indirectMethod · 0.80

Calls 11

deallocate_indirectMethod · 0.80
handlesMethod · 0.80
mapMethod · 0.80
emitMethod · 0.45
push_blockMethod · 0.45
finish_blockMethod · 0.45
sizesMethod · 0.45
liftMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected