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

Reworks Sccc computation to iteration instead of recursion #78588

Merged
merged 4 commits into from
Nov 21, 2020

Conversation

HeroicKatora
Copy link
Contributor

@HeroicKatora HeroicKatora commented Oct 31, 2020

Linear graphs, producing as many scc's as nodes, would recurse once for every node when entered from the start of the list. This adds a test that exhausted the stack at least on my machine with error:

thread 'graph::scc::tests::test_deep_linear' has overflowed its stack
fatal runtime error: stack overflow

This may or may not be connected to #78567. I was only reminded that I started this rework some time ago. It might be plausible as borrow checking a long function with many borrow regions around each other—((((((…))))))— may produce the linear list setup to trigger this stack overflow ? I don't know enough about borrow check to say for sure.

This is best read in two separate commits. The first addresses only find_state internally. This is classical union phase from union-find. There's also a common solution of using the parent pointers in the (virtual) linked list to track the backreferences while traversing upwards and then following them backwards in a second path compression phase.

The second is more involved as it rewrites the mutually recursive walk_node and walk_unvisited_node. Firstly, the caller is required to handle the unvisited case of walk_node so a new start_walk_from method is added to handle that by walking the unvisited node if necessary. Then walk_unvisited_node, where we would previously recurse into in the missing case, is rewritten to construct a manual stack of its frames. The state fields consist of the previous stack slots.

While a bit primitive, it should get us at least a better number than
nothing.
@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 Oct 31, 2020
@jonas-schievink
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Oct 31, 2020

⌛ Trying commit 4e9316527caa5ff2e392208649d48db611e7b752 with merge 761d47a65a41279f919a16d8b59f188b14a70617...

@bors
Copy link
Contributor

bors commented Oct 31, 2020

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

@rust-timer
Copy link
Collaborator

Queued 761d47a65a41279f919a16d8b59f188b14a70617 with parent ffe5288, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (761d47a65a41279f919a16d8b59f188b14a70617): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot modify labels: +S-waiting-on-review -S-waiting-on-perf

@petrochenkov
Copy link
Contributor

r? @nikomatsakis

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite review the final commit, but here is a suggested change for the first part. :)

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, one nit on the comment. I'll try to review the last bit of the PR today!

The basic conversion is a straightforward conversion of the linear
recursion to a loop forwards and backwards propagation of the result.
But this uses an optimization to avoid the need for extra space that
would otherwise be necessary to store the stack of unfinished states as
the function is not tail recursive.

Observe that only non-root-nodes in cycles have a recursive call and
that every such call overwrites their own node state. Thus we reuse the
node state itself as temporary storage for the stack of unfinished
states by inverting the links to a chain back to the previous state
update. When we hit the root or end of the full explored chain we
propagate the node state update backwards by following the chain until
a node with a link to itself.
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last commit feels like it could be done simpler. Curious what you think.

compiler/rustc_data_structures/src/graph/scc/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_data_structures/src/graph/scc/mod.rs Outdated Show resolved Hide resolved
This allows constructing the sccc for large that visit many nodes before
finding a single cycle of sccc, for example lists. When used to find
dependencies in borrow checking the list case is what occurs in very
long functions.
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 9, 2020

📌 Commit eb597f5 has been approved by nikomatsakis

@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 Nov 9, 2020
@bors
Copy link
Contributor

bors commented Nov 10, 2020

⌛ Testing commit eb597f5 with merge fb7c368a5426b2a3eb500b68d85a70f77c57d687...

@bors
Copy link
Contributor

bors commented Nov 10, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 10, 2020
@kennytm
Copy link
Member

kennytm commented Nov 12, 2020

@bors retry #78665

@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 Nov 12, 2020
@bors
Copy link
Contributor

bors commented Nov 12, 2020

⌛ Testing commit eb597f5 with merge 95c3990a522ffe839c0aac778ccf21e49163f57a...

@bors
Copy link
Contributor

bors commented Nov 12, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 12, 2020
@kennytm
Copy link
Member

kennytm commented Nov 12, 2020

2020-11-12T09:37:48.3248387Z thread panicked while panicking. aborting.
2020-11-12T09:37:49.8979786Z �[0m�[0m�[1m�[31merror�[0m�[1m:�[0m test failed, to rerun pass '--test client'
2020-11-12T09:37:49.8980348Z 
2020-11-12T09:37:49.8980671Z Caused by:
2020-11-12T09:37:49.8983606Z   process didn't exit successfully: `D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\client-dba513960caf6555.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)

🤔

@nikomatsakis nikomatsakis 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 Nov 19, 2020
@nikomatsakis
Copy link
Contributor

Just to clarify, my assumption here @HeroicKatora is that you are planning to investigate the test failures. Do you need any assistance?

@HeroicKatora
Copy link
Contributor Author

I'm quite confused about the errors. The first failed the task x86_64-apple and I have no idea whtat the error is supposed to even tell me:

auto (x86_64-apple, ./x.py --stage 2 test, --build=x86_64-apple-darwin --enable-sanitizers…
failures:

---- [debuginfo-lldb] debuginfo/pretty-std-collections.rs stdout ----
NOTE: compiletest thinks it is using LLDB version 1200
NOTE: compiletest thinks it is using LLDB without native rust support

error: Error while running LLDB
status: exit code: 1
command: "/usr/bin/python3" "/Users/runner/work/rust/rust/src/etc/lldb_batchmode.py" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/test/debuginfo/pretty-std-collections.lldb/a" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/test/debuginfo/pretty-std-collections.lldb/pretty-std-collections.debugger.script"

And the second try is at a totally different task, that as far as I can tell succeeded in the first try:

auto (x86_64-msvc-tools, src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh x.p…
2020-11-12T09:37:48.3248387Z thread panicked while panicking. aborting.
2020-11-12T09:37:49.8979786Z �[0m�[0m�[1m�[31merror�[0m�[1m:�[0m test failed, to rerun pass '--test client'
2020-11-12T09:37:49.8980348Z 
2020-11-12T09:37:49.8980671Z Caused by:
2020-11-12T09:37:49.8983606Z   process didn't exit successfully: `D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\client-dba513960caf6555.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)

Do you need any assistance?

Yes, I think so. I can replicate neither the MSVC nor the Apple Darwin setup easily.

@nagisa
Copy link
Member

nagisa commented Nov 20, 2020

The problems seem to me like they could've been spurious and not caused by this PR, at least they don't obviously look related.

(The apple one being confirmed spurious by #78588 (comment))

@bors retry rollup=never

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2020
@bors
Copy link
Contributor

bors commented Nov 21, 2020

⌛ Testing commit eb597f5 with merge 8cfa7b4...

@bors
Copy link
Contributor

bors commented Nov 21, 2020

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing 8cfa7b4 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 21, 2020
@bors bors merged commit 8cfa7b4 into rust-lang:master Nov 21, 2020
@rustbot rustbot added this to the 1.50.0 milestone Nov 21, 2020
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #78588!

Tested on commit 8cfa7b4.
Direct link to PR: #78588

🎉 rls on linux: test-fail → test-pass (cc @Xanewok).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Nov 21, 2020
Tested on commit rust-lang/rust@8cfa7b4.
Direct link to PR: <rust-lang/rust#78588>

🎉 rls on linux: test-fail → test-pass (cc @Xanewok).
@HeroicKatora HeroicKatora deleted the sccc branch November 21, 2020 13:47
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants