Skip to content

Commit

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

In bytecodealliance#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
  • Loading branch information
jameysharp authored and alexcrichton committed Jul 12, 2024
1 parent 0bbdbc4 commit c85182b
Showing 1 changed file with 206 additions and 175 deletions.
Loading

0 comments on commit c85182b

Please sign in to comment.