Skip to content
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

#[derive] below #[salsa::tracked] is not functional? #469

Open
NickNick opened this issue Dec 5, 2023 · 5 comments
Open

#[derive] below #[salsa::tracked] is not functional? #469

NickNick opened this issue Dec 5, 2023 · 5 comments

Comments

@NickNick
Copy link

NickNick commented Dec 5, 2023

With salsa-2022, I noticed the following code will compile.

#[salsa::tracked]
#[derive(what ever you write here is fine)]
struct Foo;

It seems that derive line is discarded? I didn't notice until I added a derive I actually needed.

@Y-Nak
Copy link
Contributor

Y-Nak commented Mar 8, 2024

It seems that derive line is discarded?

Yes, #[salsa::tracked]/#[salsa::input]/#[salsa::interned] attribute macros intentionally drop derive macros, please refer to here for more context.

@xiyuzhai
Copy link

xiyuzhai commented Mar 8, 2024

That's intentional. The struct becomes just a thin wrapper of an id.

@xiyuzhai
Copy link

xiyuzhai commented Mar 8, 2024

You can use rust analyzer expand macro command to see what's going on. Because the fields would require a database reference to access, the derive attr for Debug Clone Copy wouldn't make any sense. And by the way, the resulting type implements quite a few trait in its own way, Debug Clone Copy PartialEq Eq Hash

@NickNick
Copy link
Author

Thanks for the responses.

However intentional it may be, it was surprising to me that it was just discarded.

How about an error for this, indicating that this isn't supported? Not sure if that is possible, but that would remove the surprise for me.

It is some time ago now, but if I recall correctly it did work when I flipped the lines:

#[derive(...)]
#[salsa(...)]

What I mean with that it did work is that that derive seemed effective, but I may not recall this correctly (and don't have the code anymore). The previously mentioned error could mention this as fix/workaround?

Thanks again!

@xiyuzhai
Copy link

I would imagine a fix would be quite simple. Just run through attrs in the procedural macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants