-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Recompile macro on error #19916
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
Comments
I don't understand what you want. Are you talking about proc macros or macro_rules? Do the errors come from rustc or rust-analyzer? |
@ChayimFriedman2 hi, thanks for asking: Right now when i'm saving file with sqlx macro i get When i'm starting database and saving file again - error persist. To make error disappear i have to restart rust-analyzer completely |
If it appears only on save, it's probably a rustc error. Can you share the full error (when you hover over it)? |
I think we cache the proc macro expansions (we couldn't know when we have to re-run them), and IIRC rustc is also experimenting with this. You should probably try the "offline mode" of |
yeah i know about offline mode. Next time when i get panic from proc macro (not from sqlx) i will try to save as much info as possible (solution is to restart rust-analyzer too). Because errors are random and not 100% reproducible Until that happens please don't close this issue ❤ Idea is to invalidate cache when any error happens (yeah its hard, but i believe DX can be improved here) |
Let's be clear: we don't and never will properly support macros that use side channels like reading from a db. We will cache macros, and not rerun them on every change, otherwise IDE experience will be catastrophic. |
That's not going to help if you change your db schema and the macro doesn't know about it. And if the compiler moves towards caching proc macro expansions, these crates will have bigger problems on their hands. |
Again it's not only about sqlx. Other macros are panicking too (or rust analyzer panicking. I don't understand from logs). No need to rebuild every macro on every save. Only when error occurs - rebuild failed macro |
What other macros are failing? Rerunning even failed macros on every type is not an option. |
I will provide more info when i get to my pc. |
No. It is not an option because it will degrade performance to the borderline of being usable. Also note that it's very hard to detect when a proc macro is failing. Detecting panics is easy, but what happens when a macro emits a |
I see how it is difficult right now to implement. But i don't really understand how it will affect performance in any way (was it done before?). it's probably much more complicated, but i believe some mechanisms need to be implemented in order to achieve better dx. |
It will affect performance because it will mean we will have to re-execute failed macros on every keystroke. It is also hard to implement as we can't have side maps in r-a. Furthermore, it barely helps. If you change the db schema but type nothing in the editor, we have no way to know something has changed. And you can change the db schema when the macro succeeds to, and make it fail; so rerunning only failed macros does not solve the problem. But above it all, macros that use side channels like reading a db are a hack, fundamentally opposed to how r-a is operating, and also unsupported by the letter of the law. And, like @lnicola said, if rustc will also start following the letter of the law, they will be in bigger problems. |
What if we don't have to re-execute it on every keystroke? For example i have cargo-check only on save. Also this can be an opt-in feature: "do you want to recompile failed macros on each check?". This way people who want this feature - can turn it on. Btw i'm sorry i confused you recompilation of sqlx is not required since it currenly working correctly: when i save after connection error - it re-executes properly. The only problem i'm talking about right now are panics that requires me to restart rust-analyzer when error occurs. What exact errors i will write here when i get them again. |
Does panics still persist after you edit the macro's input? If it does it's a bug, unless sqlx caches the db connection in a Check on save already causes major troubles for us due to code complexity. I definitely don't want to even imagine how it will look like if we add this. The cost is just not worth the benefit. For the same reason a setting does not help. |
@ChayimFriedman2 yeah error persist, i have to restart RA to make it disappear. Same error with other macros too, not just sqlx. |
What other macros? |
Lately I get a lot of "macro expansion" errors. Is it possible to restart/recompile those macros on next "save" event if error happens?
The text was updated successfully, but these errors were encountered: