Skip to content
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

Merged
merged 1 commit into from
Jan 11, 2023

Conversation

uweigand
Copy link
Contributor

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.

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.
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2022

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 19, 2022
@compiler-errors
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 19, 2022
@bors
Copy link
Contributor

bors commented Dec 19, 2022

⌛ Trying commit 6bb2bda with merge a08ba4117383950d7eaa1512ecfc3401d69038d3...

@bors
Copy link
Contributor

bors commented Dec 19, 2022

☀️ Try build successful - checks-actions
Build commit: a08ba4117383950d7eaa1512ecfc3401d69038d3 (a08ba4117383950d7eaa1512ecfc3401d69038d3)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a08ba4117383950d7eaa1512ecfc3401d69038d3): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.6% [4.6%, 4.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 20, 2022
@Noratrieb
Copy link
Member

r? Nilstrieb
@bors r+

@bors
Copy link
Contributor

bors commented Jan 10, 2023

📌 Commit 6bb2bda has been approved by Nilstrieb

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jan 10, 2023

🌲 The tree is currently closed for pull requests below priority 50. This pull request will be tested once the tree is reopened.

@rustbot rustbot assigned Noratrieb and unassigned TaKO8Ki Jan 10, 2023
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2023
@bors
Copy link
Contributor

bors commented Jan 11, 2023

⌛ Testing commit 6bb2bda with merge 8ecaad8...

@bors
Copy link
Contributor

bors commented Jan 11, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 8ecaad8 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Jan 11, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 8ecaad8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 11, 2023
@bors bors merged commit 8ecaad8 into rust-lang:master Jan 11, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 11, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8ecaad8): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.3%] 3
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.3%, -0.3%] 1

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
2.7% [2.3%, 3.0%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.1% [-3.1%, -3.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [-3.1%, 3.0%] 3

Cycles

This benchmark run did not return any relevant results for this metric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants