Allow controlling rustc stacker segment sizes via the environment?

Hi!

While attempting to diagnose Call stack exhaustion (overflow) in parser with a very large generated file · Issue #128422 · rust-lang/rust · GitHub, one of the issues that came up was that it is impossible to control stacker's segment sizes via the environment.

Typically, stack sizes can be controlled via the RUST_MIN_STACK environment variable, but that doesn't work for the stacker-based stacks that rustc creates. The code that invokes stacker is here, and it currently hardcodes a 1MiB stack size. The ability to set a larger stack size would have made it possible to work around the issue in #128422.

Would it make sense to have an environment variable for this? There are a few possible directions. Here's two options that came to mind:

  1. If RUST_MIN_STACK is set, create stack segments with size max(1MiB, RUST_MIN_STACK). I think generally speaking, if RUST_MIN_STACK is set in the environment, there's probably some kind of stack exhaustion that's being worked around. This is the most obvious way to do it I think.
  2. Have a separate environment variable. The environment variable doesn't have to be documented -- even if it just exists in source code, enterprising folks will be able to find it.
3 Likes

rustc often calls stacker in fairly hot parts of the compiler (e.g. on entry into possibly recursive parses), so I expect the main concern to overcome here would be what performance impacts we must contend with from tacking a dynamic value onto the stack. This applies regardless of what approach is used.

Thanks -- interesting point! Note that each stacker call already involves at least one TLS lookup to obtain the current stack limit.

Also note that the issue in #128422 was that this part of the rustc parser is not using stacker. I think this means that the current performance baseline with this code is inaccurate because rustc is incorrect. The baseline to measure against would be with a patched rustc-parser that calls stacker appropriately.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.