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

Grow the stack to allow parsing deeply nested expressions if necessary. #93730

Closed
wants to merge 2 commits into from

Conversation

hkratz
Copy link
Contributor

@hkratz hkratz commented Feb 7, 2022

parse_assoc_expr_with() appears to be the best place for ensure_sufficient_stack().

This could be performance-sensitive, so a perf run is required.

Fixes #79766, #93704

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 7, 2022
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 7, 2022
@rust-log-analyzer

This comment has been minimized.

@lqd
Copy link
Member

lqd commented Feb 7, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

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

bors commented Feb 7, 2022

⌛ Trying commit fcea6bf with merge b6f8940bd8fbcba4b12dc8019074b0b60e95bf89...

@bors
Copy link
Contributor

bors commented Feb 7, 2022

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

@rust-timer
Copy link
Collaborator

Queued b6f8940bd8fbcba4b12dc8019074b0b60e95bf89 with parent 926e784, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b6f8940bd8fbcba4b12dc8019074b0b60e95bf89): comparison url.

Summary: This benchmark run shows 33 relevant regressions 😿 to instruction counts.

  • Average relevant regression: 0.7%
  • Largest regression in instruction counts: 1.8% on incr-unchanged builds of deep-vector check

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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 led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 7, 2022
@petrochenkov
Copy link
Contributor

I'm not even sure that it's something that needs to be fixed.
For every recursion case in the compiler it's possible to construct an artificial code example that will trigger stack overflow.
Then why grow the stack in this specific case but not in others? Just because someone to submitted an issue?

Stack overflow is not even an ICE or bug, just a regular runtime error caused by system resource exhaustion, like "disk full" or something.
We should be able to report such errors.

@petrochenkov
Copy link
Contributor

parse_assoc_expr_with() appears to be the best place for ensure_sufficient_stack().

Could you elaborate why?

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 8, 2022
@hkratz
Copy link
Contributor Author

hkratz commented Feb 8, 2022

parse_assoc_expr_with() appears to be the best place for ensure_sufficient_stack().

Could you elaborate why?

I thought that parse_assoc_expr_with() was called for all nested expressions but that is apparently not the case. I will have a closer look. Sorry about that.

@hkratz
Copy link
Contributor Author

hkratz commented Feb 8, 2022

I'm not even sure that it's something that needs to be fixed. For every recursion case in the compiler it's possible to construct an artificial code example that will trigger stack overflow. Then why grow the stack in this specific case but not in others? Just because someone to submitted an issue?

My rationale was that of all syntactic constructs expressions are the most likely to be deeply nested and hitting the stack limit (e.g. when auto-generated). And since segmented stacks are already used in other parts of the compiler I thought that using them was common practice.

Stack overflow is not even an ICE or bug, just a regular runtime error caused by system resource exhaustion, like "disk full" or something. We should be able to report such errors.

With "disk full" the developer knows what to do: free some space or procure a larger disk. With stack overflows in large projects and generated code they likely do not even know where to look. Alternatively we could implement configurable recursion limits with conservative defaults for the parser just like clang. Then the developer gets at least told where the problem is.

@kostis
Copy link

kostis commented Feb 10, 2022

Let me add my .02 here.

@petrochenkov is right in saying that

For every recursion case in the compiler it's possible to construct an artificial code example that will trigger stack overflow.

But there are two separate issues being reported:

  1. Parens in (very!) long expression cause stack overflow #79766, resulting in a stack overflow message (and abort)
  2. Segfault when compiling very deeply nested tuples #93704, which results in a segmentation fault.

IMO, something needs to be done about (at least) turning the segmentation fault into some other response (e.g. avoidance via automatic stack expansion or an abort with a "stack overflow" message ideally followed with a suggestion on how to overcome this).

@JohnCSimon
Copy link
Member

@hkratz
Ping from triage: this seems to have gone idle due to inactivity, Please reopen if this is in error.
Thanks for your contribution.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Mar 20, 2022
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Mar 20, 2022
@fmease fmease mentioned this pull request Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Parens in (very!) long expression cause stack overflow
10 participants