Add Frontend::clearModules() for selective module removal#2331
Open
JohnnyMorganz wants to merge 1 commit intoluau-lang:masterfrom
Open
Add Frontend::clearModules() for selective module removal#2331JohnnyMorganz wants to merge 1 commit intoluau-lang:masterfrom
JohnnyMorganz wants to merge 1 commit intoluau-lang:masterfrom
Conversation
When files are renamed or deleted, there was previously no way to selectively remove them from the Frontend. Only Frontend::clear() existed, which wipes all modules and forces a full recheck. This commit adds Frontend::clearModules(const std::vector<ModuleName>& names) which selectively erases specific modules from all caches (sourceNodes, sourceModules, requireTrace, and both module resolvers) while marking their transitive dependents dirty so they get rechecked on next access. The algorithm first calls markDirty() on each module while the dependency graph is still intact, propagating dirty flags to all transitive dependents via BFS. The early-exit optimization in markDirty (skip already-dirty nodes) naturally deduplicates work when clearing multiple modules with overlapping dependent subgraphs. After dirty propagation, each module is erased from all five caches. We keep stale references in dependents' requireSet / requireLocations, because these modules are marked as dirty. These structures are rebuilt from scratch when the dirty dependent is re-parsed. Also adds FrontendModuleResolver::eraseModules() which batch-erases modules under a single mutex lock, avoiding per-module lock acquisition. Closes luau-lang#2160
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.
When files are renamed or deleted, there was previously no way to selectively remove them from the Frontend. Only Frontend::clear() existed, which wipes all modules and forces a full recheck.
This commit adds Frontend::clearModules(const std::vector& names) which selectively erases specific modules from all caches (sourceNodes, sourceModules, requireTrace, and both module resolvers) while marking their transitive dependents dirty so they get rechecked on next access.
The algorithm first calls markDirty() on each module while the dependency graph is still intact, propagating dirty flags to all transitive dependents via BFS. The early-exit optimization in markDirty (skip already-dirty nodes) naturally deduplicates work when clearing multiple modules with overlapping dependent subgraphs. After dirty propagation, each module is erased from all five caches.
We keep stale references in dependents' requireSet / requireLocations, because these modules are marked as dirty. These structures are rebuilt from scratch when the dirty dependent is re-parsed.
Also adds FrontendModuleResolver::eraseModules() which batch-erases modules under a single mutex lock, avoiding per-module lock acquisition.
No FFlag is added because this change is purely additive and is not called by existing production code.
Closes #2160