Skip to content

Commit dcdc654

Browse files
committed
Use referencedMap in place of exportedModulesMap in preparation for not depending on d.ts having iterated over all symbols to find really needed module imports/type references etc
1 parent 8d3a02f commit dcdc654

File tree

417 files changed

+2299
-6447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+2299
-6447
lines changed

src/compiler/builder.ts

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import {
5858
isNumber,
5959
isString,
6060
map,
61-
mapDefined,
6261
maybeBind,
6362
noop,
6463
notImplemented,
@@ -632,7 +631,6 @@ function getNextAffectedFile(
632631
state.currentChangedFilePath = undefined;
633632
// Commit the changes in file signature
634633
state.oldSignatures?.clear();
635-
state.oldExportedModulesMap?.clear();
636634
state.affectedFiles = undefined;
637635
}
638636

@@ -844,7 +842,7 @@ function handleDtsMayChangeOfReferencingExportOfAffectedFile(
844842
) {
845843
// If there was change in signature (dts output) for the changed file,
846844
// then only we need to handle pending file emit
847-
if (!state.exportedModulesMap || !state.changedFilesSet.has(affectedFile.resolvedPath)) return;
845+
if (!state.referencedMap || !state.changedFilesSet.has(affectedFile.resolvedPath)) return;
848846
if (!isChangedSignature(state, affectedFile.resolvedPath)) return;
849847

850848
// Since isolated modules dont change js files, files affected by change in signature is itself
@@ -868,9 +866,8 @@ function handleDtsMayChangeOfReferencingExportOfAffectedFile(
868866
}
869867

870868
const seenFileAndExportsOfFile = new Set<string>();
871-
// Go through exported modules from cache first
872-
// If exported modules has path, all files referencing file exported from are affected
873-
state.exportedModulesMap.getKeys(affectedFile.resolvedPath)?.forEach(exportedFromPath => {
869+
// Go through files that reference affected file and handle dts emit and semantic diagnostics for them and their references
870+
state.referencedMap.getKeys(affectedFile.resolvedPath)?.forEach(exportedFromPath => {
874871
if (handleDtsMayChangeOfGlobalScope(state, exportedFromPath, cancellationToken, host)) return true;
875872
const references = state.referencedMap!.getKeys(exportedFromPath);
876873
return references && forEachKey(references, filePath =>
@@ -900,23 +897,12 @@ function handleDtsMayChangeOfFileAndExportsOfFile(
900897
if (handleDtsMayChangeOfGlobalScope(state, filePath, cancellationToken, host)) return true;
901898
handleDtsMayChangeOf(state, filePath, cancellationToken, host);
902899

903-
// If exported modules has path, all files referencing file exported from are affected
904-
state.exportedModulesMap!.getKeys(filePath)?.forEach(exportedFromPath =>
905-
handleDtsMayChangeOfFileAndExportsOfFile(
906-
state,
907-
exportedFromPath,
908-
seenFileAndExportsOfFile,
909-
cancellationToken,
910-
host,
911-
)
912-
);
913-
914-
// Remove diagnostics of files that import this file (without going to exports of referencing files)
900+
// Remove the diagnostics of files that import this file and handle all its exports too
915901
state.referencedMap!.getKeys(filePath)?.forEach(referencingFilePath =>
916-
!seenFileAndExportsOfFile.has(referencingFilePath) && // Not already removed diagnostic file
917-
handleDtsMayChangeOf( // Dont add to seen since this is not yet done with the export removal
902+
handleDtsMayChangeOfFileAndExportsOfFile(
918903
state,
919904
referencingFilePath,
905+
seenFileAndExportsOfFile,
920906
cancellationToken,
921907
host,
922908
)
@@ -1011,7 +997,6 @@ export interface ProgramMultiFileEmitBuildInfo {
1011997
options: CompilerOptions | undefined;
1012998
fileIdsList: readonly (readonly ProgramBuildInfoFileId[])[] | undefined;
1013999
referencedMap: ProgramBuildInfoReferencedMap | undefined;
1014-
exportedModulesMap: ProgramBuildInfoReferencedMap | undefined;
10151000
semanticDiagnosticsPerFile: ProgramBuildInfoDiagnostic[] | undefined;
10161001
emitDiagnosticsPerFile: ProgramBuildInfoDiagnostic[] | undefined;
10171002
affectedFilesPendingEmit: ProgramBuilderInfoFilePendingEmit[] | undefined;
@@ -1138,17 +1123,6 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
11381123
]);
11391124
}
11401125

1141-
let exportedModulesMap: ProgramBuildInfoReferencedMap | undefined;
1142-
if (state.exportedModulesMap) {
1143-
exportedModulesMap = mapDefined(arrayFrom(state.exportedModulesMap.keys()).sort(compareStringsCaseSensitive), key => {
1144-
const oldValue = state.oldExportedModulesMap?.get(key);
1145-
// Not in temporary cache, use existing value
1146-
if (oldValue === undefined) return [toFileId(key), toFileIdListId(state.exportedModulesMap!.getValues(key)!)];
1147-
if (oldValue) return [toFileId(key), toFileIdListId(oldValue)];
1148-
return undefined;
1149-
});
1150-
}
1151-
11521126
const semanticDiagnosticsPerFile = convertToProgramBuildInfoDiagnostics(state.semanticDiagnosticsPerFile);
11531127
let affectedFilesPendingEmit: ProgramBuilderInfoFilePendingEmit[] | undefined;
11541128
if (state.affectedFilesPendingEmit?.size) {
@@ -1184,7 +1158,6 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
11841158
options: convertToProgramBuildInfoCompilerOptions(state.compilerOptions),
11851159
fileIdsList,
11861160
referencedMap,
1187-
exportedModulesMap,
11881161
semanticDiagnosticsPerFile,
11891162
emitDiagnosticsPerFile,
11901163
affectedFilesPendingEmit,
@@ -1602,7 +1575,6 @@ export function createBuilderProgram(kind: BuilderProgramKind, { newProgram, hos
16021575
if (!data?.diagnostics?.length) emitSignature = signature;
16031576
if (signature !== file.version) { // Update it
16041577
if (host.storeSignatureInfo) (state.signatureInfo ??= new Map()).set(file.resolvedPath, SignatureInfo.StoredSignatureAtEmit);
1605-
if (state.exportedModulesMap) BuilderState.updateExportedModules(state, file, file.exportedModulesFromDeclarationEmit);
16061578
if (state.affectedFiles) {
16071579
// Keep old signature so we know what to undo if cancellation happens
16081580
const existing = state.oldSignatures?.get(file.resolvedPath);
@@ -1612,7 +1584,6 @@ export function createBuilderProgram(kind: BuilderProgramKind, { newProgram, hos
16121584
else {
16131585
// These are directly committed
16141586
info.signature = signature;
1615-
state.oldExportedModulesMap?.clear();
16161587
}
16171588
}
16181589
}
@@ -1861,7 +1832,6 @@ export function createBuilderProgramUsingProgramBuildInfo(buildInfo: BuildInfo,
18611832
fileInfos,
18621833
compilerOptions: program.options ? convertToOptionsWithAbsolutePaths(program.options, toAbsolutePath) : {},
18631834
referencedMap: toManyToManyPathMap(program.referencedMap),
1864-
exportedModulesMap: toManyToManyPathMap(program.exportedModulesMap),
18651835
semanticDiagnosticsPerFile: toPerFileDiagnostics(program.semanticDiagnosticsPerFile),
18661836
emitDiagnosticsPerFile: toPerFileDiagnostics(program.emitDiagnosticsPerFile),
18671837
hasReusableDiagnostic: true,

src/compiler/builderState.ts

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Debug,
77
EmitOutput,
88
emptyArray,
9-
ExportedModulesFromDeclarationEmit,
109
GetCanonicalFileName,
1110
getDirectoryPath,
1211
getIsolatedModules,
@@ -69,14 +68,6 @@ export interface BuilderState {
6968
* Thus non undefined value indicates, module emit
7069
*/
7170
readonly referencedMap?: BuilderState.ReadonlyManyToManyPathMap | undefined;
72-
/**
73-
* Contains the map of exported modules ReferencedSet=exported module files from the file if module emit is enabled
74-
* Otherwise undefined
75-
*
76-
* This is equivalent to referencedMap, but for the emitted .d.ts file.
77-
*/
78-
readonly exportedModulesMap?: BuilderState.ManyToManyPathMap | undefined;
79-
8071
/**
8172
* true if file version is used as signature
8273
* This helps in delaying the calculation of the d.ts hash as version for the file till reasonable time
@@ -92,10 +83,6 @@ export interface BuilderState {
9283
* Stores signatures before before the update till affected file is committed
9384
*/
9485
oldSignatures?: Map<Path, string | false>;
95-
/**
96-
* Stores exportedModulesMap before the update till affected file is committed
97-
*/
98-
oldExportedModulesMap?: Map<Path, ReadonlySet<Path> | false>;
9986
/**
10087
* Cache of all files excluding default library file for the current program
10188
*/
@@ -314,7 +301,6 @@ export namespace BuilderState {
314301
const isOutFile = options.outFile;
315302
const referencedMap = options.module !== ModuleKind.None && !isOutFile ?
316303
createManyToManyPathMap() : undefined;
317-
const exportedModulesMap = referencedMap ? createManyToManyPathMap() : undefined;
318304
const useOldState = canReuseOldState(referencedMap, oldState);
319305

320306
// Ensure source files have parent pointers set
@@ -332,16 +318,6 @@ export namespace BuilderState {
332318
if (newReferences) {
333319
referencedMap.set(sourceFile.resolvedPath, newReferences);
334320
}
335-
// Copy old visible to outside files map
336-
if (useOldState) {
337-
const oldUncommittedExportedModules = oldState!.oldExportedModulesMap?.get(sourceFile.resolvedPath);
338-
const exportedModules = oldUncommittedExportedModules === undefined ?
339-
oldState!.exportedModulesMap!.getValues(sourceFile.resolvedPath) :
340-
oldUncommittedExportedModules || undefined;
341-
if (exportedModules) {
342-
exportedModulesMap!.set(sourceFile.resolvedPath, exportedModules);
343-
}
344-
}
345321
}
346322
fileInfos.set(sourceFile.resolvedPath, {
347323
version,
@@ -355,7 +331,6 @@ export namespace BuilderState {
355331
return {
356332
fileInfos,
357333
referencedMap,
358-
exportedModulesMap,
359334
useFileVersionAsSignature: !disableUseFileVersionAsSignature && !useOldState,
360335
};
361336
}
@@ -386,7 +361,6 @@ export namespace BuilderState {
386361
host,
387362
);
388363
state.oldSignatures?.clear();
389-
state.oldExportedModulesMap?.clear();
390364
return result;
391365
}
392366

@@ -461,62 +435,22 @@ export namespace BuilderState {
461435
const prevSignature = info.signature;
462436
let latestSignature: string | undefined;
463437
if (!sourceFile.isDeclarationFile && !useFileVersionAsSignature) {
464-
computeDtsSignature(programOfThisState, sourceFile, cancellationToken, host, (signature, sourceFiles) => {
438+
computeDtsSignature(programOfThisState, sourceFile, cancellationToken, host, signature => {
465439
latestSignature = signature;
466440
if (host.storeSignatureInfo) (state.signatureInfo ??= new Map()).set(sourceFile.resolvedPath, SignatureInfo.ComputedDts);
467-
if (latestSignature !== prevSignature) {
468-
updateExportedModules(state, sourceFile, sourceFiles[0].exportedModulesFromDeclarationEmit);
469-
}
470441
});
471442
}
472443
// Default is to use file version as signature
473444
if (latestSignature === undefined) {
474445
latestSignature = sourceFile.version;
475446
if (host.storeSignatureInfo) (state.signatureInfo ??= new Map()).set(sourceFile.resolvedPath, SignatureInfo.UsedVersion);
476-
if (state.exportedModulesMap && latestSignature !== prevSignature) {
477-
(state.oldExportedModulesMap ||= new Map()).set(sourceFile.resolvedPath, state.exportedModulesMap.getValues(sourceFile.resolvedPath) || false);
478-
// All the references in this file are exported
479-
const references = state.referencedMap ? state.referencedMap.getValues(sourceFile.resolvedPath) : undefined;
480-
if (references) {
481-
state.exportedModulesMap.set(sourceFile.resolvedPath, references);
482-
}
483-
else {
484-
state.exportedModulesMap.deleteKey(sourceFile.resolvedPath);
485-
}
486-
}
487447
}
488448
(state.oldSignatures ||= new Map()).set(sourceFile.resolvedPath, prevSignature || false);
489449
(state.hasCalledUpdateShapeSignature ||= new Set()).add(sourceFile.resolvedPath);
490450
info.signature = latestSignature;
491451
return latestSignature !== prevSignature;
492452
}
493453

494-
/**
495-
* Coverts the declaration emit result into exported modules map
496-
*/
497-
export function updateExportedModules(state: BuilderState, sourceFile: SourceFile, exportedModulesFromDeclarationEmit: ExportedModulesFromDeclarationEmit | undefined) {
498-
if (!state.exportedModulesMap) return;
499-
(state.oldExportedModulesMap ||= new Map()).set(sourceFile.resolvedPath, state.exportedModulesMap.getValues(sourceFile.resolvedPath) || false);
500-
const exportedModules = getExportedModules(exportedModulesFromDeclarationEmit);
501-
if (exportedModules) {
502-
state.exportedModulesMap.set(sourceFile.resolvedPath, exportedModules);
503-
}
504-
else {
505-
state.exportedModulesMap.deleteKey(sourceFile.resolvedPath);
506-
}
507-
}
508-
509-
export function getExportedModules(exportedModulesFromDeclarationEmit: ExportedModulesFromDeclarationEmit | undefined) {
510-
let exportedModules: Set<Path> | undefined;
511-
exportedModulesFromDeclarationEmit?.forEach(
512-
symbol =>
513-
getReferencedFilesFromImportedModuleSymbol(symbol).forEach(
514-
path => (exportedModules ??= new Set()).add(path),
515-
),
516-
);
517-
return exportedModules;
518-
}
519-
520454
/**
521455
* Get all the dependencies of the sourceFile
522456
*/

src/compiler/transformers/declarations.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ export function transformDeclarations(context: TransformationContext) {
532532
combinedStatements = setTextRange(factory.createNodeArray([...combinedStatements, createEmptyExports(factory)]), combinedStatements);
533533
}
534534
}
535-
const updated = factory.updateSourceFile(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib, getLibReferences());
536-
updated.exportedModulesFromDeclarationEmit = exportedModulesFromDeclarationEmit;
537-
return updated;
535+
return factory.updateSourceFile(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib, getLibReferences());
538536

539537
function getLibReferences() {
540538
return arrayFrom(libs.keys(), lib => ({ fileName: lib, pos: -1, end: -1 }));

src/compiler/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,6 @@ export interface SourceFile extends Declaration, LocalsContainer {
43264326
/** @internal */ localJsxFactory?: EntityName;
43274327
/** @internal */ localJsxFragmentFactory?: EntityName;
43284328

4329-
/** @internal */ exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit;
43304329
/** @internal */ endFlowNode?: FlowNode;
43314330

43324331
/** @internal */ jsDocParsingMode?: JSDocParsingMode;
@@ -4369,9 +4368,6 @@ export const enum CommentDirectiveType {
43694368
Ignore,
43704369
}
43714370

4372-
/** @internal */
4373-
export type ExportedModulesFromDeclarationEmit = readonly Symbol[];
4374-
43754371
export interface Bundle extends Node {
43764372
readonly kind: SyntaxKind.Bundle;
43774373
readonly sourceFiles: readonly SourceFile[];

src/testRunner/unittests/helpers/baseline.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,11 @@ export type ReadableProgramBuildInfoFileInfo<T> = Omit<ts.BuilderState.FileInfo,
147147
export type ReadableProgramBuildInfoRoot =
148148
| [original: ts.ProgramBuildInfoFileId, readable: string]
149149
| [original: ts.ProgramBuildInfoRootStartEnd, readable: readonly string[]];
150-
export type ReadableProgramMultiFileEmitBuildInfo = Omit<ts.ProgramMultiFileEmitBuildInfo, "fileIdsList" | "fileInfos" | "root" | "referencedMap" | "exportedModulesMap" | "semanticDiagnosticsPerFile" | "emitDiagnosticsPerFile" | "affectedFilesPendingEmit" | "changeFileSet" | "emitSignatures"> & {
150+
export type ReadableProgramMultiFileEmitBuildInfo = Omit<ts.ProgramMultiFileEmitBuildInfo, "fileIdsList" | "fileInfos" | "root" | "referencedMap" | "semanticDiagnosticsPerFile" | "emitDiagnosticsPerFile" | "affectedFilesPendingEmit" | "changeFileSet" | "emitSignatures"> & {
151151
fileNamesList: readonly (readonly string[])[] | undefined;
152152
fileInfos: ts.MapLike<ReadableProgramBuildInfoFileInfo<ts.ProgramMultiFileEmitBuildInfoFileInfo>>;
153153
root: readonly ReadableProgramBuildInfoRoot[];
154154
referencedMap: ts.MapLike<string[]> | undefined;
155-
exportedModulesMap: ts.MapLike<string[]> | undefined;
156155
semanticDiagnosticsPerFile: readonly ReadableProgramBuildInfoDiagnostic[] | undefined;
157156
emitDiagnosticsPerFile: readonly ReadableProgramBuildInfoDiagnostic[] | undefined;
158157
affectedFilesPendingEmit: readonly ReadableProgramBuilderInfoFilePendingEmit[] | undefined;
@@ -207,7 +206,6 @@ function generateBuildInfoProgramBaseline(sys: ts.System, buildInfoPath: string,
207206
root: buildInfo.program.root.map(toReadableProgramBuildInfoRoot),
208207
options: buildInfo.program.options,
209208
referencedMap: toMapOfReferencedSet(buildInfo.program.referencedMap),
210-
exportedModulesMap: toMapOfReferencedSet(buildInfo.program.exportedModulesMap),
211209
semanticDiagnosticsPerFile: toReadableProgramBuildInfoDiagnosticsPerFile(buildInfo.program.semanticDiagnosticsPerFile),
212210
emitDiagnosticsPerFile: toReadableProgramBuildInfoDiagnosticsPerFile(buildInfo.program.emitDiagnosticsPerFile),
213211
affectedFilesPendingEmit: buildInfo.program.affectedFilesPendingEmit?.map(value => toReadableProgramBuilderInfoFilePendingEmit(value, fullEmitForOptions!)),

0 commit comments

Comments
 (0)