I'm writing code with async and quite a lot of generics. The amount of code is rather small really, but I encountered the compiler error
error: reached the type-length limit while instantiating ..... At that time, I managed to fix it with one
Now I have been rewriting my code in an attempt to make it even more generic.
This time I cannot seem to get rid of the error, no matter where I put
.boxed() it would seem.
It's on this branch: https://github.com/openanalytics/s3-algo/blob/forum/rewrite/src/copy.rs and that file in particular. If you build with
cargo build --tests you get the error.
Now, I don't merely want to ask for advice on this particular instance of the issue. In fact, I might readily abandon that branch if it turns out to be impractical.
But I'm tired of hitting this issue. I don't want to add the flag to increase the type length limit, because all dependent crates will have to do so too.
I would like to ask, and I hope someone knows the answer: What language construct should we look out for to avoid this problem?
We are clearly facing some kind of exponential growth, since the compiler suggests to increase the limit to, say, 5 million. So what is relevant is anything that causes such exponential growth, not anything linear. We can use the linked branch to discuss some language constructs:
- generics? https://github.com/openanalytics/s3-algo/blob/forum/rewrite/src/copy.rs#L35
- combinators? https://github.com/openanalytics/s3-algo/blob/forum/rewrite/src/copy.rs#L61
- returning opaque types (and using them in async blocks)? https://github.com/openanalytics/s3-algo/blob/forum/rewrite/src/copy.rs#L165
- ... or returning an opaque type from an async function? https://github.com/openanalytics/s3-algo/blob/forum/rewrite/src/copy.rs#L128
- async functions and async blocks?
- anything else?
Does async/await syntax improve things (compared to e.g. manually
It would be helpful if I could have any idea what to look for when I try to fix this problem. Whether it's about putting
.boxed() in the right places, or just redesign.