Skip to content

Commit

Permalink
documentation formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kyren committed Nov 27, 2022
1 parent d786b09 commit 3a2ef58
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/gc-arena/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Default for ArenaParameters {

impl ArenaParameters {
/// The garbage collector will wait until the live size reaches <current heap size> + <previous
/// retained size> * `pause_multiplier` before beginning a new collection. Must be >= 0.0,
/// retained size> * `pause_multiplier` before beginning a new collection. Must be >= 0.0,
/// setting this to 0.0 causes the collector to never sleep longer than `min_sleep` before
/// beginning a new collection.
pub fn set_pause_factor(mut self, pause_factor: f64) -> ArenaParameters {
Expand All @@ -42,18 +42,18 @@ impl ArenaParameters {
}

/// The garbage collector will try and finish a collection by the time <current heap size> *
/// `timing_factor` additional bytes are allocated. For example, if the collection is started
/// `timing_factor` additional bytes are allocated. For example, if the collection is started
/// when the arena has 100KB live data, and the timing_multiplier is 1.0, the collector should
/// finish its final phase of this collection after another 100KB has been allocated. Must be
/// >= 0.0, setting this to 0.0 causes the collector to behave like a stop-the-world collector.
/// finish its final phase of this collection after another 100KB has been allocated. Must be >=
/// 0.0, setting this to 0.0 causes the collector to behave like a stop-the-world collector.
pub fn set_timing_factor(mut self, timing_factor: f64) -> ArenaParameters {
assert!(timing_factor >= 0.0);
self.timing_factor = timing_factor;
self
}

/// The minimum allocation amount during sleep before the arena starts collecting again. This
/// is mostly useful when the heap is very small to prevent rapidly restarting collections.
/// The minimum allocation amount during sleep before the arena starts collecting again. This is
/// mostly useful when the heap is very small to prevent rapidly restarting collections.
pub fn set_min_sleep(mut self, min_sleep: usize) -> ArenaParameters {
self.min_sleep = min_sleep;
self
Expand Down Expand Up @@ -113,21 +113,21 @@ pub type Root<'a, R> = <R as RootProvider<'a>>::Root;
/// A generic, garbage collected arena.
///
/// Garbage collected arenas allow for isolated sets of garbage collected objects with zero-overhead
/// garbage collected pointers. It provides incremental mark and sweep garbage collection which
/// garbage collected pointers. It provides incremental mark and sweep garbage collection which
/// must be manually triggered outside the `mutate` method, and works best when units of work inside
/// `mutate` can be kept relatively small. It is designed primarily to be a garbage collector for
/// `mutate` can be kept relatively small. It is designed primarily to be a garbage collector for
/// scripting language runtimes.
///
/// The arena API is able to provide extremely cheap Gc pointers because it is based around
/// "generativity". During construction and access, the root type is branded by a unique, invariant
/// "generativity". During construction and access, the root type is branded by a unique, invariant
/// lifetime `'gc` which ensures that `Gc` pointers must be contained inside the root object
/// hierarchy and cannot escape the arena callbacks or be smuggled inside another arena. This way,
/// the arena can be sure that during mutation, all `Gc` pointers come from the arena we expect them
/// to come from, and that they're all either reachable from root or have been allocated during the
/// current `mutate` call. When not inside the `mutate` callback, the arena knows that all `Gc`
/// pointers must be either reachable from root or they are unreachable and safe to collect. In
/// this way, incremental garbage collection can be achieved (assuming "sufficiently small" calls to
/// `mutate`) that is both extremely safe and zero overhead vs what you would write in C with raw
/// hierarchy and cannot escape the arena callbacks or be smuggled inside another arena. This way,
/// the arena can be sure that during mutation, all `Gc` pointers come from the arena we expect
/// them to come from, and that they're all either reachable from root or have been allocated during
/// the current `mutate` call. When not inside the `mutate` callback, the arena knows that all `Gc`
/// pointers must be either reachable from root or they are unreachable and safe to collect. In
/// this way, incremental garbage collection can be achieved (assuming "sufficiently small" calls
/// to `mutate`) that is both extremely safe and zero overhead vs what you would write in C with raw
/// pointers and manually ensuring that invariants are held.
pub struct Arena<R: for<'a> RootProvider<'a> + ?Sized> {
context: Context,
Expand All @@ -140,8 +140,8 @@ pub struct Arena<R: for<'a> RootProvider<'a> + ?Sized> {
}

impl<R: for<'a> RootProvider<'a> + ?Sized> Arena<R> {
/// Create a new arena with the given garbage collector tuning parameters. You must
/// provide a closure that accepts a `MutationContext` and returns the appropriate root.
/// Create a new arena with the given garbage collector tuning parameters. You must provide a
/// closure that accepts a `MutationContext` and returns the appropriate root.
pub fn new<F>(arena_parameters: crate::ArenaParameters, f: F) -> Arena<R>
where
F: for<'gc> FnOnce(crate::MutationContext<'gc, '_>) -> Root<'gc, R>,
Expand Down Expand Up @@ -178,10 +178,10 @@ impl<R: for<'a> RootProvider<'a> + ?Sized> Arena<R> {
}
}

/// The primary means of interacting with a garbage collected arena. Accepts a callback
/// which receives a `MutationContext` and a reference to the root, and can return any
/// non garbage collected value. The callback may "mutate" any part of the object graph
/// during this call, but no garbage collection will take place during this method.
/// The primary means of interacting with a garbage collected arena. Accepts a callback which
/// receives a `MutationContext` and a reference to the root, and can return any non garbage
/// collected value. The callback may "mutate" any part of the object graph during this call,
/// but no garbage collection will take place during this method.
#[inline]
pub fn mutate<'a, F, T>(&'a self, f: F) -> T
where
Expand Down Expand Up @@ -226,18 +226,18 @@ impl<R: for<'a> RootProvider<'a> + ?Sized> Arena<R> {
}

/// When the garbage collector is not sleeping, all allocated objects cause the arena to
/// accumulate "allocation debt". This debt is then be used to time incremental garbage
/// collection based on the tuning parameters set in `ArenaParameters`. The allocation
/// debt is measured in bytes, but will generally increase at a rate faster than that of
/// allocation so that collection will always complete.
/// accumulate "allocation debt". This debt is then be used to time incremental garbage
/// collection based on the tuning parameters set in `ArenaParameters`. The allocation debt is
/// measured in bytes, but will generally increase at a rate faster than that of allocation so
/// that collection will always complete.
#[inline]
pub fn allocation_debt(&self) -> f64 {
self.context.allocation_debt()
}

/// Run the incremental garbage collector until the allocation debt is <= 0.0. There is
/// no minimum unit of work enforced here, so it may be faster to only call this method
/// when the allocation debt is above some threshold.
/// Run the incremental garbage collector until the allocation debt is <= 0.0. There is no
/// minimum unit of work enforced here, so it may be faster to only call this method when the
/// allocation debt is above some threshold.
#[inline]
pub fn collect_debt(&mut self) {
unsafe {
Expand All @@ -248,9 +248,9 @@ impl<R: for<'a> RootProvider<'a> + ?Sized> Arena<R> {
}
}

/// Run the current garbage collection cycle to completion, stopping once the garbage
/// collector has entered the sleeping phase. If the garbage collector is currently
/// sleeping, starts a new cycle and runs that cycle to completion.
/// Run the current garbage collection cycle to completion, stopping once the garbage collector
/// has entered the sleeping phase. If the garbage collector is currently sleeping, starts a new
/// cycle and runs that cycle to completion.
pub fn collect_all(&mut self) {
self.context.wake();
unsafe {
Expand All @@ -259,9 +259,9 @@ impl<R: for<'a> RootProvider<'a> + ?Sized> Arena<R> {
}
}

/// Create a temporary arena without a root object and perform the given operation on it. No
/// garbage collection will be done until the very end of the call, at which point all allocations
/// will be collected.
/// Create a temporary arena without a root object and perform the given operation on it. No garbage
/// collection will be done until the very end of the call, at which point all allocations will
/// be collected.
pub fn rootless_arena<F, R>(f: F) -> R
where
F: for<'gc> FnOnce(MutationContext<'gc, '_>) -> R,
Expand Down

0 comments on commit 3a2ef58

Please sign in to comment.