Stream: general

Topic: Meaning of `type_length_limit`


Jake Goulding (Jan 18 2020 at 19:47, on Zulip):

I got a few errors that instructed me to increase my type_length_limit to 1394658. What is the unit of this setting? Should I be worried about running into this soft-limit?

Zexbe (Jan 18 2020 at 19:51, on Zulip):

@Jake Goulding https://github.com/rust-lang/rust/blob/master/src/librustc/middle/recursion_limit.rs
It looks like the default is 1048576

Jake Goulding (Jan 18 2020 at 19:53, on Zulip):

@Zexbe ok, but what is the unit of this setting? Should I be worried about running into this soft-limit?

Matthew Jasper (Jan 18 2020 at 19:55, on Zulip):

The unit is types. So u32 has length 1, Vec<u32> has length 2 (Vec<u32> and u32), Vec(u32, u32)> has length 4 (Vec(u32, u32)>, (u32, u32), u32, `u32).

Zexbe (Jan 18 2020 at 19:57, on Zulip):

wow, so 1048576 is really big then

Matthew Jasper (Jan 18 2020 at 19:58, on Zulip):

Futures code can fairly easily hit this limit (it's after monomorphization and sees through impl trait). You may want to consider strategic use of Pin<Box<dyn Future>>.

centril (Jan 18 2020 at 19:58, on Zulip):

https://doc.rust-lang.org/nightly/reference/attributes/limits.html#the-type_length_limit-attribute

centril (Jan 18 2020 at 20:00, on Zulip):

@Matthew Jasper hmm; why does the limit exist?

Matthew Jasper (Jan 18 2020 at 20:00, on Zulip):

To avoid really slow codegen.

Jake Goulding (Jan 18 2020 at 20:00, on Zulip):

@centril thanks for the docs, but I don't see how it correlates to what @Matthew Jasper says:

maximum number of type substitutions

How is u32 a "type substitution"?

centril (Jan 18 2020 at 20:01, on Zulip):

since it's after monomorphization, it doesn't seem to be about preventing non-termination in e.g. the trait system

Matthew Jasper (Jan 18 2020 at 20:01, on Zulip):

No, that's what the recursion limit is for.

centril (Jan 18 2020 at 20:01, on Zulip):

oh; it's used for traits as well, not just macros

Matthew Jasper (Jan 18 2020 at 20:02, on Zulip):

and recursive monomorphizations, etc.

Jake Goulding (Jan 18 2020 at 20:02, on Zulip):

@Matthew Jasper I don't suppose there's an issue about improving the error to guide us to a judicious use of boxing?

centril (Jan 18 2020 at 20:03, on Zulip):

is type_length_limit somehow related to the linker and avoiding literally too long type names in debuginfo?

Matthew Jasper (Jan 18 2020 at 20:03, on Zulip):

I don't think so. There may be a more general issue about tracking sizes of async futures.

Jake Goulding (Jan 18 2020 at 20:03, on Zulip):

@centril is the "really slow codegen" answer insufficient a reason?

centril (Jan 18 2020 at 20:04, on Zulip):

ah, I missed matthew's answer

Jake Goulding (Jan 18 2020 at 20:09, on Zulip):

Is there a rough relation of number of types to compilation time? Like, if the default were 1M and I "needed" 100M (made up numbers), what kind of pain would I be feeling?

Matthew Jasper (Jan 18 2020 at 20:10, on Zulip):

/me ponders whether storing generator witnesses out of line to reduce the impact of this would make any sense

Last update: Feb 25 2020 at 04:25UTC