fix(fmt_index): implement with the helper function

This commit is contained in:
zjp 2022-08-22 10:03:03 +08:00
parent 9f9b46f5e0
commit 67fd9792f0
4 changed files with 30 additions and 25 deletions

View file

@ -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<crate::Id>,
_fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
todo!()
index: Option<crate::Id>,
fmt: &mut fmt::Formatter<'_>,
) -> fmt::Result {
fmt_index(self.debug_name, index, fmt)
}
}

View file

@ -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<DB: ?Sized> {
/// [`IngredientRequiresReset::RESET_ON_NEW_REVISION`] to true.
fn reset_for_new_revision(&mut self);
fn fmt_index(
&self,
index: Option<crate::Id>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result;
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
}
/// A helper function to show human readable fmt.
pub(crate) fn fmt_index(
debug_name: &str,
id: Option<Id>,
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.

View file

@ -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<crate::Id>,
_fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
todo!()
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_index(self.debug_name, index, fmt)
}
}

View file

@ -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