diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index d531a02b..ad43f3d3 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -1,11 +1,11 @@ -use std::sync::Arc; +use std::{sync::Arc, fmt}; use arc_swap::ArcSwap; use crossbeam::{atomic::AtomicCell, queue::SegQueue}; use crate::{ cycle::CycleRecoveryStrategy, - ingredient::IngredientRequiresReset, + ingredient::{IngredientRequiresReset, fmt_index}, jar::Jar, key::{DatabaseKeyIndex, DependencyIndex}, runtime::local_state::QueryOrigin, @@ -89,7 +89,7 @@ pub trait Configuration { type Key: AsId; /// The value computed by the function. - type Value: std::fmt::Debug; + type Value: fmt::Debug; /// Determines whether this function can recover from being a participant in a cycle /// (and, if so, how). @@ -275,10 +275,10 @@ where fn fmt_index( &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + index: Option, + fmt: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } diff --git a/components/salsa-2022/src/ingredient.rs b/components/salsa-2022/src/ingredient.rs index 729011dc..5d051289 100644 --- a/components/salsa-2022/src/ingredient.rs +++ b/components/salsa-2022/src/ingredient.rs @@ -1,3 +1,5 @@ +use std::fmt; + use crate::{ cycle::CycleRecoveryStrategy, key::DependencyIndex, runtime::local_state::QueryOrigin, DatabaseKeyIndex, Id, @@ -60,11 +62,20 @@ pub trait Ingredient { /// [`IngredientRequiresReset::RESET_ON_NEW_REVISION`] to true. fn reset_for_new_revision(&mut self); - fn fmt_index( - &self, - index: Option, - fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result; + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; +} + +/// A helper function to show human readable fmt. +pub(crate) fn fmt_index( + debug_name: &str, + id: Option, + fmt: &mut fmt::Formatter<'_>, +) -> fmt::Result { + if let Some(i) = id { + write!(fmt, "{}({})", debug_name, u32::from(i)) + } else { + write!(fmt, "{}()", debug_name) + } } /// Defines a const indicating if an ingredient needs to be reset each round. diff --git a/components/salsa-2022/src/input.rs b/components/salsa-2022/src/input.rs index 7059ca6f..f304e051 100644 --- a/components/salsa-2022/src/input.rs +++ b/components/salsa-2022/src/input.rs @@ -1,6 +1,8 @@ +use std::fmt; + use crate::{ cycle::CycleRecoveryStrategy, - ingredient::{Ingredient, IngredientRequiresReset}, + ingredient::{Ingredient, IngredientRequiresReset, fmt_index}, key::{DatabaseKeyIndex, DependencyIndex}, runtime::{local_state::QueryOrigin, Runtime}, AsId, IngredientIndex, Revision, @@ -98,12 +100,8 @@ where ); } - fn fmt_index( - &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } diff --git a/components/salsa-2022/src/storage.rs b/components/salsa-2022/src/storage.rs index 7d37fd75..83e3d617 100644 --- a/components/salsa-2022/src/storage.rs +++ b/components/salsa-2022/src/storage.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{fmt, sync::Arc}; use parking_lot::Condvar; @@ -221,11 +221,7 @@ pub trait HasJarsDyn { /// [`SalsaStructInDb::register_dependent_fn`](`crate::salsa_struct::SalsaStructInDb::register_dependent_fn`). fn salsa_struct_deleted(&self, ingredient: IngredientIndex, id: Id); - fn fmt_index( - &self, - index: DependencyIndex, - fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result; + fn fmt_index(&self, index: DependencyIndex, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; } // ANCHOR_END: HasJarsDyn