- 
                Notifications
    
You must be signed in to change notification settings  - Fork 190
 
Track cycle function dependencies as part of the cyclic query #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
60e3468
              a9e51fa
              45158fc
              fceeb37
              686b929
              48fef27
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #![cfg(feature = "inventory")] | ||
| 
     | 
||
| //! Queries or inputs read within the cycle recovery function | ||
| //! are tracked on the cycle function and don't "leak" into the | ||
| //! function calling the query with cycle handling. | ||
| use expect_test::expect; | ||
| use salsa::Setter as _; | ||
| 
     | 
||
| use crate::common::LogDatabase; | ||
| 
     | 
||
| mod common; | ||
| 
     | 
||
| #[salsa::input] | ||
| struct Input { | ||
| value: u32, | ||
| } | ||
| 
     | 
||
| #[salsa::tracked] | ||
| fn entry(db: &dyn salsa::Database, input: Input) -> u32 { | ||
| query(db, input) | ||
| } | ||
| 
     | 
||
| #[salsa::tracked(cycle_fn=cycle_fn, cycle_initial=cycle_initial)] | ||
| fn query(db: &dyn salsa::Database, input: Input) -> u32 { | ||
| let val = query(db, input); | ||
| if val < 5 { | ||
| val + 1 | ||
| } else { | ||
| val | ||
| } | ||
| } | ||
| 
     | 
||
| fn cycle_initial(_db: &dyn salsa::Database, _id: salsa::Id, _input: Input) -> u32 { | ||
| 0 | ||
| } | ||
| 
     | 
||
| fn cycle_fn( | ||
| db: &dyn salsa::Database, | ||
| _id: salsa::Id, | ||
| _last_provisional_value: &u32, | ||
| _value: &u32, | ||
| _count: u32, | ||
| input: Input, | ||
| ) -> salsa::CycleRecoveryAction<u32> { | ||
| let _input = input.value(db); | ||
| salsa::CycleRecoveryAction::Iterate | ||
| } | ||
| 
     | 
||
| #[test_log::test] | ||
| fn the_test() { | ||
| let mut db = common::EventLoggerDatabase::default(); | ||
| 
     | 
||
| let input = Input::new(&db, 1); | ||
| assert_eq!(entry(&db, input), 5); | ||
| 
     | 
||
| db.assert_logs_len(15); | ||
| 
     | 
||
| input.set_value(&mut db).to(2); | ||
| 
     | 
||
| assert_eq!(entry(&db, input), 5); | ||
| db.assert_logs(expect![[r#" | ||
| [ | ||
| "DidSetCancellationFlag", | ||
| "WillCheckCancellation", | ||
| "WillCheckCancellation", | ||
| "WillCheckCancellation", | ||
| "WillExecute { database_key: query(Id(0)) }", | ||
| "WillCheckCancellation", | ||
| "WillIterateCycle { database_key: query(Id(0)), iteration_count: IterationCount(1) }", | ||
| "WillCheckCancellation", | ||
| "WillIterateCycle { database_key: query(Id(0)), iteration_count: IterationCount(2) }", | ||
| "WillCheckCancellation", | ||
| "WillIterateCycle { database_key: query(Id(0)), iteration_count: IterationCount(3) }", | ||
| "WillCheckCancellation", | ||
| "WillIterateCycle { database_key: query(Id(0)), iteration_count: IterationCount(4) }", | ||
| "WillCheckCancellation", | ||
| "WillIterateCycle { database_key: query(Id(0)), iteration_count: IterationCount(5) }", | ||
| "WillCheckCancellation", | ||
| "DidValidateMemoizedValue { database_key: entry(Id(0)) }", | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before the fix, this incorrectly re-executed  With the fix in   | 
||
| ]"#]]); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand in what case this would be
trueand we need to reset it tofalse.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QueryRevisions::newdefaults totrueif cycle heads are empty. The cycle heads are always empty when callingpopbecause of the precedingquery_guard.take_cycle_heads