Commit graph

1271 commits

Author SHA1 Message Date
Per Vognsen
d817d14d1e Update videos.md with architecture walkthrough 2023-02-03 17:45:17 +07:00
bors[bot]
20c7834ff3
Merge #428
428: salsa-2022: fix hanging cancellations due to cvar not being notified r=nikomatsakis a=manapointer

This PR fixes an issue with the `cvar` condvar field of `Shared<DB>` not being notified when `Arc<Shared<DB>>`s were getting dropped. 

Previously, the condvar was being notified here:

```rust
impl<DB> Drop for Shared<DB>
where
    DB: HasJars,
{
    fn drop(&mut self) {
        self.cvar.notify_all();
    }
}
```

However, because this is implemented on `Shared<DB>`, the `drop` code only ran after all `Arc<Shared<DB>>`s (including that of the actual database and not just its snapshots) had dropped first, even though the intention was for the `drop` code to run when each individual `Arc<Shared<DB>>` was dropped so that the condvar would be notified each time.

To fix this, I've modified the `Shared<DB>` struct to instead hold `Arc`s to both the jars and the condvar, and `Storage` now holds `Shared<DB>` directly rather than `Arc<Shared<DB>>`. When `Shared<DB>` is dropped, it first drops its `Arc` for the jars, and then notifies the condvar.

## Note 
On my local branch I have a test case for this functionality, although it relied on timing using `std:🧵:sleep`. I figured this was less than ideal, so I decided not to include it in this PR - I'd love to get feedback on a better way to test this!

Co-authored-by: manapointer <manapointer@gmail.com>
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-12-29 16:37:53 +00:00
Niko Matsakis
ce4b041048
Update components/salsa-2022/src/storage.rs 2022-12-29 11:37:06 -05:00
manapointer
f1a775c355 update docs to be accurate to the change 2022-12-25 18:18:11 -08:00
manapointer
57b848da3e impl drop for storage 2022-12-25 18:10:42 -08:00
manapointer
2fc0a3c08f fix cvar not being notified when Arc<Shared<DB>> is dropped 2022-12-22 15:46:28 -08:00
bors[bot]
252d21e358
Merge #423
423: salsa 2022: fix input macro set_* being off by one if id field present r=XFFXFF a=jhgg

This PR fixes an issue with code generation for `#[salsa::input]` struct's `set_` methods. 

Consider the following code:

```rust
#[salsa::input(jar = Jar)]
struct BuggedInput {
    #[id]
    id: u32,
    other: String,
}
```

This will expand to:

```rust
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
struct BuggedInput(salsa::Id);

impl BuggedInput {
     // snip...
    fn set_other<'db>(
        self,
        __db: &'db mut <Jar as salsa:🫙:Jar<'_>>::DynDb,
    ) -> salsa::setter::Setter<'db, BuggedInput, u32> {
        //                                       ^^^ wrong type (should be `String`)
        let (__jar, __runtime) = <_ as salsa::storage::HasJar<Jar>>::jar_mut(__db);
        let __ingredients =
            <Jar as salsa::storage::HasIngredientsFor<BuggedInput>>::ingredient_mut(__jar);
        salsa::setter::Setter::new(__runtime, self, &mut __ingredients.0)
        //                                                             ^ wrong index (should be `1`)
   }
}
```

Here we can see that the generated `set_other` impl is improperly setting the `id` field. This bug is caused because the filtering of the id fields in `InputStruct::all_set_field_names` causes a mismatch in `InputStruct::input_inherent_impl` when zipped with the field indices and types.

This PR changes `all_set_field_names` to return an `Option<&syn::Ident>` where the None is provided when a setter should not be generated, thus not causing index mismatches because no filtering occurs. Instead, we filter inside of `input_inherent_impl` after all the zips have been applied to the iterator.

After this PR, the code generated is now correct:

```rust
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
struct BuggedInput(salsa::Id);

impl BuggedInput {
     // snip...
    fn set_other<'db>(
        self,
        __db: &'db mut <Jar as salsa:🫙:Jar<'_>>::DynDb,
    ) -> salsa::setter::Setter<'db, BuggedInput, String> {
        let (__jar, __runtime) = <_ as salsa::storage::HasJar<Jar>>::jar_mut(__db);
        let __ingredients =
            <Jar as salsa::storage::HasIngredientsFor<BuggedInput>>::ingredient_mut(__jar);
        salsa::setter::Setter::new(__runtime, self, &mut __ingredients.1)
    }
}
```


Co-authored-by: Jake Heinz <jh@discordapp.com>
2022-11-29 04:54:45 +00:00
bors[bot]
328e459bee
Merge #426
426: update compile fail tests for latest stable rustc r=XFFXFF a=XFFXFF



Co-authored-by: XFFXFF <1247714429@qq.com>
2022-11-29 04:46:33 +00:00
XFFXFF
51f1f0c36d update compile fail tests for latest stable rustc 2022-11-29 12:36:12 +08:00
Jake Heinz
dd10b16964 salsa 2022: fix input macro set_* being off by one if id field present 2022-11-04 23:39:35 +00:00
bors[bot]
30b5e9760a
Merge #412
412: Fix race condition in interned data r=nikomatsakis a=Skepfyr

In some scenarios the `InternedIngredient` could return two different ids for the same data if called in parallel.

Co-authored-by: Jack Rickard <jack.rickard@outlook.com>
2022-09-27 22:48:54 +00:00
bors[bot]
ccd604d028
Merge #413
413: panic when reading fields of tracked structs from older revisions r=nikomatsakis a=XFFXFF

fix #407 

Co-authored-by: XFFXFF <1247714429@qq.com>
Co-authored-by: zhou fan <1247714429@qq.com>
2022-09-26 20:41:48 +00:00
XFFXFF
f48ca09a65 add empty dependencies back 2022-09-26 10:58:21 +00:00
XFFXFF
589bbeb65e Revert "remove unused variables and functions"
This reverts commit a2be847e1a.
2022-09-26 10:51:23 +00:00
XFFXFF
8f85d4ee27 cargo fmt 2022-09-26 09:15:10 +00:00
XFFXFF
409ed367c2 using flat-map trick 2022-09-26 09:14:30 +00:00
zhou fan
6239fc217a
add a comment
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-09-26 17:09:19 +08:00
Jack Rickard
c58ff26d87
Simplify interning by restricting deletes 2022-09-25 22:33:37 +01:00
XFFXFF
a8e16a72d2 update test: don't need mut reference when create inputs 2022-09-25 01:38:41 +00:00
XFFXFF
cc6ab647fa refactor outputs method of LocalState 2022-09-25 01:21:39 +00:00
XFFXFF
e7c7f386fe fix accumulator: clear the outdated accumulated values 2022-09-25 00:24:16 +00:00
XFFXFF
1214610451 remove inputs method of QueryEdges 2022-09-24 23:59:25 +00:00
XFFXFF
559c02ba80 update a test 2022-09-24 23:59:25 +00:00
XFFXFF
a2be847e1a remove unused variables and functions 2022-09-24 23:59:25 +00:00
XFFXFF
d71892c047 update diff output 2022-09-24 23:59:25 +00:00
XFFXFF
961c4ce154 update some tests and run cargo fmt 2022-09-24 23:59:25 +00:00
XFFXFF
98d1be0650 mark the outputs as valid as we encounter them in deep_verify_memo 2022-09-24 23:59:25 +00:00
XFFXFF
c219944699 merge input/output lists into one list 2022-09-24 23:59:25 +00:00
XFFXFF
a1db7d4e84 add a test 2022-09-24 23:59:25 +00:00
XFFXFF
1ae6a7bbc5 use Assigned insread of Field and remove Field 2022-09-24 23:59:25 +00:00
XFFXFF
99cfca5799 add the fields of tracked struct to the output of queries 2022-09-24 23:59:25 +00:00
XFFXFF
4c4096e39b panic when reading fields of tracked structs from older revisions 2022-09-24 23:59:25 +00:00
bors[bot]
2ffe4a78a8
Merge #417
417: Fix Chinese book link r=XFFXFF a=armoha

