Skip to content

Commit

Permalink
ISLE: Make block codegen non-recursive
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jameysharp committed Jul 10, 2024
1 parent 353befd commit d9e04b7
Showing 1 changed file with 214 additions and 177 deletions.
Loading

0 comments on commit d9e04b7

Please sign in to comment.