Recursion stack for detecting cyclic imports#158035
Open
LorrensP-2158466 wants to merge 1 commit into
Open
Conversation
Comment on lines
+361
to
+369
| thread_local! { | ||
| /// During import resolution, recursive imports can form cycles. | ||
| /// This set stores the active resolution stack for the current thread. | ||
| /// So it's essentially a recursion stack. | ||
| /// | ||
| /// The key is the address of a `NameResolution`; we only need identity, | ||
| /// not access to the value. | ||
| static ACTIVE_RESOLUTIONS: CacheRefCell<BTreeSet<*const ()>> = Default::default(); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
So I already did it using TLS to show how I was thinking of a solution for parallel import resolution.
Can be easily translated to Rc<RefCell<...>> in the Resolver itself.
This comment has been minimized.
This comment has been minimized.
…mut`. Place recursion stack in TLS ahead of parallel import resolution
1858b06 to
a2da807
Compare
| active.remove(&self.key); | ||
| }); | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
DropGuard is possible (unstable feature though). But I don't like how I need to fill in the types:
/// We need a way to remove the resolution from the stack whenever we return, this type
/// holds that resolution key and removes it on drop.
pub(crate) type ImportCycleGuard<D: FnOnce(*const ())> = DropGuard<*const (), D>;
pub(crate) fn enter_cycle_detector(
&self,
resolution: &'ra CmRefCell<NameResolution<'ra>>,
) -> Result<ImportCycleGuard<impl FnOnce(*const ())>, ()> {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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