Pin the future on the heap in tests to prevent stack overflows #5136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When we switched from
async_std
totokio
, some tests started overflowing their stack, which we fixed by settingopt_level = 1
in[profile.dev]
back then. This, however, increased the compilation times a lot, so it would be nice to be able to setopt_level = 0
at least for tests. See #2055 for an old issue about this, #4009 for another PR for this issue, and chatmail/core#3666 for a PR in our repo that would fix this by not using the macro and instead writing out the code that would be generated.I don't know why this didn't happen with
async_std
.Solution
The first thing I tried was adding lots of
#[inline(always)]
as outlined by @blasrodri in #2055 (comment), and boxing the future in more places similarly to https://github.com/tokio-rs/tokio/pull/4009/files. Both is in Hocuri@14cad1a, but that didn't fix our tests.Directly boxing the future, as done in this PR here, does fix our tests, however.
What do you think?