From 4f4d01958f4b5de3f4757d4be7dcefc926609d46 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 21 May 2024 05:47:13 -0400 Subject: [PATCH] generate a custom `std::fmt::Debug` impl This leads less representation information and in particular avoids serializing pointers. --- components/salsa-2022-macros/src/input.rs | 2 + components/salsa-2022-macros/src/interned.rs | 2 + .../salsa-2022-macros/src/salsa_struct.rs | 25 +- .../salsa-2022-macros/src/tracked_struct.rs | 2 + examples-2022/calc/src/parser.rs | 232 +++++++----------- .../tests/accumulate-reuse-workaround.rs | 10 +- salsa-2022-tests/tests/accumulate-reuse.rs | 8 +- salsa-2022-tests/tests/deletion-cascade.rs | 8 +- salsa-2022-tests/tests/deletion.rs | 8 +- ...truct_changes_but_fn_depends_on_field_y.rs | 6 +- ...input_changes_but_fn_depends_on_field_y.rs | 6 +- salsa-2022-tests/tests/hello_world.rs | 14 +- .../specify_tracked_fn_in_rev_1_but_not_2.rs | 78 +++--- .../tests/tracked_fn_read_own_entity.rs | 14 +- .../tests/tracked_with_struct_db.rs | 7 +- 15 files changed, 195 insertions(+), 227 deletions(-) diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index 9c043daf..de273d48 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -58,6 +58,7 @@ impl InputStruct { let from_id_impl = self.from_id_impl(); let salsa_struct_in_db_impl = self.salsa_struct_in_db_impl(); let as_debug_with_db_impl = self.as_debug_with_db_impl(); + let debug_impl = self.debug_impl(); Ok(quote! { #id_struct @@ -67,6 +68,7 @@ impl InputStruct { #from_id_impl #as_debug_with_db_impl #salsa_struct_in_db_impl + #debug_impl }) } diff --git a/components/salsa-2022-macros/src/interned.rs b/components/salsa-2022-macros/src/interned.rs index 027e1d92..f9b749ce 100644 --- a/components/salsa-2022-macros/src/interned.rs +++ b/components/salsa-2022-macros/src/interned.rs @@ -68,6 +68,7 @@ impl InternedStruct { let named_fields_impl = self.inherent_impl_for_named_fields(); let salsa_struct_in_db_impl = self.salsa_struct_in_db_impl(); let as_debug_with_db_impl = self.as_debug_with_db_impl(); + let debug_impl = self.debug_impl(); let update_impl = self.update_impl(); Ok(crate::debug::dump_tokens( @@ -86,6 +87,7 @@ impl InternedStruct { #salsa_struct_in_db_impl #as_debug_with_db_impl #update_impl + #debug_impl }, )) } diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index cb7a0c0a..9eec63ea 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -309,7 +309,7 @@ impl SalsaStruct { parse_quote_spanned! { ident.span() => #(#attrs)* - #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)] + #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] #visibility struct #ident(salsa::Id); } } @@ -347,7 +347,7 @@ impl SalsaStruct { Ok(parse_quote_spanned! { ident.span() => #(#attrs)* - #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)] + #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] #visibility struct #ident #generics ( *const salsa::#module::ValueStruct < #config_ident >, std::marker::PhantomData < & #lifetime salsa::#module::ValueStruct < #config_ident > > @@ -465,6 +465,27 @@ impl SalsaStruct { } } + /// Generate `impl salsa::DebugWithDb for Foo`, but only if this is an id struct. + pub(crate) fn debug_impl(&self) -> syn::ItemImpl { + let ident = self.the_ident(); + let (impl_generics, type_generics, where_clause) = + self.struct_item.generics.split_for_impl(); + let ident_string = ident.to_string(); + + // `use ::salsa::debug::helper::Fallback` is needed for the fallback to `Debug` impl + parse_quote_spanned! {ident.span()=> + impl #impl_generics ::std::fmt::Debug for #ident #type_generics + #where_clause + { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + f.debug_struct(#ident_string) + .field("[salsa id]", &self.salsa_id().as_u32()) + .finish() + } + } + } + } + /// Generate `impl salsa::DebugWithDb for Foo`, but only if this is an id struct. pub(crate) fn as_debug_with_db_impl(&self) -> Option { if self.customizations.contains(&Customization::DebugWithDb) { diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index e86ca6c4..c6a49120 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -67,6 +67,7 @@ impl TrackedStruct { let send_sync_impls = self.send_sync_impls(); let from_id_impl = self.from_id_impl(); let lookup_id_impl = self.lookup_id_impl(); + let debug_impl = self.debug_impl(); let as_debug_with_db_impl = self.as_debug_with_db_impl(); Ok(quote! { #config_struct @@ -82,6 +83,7 @@ impl TrackedStruct { #(#send_sync_impls)* #lookup_id_impl #as_debug_with_db_impl + #debug_impl }) } diff --git a/examples-2022/calc/src/parser.rs b/examples-2022/calc/src/parser.rs index 38439c04..1b4ec00a 100644 --- a/examples-2022/calc/src/parser.rs +++ b/examples-2022/calc/src/parser.rs @@ -381,25 +381,19 @@ fn parse_print() { [salsa id]: 0, statements: [ Statement { - span: Span( - Id { - value: 5, - }, - ), + span: Span { + [salsa id]: 4, + }, data: Print( Expression { - span: Span( - Id { - value: 4, - }, - ), + span: Span { + [salsa id]: 3, + }, data: Op( Expression { - span: Span( - Id { - value: 1, - }, - ), + span: Span { + [salsa id]: 0, + }, data: Number( OrderedFloat( 1.0, @@ -408,11 +402,9 @@ fn parse_print() { }, Add, Expression { - span: Span( - Id { - value: 3, - }, - ), + span: Span { + [salsa id]: 2, + }, data: Number( OrderedFloat( 2.0, @@ -448,59 +440,43 @@ fn parse_example() { [salsa id]: 0, statements: [ Statement { - span: Span( - Id { - value: 10, - }, - ), + span: Span { + [salsa id]: 9, + }, data: Function( - Function( - Id { - value: 1, - }, - ), + Function { + [salsa id]: 0, + }, ), }, Statement { - span: Span( - Id { - value: 22, - }, - ), + span: Span { + [salsa id]: 21, + }, data: Function( - Function( - Id { - value: 2, - }, - ), + Function { + [salsa id]: 1, + }, ), }, Statement { - span: Span( - Id { - value: 29, - }, - ), + span: Span { + [salsa id]: 28, + }, data: Print( Expression { - span: Span( - Id { - value: 28, - }, - ), + span: Span { + [salsa id]: 27, + }, data: Call( - FunctionId( - Id { - value: 1, - }, - ), + FunctionId { + [salsa id]: 0, + }, [ Expression { - span: Span( - Id { - value: 24, - }, - ), + span: Span { + [salsa id]: 23, + }, data: Number( OrderedFloat( 3.0, @@ -508,11 +484,9 @@ fn parse_example() { ), }, Expression { - span: Span( - Id { - value: 26, - }, - ), + span: Span { + [salsa id]: 25, + }, data: Number( OrderedFloat( 4.0, @@ -525,31 +499,23 @@ fn parse_example() { ), }, Statement { - span: Span( - Id { - value: 34, - }, - ), + span: Span { + [salsa id]: 33, + }, data: Print( Expression { - span: Span( - Id { - value: 33, - }, - ), + span: Span { + [salsa id]: 32, + }, data: Call( - FunctionId( - Id { - value: 2, - }, - ), + FunctionId { + [salsa id]: 1, + }, [ Expression { - span: Span( - Id { - value: 31, - }, - ), + span: Span { + [salsa id]: 30, + }, data: Number( OrderedFloat( 1.0, @@ -562,25 +528,19 @@ fn parse_example() { ), }, Statement { - span: Span( - Id { - value: 39, - }, - ), + span: Span { + [salsa id]: 38, + }, data: Print( Expression { - span: Span( - Id { - value: 38, - }, - ), + span: Span { + [salsa id]: 37, + }, data: Op( Expression { - span: Span( - Id { - value: 35, - }, - ), + span: Span { + [salsa id]: 34, + }, data: Number( OrderedFloat( 11.0, @@ -589,11 +549,9 @@ fn parse_example() { }, Multiply, Expression { - span: Span( - Id { - value: 37, - }, - ), + span: Span { + [salsa id]: 36, + }, data: Number( OrderedFloat( 2.0, @@ -644,32 +602,24 @@ fn parse_precedence() { [salsa id]: 0, statements: [ Statement { - span: Span( - Id { - value: 11, - }, - ), + span: Span { + [salsa id]: 10, + }, data: Print( Expression { - span: Span( - Id { - value: 10, - }, - ), + span: Span { + [salsa id]: 9, + }, data: Op( Expression { - span: Span( - Id { - value: 7, - }, - ), + span: Span { + [salsa id]: 6, + }, data: Op( Expression { - span: Span( - Id { - value: 1, - }, - ), + span: Span { + [salsa id]: 0, + }, data: Number( OrderedFloat( 1.0, @@ -678,18 +628,14 @@ fn parse_precedence() { }, Add, Expression { - span: Span( - Id { - value: 6, - }, - ), + span: Span { + [salsa id]: 5, + }, data: Op( Expression { - span: Span( - Id { - value: 3, - }, - ), + span: Span { + [salsa id]: 2, + }, data: Number( OrderedFloat( 2.0, @@ -698,11 +644,9 @@ fn parse_precedence() { }, Multiply, Expression { - span: Span( - Id { - value: 5, - }, - ), + span: Span { + [salsa id]: 4, + }, data: Number( OrderedFloat( 3.0, @@ -715,11 +659,9 @@ fn parse_precedence() { }, Add, Expression { - span: Span( - Id { - value: 9, - }, - ), + span: Span { + [salsa id]: 8, + }, data: Number( OrderedFloat( 4.0, diff --git a/salsa-2022-tests/tests/accumulate-reuse-workaround.rs b/salsa-2022-tests/tests/accumulate-reuse-workaround.rs index e960db1b..4a81e85e 100644 --- a/salsa-2022-tests/tests/accumulate-reuse-workaround.rs +++ b/salsa-2022-tests/tests/accumulate-reuse-workaround.rs @@ -75,9 +75,9 @@ fn test1() { assert_eq!(compute(&db, l2), 2); db.assert_logs(expect![[r#" [ - "compute(List(Id { value: 2 }))", - "accumulated(List(Id { value: 1 }))", - "compute(List(Id { value: 1 }))", + "compute(List { [salsa id]: 1 })", + "accumulated(List { [salsa id]: 0 })", + "compute(List { [salsa id]: 0 })", ]"#]]); // When we mutate `l1`, we should re-execute `compute` for `l1`, @@ -87,7 +87,7 @@ fn test1() { assert_eq!(compute(&db, l2), 2); db.assert_logs(expect![[r#" [ - "accumulated(List(Id { value: 1 }))", - "compute(List(Id { value: 1 }))", + "accumulated(List { [salsa id]: 0 })", + "compute(List { [salsa id]: 0 })", ]"#]]); } diff --git a/salsa-2022-tests/tests/accumulate-reuse.rs b/salsa-2022-tests/tests/accumulate-reuse.rs index 9790d6ba..ca164c57 100644 --- a/salsa-2022-tests/tests/accumulate-reuse.rs +++ b/salsa-2022-tests/tests/accumulate-reuse.rs @@ -70,8 +70,8 @@ fn test1() { assert_eq!(compute(&db, l2), 2); db.assert_logs(expect![[r#" [ - "compute(List(Id { value: 2 }))", - "compute(List(Id { value: 1 }))", + "compute(List { [salsa id]: 1 })", + "compute(List { [salsa id]: 0 })", ]"#]]); // When we mutate `l1`, we should re-execute `compute` for `l1`, @@ -82,7 +82,7 @@ fn test1() { assert_eq!(compute(&db, l2), 2); db.assert_logs(expect![[r#" [ - "compute(List(Id { value: 2 }))", - "compute(List(Id { value: 1 }))", + "compute(List { [salsa id]: 1 })", + "compute(List { [salsa id]: 0 })", ]"#]]); } diff --git a/salsa-2022-tests/tests/deletion-cascade.rs b/salsa-2022-tests/tests/deletion-cascade.rs index 036e4adc..93233620 100644 --- a/salsa-2022-tests/tests/deletion-cascade.rs +++ b/salsa-2022-tests/tests/deletion-cascade.rs @@ -95,8 +95,8 @@ fn basic() { assert_eq!(final_result(&db, input), 2 * 2 + 2); db.assert_logs(expect![[r#" [ - "final_result(MyInput(Id { value: 1 }))", - "intermediate_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); // Creates only 2 tracked structs in this revision, should delete 1 @@ -117,12 +117,12 @@ fn basic() { assert_eq!(final_result(&db, input), 2); db.assert_logs(expect![[r#" [ - "intermediate_result(MyInput(Id { value: 1 }))", + "intermediate_result(MyInput { [salsa id]: 0 })", "salsa_event(WillDiscardStaleOutput { execute_key: create_tracked_structs(0), output_key: MyTracked(2) })", "salsa_event(DidDiscard { key: MyTracked(2) })", "salsa_event(DidDiscard { key: contribution_from_struct(2) })", "salsa_event(DidDiscard { key: MyTracked(5) })", "salsa_event(DidDiscard { key: copy_field(5) })", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", ]"#]]); } diff --git a/salsa-2022-tests/tests/deletion.rs b/salsa-2022-tests/tests/deletion.rs index 5d981ff5..89cfd412 100644 --- a/salsa-2022-tests/tests/deletion.rs +++ b/salsa-2022-tests/tests/deletion.rs @@ -88,8 +88,8 @@ fn basic() { assert_eq!(final_result(&db, input), 2 * 2 + 2); db.assert_logs(expect![[r#" [ - "final_result(MyInput(Id { value: 1 }))", - "intermediate_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); // Creates only 2 tracked structs in this revision, should delete 1 @@ -103,10 +103,10 @@ fn basic() { assert_eq!(final_result(&db, input), 2); db.assert_logs(expect![[r#" [ - "intermediate_result(MyInput(Id { value: 1 }))", + "intermediate_result(MyInput { [salsa id]: 0 })", "salsa_event(WillDiscardStaleOutput { execute_key: create_tracked_structs(0), output_key: MyTracked(2) })", "salsa_event(DidDiscard { key: MyTracked(2) })", "salsa_event(DidDiscard { key: contribution_from_struct(2) })", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", ]"#]]); } diff --git a/salsa-2022-tests/tests/expect_reuse_field_x_of_a_tracked_struct_changes_but_fn_depends_on_field_y.rs b/salsa-2022-tests/tests/expect_reuse_field_x_of_a_tracked_struct_changes_but_fn_depends_on_field_y.rs index 822945c0..f5058b97 100644 --- a/salsa-2022-tests/tests/expect_reuse_field_x_of_a_tracked_struct_changes_but_fn_depends_on_field_y.rs +++ b/salsa-2022-tests/tests/expect_reuse_field_x_of_a_tracked_struct_changes_but_fn_depends_on_field_y.rs @@ -78,13 +78,13 @@ fn execute() { assert_eq!(final_result_depends_on_x(&db, input), 22); db.assert_logs(expect![[r#" [ - "final_result_depends_on_x(MyInput(Id { value: 1 }))", + "final_result_depends_on_x(MyInput { [salsa id]: 0 })", ]"#]]); assert_eq!(final_result_depends_on_y(&db, input), 22); db.assert_logs(expect![[r#" [ - "final_result_depends_on_y(MyInput(Id { value: 1 }))", + "final_result_depends_on_y(MyInput { [salsa id]: 0 })", ]"#]]); input.set_field(&mut db).to(23); @@ -94,7 +94,7 @@ fn execute() { assert_eq!(final_result_depends_on_x(&db, input), 24); db.assert_logs(expect![[r#" [ - "final_result_depends_on_x(MyInput(Id { value: 1 }))", + "final_result_depends_on_x(MyInput { [salsa id]: 0 })", ]"#]]); // y = 23 / 2 = 11 diff --git a/salsa-2022-tests/tests/expect_reuse_field_x_of_an_input_changes_but_fn_depends_on_field_y.rs b/salsa-2022-tests/tests/expect_reuse_field_x_of_an_input_changes_but_fn_depends_on_field_y.rs index 0cd9da7b..0096210b 100644 --- a/salsa-2022-tests/tests/expect_reuse_field_x_of_an_input_changes_but_fn_depends_on_field_y.rs +++ b/salsa-2022-tests/tests/expect_reuse_field_x_of_an_input_changes_but_fn_depends_on_field_y.rs @@ -57,13 +57,13 @@ fn execute() { assert_eq!(result_depends_on_x(&db, input), 23); db.assert_logs(expect![[r#" [ - "result_depends_on_x(MyInput(Id { value: 1 }))", + "result_depends_on_x(MyInput { [salsa id]: 0 })", ]"#]]); assert_eq!(result_depends_on_y(&db, input), 32); db.assert_logs(expect![[r#" [ - "result_depends_on_y(MyInput(Id { value: 1 }))", + "result_depends_on_y(MyInput { [salsa id]: 0 })", ]"#]]); input.set_x(&mut db).to(23); @@ -71,7 +71,7 @@ fn execute() { assert_eq!(result_depends_on_x(&db, input), 24); db.assert_logs(expect![[r#" [ - "result_depends_on_x(MyInput(Id { value: 1 }))", + "result_depends_on_x(MyInput { [salsa id]: 0 })", ]"#]]); // input y is the same, so result depends on y diff --git a/salsa-2022-tests/tests/hello_world.rs b/salsa-2022-tests/tests/hello_world.rs index b3471b5b..d4726306 100644 --- a/salsa-2022-tests/tests/hello_world.rs +++ b/salsa-2022-tests/tests/hello_world.rs @@ -58,8 +58,8 @@ fn execute() { assert_eq!(final_result(&db, input), 22); db.assert_logs(expect![[r#" [ - "final_result(MyInput(Id { value: 1 }))", - "intermediate_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); // Intermediate result is the same, so final result does @@ -68,15 +68,15 @@ fn execute() { assert_eq!(final_result(&db, input), 22); db.assert_logs(expect![[r#" [ - "intermediate_result(MyInput(Id { value: 1 }))", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); input.set_field(&mut db).to(24); assert_eq!(final_result(&db, input), 24); db.assert_logs(expect![[r#" [ - "intermediate_result(MyInput(Id { value: 1 }))", - "final_result(MyInput(Id { value: 1 }))", + "intermediate_result(MyInput { [salsa id]: 0 })", + "final_result(MyInput { [salsa id]: 0 })", ]"#]]); } @@ -89,8 +89,8 @@ fn red_herring() { assert_eq!(final_result(&db, input), 22); db.assert_logs(expect![[r#" [ - "final_result(MyInput(Id { value: 1 }))", - "intermediate_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); // Create a distinct input and mutate it. diff --git a/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs b/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs index 00ddef1a..f6e33b9e 100644 --- a/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs +++ b/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs @@ -95,13 +95,13 @@ fn test_run_0() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); } @@ -116,13 +116,13 @@ fn test_run_5() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); } @@ -137,16 +137,16 @@ fn test_run_10() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", - "maybe_specified(MyTracked(Id { value: 1 }))", + "maybe_specified(MyTracked { [salsa id]: 0 })", ]"#]]); } @@ -160,16 +160,16 @@ fn test_run_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", - "maybe_specified(MyTracked(Id { value: 1 }))", + "maybe_specified(MyTracked { [salsa id]: 0 })", ]"#]]); } @@ -187,13 +187,13 @@ fn test_run_0_then_5_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -208,7 +208,7 @@ fn test_run_0_then_5_then_20() { "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: read_maybe_specified(0) } }", @@ -227,17 +227,17 @@ fn test_run_0_then_5_then_20() { "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: create_tracked(0), output_key: maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", - "maybe_specified(MyTracked(Id { value: 1 }))", + "maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -257,13 +257,13 @@ fn test_run_0_then_5_then_10_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -278,7 +278,7 @@ fn test_run_0_then_5_then_10_then_20() { "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: read_maybe_specified(0) } }", @@ -297,12 +297,12 @@ fn test_run_0_then_5_then_10_then_20() { "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: create_tracked(0), output_key: maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", - "maybe_specified(MyTracked(Id { value: 1 }))", + "maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: read_maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: final_result(0) } }", ]"#]]); @@ -317,16 +317,16 @@ fn test_run_0_then_5_then_10_then_20() { "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", - "maybe_specified(MyTracked(Id { value: 1 }))", + "maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -342,13 +342,13 @@ fn test_run_5_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -359,17 +359,17 @@ fn test_run_5_then_20() { "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", - "create_tracked(MyInput(Id { value: 1 }))", + "create_tracked(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: create_tracked(0), output_key: maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", - "maybe_specified(MyTracked(Id { value: 1 }))", + "maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", - "read_maybe_specified(MyTracked(Id { value: 1 }))", + "read_maybe_specified(MyTracked { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", - "final_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); diff --git a/salsa-2022-tests/tests/tracked_fn_read_own_entity.rs b/salsa-2022-tests/tests/tracked_fn_read_own_entity.rs index a79860f8..d4621586 100644 --- a/salsa-2022-tests/tests/tracked_fn_read_own_entity.rs +++ b/salsa-2022-tests/tests/tracked_fn_read_own_entity.rs @@ -59,8 +59,8 @@ fn one_entity() { assert_eq!(final_result(&db, input), 22); db.assert_logs(expect![[r#" [ - "final_result(MyInput(Id { value: 1 }))", - "intermediate_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); // Intermediate result is the same, so final result does @@ -69,15 +69,15 @@ fn one_entity() { assert_eq!(final_result(&db, input), 22); db.assert_logs(expect![[r#" [ - "intermediate_result(MyInput(Id { value: 1 }))", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); input.set_field(&mut db).to(24); assert_eq!(final_result(&db, input), 24); db.assert_logs(expect![[r#" [ - "intermediate_result(MyInput(Id { value: 1 }))", - "final_result(MyInput(Id { value: 1 }))", + "intermediate_result(MyInput { [salsa id]: 0 })", + "final_result(MyInput { [salsa id]: 0 })", ]"#]]); } @@ -90,8 +90,8 @@ fn red_herring() { assert_eq!(final_result(&db, input), 22); db.assert_logs(expect![[r#" [ - "final_result(MyInput(Id { value: 1 }))", - "intermediate_result(MyInput(Id { value: 1 }))", + "final_result(MyInput { [salsa id]: 0 })", + "intermediate_result(MyInput { [salsa id]: 0 })", ]"#]]); // Create a distinct input and mutate it. diff --git a/salsa-2022-tests/tests/tracked_with_struct_db.rs b/salsa-2022-tests/tests/tracked_with_struct_db.rs index 38fae912..e3890948 100644 --- a/salsa-2022-tests/tests/tracked_with_struct_db.rs +++ b/salsa-2022-tests/tests/tracked_with_struct_db.rs @@ -57,10 +57,9 @@ fn execute() { field: "foo", }, next: Next( - MyTracked( - 0x00007fc15c011010, - PhantomData<&salsa_2022::tracked_struct::ValueStruct>, - ), + MyTracked { + [salsa id]: 0, + }, ), } "#]].assert_debug_eq(&t0.debug(&db));