Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe deadlock risk for assemble closure in interning #652

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading