Instead of maintaining cache id etc, reset the "working" exports map cache. (#48579)

* Revert "Avoid no-op export map updates (#45238)"

This reverts commit 0f6e6efde08385916602e254f406f1703907b2a5.

* Need to reset currentAffectedFilesExportedModulesMap after commiting to final exports map
This commit is contained in:
Sheetal Nandi 2022-04-15 15:11:30 -07:00 committed by GitHub
parent 0976658418
commit 56a4a93718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 37 deletions

View File

@ -372,6 +372,7 @@ namespace ts {
BuilderState.updateSignaturesFromCache(state, state.currentAffectedFilesSignatures!);
state.currentAffectedFilesSignatures!.clear();
BuilderState.updateExportedFilesMapFromCache(state, state.currentAffectedFilesExportedModulesMap);
state.currentAffectedFilesExportedModulesMap?.clear();
state.affectedFiles = undefined;
}

View File

@ -48,11 +48,6 @@ namespace ts {
*/
readonly exportedModulesMap: BuilderState.ManyToManyPathMap | undefined;
previousCache?: {
id: number,
version: number,
};
/**
* true if file version is used as signature
* This helps in delaying the calculation of the d.ts hash as version for the file till reasonable time
@ -86,7 +81,6 @@ namespace ts {
}
export interface ReadonlyManyToManyPathMap {
readonly id: number;
clone(): ManyToManyPathMap;
forEach(action: (v: ReadonlySet<Path>, k: Path) => void): void;
getKeys(v: Path): ReadonlySet<Path> | undefined;
@ -103,18 +97,14 @@ namespace ts {
}
export interface ManyToManyPathMap extends ReadonlyManyToManyPathMap {
version(): number; // Incremented each time the contents are changed
deleteKey(k: Path): boolean;
set(k: Path, v: ReadonlySet<Path>): void;
clear(): void;
}
let manyToManyPathMapCount = 0;
export function createManyToManyPathMap(): ManyToManyPathMap {
function create(forward: ESMap<Path, ReadonlySet<Path>>, reverse: ESMap<Path, Set<Path>>, deleted: Set<Path> | undefined): ManyToManyPathMap {
let version = 0;
const map: ManyToManyPathMap = {
id: manyToManyPathMapCount++,
version: () => version,
clone: () => create(new Map(forward), new Map(reverse), deleted && new Set(deleted)),
forEach: fn => forward.forEach(fn),
getKeys: v => reverse.get(v),
@ -133,35 +123,33 @@ namespace ts {
set.forEach(v => deleteFromMultimap(reverse, v, k));
forward.delete(k);
version++;
return true;
},
set: (k, vSet) => {
let changed = !!deleted?.delete(k);
deleted?.delete(k);
const existingVSet = forward.get(k);
forward.set(k, vSet);
existingVSet?.forEach(v => {
if (!vSet.has(v)) {
changed = true;
deleteFromMultimap(reverse, v, k);
}
});
vSet.forEach(v => {
if (!existingVSet?.has(v)) {
changed = true;
addToMultimap(reverse, v, k);
}
});
if (changed) {
version++;
}
return map;
},
clear: () => {
forward.clear();
reverse.clear();
deleted?.clear();
}
};
return map;
@ -179,11 +167,11 @@ namespace ts {
set.add(v);
}
function deleteFromMultimap<K, V>(map: ESMap<K, Set<V>>, k: K, v: V, removeEmpty = true): boolean {
function deleteFromMultimap<K, V>(map: ESMap<K, Set<V>>, k: K, v: V): boolean {
const set = map.get(k);
if (set?.delete(v)) {
if (removeEmpty && !set.size) {
if (!set.size) {
map.delete(k);
}
return true;
@ -494,22 +482,6 @@ namespace ts {
export function updateExportedFilesMapFromCache(state: BuilderState, exportedModulesMapCache: ManyToManyPathMap | undefined) {
if (exportedModulesMapCache) {
Debug.assert(!!state.exportedModulesMap);
const cacheId = exportedModulesMapCache.id;
const cacheVersion = exportedModulesMapCache.version();
if (state.previousCache) {
if (state.previousCache.id === cacheId && state.previousCache.version === cacheVersion) {
// If this is the same cache at the same version as last time this BuilderState
// was updated, there's no need to update again
return;
}
state.previousCache.id = cacheId;
state.previousCache.version = cacheVersion;
}
else {
state.previousCache = { id: cacheId, version: cacheVersion };
}
exportedModulesMapCache.deletedKeys()?.forEach(path => state.exportedModulesMap!.deleteKey(path));
exportedModulesMapCache.forEach((exportedModules, path) => state.exportedModulesMap!.set(path, exportedModules));
}