resolve: Explicit Set for detecting resolution cycles#158035
resolve: Explicit Set for detecting resolution cycles#158035LorrensP-2158466 wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
1858b06 to
a2da807
Compare
|
It's clear that using a thread-local is more compact, but is it technically possible to pass the "active resolution" set explicitly as a parameter through all the relevant functions? We are already doing that for |
I will try it and see how it looks. |
|
To be honest, this gets quite cumbersome. There are a lot of functions that use the So now i have: pub(crate) fn maybe_resolve_ident_in_module<'r>(
// ...
cycle_detector: &mut ImportCycleDetector<'ra>,
){ ... }( But this detecting is not needed everywhere, so we could do this: pub(crate) fn maybe_resolve_ident_in_module<'r>(
// ...
cycle_detector: Option<&mut ImportCycleDetector<'ra>>,
){ ... }But then we require reborrowing in closures and loops, which is the same story as with So before I complete this big refactor i have 2 questions:
|
I think we need the cycle detector in exactly the same cases as |
|
@rustbot ready The cycle detector was also needed in macro resolution. |
This comment has been minimized.
This comment has been minimized.
3b561b9 to
d8e3473
Compare
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
So i reproduced that failing CI job locally to try and find the stack trace, here is the minimal version: So it does seem that infinite recursion can happen anywhere, anytime. If you think that the cycle_detector should still be an argument to these resolve calls, then I think its best to just have a separate argument, instead of combining it with |
|
Let's return to the (scoped) TLS approach and just keep doing what we do on the main branch. |
The issue may also be in TLS accesses rather than in the data structure. |
If |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (3c16dbb): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -4.3%, secondary -1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 3.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 482.353s -> 481.03s (-0.27%) |
|
Lets do the explicit argument way as well, just to be sure. @rustbot author |
Just a heads up, there are a lot of places where we need to insert an explicit cycle detector if we assume a cycle can happen from anywhere. |
|
Would it be correct to not add some |
|
That would reduce the amount of entries in the detector, thus reducing the amount of times we access the TLS.
Going of my knowledge of the language, i think only imports can cause cycles. So one would assume only checking cycles due to imports to be enough, instead of all resolutions. If you want, I can stash the "detector in argument" changes and see if the above works and then improves the bench results. |
e73e679 to
2ffac84
Compare
|
Current state of PR is a CycleDetector with Some things:
|
|
Let's benchmark this, and then probably revert to another solution. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
resolve: Explicit Set for detecting resolution cycles
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (494adc3): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.1%, secondary 3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 1.2%, secondary -4.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 505.379s -> 504.315s (-0.21%) |
|
Almost the same as with Want to try Either way, if we would only track local imports, we should get that number down. |
No, what we already measured is enough |
View all comments
Instead of using the
borrow_mutcounter of aRefCellfor aNameResolutionfor detecting cyclic imports during import resolution, we use an explicit recursion stack that keeps track of the current usedNameResolutions.Because of the upcoming parallelisation of the import resolution algorithm, the current way cannot used in a parallel context.
r? @petrochenkov