cc `@zjp-CN` 

- Previous link: https://zjp-cn.github.io/salsa
- Fixed link: https://rust-chinese-translation.github.io/salsa-book/

Co-authored-by: armoha <kein0011@naver.com>
2022-09-24 06:16:13 +00:00
armoha
9fc958bb1d update compile-fail test .stderr message 2022-09-24 14:40:02 +09:00
armoha
892d555792
Fix Chinese book link 2022-09-24 01:00:36 +09:00
bors[bot]
07848c2818
Merge #416
416: Correct docs to refer to `#[salsa::cycle]` r=nikomatsakis a=ssbr

Judging by the examples, `recover` is an outdated name.

E.g. https://github.com/salsa-rs/salsa/blob/master/tests/cycles.rs

(I can't really test this on version 0.16, so I'm just going by the examples.)

Co-authored-by: Devin Jeanpierre <jeanpierreda@google.com>
2022-09-17 11:13:06 +00:00
bors[bot]
0357e53ce9
Merge #414
414: better debugging for input structs by including id fields r=nikomatsakis a=OLUWAMUYIWA

Ref: #405 

Fixes #415 

Co-authored-by: OLUWAMUYIWA <onigbindemy@gmail.com>
Co-authored-by: Onigbinde Oluwamuyiwa Elijah <onigbindemy@gmail.com>
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-09-17 10:44:59 +00:00
Niko Matsakis
684ab6f4fe
Update components/salsa-2022/src/input.rs 2022-09-17 06:44:11 -04:00
OLUWAMUYIWA
4bb4262569 cargo fmt 2022-09-16 15:02:15 +01:00
OLUWAMUYIWA
0f21bf0fd8 made singleton struct panic upon duplication and added tests to immutable fields 2022-09-16 14:53:56 +01:00
Devin Jeanpierre
71c1d2e48e Correct docs to refer to #[salsa::cycle]
Judging by the examples, `recover` is an outdated name.

E.g. https://github.com/salsa-rs/salsa/blob/master/tests/cycles.rs
2022-09-16 11:10:06 +00:00
Onigbinde Oluwamuyiwa Elijah
e3661de899
Merge branch 'salsa-rs:master' into immutable_fields_in_inputs 2022-09-16 01:53:42 +01:00
bors[bot]
3eedb656e0
Merge #404
404: On-demand input r=nikomatsakis a=Skepfyr

Fixes #394 

This is not yet done, but I'd like to get some feedback on the approach.
I think these things are remaining:
- [x] Clean up some now incorrect comments in `input_field.rs`
- [x] ~Update calc-example to use on-demand inputs, and remove the lazy-input example (this is quite fun as you end up with an interactive calculator)~
- [x] Update the book

Co-authored-by: Jack Rickard <jack.rickard@outlook.com>
2022-09-15 23:25:14 +00:00
Jack Rickard
0403696c4e
Update on-demand input docs 2022-09-16 00:14:54 +01:00
Jack Rickard
28987ed733
Move calc and lazy-input examples to examples-2022 2022-09-16 00:14:44 +01:00
Jack Rickard
79823c7f65
Fix deadlock in InternedIngredient::intern 2022-09-16 00:10:33 +01:00
Jack Rickard
9f85023dee
Improve error handling in lazy-input 2022-09-15 21:25:54 +01:00
Jack Rickard
f1499a20e2
Fix unsoundness in input_field.rs 2022-09-15 21:25:54 +01:00
Jack Rickard
609acc396c
Add lazy-input (on-demand) example 2022-09-15 21:25:54 +01:00
Jack Rickard
5b8464c4f9
Support on-demand inputs
This adds initial support for on-demand inputs by allowing new inputs to
be created with only a shared reference to the database. This allows
creating new inputs during a revision and therefore from inside tracked
functions.
2022-09-15 21:25:53 +01:00