-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stack overflow in recursive AST walk in early lint #105919
Conversation
The src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs test case added to verify rust-lang#74564 still crashes with a stack overflow on s390x-ibm-linux. Symptom is a very deep recursion in compiler/rustc_lint/src/early.rs: fn visit_expr(&mut self, e: &'a ast::Expr) { self.with_lint_attrs(e.id, &e.attrs, |cx| { lint_callback!(cx, check_expr, e); ast_visit::walk_expr(cx, e); }) } (where walk_expr recursively calls back into visit_expr). The crash happens at a nesting depth of over 17000 stack frames when using the default 8 MB stack size on s390x. This patch fixes the problem by adding a ensure_sufficient_stack call to the with_lint_attrs routine (which also should take care of all the other mutually recursive visitors here). Fixes part of rust-lang#105383.
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 6bb2bda with merge a08ba4117383950d7eaa1512ecfc3401d69038d3... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (a08ba4117383950d7eaa1512ecfc3401d69038d3): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
r? Nilstrieb |
🌲 The tree is currently closed for pull requests below priority 50. This pull request will be tested once the tree is reopened. |
☀️ Test successful - checks-actions |
1 similar comment
☀️ Test successful - checks-actions |
Finished benchmarking commit (8ecaad8): comparison URL. Overall result: ❌✅ regressions and improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
The src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs test case added to verify #74564 still crashes with a stack overflow on s390x-ibm-linux.
Symptom is a very deep recursion in compiler/rustc_lint/src/early.rs:
fn visit_expr(&mut self, e: &'a ast::Expr) {
self.with_lint_attrs(e.id, &e.attrs, |cx| {
lint_callback!(cx, check_expr, e);
ast_visit::walk_expr(cx, e);
})
}
(where walk_expr recursively calls back into visit_expr). The crash happens at a nesting depth of over 17000 stack frames when using the default 8 MB stack size on s390x.
This patch fixes the problem by adding a ensure_sufficient_stack call to the with_lint_attrs routine (which also should take care of all the other mutually recursive visitors here).
Fixes part of #105383.