Commit graph

133 commits

Author SHA1 Message Date
Niko Matsakis
ea1d452143 create a struct_map that encapsulates access
The internal API is now based around providing
references to the `TrackedStructValue`.

Documenting the invariants led to one interesting
case, which is that we sometimes verify a tracked
struct as not having changed (and even create
`&`-ref to it!) but then re-execute the function
around it.

We now guarantee that, in this case, the data
does not change, even if it has leaked values.
This is required to ensure soundness.
Add a test case about it.
2024-05-24 07:16:47 -04:00
Niko Matsakis
4533cd9e4b adopt the Salsa 3.0 Update` trait
Right now, this doesn't change much except the
behavior in the event that `Eq` is not properly
implemented. In the future, it will enable
the use of references and slices and things.
2024-05-24 07:15:40 -04:00
Niko Matsakis
b12ff3297c update tracked struct created_at when validated
Fixes #484
2024-04-05 05:16:50 -04:00
Niko Matsakis
f4a8ed650f update tracked struct created_at when validated
Fixes #484
2024-04-05 05:15:59 -04:00
Niko Matsakis
5d6f883b18 improve spans for inputs 2024-04-04 06:24:07 -04:00
Niko Matsakis
e2f6437890 add tests that show improved spans 2024-04-04 06:21:33 -04:00
Niko Matsakis
fd15c3a600 support customizing the DebugWithDb impl 2024-04-03 06:23:43 -04:00
Niko Matsakis
389aa66bcf print all fields in debug() but ignore deps
In a previous PR we added the `include_all_fields`
parameter to `DebugWithDb` to allow it to
not create spurious dependencies.

This PR takes a different approach: we simply
ignore the dependencies created during debug
operations. This is risky as it can create
incorrect dependencies, but it is way more
convenient and seems like what users probably
want.

It also means that `DebugWithDb` has a simpler
signature that matches the `Debug` trait again,
which seems good to me.
2024-04-03 05:59:11 -04:00
Niko Matsakis
8772961573 clippy, you are truly righteous and exacting 2024-04-02 07:05:17 -04:00
Niko Matsakis
54b33c335a create tracked field-ingredients 2024-04-02 06:08:55 -04:00
Niko Matsakis
f1d318a279
Merge pull request #450 from DropDemBits/placement-new-jars
Initialize jars in-place
2023-11-09 10:25:26 +00:00
Niko Matsakis
703794b1c7
Merge pull request #461 from Y-Nak/provide-access-to-ingredient-index
Provide a public API to obtain `IngredientIndex`
2023-11-09 10:21:37 +00:00
Yoshitomo Nakanishi
d0ca81e58f Update macro test fixtures to reflect rustc diagnostics updates 2023-10-08 21:47:01 +02:00
DropDemBits
5b8412656c
Initialize jars in-place
Requires unsafe, since Rust currently doesn't have built-in
support for guaranteed in-place initialization. Unfortunately,
this unsafety propagates to making `Jar` unsafe to implement
in order to guarantee that the jar is initialized, but since
the preferred way to implement it is via `salsa::jar`, this
won't impact most users.
2023-06-14 01:09:58 -04:00
DropDemBits
22646a8fb4
Improve assert message when creating a tracked struct outside of a tracked function 2023-06-13 16:35:28 -04:00
Yoshitomo Nakanishi
cbafc307fc Fix trybuild ui test to adapt the change of rustc error message 2023-04-22 11:16:51 +02:00
bors[bot]
a327acc126
Merge #435
435: Allow `clippy::needless_lifetimes` on tracked method getters r=XFFXFF a=DropDemBits

The tracked method generation adds an extra `__db` lifetime to the signature, but clippy complains that this lifetime can be elided in some cases, so add an allow to silence this warning.

Unfortunately clippy doesn't lint inside of the warning tests, so those tests don't do anything to check that no clippy warnings are generated.

Co-authored-by: DropDemBits <r3usrlnd@gmail.com>
2023-03-17 12:32:20 +00:00
DropDemBits
ee762e8bdf
Update trybuild tests
Rust 1.68 changed how the help suggestion text renders, showing a diff
for the suggested change.
2023-03-15 10:37:08 -04:00
DropDemBits
7c8647e572
Allow clippy::needless_lifetimes on tracked method getters
Previously, this would necessitate having to manually add an allow for this
clippy lint, since an extra `'db` lifetime was added to the signature.
2023-03-15 09:56:00 -04: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
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
XFFXFF
a8e16a72d2 update test: don't need mut reference when create inputs 2022-09-25 01:38:41 +00:00
XFFXFF
e7c7f386fe fix accumulator: clear the outdated accumulated values 2022-09-25 00:24:16 +00:00
XFFXFF
559c02ba80 update a test 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
a1db7d4e84 add a test 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
armoha
9fc958bb1d update compile-fail test .stderr message 2022-09-24 14:40:02 +09:00
OLUWAMUYIWA
0f21bf0fd8 made singleton struct panic upon duplication and added tests to immutable fields 2022-09-16 14:53:56 +01:00
Onigbinde Oluwamuyiwa Elijah
e3661de899
Merge branch 'salsa-rs:master' into immutable_fields_in_inputs 2022-09-16 01:53:42 +01:00
Jack Rickard
f1499a20e2
Fix unsoundness in input_field.rs 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
OLUWAMUYIWA
32f0ce0cff better debugging for input structs by including id fields 2022-09-14 14:45:59 +01:00
Bernardo Uriarte
3f74f36418 format 2022-09-13 18:01:21 +02:00
Bernardo Uriarte
84445d5120 propagate include_all_fields option 2022-09-13 18:01:21 +02:00
Bernardo Uriarte
f4c6f4126e make DebugWithDb::debug only read identiy fields
and add `DebugWithDb::debug_all` which reads all fields
2022-09-13 18:01:19 +02:00
Onigbinde Oluwamuyiwa Elijah
fac05b3c9f
Merge branch 'salsa-rs:master' into singleton 2022-09-11 09:12:17 +01:00
OLUWAMUYIWA
7f691e3907 fixed difference in .stderr files 2022-09-07 22:19:05 +01:00
Onigbinde Oluwamuyiwa Elijah
a2fbd1c09e
Merge branch 'salsa-rs:master' into exhaustive-macros-test 2022-09-07 21:39:28 +01:00
OLUWAMUYIWA
08449c61b4 eshaustive tests to check salsa macros using the trybuild tool 2022-09-07 20:09:33 +01:00
Jack Rickard
5832ad3090
Replace () with Singleton Salsa struct 2022-09-06 00:34:00 +01:00
Jack Rickard
a9e24d8b0d
Allow "constant" tracked functions
This adds support for tracked functions with only a database as input,
that is, it does not take a salsa struct.
2022-09-06 00:33:43 +01:00
bors[bot]
e0d07812fa
Merge #392
392: Allow creation of tracked methods r=nikomatsakis a=Skepfyr

