Struct GC

Source
pub struct GC {
    pub instances: Vec<HeapObj>,
    /* private fields */
}
Expand description

The garbage collector. Let’s go

Important note to make sure I never break the GC: The only way we can deallocate something that we didnt mean to is if we have a PhoenixPointer somewhere other than the stack, globals, or in a reachable HeapObj So be careful if we ever alloc a PhoenixClosure or a PhoenixInstance when a PhoenixPointer is floating around on the rust stack => ie popping a value off, calling alloc, and then doing something with that value. If that value is the last pointer to an instance, it’ll cause the instance to be deleted

Ideas for making this not have placeholder values / fewer placeholder values: Steps to making it work:

  1. Use a linked list for instances
  2. When removing a value, replace the node with a placeholder
  3. When removing a value next to a placeholder, merge the two together and increment a counter in the placeholder
  4. When traversing the linked list, a placeholder is worth {counter} slots
  5. When allocating values, use the same queue but if it hits the middle of a placeholder, split it down the middle into two placeholders? => Ideally we would not but since the free_slots stack is not ordered in any way we don’t have any guarantees

This would get rid of most of the placeholder values but with a few problems

  • A) The memory usage of the placeholders is minimal already
  • B) Placeholders don’t necessarily “leak”, ie: running the program for a long enough time will not cause a memory shortage unless the code itself had used that much memory without GC’ing
  • C) Linked lists and doing those traversals will undoubtedly be slower than the current Vec implementation, will it even be worth it?

All in all, I think I’ll need to wait until I have some code to profile.

Fields§

§instances: Vec<HeapObj>

Implementations§

Source§

impl GC

Source

pub fn alloc( &mut self, val: HeapObj, stack: &[Value], globals: &[Global], ) -> Value

Source

pub fn new() -> GC

Trait Implementations§

Source§

impl Clone for GC

Source§

fn clone(&self) -> GC

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GC

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GC

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for GC

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for GC

§

impl RefUnwindSafe for GC

§

impl Send for GC

§

impl Sync for GC

§

impl Unpin for GC

§

impl UnwindSafe for GC

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V