Skip to content

Commit

Permalink
ISLE: Make block codegen non-recursive (#8935) (#8947)
Browse files Browse the repository at this point in the history
* ISLE: Make block codegen non-recursive

In #8919 we learned that `Codegen::emit_block` can overrun the stack
when generating Rust source for deeply-nested blocks. Stack usage can be
worse than one might expect because ISLE is called from a build script,
and those are always built in debug mode.

This commit avoids the problem by using an explicit heap-allocated stack
instead of recursion.

I recommend turning on the "ignore whitespace" option in your diff tool
of choice when reviewing this commit.

The amount of stack space that this recursive function uses is affected
by the version of rustc used to compile it, and the amount of stack
space available depends on the host platform. As a result, this was only
observed on Windows with a recent nightly version of rustc, but it could
eventually affect other platforms or compiler versions, especially as
ISLE rules grow in complexity.

Note that there are several other places in ISLE which recurse over the
user-provided rules. This commit does not change those, but they could
also become a problem in the future.

* Review comments: make stack manipulation local to emit_block

Co-authored-by: Jamey Sharp <[email protected]>
  • Loading branch information
alexcrichton and jameysharp authored Jul 12, 2024
1 parent 0bbdbc4 commit 6b3719a
Showing 1 changed file with 206 additions and 175 deletions.
Loading

0 comments on commit 6b3719a

Please sign in to comment.