Fixes #319.

This allows users to annotate impl blocks with `#[salsa::tracked]` and
then create tracked methods by marking individual functions with
`#[salsa::tracked]`.

Note this requires your code that looks like:
```rust
#[salsa::tracked(jar = Jar)]
impl MyInput {
    #[salsa::tracked]
    fn tracked_fn(self, db: &dyn Db) -> u32 {
        self.field(db) * 2
    }
}
```
You get an error if you annotate a method with `#[salsa::tracked]` but forget to mark the impl block.

It got messier than I was hoping but I think it turned out alright, this would look really pretty if we had [inherent associated types](https://github.com/rust-lang/rust/issues/8995), but we don't. Annoyingly even if that landed I think we'd still need the attribute on the impl block just so that it was possible to create the associated struct somewhere as you can't put types inside an impl block (and they aren't accessible if placed inside a function).

Co-authored-by: Jack Rickard <jack.rickard@outlook.com>
2022-09-05 10:44:51 +00:00
Jack Rickard
bac4c668cf
Add more tests for tracked methods 2022-09-03 15:44:56 +01:00
Onigbinde Oluwamuyiwa Elijah
aa25761bd4
Merge branch 'salsa-rs:master' into singleton 2022-09-03 14:37:27 +01:00
OLUWAMUYIWA
25809151dd removed AllowedMode trait and added compile-fail tests 2022-09-02 13:09:28 +01:00
OLUWAMUYIWA
3ca70e6b04 cargo fmt 2022-09-02 03:02:51 +01:00