Replace derived Debug implementation of salsa::Id

This commit is contained in:
Micha Reiser 2024-06-20 14:45:38 +02:00
parent 431fd14b69
commit 6975a47690
No known key found for this signature in database
18 changed files with 142 additions and 138 deletions

View file

@ -189,14 +189,14 @@ macro_rules! setup_input_struct {
$zalsa::with_attached_database(|db| {
let fields = $Configuration::ingredient(db).leak_fields(this);
let mut f = f.debug_struct(stringify!($Struct));
let f = f.field("[salsa id]", &$zalsa::AsId::as_id(&this).as_u32());
let f = f.field("[salsa id]", &$zalsa::AsId::as_id(&this));
$(
let f = f.field(stringify!($field_id), &fields.$field_index);
)*
f.finish()
}).unwrap_or_else(|| {
f.debug_struct(stringify!($Struct))
.field("[salsa id]", &this.0.as_u32())
.field("[salsa id]", &this.0)
.finish()
})
}

View file

@ -219,14 +219,14 @@ macro_rules! setup_tracked_struct {
$zalsa::with_attached_database(|db| {
let fields = $Configuration::ingredient(db).leak_fields(this);
let mut f = f.debug_struct(stringify!($Struct));
let f = f.field("[salsa id]", &$zalsa::AsId::as_id(&this).as_u32());
let f = f.field("[salsa id]", &$zalsa::AsId::as_id(&this));
$(
let f = f.field(stringify!($field_id), &fields.$field_index);
)*
f.finish()
}).unwrap_or_else(|| {
f.debug_struct(stringify!($Struct))
.field("[salsa id]", &$zalsa::AsId::as_id(&this).as_u32())
.field("[salsa id]", &$zalsa::AsId::as_id(&this))
.finish()
})
}

View file

