-
Notifications
You must be signed in to change notification settings - Fork 635
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
futures_util::select! runs into recursion limits #1917
Comments
This is really just an issue with any Rust macro which generates too much code. This happens because Rust has a very low recursion limit. You can fix this by adding this at the top of your #![recursion_limit="1024"] |
It's quite annoying though, I had to put it at 4096 before rustc stopped complaining. At that point, I started thinking I was doing something wrong! (Maybe I was...) |
@rubdos 4096 sounds quite large! Could you post what your |
You can have a look here. I've just tried with 1024, which didn't work, while 2048 still seems to work. We just refactored that |
@rubdos Yeah, that's a lot of code. So it doesn't surprise me that it would run into the recursion limits. |
What confuses me here is how it actually relates to recursion. The linked code is more or less a long list of statements. But those don't seem to be recursive (like with other macros inside)? @rubdos The select looks very cool for a main state-machine. However be aware that every wakeup of the task will lead to polling all 9 sub-futures in the select loop. Probably won't matter if those are small, but is worthwhile to note. |
Yes, figured that, but I agree with @Matthias247:
i.e., I (and probably Matthias too) wonder why/where
Actually, they're all |
This is issue unfortunately unsolvable (as far as I know) due to the current way that the |
@cramertj: What about a note in the |
Sure, I wouldn't object to a PR adding docs for that! |
Warning as discussion in issue rust-lang#1917.
Warning as discussion in issue rust-lang#1917.
Warning as discussion in issue rust-lang#1917.
Warning as discussion in issue #1917.
It looks like that stabilization will happen in 1.45, which is likely to drop next week sometime. Is there an approximate ETA available for when |
@coriolinus We don't have an exact msrv policy so I'm not sure exactly how long we have to wait, but we probably have to wait for 3 to 6 months after it stabilized in stable channel (because this crate is widely used). |
Alternatively, it can probably submit a patch to proc-macro-hack that allows you to use normal |
Warning as discussion in issue rust-lang#1917.
Whenever I use
futures_util::select!
from0.3.0-alpha.19
, I frequently run into the errorIt seems like if I have too many match arms within the
select! { ... }
macro, regardless of whether they are top-level or not, I get this error.This means that when I have 4 different futures I'm selecting on, I can't really use match arms on most of them otherwise I get this error.
I can get around this by abstracting the logic into a different function and doing the logic there, which in general is a better approach anyway. But there are times when I want to use some match arms with a
break
, and it makes the code harder to read when I abstract the code into functions.Below are a variety of different examples of how a certain amount of complexity causes the recursion error. Note that it seems like it's somehow a total of complexity, not any certain type.
This gives me the impression that somehow the macro is recursing into the portion of the code that it shouldn't be getting into? But I don't know enough about macros at this point to be able to diagnose.
The text was updated successfully, but these errors were encountered: