Skip to content

Commit

Permalink
Merge pull request #652 from Veykril/veykril/push-zsooqlqtvrtr
Browse files Browse the repository at this point in the history
Describe deadlock risk for assemble closure in interning
  • Loading branch information
nikomatsakis authored Jan 7, 2025
2 parents b0623c0 + 16b747b commit 639fd29
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ where
unsafe { std::mem::transmute(data) }
}

/// Intern data to a unique reference.
///
/// If `key` is already interned, returns the existing [`Id`] for the interned data without
/// invoking `assemble`.
/// Otherwise, invokes `assemble` with the given `key` and the [`Id`] to be allocated for this
/// interned value. The resulting [`C::Data`] will then be interned.
///
/// Note: Using the database within the `assemble` function may result in a deadlock if
/// the database ends up trying to intern or allocate a new value.
pub fn intern<'db, Key>(
&'db self,
db: &'db dyn crate::Database,
Expand All @@ -135,6 +144,14 @@ where
}

/// Intern data to a unique reference.
///
/// If `key` is already interned, returns the existing [`Id`] for the interned data without
/// invoking `assemble`.
/// Otherwise, invokes `assemble` with the given `key` and the [`Id`] to be allocated for this
/// interned value. The resulting [`C::Data`] will then be interned.
///
/// Note: Using the database within the `assemble` function may result in a deadlock if
/// the database ends up trying to intern or allocate a new value.
pub fn intern_id<'db, Key>(
&'db self,
db: &'db dyn crate::Database,
Expand Down Expand Up @@ -324,6 +341,8 @@ where
&self.syncs
}
}

/// A trait for types that hash and compare like `O`.
pub trait HashEqLike<O> {
fn hash<H: Hasher>(&self, h: &mut H);
fn eq(&self, data: &O) -> bool;
Expand Down

0 comments on commit 639fd29

Please sign in to comment.