@ -376,25 +376,25 @@ fn parse_print() {
let expected = expect_test::expect![[r#"
(
Program {
[salsa id]: 0,
[salsa id]: Id(0),
statements: [
Statement {
span: Span {
[salsa id]: 4,
[salsa id]: Id(4),
start: 0,
end: 11,
},
data: Print(
Expression {
span: Span {
[salsa id]: 3,
[salsa id]: Id(3),
start: 6,
end: 11,
},
data: Op(
Expression {
span: Span {
[salsa id]: 0,
[salsa id]: Id(0),
start: 6,
end: 7,
},
@ -407,7 +407,7 @@ fn parse_print() {
Add,
Expression {
span: Span {
[salsa id]: 2,
[salsa id]: Id(2),
start: 10,
end: 11,
},
@ -443,22 +443,22 @@ fn parse_example() {
let expected = expect_test::expect![[r#"
(
Program {
[salsa id]: 0,
[salsa id]: Id(0),
statements: [
Statement {
span: Span {
[salsa id]: 9,
[salsa id]: Id(9),
start: 13,
end: 57,
},
data: Function(
Function {
[salsa id]: 0,
[salsa id]: Id(0),
name: FunctionId {
text: "area_rectangle",
},
name_span: Span {
[salsa id]: 0,
[salsa id]: Id(0),
start: 16,
end: 30,
},
@ -472,14 +472,14 @@ fn parse_example() {
],
body: Expression {
span: Span {
[salsa id]: 8,
[salsa id]: Id(8),
start: 39,
end: 57,
},
data: Op(
Expression {
span: Span {
[salsa id]: 5,
[salsa id]: Id(5),
start: 39,
end: 41,
},
@ -492,7 +492,7 @@ fn parse_example() {
Multiply,
Expression {
span: Span {
[salsa id]: 7,
[salsa id]: Id(7),
start: 43,
end: 57,
},
@ -509,18 +509,18 @@ fn parse_example() {
},
Statement {
span: Span {
[salsa id]: 21,
[salsa id]: Id(21),
start: 57,
end: 102,
},
data: Function(
Function {
[salsa id]: 1,
[salsa id]: Id(1),
name: FunctionId {
text: "area_circle",
},
name_span: Span {
[salsa id]: 10,
[salsa id]: Id(10),
start: 60,
end: 71,
},
@ -531,21 +531,21 @@ fn parse_example() {
],
body: Expression {
span: Span {
[salsa id]: 20,
[salsa id]: Id(20),
start: 77,
end: 102,
},
data: Op(
Expression {
span: Span {
[salsa id]: 17,
[salsa id]: Id(17),
start: 77,
end: 86,
},
data: Op(
Expression {
span: Span {
[salsa id]: 14,
[salsa id]: Id(14),
start: 77,
end: 81,
},
@ -558,7 +558,7 @@ fn parse_example() {
Multiply,
Expression {
span: Span {
[salsa id]: 16,
[salsa id]: Id(16),
start: 84,
end: 86,
},
@ -573,7 +573,7 @@ fn parse_example() {
Multiply,
Expression {
span: Span {
[salsa id]: 19,
[salsa id]: Id(19),
start: 88,
end: 102,
},
@ -590,14 +590,14 @@ fn parse_example() {
},
Statement {
span: Span {
[salsa id]: 28,
[salsa id]: Id(28),
start: 102,
end: 141,
},
data: Print(
Expression {
span: Span {
[salsa id]: 27,
[salsa id]: Id(27),
start: 108,
end: 128,
},
@ -608,7 +608,7 @@ fn parse_example() {
[
Expression {
span: Span {
[salsa id]: 23,
[salsa id]: Id(23),
start: 123,
end: 124,
},
@ -620,7 +620,7 @@ fn parse_example() {
},
Expression {
span: Span {
[salsa id]: 25,
[salsa id]: Id(25),
start: 126,
end: 127,
},
@ -637,14 +637,14 @@ fn parse_example() {
},
Statement {
span: Span {
[salsa id]: 33,
[salsa id]: Id(33),
start: 141,
end: 174,
},
data: Print(
Expression {
span: Span {
[salsa id]: 32,
[salsa id]: Id(32),
start: 147,
end: 161,
},
@ -655,7 +655,7 @@ fn parse_example() {
[
Expression {
span: Span {
[salsa id]: 30,
[salsa id]: Id(30),
start: 159,
end: 160,
},
@ -672,21 +672,21 @@ fn parse_example() {
},
Statement {
span: Span {
[salsa id]: 38,
[salsa id]: Id(38),
start: 174,
end: 195,
},
data: Print(
Expression {
span: Span {
[salsa id]: 37,
[salsa id]: Id(37),
start: 180,
end: 186,
},
data: Op(
Expression {
span: Span {
[salsa id]: 34,
[salsa id]: Id(34),
start: 180,
end: 182,
},
@ -699,7 +699,7 @@ fn parse_example() {
Multiply,
Expression {
span: Span {
[salsa id]: 36,
[salsa id]: Id(36),
start: 185,
end: 186,
},
@ -728,7 +728,7 @@ fn parse_error() {
let expected = expect_test::expect![[r#"
(
Program {
[salsa id]: 0,
[salsa id]: Id(0),
statements: [],
},
[
@ -750,32 +750,32 @@ fn parse_precedence() {
let expected = expect_test::expect![[r#"
(
Program {
[salsa id]: 0,
[salsa id]: Id(0),
statements: [
Statement {
span: Span {
[salsa id]: 10,
[salsa id]: Id(10),
start: 0,
end: 19,
},
data: Print(
Expression {
span: Span {
[salsa id]: 9,
[salsa id]: Id(9),
start: 6,
end: 19,
},
data: Op(
Expression {
span: Span {
[salsa id]: 6,
[salsa id]: Id(6),
start: 6,
end: 16,
},
data: Op(
Expression {
span: Span {
[salsa id]: 0,
[salsa id]: Id(0),
start: 6,
end: 7,
},
@ -788,14 +788,14 @@ fn parse_precedence() {
Add,
Expression {
span: Span {
[salsa id]: 5,
[salsa id]: Id(5),
start: 10,
end: 15,
},
data: Op(
Expression {
span: Span {
[salsa id]: 2,
[salsa id]: Id(2),
start: 10,
end: 11,
},
@ -808,7 +808,7 @@ fn parse_precedence() {
Multiply,
Expression {
span: Span {
[salsa id]: 4,
[salsa id]: Id(4),
start: 14,
end: 15,
},
@ -825,7 +825,7 @@ fn parse_precedence() {
Add,
Expression {
span: Span {
[salsa id]: 8,
[salsa id]: Id(8),
start: 18,
end: 19,
},

View file

@ -12,7 +12,7 @@ use crate::Database;
/// You will rarely use the `Id` type directly, though you can.
/// You are more likely to use types that implement the `AsId` trait,
/// such as entity keys.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Id {
value: NonZeroU32,
}
@ -42,6 +42,12 @@ impl Id {
}
}
impl Debug for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Id({})", self.as_u32())
}
}
impl From<u32> for Id {
fn from(n: u32) -> Self {
Id::from_u32(n)

View file

@ -81,9 +81,9 @@ fn test1() {
assert_eq!(compute(&db, l2), 2);
db.assert_logs(expect![[r#"
[
"compute(List { [salsa id]: 1, value: 2, next: Some(List { [salsa id]: 0, value: 1, next: None }) })",
"accumulated(List { [salsa id]: 0, value: 1, next: None })",
"compute(List { [salsa id]: 0, value: 1, next: None })",
"compute(List { [salsa id]: Id(1), value: 2, next: Some(List { [salsa id]: Id(0), value: 1, next: None }) })",
"accumulated(List { [salsa id]: Id(0), value: 1, next: None })",
"compute(List { [salsa id]: Id(0), value: 1, next: None })",
]"#]]);
// When we mutate `l1`, we should re-execute `compute` for `l1`,
@ -93,7 +93,7 @@ fn test1() {
assert_eq!(compute(&db, l2), 2);
db.assert_logs(expect![[r#"
[
"accumulated(List { [salsa id]: 0, value: 2, next: None })",
"compute(List { [salsa id]: 0, value: 2, next: None })",
"accumulated(List { [salsa id]: Id(0), value: 2, next: None })",
"compute(List { [salsa id]: Id(0), value: 2, next: None })",
]"#]]);
}

View file

@ -72,8 +72,8 @@ fn test1() {
assert_eq!(compute(&db, l2), 2);
db.assert_logs(expect![[r#"
[
"compute(List { [salsa id]: 1, value: 2, next: Some(List { [salsa id]: 0, value: 1, next: None }) })",
"compute(List { [salsa id]: 0, value: 1, next: None })",
"compute(List { [salsa id]: Id(1), value: 2, next: Some(List { [salsa id]: Id(0), value: 1, next: None }) })",
"compute(List { [salsa id]: Id(0), value: 1, next: None })",
]"#]]);
// When we mutate `l1`, we should re-execute `compute` for `l1`,
@ -84,7 +84,7 @@ fn test1() {
assert_eq!(compute(&db, l2), 2);
db.assert_logs(expect![[r#"
[
"compute(List { [salsa id]: 1, value: 2, next: Some(List { [salsa id]: 0, value: 2, next: None }) })",
"compute(List { [salsa id]: 0, value: 2, next: None })",
"compute(List { [salsa id]: Id(1), value: 2, next: Some(List { [salsa id]: Id(0), value: 2, next: None }) })",
"compute(List { [salsa id]: Id(0), value: 2, next: None })",
]"#]]);
}

View file

@ -39,9 +39,7 @@ fn input() {
// debug includes all fields
let actual = format!("{complex_struct:?}");
let expected = expect![[
r#"ComplexStruct { [salsa id]: 0, my_input: MyInput { [salsa id]: 0, field: 22 }, not_salsa: NotSalsa { field: "it's salsa time" } }"#
]];
let expected = expect![[r#"ComplexStruct { [salsa id]: Id(0), my_input: MyInput { [salsa id]: Id(0), field: 22 }, not_salsa: NotSalsa { field: "it's salsa time" } }"#]];
expected.assert_eq(&actual);
})
}
@ -62,7 +60,7 @@ fn untracked_dependencies() {
let s = leak_debug_string(&db, input);
expect![[r#"
"MyInput { [salsa id]: 0, field: 22 }"
"MyInput { [salsa id]: Id(0), field: 22 }"
"#]]
.assert_debug_eq(&s);
@ -103,7 +101,7 @@ fn custom_debug_impl() {
let s = leak_derived_custom(&db, input, 23);
expect![[r#"
"MyInput { [salsa id]: 0, field: 22 } / 23"
"MyInput { [salsa id]: Id(0), field: 22 } / 23"
"#]]
.assert_debug_eq(&s);
}

View file

@ -89,8 +89,8 @@ fn basic() {
assert_eq!(final_result(&db, input), 2 * 2 + 2);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 3 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 3 })",
"final_result(MyInput { [salsa id]: Id(0), field: 3 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 3 })",
]"#]]);
// Creates only 2 tracked structs in this revision, should delete 1
@ -111,12 +111,12 @@ fn basic() {
assert_eq!(final_result(&db, input), 2);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 2 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 2 })",
"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 { [salsa id]: 0, field: 2 })",
"final_result(MyInput { [salsa id]: Id(0), field: 2 })",
]"#]]);
}

View file

@ -83,8 +83,8 @@ fn basic() {
assert_eq!(final_result(&db, input), 2 * 2 + 2);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 3 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 3 })",
"final_result(MyInput { [salsa id]: Id(0), field: 3 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 3 })",
]"#]]);
// Creates only 2 tracked structs in this revision, should delete 1
@ -98,10 +98,10 @@ fn basic() {
assert_eq!(final_result(&db, input), 2);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 2 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 2 })",
"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 { [salsa id]: 0, field: 2 })",
"final_result(MyInput { [salsa id]: Id(0), field: 2 })",
]"#]]);
}

View file

@ -60,8 +60,8 @@ fn execute() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 22 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 22 })",
"final_result(MyInput { [salsa id]: Id(0), field: 22 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
// Intermediate result is the same, so final result does
@ -70,14 +70,14 @@ fn execute() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 23 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 23 })",
]"#]]);
input.set_field(&mut db).to(24);
assert_eq!(final_result(&db, input), 24);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 24 })",
"final_result(MyInput { [salsa id]: 0, field: 24 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 24 })",
"final_result(MyInput { [salsa id]: Id(0), field: 24 })",
]"#]]);
}

View file

@ -74,13 +74,13 @@ fn execute() {
assert_eq!(final_result_depends_on_x(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result_depends_on_x(MyInput { [salsa id]: 0, field: 22 })",
"final_result_depends_on_x(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
assert_eq!(final_result_depends_on_y(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result_depends_on_y(MyInput { [salsa id]: 0, field: 22 })",
"final_result_depends_on_y(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
input.set_field(&mut db).to(23);
@ -90,7 +90,7 @@ fn execute() {
assert_eq!(final_result_depends_on_x(&db, input), 24);
db.assert_logs(expect![[r#"
[
"final_result_depends_on_x(MyInput { [salsa id]: 0, field: 23 })",
"final_result_depends_on_x(MyInput { [salsa id]: Id(0), field: 23 })",
]"#]]);
// y = 23 / 2 = 11

View file

@ -59,13 +59,13 @@ fn execute() {
assert_eq!(result_depends_on_x(&db, input), 23);
db.assert_logs(expect![[r#"
[
"result_depends_on_x(MyInput { [salsa id]: 0, x: 22, y: 33 })",
"result_depends_on_x(MyInput { [salsa id]: Id(0), x: 22, y: 33 })",
]"#]]);
assert_eq!(result_depends_on_y(&db, input), 32);
db.assert_logs(expect![[r#"
[
"result_depends_on_y(MyInput { [salsa id]: 0, x: 22, y: 33 })",
"result_depends_on_y(MyInput { [salsa id]: Id(0), x: 22, y: 33 })",
]"#]]);
input.set_x(&mut db).to(23);
@ -73,7 +73,7 @@ fn execute() {
assert_eq!(result_depends_on_x(&db, input), 24);
db.assert_logs(expect![[r#"
[
"result_depends_on_x(MyInput { [salsa id]: 0, x: 23, y: 33 })",
"result_depends_on_x(MyInput { [salsa id]: Id(0), x: 23, y: 33 })",
]"#]]);
// input y is the same, so result depends on y

View file

@ -60,8 +60,8 @@ fn execute() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 22 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 22 })",
"final_result(MyInput { [salsa id]: Id(0), field: 22 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
// Intermediate result is the same, so final result does
@ -70,15 +70,15 @@ fn execute() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 23 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 23 })",
]"#]]);
input.set_field(&mut db).to(24);
assert_eq!(final_result(&db, input), 24);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 24 })",
"final_result(MyInput { [salsa id]: 0, field: 24 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 24 })",
"final_result(MyInput { [salsa id]: Id(0), field: 24 })",
]"#]]);
}
@ -91,8 +91,8 @@ fn red_herring() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 22 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 22 })",
"final_result(MyInput { [salsa id]: Id(0), field: 22 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
// Create a distinct input and mutate it.

View file

@ -61,7 +61,7 @@ fn debug() {
Database::default().attach(|db| {
let input = MyInput::new(db, 3, 4);
let actual = format!("{:?}", input);
let expected = expect!["MyInput { [salsa id]: 0, field: 3, id_field: 4 }"];
let expected = expect!["MyInput { [salsa id]: Id(0), field: 3, id_field: 4 }"];
expected.assert_eq(&actual);
});
}

View file

@ -89,13 +89,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 { [salsa id]: 0, field: 0 })",
"final_result(MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, field: 0 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 0 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 0 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
}
@ -110,13 +110,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 { [salsa id]: 0, field: 5 })",
"final_result(MyInput { [salsa id]: Id(0), field: 5 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }",
"create_tracked(MyInput { [salsa id]: 0, field: 5 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 5 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 5 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 5 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
}
@ -131,16 +131,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 { [salsa id]: 0, field: 10 })",
"final_result(MyInput { [salsa id]: Id(0), field: 10 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }",
"create_tracked(MyInput { [salsa id]: 0, field: 10 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 10 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 10 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 10 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }",
"maybe_specified(MyTracked { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 10 } })",
"maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 10 } })",
]"#]]);
}
@ -154,16 +154,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 { [salsa id]: 0, field: 20 })",
"final_result(MyInput { [salsa id]: Id(0), field: 20 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }",
"create_tracked(MyInput { [salsa id]: 0, field: 20 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 20 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 20 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }",
"maybe_specified(MyTracked { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 20 } })",
]"#]]);
}
@ -181,13 +181,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 { [salsa id]: 0, field: 0 })",
"final_result(MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, field: 0 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 0 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 0 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
@ -202,7 +202,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 { [salsa id]: 0, field: 5 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 5 })",
"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) } }",
@ -221,17 +221,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 { [salsa id]: 0, field: 20 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 20 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 20 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }",
"read_maybe_specified(MyTracked { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, field: 20 })",
"final_result(MyInput { [salsa id]: Id(0), field: 20 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
@ -251,13 +251,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 { [salsa id]: 0, field: 0 })",
"final_result(MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, field: 0 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 0 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 0 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
@ -272,7 +272,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 { [salsa id]: 0, field: 5 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 5 })",
"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) } }",
@ -291,12 +291,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 { [salsa id]: 0, field: 10 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 10 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 10 } })",
"maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 10 } })",
"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) } }",
]"#]]);
@ -311,16 +311,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 { [salsa id]: 0, field: 20 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 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: maybe_specified(0) } }",
"maybe_specified(MyTracked { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 20 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }",
"read_maybe_specified(MyTracked { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, field: 20 })",
"final_result(MyInput { [salsa id]: Id(0), field: 20 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
@ -336,13 +336,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 { [salsa id]: 0, field: 5 })",
"final_result(MyInput { [salsa id]: Id(0), field: 5 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }",
"create_tracked(MyInput { [salsa id]: 0, field: 5 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 5 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 5 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 5 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);
@ -353,17 +353,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 { [salsa id]: 0, field: 20 })",
"create_tracked(MyInput { [salsa id]: Id(0), field: 20 })",
"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 { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 20 } })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }",
"read_maybe_specified(MyTracked { [salsa id]: 0, input: MyInput { [salsa id]: 0, field: 20 } })",
"read_maybe_specified(MyTracked { [salsa id]: Id(0), input: MyInput { [salsa id]: Id(0), field: 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 { [salsa id]: 0, field: 20 })",
"final_result(MyInput { [salsa id]: Id(0), field: 20 })",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
"Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }",
]"#]]);

View file

@ -61,8 +61,8 @@ fn one_entity() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 22 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 22 })",
"final_result(MyInput { [salsa id]: Id(0), field: 22 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
// Intermediate result is the same, so final result does
@ -71,15 +71,15 @@ fn one_entity() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 23 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 23 })",
]"#]]);
input.set_field(&mut db).to(24);
assert_eq!(final_result(&db, input), 24);
db.assert_logs(expect![[r#"
[
"intermediate_result(MyInput { [salsa id]: 0, field: 24 })",
"final_result(MyInput { [salsa id]: 0, field: 24 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 24 })",
"final_result(MyInput { [salsa id]: Id(0), field: 24 })",
]"#]]);
}
@ -92,8 +92,8 @@ fn red_herring() {
assert_eq!(final_result(&db, input), 22);
db.assert_logs(expect![[r#"
[
"final_result(MyInput { [salsa id]: 0, field: 22 })",
"intermediate_result(MyInput { [salsa id]: 0, field: 22 })",
"final_result(MyInput { [salsa id]: Id(0), field: 22 })",
"intermediate_result(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
// Create a distinct input and mutate it.

View file

@ -56,7 +56,7 @@ fn execute() {
assert_eq!(tracked_fn(&db, input), 2222);
db.assert_logs(expect![[r#"
[
"tracked_fn(MyInput { [salsa id]: 0, field: 22 })",
"tracked_fn(MyInput { [salsa id]: Id(0), field: 22 })",
]"#]]);
// A "synthetic write" causes the system to act *as though* some

View file

@ -45,16 +45,16 @@ fn execute() {
let t1 = create_tracked_list(db, input);
expect_test::expect![[r#"
MyTracked {
[salsa id]: 1,
[salsa id]: Id(1),
data: MyInput {
[salsa id]: 0,
[salsa id]: Id(0),
field: "foo",
},
next: Next(
MyTracked {
[salsa id]: 0,
[salsa id]: Id(0),
data: MyInput {
[salsa id]: 0,
[salsa id]: Id(0),
field: "foo",
},
next: None,