-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
infer_schema! reaches the recursion limit easily #1127
Comments
That is sadly a problem we can't easily solve in Diesel. For now, just follow the compiler's advice: Add the Personally, I set this to 1024 at the first error just to not have to deal with this again. Also, IIRC, the default (64 apparently) was recently increased in rustc, so maybe you'll see this error less often in the future. That said, we could solve this in Diesel: We'd need to replace the macro with a procedural macro. That is not an easy feat (the macro is quite complex and has a lot of edge cases), and not currently our focus. We'll absolutely look more deeply into this once the next batch of proc-macro features becomes stable in rustc, though. |
Oh, or do you have a quick fix for this in mind? I've not looked into it more deeply, but if there was an easy change we could make to consume more doc attribute tokens per macro call we'd reduce the table macro's call stack drastically. (Still, not something I really want to spend much time on—there are more pressing matters—but I'd accept a PR for this for sure!) |
Hi, so the trouble I'm having is that any table with more than 24 columns (these are extant tables) throws this error. I can run I tried doing edit: Ok apparently the answer is this is a limitation of Rust itself. Here is an explanation with pointers to more detailed explanations. |
So basically my understanding of it is that the recursion limit is hit when expanding the Like killercup said, the way the So unless the macro gets re-written which has a lot of problems in itself, the only real solution is increasing the recursion limit of your program. |
@Kazakuri Ya I have added that to the top of my Also I added the |
This issue is from 2 years ago... I guess nobody got around to it because this still happens if you want to ever use docs on the schema. |
@ConnorBP |
If infer_schema is deprecated then why is diesel itself using it? I never used infer_schema but the auto generated schema.rs gives me an error about this if I let the generator add comments. Maybe this should be a separate issue about removing the deprecated calls to this function from the schema.rs generator but either way this ancient issue still exists at the moment. Yes for now I can force the compiler to add more recursion, but that will make building significantly slower than before. I can also disable comments generation, which I did, but that is also not ideal and is a rather clunky workaround for a fundamentally flawed system that has existed for years on ancient rust features and deprecated diesel features. |
We are talking about different things.
As far as I see there is no real way forward to fix that. We want a macro that is able to handle all cases and provide a consistent API. This makes the macro quite complex, which requires adding those recursion limit attribute. One option here is to make that macro simpler by removing options which would a) break all/some existing code, b) remove some use cases. Another option would be to rewrite that as procedural macro, which requires a huge amount of work without any direct gain. Given that no one has currently much time to work on more urging issues/features I don't think that will happen anytime soon. (Also such a rewrite needs to prove that all existing valid code works, which is no simple task) |
I am just curious why infer_schema! is for some reason causing errors from the comments in the auto generated file then if it is as you say deprecated and I am not personally using it. My best guess is that the underlying library is itself using this "deprecated" macro. If it is deprecated a better / newer alternative surely exists already and shouldn't it be not using the deprecated macro? Or is there simply no alternative and therefor it shouldn't be "deprecated". |
This issue is about
Both, |
Setup
Versions
Problem Description
What are you trying to accomplish?
Having diesel automatically infer the schema for a table with more than ~10 columns.
It looks like the default recursion limit for macros is 64 which can be quite easy to reach with 6 lines of code being generated for each database column.
What is the expected output?
Diesel compiles with no issues.
What is the actual output?
Steps to reproduce
You can use pretty much any schema, just pad it with a bunch of extra blank documentation comments.
Checklist
The text was updated successfully, but these errors were encountered: