Skip to content

Add Frontend::clearModules() for selective module removal#2331

Open
JohnnyMorganz wants to merge 1 commit intoluau-lang:masterfrom
JohnnyMorganz:selective-frontend-clear
Open

Add Frontend::clearModules() for selective module removal#2331
JohnnyMorganz wants to merge 1 commit intoluau-lang:masterfrom
JohnnyMorganz:selective-frontend-clear

Conversation

@JohnnyMorganz
Copy link
Copy Markdown
Contributor

@JohnnyMorganz JohnnyMorganz commented Apr 5, 2026

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to clear out certain modules in Luau::Frontend

1 participant