Skip to content

Commit

Permalink
add ingredient_debug_name API
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Aug 4, 2024
1 parent 83be1e4 commit 118e89c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::any::Any;
use std::{any::Any, borrow::Cow};

use crate::{zalsa::ZalsaDatabase, Durability, Event, Revision};
use crate::{
zalsa::{IngredientIndex, ZalsaDatabase},
Durability, Event, Revision,
};

/// The trait implemented by all Salsa databases.
/// You can create your own subtraits of this trait using the `#[salsa::db]`(`crate::db`) procedural macro.
Expand Down Expand Up @@ -38,6 +41,19 @@ pub trait Database: Send + AsDynDatabase + Any + ZalsaDatabase {
zalsa_local.report_untracked_read(db.zalsa().current_revision())
}

/// Return the "debug name" (i.e., the struct name, etc) for an "ingredient",
/// which are the fine-grained components we use to track data. This is intended
/// for debugging and the contents of the returned string are not semver-guaranteed.
///
/// Ingredient indices can be extracted from [`DependencyIndex`](`crate::DependencyIndex`) values.
fn ingredient_debug_name(&self, ingredient_index: IngredientIndex) -> Cow<'_, str> {
Cow::Borrowed(
self.zalsa()
.lookup_ingredient(ingredient_index)
.debug_name(),
)
}

/// Execute `op` with the database in thread-local storage for debug print-outs.
fn attach<R>(&self, op: impl FnOnce(&Self) -> R) -> R
where
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub use self::revision::Revision;
pub use self::runtime::Runtime;
pub use self::storage::Storage;
pub use self::update::Update;
pub use self::zalsa::IngredientIndex;
pub use crate::attach::with_attached_database;
pub use salsa_macros::accumulator;
pub use salsa_macros::db;
Expand Down

0 comments on commit 118e89c

Please sign in to comment.