Repository navigation
Prevent stack overflow in JsirToAst under ThinLTO and add depth limit. - #231
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Under ThinLTO, Clang inlined leaf `JsirToAst::Visit*` methods into dispatchers like `VisitExpression` and inlined `JsirToAst::Create` (with `JsTrivia` and its `nlohmann::json` `extra` field) into recursive expression visitors. Combined per-level frames on nested `JshirConditionalExpressionOp` trees expanded to ~2.5 KiB, overflowing thread stacks on deeply nested IR trees, while `JshirFileToAst` had no recursion depth bound. Annotate leaf `JsirToAst::Visit*` declarations and `JsirToAst::Create` with `ABSL_ATTRIBUTE_NOINLINE` so `JsTrivia` stays off recursive caller frames and dispatchers remain compact (24 B for `VisitExpression`, 360 B for `VisitConditionalExpression`, 392 B for `VisitBinaryExpression` under ThinLTO). Add an `IrToAst` base class in `ir_to_ast_util.h` that tracks active recursion depth during traversal via `MakeOpConverter` (using a compile-time member pointer so the `[this]` closure stays 8 B in `std::function` SBO and emits a direct call) and convert `IrToAstSourcePrinter`, `JsirToAst`, and the `astgen` conversion tests to instance-based `Visit*` methods. `JshirFileToAst` defaults to `kDefaultMaxJshirToAstRecursionDepth = 4096` (configurable via `std::optional<int>`) and returns `absl::ResourceExhaustedError` on overflow without a second traversal or `thread_local` state. PiperOrigin-RevId: 1035289758
copybara-service
Bot
force-pushed
the
test_1035289758
branch
from
December 4, 2026 13:08
ef64547 to
9691e74
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevent stack overflow in JsirToAst under ThinLTO and add depth limit.
Under ThinLTO, Clang inlined leaf
JsirToAst::Visit*methods into dispatchers likeVisitExpressionand inlinedJsirToAst::Create(withJsTriviaand itsnlohmann::jsonextrafield) into recursive expression visitors. Combined per-level frames on nestedJshirConditionalExpressionOptrees expanded to ~2.5 KiB, overflowing thread stacks on deeply nested IR trees, whileJshirFileToAsthad no recursion depth bound.Annotate leaf
JsirToAst::Visit*declarations andJsirToAst::CreatewithABSL_ATTRIBUTE_NOINLINEsoJsTriviastays off recursive caller frames and dispatchers remain compact (24 B forVisitExpression, 360 B forVisitConditionalExpression, 392 B forVisitBinaryExpressionunder ThinLTO). Add anIrToAstbase class inir_to_ast_util.hthat tracks active recursion depth during traversal viaMakeOpConverter(using a compile-time member pointer so the[this]closure stays 8 B instd::functionSBO and emits a direct call) and convertIrToAstSourcePrinter,JsirToAst, and theastgenconversion tests to instance-basedVisit*methods.JshirFileToAstdefaults tokDefaultMaxJshirToAstRecursionDepth = 4096(configurable viastd::optional<int>) and returnsabsl::ResourceExhaustedErroron overflow without a second traversal orthread_localstate.