Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve get referenced files #209

Merged
merged 2 commits into from Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions effect/packages/package1/src/type-driven-overloads/op1.ts
Expand Up @@ -7,9 +7,6 @@ import { T } from './T.js'
* @tsplus operator T + 0.1
*/
export function op1_<A>(_self: T<A>, x: string): T<string>
/**
* Comment 2
*/
export function op1_<A>(_self: T<A>, x: boolean): T<string>
export function op1_<A>(_self: T<A>, x: string | boolean): T<string> {
return { value: x.toString() }
Expand Down
4 changes: 3 additions & 1 deletion effect/packages/package1/tsconfig.json
Expand Up @@ -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"]
}
14 changes: 12 additions & 2 deletions src/compiler/builderState.ts
Expand Up @@ -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

Expand Down
67 changes: 46 additions & 21 deletions src/compiler/checker.ts
Expand Up @@ -387,7 +387,8 @@ namespace ts {
const unificationInProgress = {
isRunning: false
};
const tsPlusFiles = new Set<SourceFile>();
const tsPlusFiles = new Map<string, Set<SourceFile>>();
const tsPlusFilesFinal = new Map<SourceFile, Set<SourceFile>>();
// TSPLUS EXTENSION END

// Cancellation that controls whether or not we can cancel in the middle of type checking.
Expand Down Expand Up @@ -829,9 +830,12 @@ namespace ts {
collectTsPlusFluentTags,
hasExportedPlusTags: (declaration) => {
return collectTsPlusFluentTags(declaration).length > 0 ||
collectTsPlusPipeableTags(declaration).length > 0 ||
collectTsPlusGetterTags(declaration).length > 0 ||
collectTsPlusIndexTags(declaration).length > 0 ||
collectTsPlusPipeableIndexTags(declaration).length > 0 ||
collectTsPlusOperatorTags(declaration).length > 0 ||
collectTsPlusPipeableTags(declaration).length > 0 ||
collectTsPlusPipeableOperatorTags(declaration).length > 0 ||
collectTsPlusStaticTags(declaration).length > 0 ||
isTsPlusImplicit(declaration) ||
collectTsPlusDeriveTags(declaration).length > 0
Expand Down Expand Up @@ -913,7 +917,8 @@ namespace ts {
.concat(collectTsPlusGetterTags(node))
.concat(collectTsPlusOperatorTags(node))
},
getTsPlusFiles: () => tsPlusFiles
getTsPlusFiles: () => tsPlusFilesFinal,
getTsPlusGlobalImports: () => tsPlusGlobalImportCache
// TSPLUS EXTENSION END
};

Expand Down Expand Up @@ -46606,7 +46611,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");
}
Expand Down Expand Up @@ -46691,23 +46695,26 @@ 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);
}
}
}
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());
}
Expand All @@ -46727,7 +46734,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());
}
Expand Down Expand Up @@ -46757,6 +46764,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());
}
Expand All @@ -46776,10 +46784,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());
}
Expand All @@ -46804,7 +46812,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());
}
Expand All @@ -46825,7 +46833,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());
}
Expand Down Expand Up @@ -46857,8 +46865,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())
}
Expand Down Expand Up @@ -46909,8 +46917,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())
}
Expand Down Expand Up @@ -46960,7 +46968,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());
}
Expand Down Expand Up @@ -47014,7 +47022,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());
}
Expand Down Expand Up @@ -47073,7 +47081,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());
}
Expand All @@ -47090,7 +47098,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());
}
Expand Down Expand Up @@ -47127,15 +47135,15 @@ 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);
}
}
}
function cacheTsPlusIndexFunction(declaration: FunctionDeclaration) {
if(declaration.name && isIdentifier(declaration.name)) {
for (const target of collectTsPlusIndexTags(declaration)) {
tsPlusFiles.add(getSourceFileOfNode(declaration));
getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration));
indexCache.set(target, () => {
if (resolvedIndexCache.has(target)) {
return resolvedIndexCache.get(target);
Expand All @@ -47152,7 +47160,7 @@ namespace ts {
}
function cacheTsPlusIndexVariable(declaration: VariableDeclarationWithIdentifier) {
for (const target of collectTsPlusIndexTags(declaration)) {
tsPlusFiles.add(getSourceFileOfNode(declaration));
getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration));
indexCache.set(target, () => {
if (resolvedIndexCache.has(target)) {
return resolvedIndexCache.get(target);
Expand All @@ -47169,7 +47177,7 @@ namespace ts {
function cacheTsPlusPipeableIndexFunction(declaration: FunctionDeclaration) {
if(declaration.name && isIdentifier(declaration.name)) {
for (const target of collectTsPlusPipeableIndexTags(declaration)) {
tsPlusFiles.add(getSourceFileOfNode(declaration));
getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration));
indexCache.set(target, () => {
if (resolvedIndexCache.has(target)) {
return resolvedIndexCache.get(target);
Expand All @@ -47187,7 +47195,7 @@ namespace ts {
}
function cacheTsPlusPipeableIndexVariable(declaration: VariableDeclarationWithIdentifier) {
for (const target of collectTsPlusPipeableIndexTags(declaration)) {
tsPlusFiles.add(getSourceFileOfNode(declaration));
getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration));
indexCache.set(target, () => {
if (resolvedIndexCache.has(target)) {
return resolvedIndexCache.get(target);
Expand Down Expand Up @@ -47325,6 +47333,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);
Expand All @@ -47340,6 +47363,7 @@ namespace ts {
unresolvedStaticCache.clear();
identityCache.clear();
tsPlusFiles.clear();
tsPlusFilesFinal.clear();
getterCache.clear();
callCache.clear();
indexCache.clear();
Expand Down Expand Up @@ -47557,6 +47581,7 @@ namespace ts {
tsPlusDebug && console.time("initTsPlusTypeChecker implicits")
initTsPlusTypeCheckerImplicits();
tsPlusDebug && console.timeEnd("initTsPlusTypeChecker implicits")
postInitTsPlusTypeChecker();
}
// TSPLUS EXTENSION END

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/types.ts
Expand Up @@ -4984,7 +4984,8 @@ namespace ts {
getResolvedOperator(node: BinaryExpression): Signature | undefined
getNodeLinks(node: Node): NodeLinks
// TSPLUS START
getTsPlusFiles(): Set<SourceFile>
getTsPlusFiles(): ESMap<SourceFile, Set<SourceFile>>
getTsPlusGlobalImports(): ESMap<string, TsPlusGlobalImport>
collectTsPlusMacroTags(statement: Declaration): readonly string[]
getTsPlusGlobals(): Symbol[];
getTsPlusGlobal(name: string): TsPlusGlobalImport | undefined;
Expand Down