Skip to content

Commit 444fc99

Browse files
sheetalkamatJack-Works
authored andcommitted
Instead of maintaining cache id etc, reset the "working" exports map cache. (microsoft#48579)
* Revert "Avoid no-op export map updates (microsoft#45238)" This reverts commit 0f6e6ef. * Need to reset currentAffectedFilesExportedModulesMap after commiting to final exports map
1 parent 006d9da commit 444fc99

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

src/compiler/builder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ namespace ts {
372372
BuilderState.updateSignaturesFromCache(state, state.currentAffectedFilesSignatures!);
373373
state.currentAffectedFilesSignatures!.clear();
374374
BuilderState.updateExportedFilesMapFromCache(state, state.currentAffectedFilesExportedModulesMap);
375+
state.currentAffectedFilesExportedModulesMap?.clear();
375376
state.affectedFiles = undefined;
376377
}
377378

src/compiler/builderState.ts

+9-37
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ namespace ts {
4848
*/
4949
readonly exportedModulesMap: BuilderState.ManyToManyPathMap | undefined;
5050

51-
previousCache?: {
52-
id: number,
53-
version: number,
54-
};
55-
5651
/**
5752
* true if file version is used as signature
5853
* 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 {
8681
}
8782

8883
export interface ReadonlyManyToManyPathMap {
89-
readonly id: number;
9084
clone(): ManyToManyPathMap;
9185
forEach(action: (v: ReadonlySet<Path>, k: Path) => void): void;
9286
getKeys(v: Path): ReadonlySet<Path> | undefined;
@@ -103,18 +97,14 @@ namespace ts {
10397
}
10498

10599
export interface ManyToManyPathMap extends ReadonlyManyToManyPathMap {
106-
version(): number; // Incremented each time the contents are changed
107100
deleteKey(k: Path): boolean;
108101
set(k: Path, v: ReadonlySet<Path>): void;
102+
clear(): void;
109103
}
110104

111-
let manyToManyPathMapCount = 0;
112105
export function createManyToManyPathMap(): ManyToManyPathMap {
113106
function create(forward: ESMap<Path, ReadonlySet<Path>>, reverse: ESMap<Path, Set<Path>>, deleted: Set<Path> | undefined): ManyToManyPathMap {
114-
let version = 0;
115107
const map: ManyToManyPathMap = {
116-
id: manyToManyPathMapCount++,
117-
version: () => version,
118108
clone: () => create(new Map(forward), new Map(reverse), deleted && new Set(deleted)),
119109
forEach: fn => forward.forEach(fn),
120110
getKeys: v => reverse.get(v),
@@ -133,35 +123,33 @@ namespace ts {
133123

134124
set.forEach(v => deleteFromMultimap(reverse, v, k));
135125
forward.delete(k);
136-
version++;
137126
return true;
138127
},
139128
set: (k, vSet) => {
140-
let changed = !!deleted?.delete(k);
129+
deleted?.delete(k);
141130

142131
const existingVSet = forward.get(k);
143132
forward.set(k, vSet);
144133

145134
existingVSet?.forEach(v => {
146135
if (!vSet.has(v)) {
147-
changed = true;
148136
deleteFromMultimap(reverse, v, k);
149137
}
150138
});
151139

152140
vSet.forEach(v => {
153141
if (!existingVSet?.has(v)) {
154-
changed = true;
155142
addToMultimap(reverse, v, k);
156143
}
157144
});
158145

159-
if (changed) {
160-
version++;
161-
}
162-
163146
return map;
164147
},
148+
clear: () => {
149+
forward.clear();
150+
reverse.clear();
151+
deleted?.clear();
152+
}
165153
};
166154

167155
return map;
@@ -179,11 +167,11 @@ namespace ts {
179167
set.add(v);
180168
}
181169

182-
function deleteFromMultimap<K, V>(map: ESMap<K, Set<V>>, k: K, v: V, removeEmpty = true): boolean {
170+
function deleteFromMultimap<K, V>(map: ESMap<K, Set<V>>, k: K, v: V): boolean {
183171
const set = map.get(k);
184172

185173
if (set?.delete(v)) {
186-
if (removeEmpty && !set.size) {
174+
if (!set.size) {
187175
map.delete(k);
188176
}
189177
return true;
@@ -494,22 +482,6 @@ namespace ts {
494482
export function updateExportedFilesMapFromCache(state: BuilderState, exportedModulesMapCache: ManyToManyPathMap | undefined) {
495483
if (exportedModulesMapCache) {
496484
Debug.assert(!!state.exportedModulesMap);
497-
498-
const cacheId = exportedModulesMapCache.id;
499-
const cacheVersion = exportedModulesMapCache.version();
500-
if (state.previousCache) {
501-
if (state.previousCache.id === cacheId && state.previousCache.version === cacheVersion) {
502-
// If this is the same cache at the same version as last time this BuilderState
503-
// was updated, there's no need to update again
504-
return;
505-
}
506-
state.previousCache.id = cacheId;
507-
state.previousCache.version = cacheVersion;
508-
}
509-
else {
510-
state.previousCache = { id: cacheId, version: cacheVersion };
511-
}
512-
513485
exportedModulesMapCache.deletedKeys()?.forEach(path => state.exportedModulesMap!.deleteKey(path));
514486
exportedModulesMapCache.forEach((exportedModules, path) => state.exportedModulesMap!.set(path, exportedModules));
515487
}

0 commit comments

Comments
 (0)