From b76ac29a0973efe45093b1337fa53946fdf3ab9c Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 10:33:39 +0800 Subject: [PATCH] fix(fmt_index): impl for InputFieldIngredient --- components/salsa-2022-macros/src/input.rs | 11 ++++++++--- components/salsa-2022/src/input_field.rs | 15 +++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index d2d5c9e4..aa7fbf6b 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -135,7 +135,12 @@ impl InputStruct { let jar_ty = self.jar_ty(); let all_field_indices: Vec = self.all_field_indices(); let input_index: Literal = self.input_index(); - let debug_name = Literal::string(&format!("{}", self.id_ident())); + let debug_name_struct = Literal::string(&self.id_ident().to_string()); + let debug_name_fields: Vec<_> = self + .all_field_names() + .into_iter() + .map(|ident| Literal::string(&ident.to_string())) + .collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident { @@ -168,7 +173,7 @@ impl InputStruct { &mut ingredients.#all_field_indices }, ); - salsa::input_field::InputFieldIngredient::new(index) + salsa::input_field::InputFieldIngredient::new(index, #debug_name_fields) }, )* { @@ -184,7 +189,7 @@ impl InputStruct { &mut ingredients.#input_index }, ); - salsa::input::InputIngredient::new(index, #debug_name) + salsa::input::InputIngredient::new(index, #debug_name_struct) }, ) } diff --git a/components/salsa-2022/src/input_field.rs b/components/salsa-2022/src/input_field.rs index 54ce093a..0ad5cd78 100644 --- a/components/salsa-2022/src/input_field.rs +++ b/components/salsa-2022/src/input_field.rs @@ -1,10 +1,11 @@ use crate::cycle::CycleRecoveryStrategy; -use crate::ingredient::{Ingredient, IngredientRequiresReset}; +use crate::ingredient::{fmt_index, Ingredient, IngredientRequiresReset}; use crate::key::DependencyIndex; use crate::runtime::local_state::QueryOrigin; use crate::runtime::StampedValue; use crate::{AsId, DatabaseKeyIndex, Durability, Id, IngredientIndex, Revision, Runtime}; use rustc_hash::FxHashMap; +use std::fmt; use std::hash::Hash; /// Ingredient used to represent the fields of a `#[salsa::input]`. @@ -15,16 +16,18 @@ use std::hash::Hash; pub struct InputFieldIngredient { index: IngredientIndex, map: FxHashMap>, + debug_name: &'static str, } impl InputFieldIngredient where K: Eq + Hash + AsId, { - pub fn new(index: IngredientIndex) -> Self { + pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { index, map: Default::default(), + debug_name, } } @@ -114,12 +117,8 @@ where panic!("unexpected call: input fields don't register for resets"); } - 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) } }