Struct phoenix_lang::gc::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 copy 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<GC> for GC

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.