From a1ea48a830ac4b1c61e3db2522517f5b7a2f6e6a Mon Sep 17 00:00:00 2001 From: Michael Arnaldi Date: Sat, 2 Jul 2022 18:53:53 +0000 Subject: [PATCH] chore: improve get referenced files --- .../package1/src/type-driven-overloads.ts | 1 - .../package1/src/type-driven-overloads/op1.ts | 3 - effect/packages/package1/tsconfig.json | 4 +- src/compiler/builderState.ts | 14 ++++- src/compiler/checker.ts | 57 +++++++++++++------ src/compiler/types.ts | 3 +- 6 files changed, 56 insertions(+), 26 deletions(-) diff --git a/effect/packages/package1/src/type-driven-overloads.ts b/effect/packages/package1/src/type-driven-overloads.ts index d8cb7c80a9b..f999961aaf7 100644 --- a/effect/packages/package1/src/type-driven-overloads.ts +++ b/effect/packages/package1/src/type-driven-overloads.ts @@ -8,7 +8,6 @@ T.make(1).op(1) T.make(1) + true -// @ts-expect-error T.make(1).op(true) T.make(1) diff --git a/effect/packages/package1/src/type-driven-overloads/op1.ts b/effect/packages/package1/src/type-driven-overloads/op1.ts index a56801384fe..8acb04a374b 100644 --- a/effect/packages/package1/src/type-driven-overloads/op1.ts +++ b/effect/packages/package1/src/type-driven-overloads/op1.ts @@ -7,9 +7,6 @@ import { T } from './T.js' * @tsplus operator T + 0.1 */ export function op1_(_self: T, x: string): T -/** - * Comment 2 - */ export function op1_(_self: T, x: boolean): T export function op1_(_self: T, x: string | boolean): T { return { value: x.toString() } diff --git a/effect/packages/package1/tsconfig.json b/effect/packages/package1/tsconfig.json index 46c3a1f8b52..9f4f5a85b8a 100644 --- a/effect/packages/package1/tsconfig.json +++ b/effect/packages/package1/tsconfig.json @@ -5,7 +5,9 @@ "declarationDir": "build/dts", "declarationMap": true, "tsPlusConfig": "../../tsplus.config.json", - "rootDir": "src" + "rootDir": "src", + "incremental": true, + "tsBuildInfoFile": "build/.tsbuildinfo" }, "include": ["src/**/*.ts"] } \ No newline at end of file diff --git a/src/compiler/builderState.ts b/src/compiler/builderState.ts index 4b7defd38b0..c828b9a9380 100644 --- a/src/compiler/builderState.ts +++ b/src/compiler/builderState.ts @@ -225,8 +225,18 @@ namespace ts { } // TSPLUS START - for (const file of arrayFrom(program.getTypeChecker().getTsPlusFiles().values())) { - addReferencedFile(file.resolvedPath); + program.getTypeChecker().getTsPlusFiles().get(sourceFile)?.forEach((file) => { + if (file !== sourceFile) { + addReferencedFile(file.resolvedPath); + } + }) + if (!sourceFile.isDeclarationFile) { + program.getTypeChecker().getTsPlusGlobalImports().forEach((imp) => { + const file = getSourceFileOfNode(imp.declaration); + if (file !== sourceFile) { + addReferencedFile(file.resolvedPath); + } + }) } // TSPLUS END diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 691da833e99..d305c0e4ba6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -386,7 +386,8 @@ namespace ts { const unificationInProgress = { isRunning: false }; - const tsPlusFiles = new Set(); + const tsPlusFiles = new Map>(); + const tsPlusFilesFinal = new Map>(); // TSPLUS EXTENSION END // Cancellation that controls whether or not we can cancel in the middle of type checking. @@ -912,7 +913,8 @@ namespace ts { .concat(collectTsPlusGetterTags(node)) .concat(collectTsPlusOperatorTags(node)) }, - getTsPlusFiles: () => tsPlusFiles + getTsPlusFiles: () => tsPlusFilesFinal, + getTsPlusGlobalImports: () => tsPlusGlobalImportCache // TSPLUS EXTENSION END }; @@ -46594,7 +46596,6 @@ namespace ts { function cacheTsPlusType(declaration: InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration): void { const type = getTypeOfNode(declaration); for (const typeTag of collectTsPlusTypeTags(declaration)) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); if (type === globalStringType) { addToTypeSymbolCache(tsplusStringPrimitiveSymbol, typeTag, "after"); } @@ -46679,12 +46680,15 @@ namespace ts { } } } + function getTsPlusSourceFileCache(tag: string) { + return tsPlusFiles.has(tag) ? tsPlusFiles.get(tag)! : (tsPlusFiles.set(tag, new Set()), tsPlusFiles.get(tag)!); + } function cacheTsPlusCompanion(declaration: ClassDeclaration): void { const type = getTypeOfNode(declaration); const tags = collectTsPlusCompanionTags(declaration); if (type.symbol) { for (const companionTag of tags) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(companionTag).add(getSourceFileOfNode(declaration)); addToCompanionSymbolCache(type.symbol, companionTag); } } @@ -46692,10 +46696,10 @@ namespace ts { function cacheTsPlusStaticVariable(file: SourceFile, declaration: VariableDeclarationWithIdentifier) { const staticTags = collectTsPlusStaticTags(declaration); if (staticTags.length > 0) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); const symbol = getSymbolAtLocation(declaration.name); if (symbol) { for (const { target, name } of staticTags) { + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!unresolvedStaticCache.get(target)) { unresolvedStaticCache.set(target, new Map()); } @@ -46715,7 +46719,7 @@ namespace ts { function cacheTsPlusFluentVariable(file: SourceFile, declaration: VariableDeclarationWithIdentifier) { const fluentTags = collectTsPlusFluentTags(declaration); for (const tag of fluentTags) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(tag.target).add(getSourceFileOfNode(declaration)); if (!unresolvedFluentCache.has(tag.target)) { unresolvedFluentCache.set(tag.target, new Map()); } @@ -46745,6 +46749,7 @@ namespace ts { } function cacheTsPlusGetterVariable(file: SourceFile, declaration: VariableDeclarationWithIdentifier) { for (const { target, name } of collectTsPlusGetterTags(declaration)) { + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!getterCache.has(target)) { getterCache.set(target, new Map()); } @@ -46764,10 +46769,10 @@ namespace ts { if(declaration.name && isIdentifier(declaration.name)) { const operatorTags = collectTsPlusOperatorTags(declaration); if (operatorTags.length > 0) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); const symbol = getSymbolAtLocation(declaration.name); if (symbol) { for (const tag of operatorTags) { + getTsPlusSourceFileCache(tag.target).add(getSourceFileOfNode(declaration)); if (!operatorCache.has(tag.target)) { operatorCache.set(tag.target, new Map()); } @@ -46792,7 +46797,7 @@ namespace ts { const symbol = getSymbolAtLocation(declaration.name); if (symbol) { for (const tag of operatorTags) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(tag.target).add(getSourceFileOfNode(declaration)); if (!operatorCache.has(tag.target)) { operatorCache.set(tag.target, new Map()); } @@ -46813,7 +46818,7 @@ namespace ts { function cacheTsPlusFluentFunction(file: SourceFile, declaration: FunctionDeclaration) { const fluentTags = collectTsPlusFluentTags(declaration); for (const tag of fluentTags) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(tag.target).add(getSourceFileOfNode(declaration)); if (!unresolvedFluentCache.has(tag.target)) { unresolvedFluentCache.set(tag.target, new Map()); } @@ -46845,8 +46850,8 @@ namespace ts { if (declaration.name && isIdentifier(declaration.name)) { const pipeableOperatorTags = collectTsPlusPipeableOperatorTags(declaration); if (pipeableOperatorTags.length > 0) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); for (const { target, name, priority } of pipeableOperatorTags) { + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!unresolvedPipeableOperatorCache.has(target)) { unresolvedPipeableOperatorCache.set(target, new Map()) } @@ -46897,8 +46902,8 @@ namespace ts { (declaration.type && isFunctionTypeNode(declaration.type))) { const pipeableOperatorTags = collectTsPlusPipeableOperatorTags(declaration); if (pipeableOperatorTags.length > 0) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); for (const { target, name, priority } of pipeableOperatorTags) { + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!unresolvedPipeableOperatorCache.has(target)) { unresolvedPipeableOperatorCache.set(target, new Map()) } @@ -46948,7 +46953,7 @@ namespace ts { if (declaration.name && isIdentifier(declaration.name)) { const pipeableTags = collectTsPlusPipeableTags(declaration); for (const { target, name, priority } of pipeableTags) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!unresolvedPipeableCache.has(target)) { unresolvedPipeableCache.set(target, new Map()); } @@ -47002,7 +47007,7 @@ namespace ts { if((declaration.initializer && isFunctionLikeDeclaration(declaration.initializer)) || (declaration.type && isFunctionTypeNode(declaration.type))) { for (const { target, name, priority } of collectTsPlusPipeableTags(declaration)) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!unresolvedPipeableCache.has(target)) { unresolvedPipeableCache.set(target, new Map()); } @@ -47061,7 +47066,7 @@ namespace ts { function cacheTsPlusGetterFunction(file: SourceFile, declaration: FunctionDeclaration) { if(declaration.name && isIdentifier(declaration.name)) { for (const { target, name } of collectTsPlusGetterTags(declaration)) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!getterCache.has(target)) { getterCache.set(target, new Map()); } @@ -47078,7 +47083,7 @@ namespace ts { function cacheTsPlusStaticFunction(file: SourceFile, declaration: FunctionDeclaration) { if(declaration.name && isIdentifier(declaration.name)) { for (const { target, name } of collectTsPlusStaticTags(declaration)) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); if (!staticCache.has(target)) { staticCache.set(target, new Map()); } @@ -47115,7 +47120,7 @@ namespace ts { function cacheTsPlusUnifyFunction(declaration: FunctionDeclaration) { if(declaration.name && isIdentifier(declaration.name)) { for (const target of collectTsPlusUnifyTags(declaration)) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); identityCache.set(target, declaration); } } @@ -47123,8 +47128,7 @@ namespace ts { function cacheTsPlusIndexFunction(declaration: FunctionDeclaration) { if(declaration.name && isIdentifier(declaration.name)) { for (const target of collectTsPlusIndexTags(declaration)) { - tsPlusFiles.add(getSourceFileOfNode(declaration)); - tsPlusFiles.add(getSourceFileOfNode(declaration)); + getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration)); indexCache.set(target, { declaration, definition: getSourceFileOfNode(declaration), @@ -47243,6 +47247,21 @@ namespace ts { fillTsPlusLocalScope(file); } } + function postInitTsPlusTypeChecker() { + tsPlusDebug && console.time("initTsPlusTypeChecker build dependency tree") + typeSymbolCache.forEach((tags, symbol) => { + forEach(symbol.declarations, (declaration) => { + const source = getSourceFileOfNode(declaration); + const set = tsPlusFilesFinal.has(source) ? tsPlusFilesFinal.get(source)! : (tsPlusFilesFinal.set(source, new Set()), tsPlusFilesFinal.get(source)!); + forEach(tags, (tag) => { + tsPlusFiles.get(tag)?.forEach((dep) => { + set.add(dep); + }) + }) + }) + }) + tsPlusDebug && console.timeEnd("initTsPlusTypeChecker build dependency tree") + } function initTsPlusTypeChecker() { tsPlusDebug && console.time("initTsPlusTypeChecker caches") fileMap.map = getFileMap(host.getCompilerOptions(), host); @@ -47258,6 +47277,7 @@ namespace ts { unresolvedStaticCache.clear(); identityCache.clear(); tsPlusFiles.clear(); + tsPlusFilesFinal.clear(); getterCache.clear(); callCache.clear(); indexCache.clear(); @@ -47474,6 +47494,7 @@ namespace ts { tsPlusDebug && console.time("initTsPlusTypeChecker implicits") initTsPlusTypeCheckerImplicits(); tsPlusDebug && console.timeEnd("initTsPlusTypeChecker implicits") + postInitTsPlusTypeChecker(); } // TSPLUS EXTENSION END diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 71f7368828c..8be66112343 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4981,7 +4981,8 @@ namespace ts { getResolvedOperator(node: BinaryExpression): Signature | undefined getNodeLinks(node: Node): NodeLinks // TSPLUS START - getTsPlusFiles(): Set + getTsPlusFiles(): ESMap> + getTsPlusGlobalImports(): ESMap collectTsPlusMacroTags(statement: Declaration): readonly string[] getTsPlusGlobals(): Symbol[]; getTsPlusGlobal(name: string): TsPlusGlobalImport | undefined;