Skip to content

Commit

Permalink
chore: improve get referenced files
Browse files Browse the repository at this point in the history
  • Loading branch information
mikearnaldi committed Jul 2, 2022
1 parent 0e2d2a6 commit a1ea48a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 26 deletions.
1 change: 0 additions & 1 deletion effect/packages/package1/src/type-driven-overloads.ts
Expand Up @@ -8,7 +8,6 @@ T.make(1).op(1)

T.make(1) + true

// @ts-expect-error
T.make(1).op(true)

T.make(1)
Expand Down
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
57 changes: 39 additions & 18 deletions src/compiler/checker.ts
Expand Up @@ -386,7 +386,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 @@ -912,7 +913,8 @@ namespace ts {
.concat(collectTsPlusGetterTags(node))
.concat(collectTsPlusOperatorTags(node))
},
getTsPlusFiles: () => tsPlusFiles
getTsPlusFiles: () => tsPlusFilesFinal,
getTsPlusGlobalImports: () => tsPlusGlobalImportCache
// TSPLUS EXTENSION END
};

Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -46679,23 +46680,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 @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -47115,16 +47120,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));
tsPlusFiles.add(getSourceFileOfNode(declaration));
getTsPlusSourceFileCache(target).add(getSourceFileOfNode(declaration));
indexCache.set(target, {
declaration,
definition: getSourceFileOfNode(declaration),
Expand Down Expand Up @@ -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);
Expand All @@ -47258,6 +47277,7 @@ namespace ts {
unresolvedStaticCache.clear();
identityCache.clear();
tsPlusFiles.clear();
tsPlusFilesFinal.clear();
getterCache.clear();
callCache.clear();
indexCache.clear();
Expand Down Expand Up @@ -47474,6 +47494,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 @@ -4981,7 +4981,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

0 comments on commit a1ea48a

Please sign in to comment.