Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/active_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ impl ActiveQuery {
// Mark all tracked structs from the previous iteration as active.
self.tracked_struct_ids
.mark_all_active(active_tracked_ids.iter().copied());
self.disambiguator_map
.seed(active_tracked_ids.iter().map(|(id, _)| id));
}

pub(super) fn take_cycle_heads(&mut self) -> CycleHeads {
Expand Down
1 change: 0 additions & 1 deletion src/function/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ where
// This is different from `opt_old_memo` which might be from a different revision.
let mut last_provisional_memo_opt: Option<&Memo<'db, C>> = None;

// TODO: Can we seed those somehow?
let mut last_stale_tracked_ids: Vec<(Identity, Id)> = Vec::new();
let mut iteration_count = IterationCount::initial();

Expand Down
13 changes: 11 additions & 2 deletions src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,20 @@ impl DisambiguatorMap {
result
}

pub fn clear(&mut self) {
pub(crate) fn seed<'a>(&mut self, identities: impl Iterator<Item = &'a Identity>) {
for identity in identities {
self.disambiguate(IdentityHash {
ingredient_index: identity.ingredient_index,
hash: identity.hash,
});
}
}

pub(crate) fn clear(&mut self) {
self.map.clear()
}

pub fn is_empty(&self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
self.map.is_empty()
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/cycle_tracked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,36 @@ fn test_cycle_with_fixpoint_structs() {
"DidDiscard { key: IterationNode(Id(402)) }",
]"#]]);
}

#[salsa::tracked(debug)]
struct NameWithOffset<'db> {
name: String,

#[tracked]
offset: u32,
}

#[test]
fn cycle_tracked_struct_with_tracked_field() {
#[salsa::tracked(cycle_initial=|_,_| 0)]
fn query_a(db: &dyn salsa::Database) -> u32 {
let offset = query_b(db);

let tracked = NameWithOffset::new(db, "test".to_string(), offset);

tracked.offset(db)
}

#[salsa::tracked]
fn query_b(db: &dyn salsa::Database) -> u32 {
let base_offset = query_a(db);

(base_offset + 1).min(5)
}

let db = salsa::DatabaseImpl::default();

let result = query_a(&db);

assert_eq!(result, 5);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always returned 1 before

}
Loading