resolve: Explicit Set for detecting resolution cycles#158035
resolve: Explicit Set for detecting resolution cycles#158035LorrensP-2158466 wants to merge 1 commit 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. |
|
I am not quite sure what benefit a scoped TLS would give here, so i am missing something. With a scoped TLS, do you mean to do this at every top-level resolve call (scoped-thread-local crate)?: Because recursive |
|
If scoped TLS is inconvenient, then let's use the regular TLS.
I'd expect |
97cbeb3 to
2f99220
Compare
|
@rustbot ready |
|
r=me after addressing the remaining comments. |
…w_mut` on `RefCell<NameResolution>`. Use a TLS for this set ahead of parallel import resolution.
2f99220 to
45bac96
Compare
Don't have those privileges, @rustbot ready. |
|
I'll run benchmarks just in case. |
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 (6e82f9e): 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.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.3%, secondary 4.0%)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: 481.965s -> 480.413s (-0.32%) |
|
☔ The latest upstream changes (presumably #158145) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
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