-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from MichaReiser/micha/tracked-fn-update-fall…
…back Use *fallback* trick for tracked-fn `Update` constraint
- Loading branch information
Showing
12 changed files
with
174 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
use salsa::Database as Db; | ||
use salsa::Update; | ||
|
||
#[salsa::input] | ||
struct MyInput { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,20 @@ | ||
warning: unused import: `salsa::Update` | ||
--> tests/compile-fail/tracked_fn_return_ref.rs:2:5 | ||
| | ||
2 | use salsa::Update; | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_imports)]` on by default | ||
|
||
error[E0277]: the trait bound `&'db str: Update` is not satisfied | ||
--> tests/compile-fail/tracked_fn_return_ref.rs:16:67 | ||
| | ||
16 | fn tracked_fn_return_ref<'db>(db: &'db dyn Db, input: MyInput) -> &'db str { | ||
| ^^^^^^^^ the trait `Update` is not implemented for `&'db str` | ||
error: lifetime may not live long enough | ||
--> tests/compile-fail/tracked_fn_return_ref.rs:14:1 | ||
| | ||
= help: the trait `Update` is implemented for `String` | ||
note: required by a bound in `salsa::plumbing::function::Configuration::Output` | ||
--> src/function.rs | ||
14 | #[salsa::tracked] | ||
| ^^^^^^^^^^^^^^^^^ requires that `'db` must outlive `'static` | ||
15 | fn tracked_fn_return_ref<'db>(db: &'db dyn Db, input: MyInput) -> &'db str { | ||
| - lifetime `'db` defined here | ||
| | ||
| type Output<'db>: fmt::Debug + Send + Sync + Update; | ||
| ^^^^^^ required by this bound in `Configuration::Output` | ||
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `ContainsRef<'db>: Update` is not satisfied | ||
--> tests/compile-fail/tracked_fn_return_ref.rs:24:6 | ||
| | ||
24 | ) -> ContainsRef<'db> { | ||
| ^^^^^^^^^^^^^^^^ the trait `Update` is not implemented for `ContainsRef<'db>` | ||
error: lifetime may not live long enough | ||
--> tests/compile-fail/tracked_fn_return_ref.rs:19:1 | ||
| | ||
= help: the following other types implement trait `Update`: | ||
() | ||
(A, B) | ||
(A, B, C) | ||
(A, B, C, D) | ||
(A, B, C, D, E) | ||
(A, B, C, D, E, F) | ||
(A, B, C, D, E, F, G) | ||
(A, B, C, D, E, F, G, H) | ||
and $N others | ||
note: required by a bound in `salsa::plumbing::function::Configuration::Output` | ||
--> src/function.rs | ||
19 | #[salsa::tracked] | ||
| ^^^^^^^^^^^^^^^^^ requires that `'db` must outlive `'static` | ||
... | ||
23 | ) -> ContainsRef<'db> { | ||
| ----------- lifetime `'db` defined here | ||
| | ||
| type Output<'db>: fmt::Debug + Send + Sync + Update; | ||
| ^^^^^^ required by this bound in `Configuration::Output` | ||
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
mod common; | ||
|
||
use salsa::{Database, Setter}; | ||
|
||
#[salsa::tracked] | ||
struct Tracked<'db> { | ||
untracked_1: usize, | ||
|
||
untracked_2: usize, | ||
} | ||
|
||
#[salsa::input] | ||
struct MyInput { | ||
field1: usize, | ||
field2: usize, | ||
} | ||
|
||
#[salsa::tracked] | ||
fn intermediate(db: &dyn salsa::Database, input: MyInput) -> Tracked<'_> { | ||
Tracked::new(db, input.field1(db), input.field2(db)) | ||
} | ||
|
||
#[salsa::tracked] | ||
fn accumulate(db: &dyn salsa::Database, input: MyInput) -> (usize, usize) { | ||
let tracked = intermediate(db, input); | ||
let one = read_tracked_1(db, tracked); | ||
let two = read_tracked_2(db, tracked); | ||
|
||
(one, two) | ||
} | ||
|
||
#[salsa::tracked] | ||
fn read_tracked_1<'db>(db: &'db dyn Database, tracked: Tracked<'db>) -> usize { | ||
tracked.untracked_1(db) | ||
} | ||
|
||
#[salsa::tracked] | ||
fn read_tracked_2<'db>(db: &'db dyn Database, tracked: Tracked<'db>) -> usize { | ||
tracked.untracked_2(db) | ||
} | ||
|
||
#[test] | ||
fn execute() { | ||
let mut db = salsa::DatabaseImpl::default(); | ||
let input = MyInput::new(&db, 1, 1); | ||
|
||
assert_eq!(accumulate(&db, input), (1, 1)); | ||
|
||
// Should only re-execute `read_tracked_1`. | ||
input.set_field1(&mut db).to(2); | ||
assert_eq!(accumulate(&db, input), (2, 1)); | ||
|
||
// Should only re-execute `read_tracked_2`. | ||
input.set_field2(&mut db).to(2); | ||
assert_eq!(accumulate(&db, input), (2, 2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters