Skip to content

Commit

Permalink
Add comment on impl safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-hughes committed Nov 17, 2023
1 parent ef270a4 commit e43d305
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/vm/objects/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ pub struct Block {
pub method_stack_base: usize,
}

// By default, `Block` is not `FinalizerSafe` because it has fields to other
// `Gc`s. These fields would be unsound to access inside a `drop` method, so
// this explicit impl is needed to tell the compiler we are not doing that.
// The following impls are needed to allow the GC to finalise `Block`. By
// default, `Block` is not `FinalizerSafe` because it has fields to other `Gc`s.
// These fields would be unsound to access inside a `drop` method, so this
// explicit impl is needed to tell the compiler we are not doing that. The only
// time a `Block` is shared between threads is inside a finaliser, which is
// Sync-safe because we guarantee it will not be accessed at the same time as
// the main-thread.
unsafe impl FinalizerSafe for Block {}

unsafe impl Sync for Block {}

impl Obj for Block {
Expand Down

0 comments on commit e43d305

Please sign in to comment.