Struct and enum accessors take a large amount of stack space

We recently found an issue where the compiler was failing to reuse stack space between switch cases, and allocating the stack space necessary for all of the enum payloads and cases' local state even though only one actually executes at a time. You might be running into the same problem.

Until we fix that issue, one workaround we've found for this issue is to wrap up each case block in an immediately-invoked closure, like:

switch foo {
case .bar:
  _ = {
    ...
  }()
case .bas:
  __ = {
    ...
  }()
}

If you see stack size issues even after adopting indirect cases, you might try that to see if it helps.

4 Likes