Compare commits
2 commits
main
...
dump-varia
Author | SHA1 | Date | |
---|---|---|---|
416323d967 | |||
18b0fc0040 |
|
@ -621,6 +621,7 @@ namespace ts {
|
||||||
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
|
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
|
||||||
},
|
},
|
||||||
getApparentType,
|
getApparentType,
|
||||||
|
dumpVariances,
|
||||||
getUnionType,
|
getUnionType,
|
||||||
isTypeAssignableTo,
|
isTypeAssignableTo,
|
||||||
createAnonymousType,
|
createAnonymousType,
|
||||||
|
@ -3999,7 +4000,7 @@ namespace ts {
|
||||||
typeCount++;
|
typeCount++;
|
||||||
result.id = typeCount;
|
result.id = typeCount;
|
||||||
if (produceDiagnostics) { // Only record types from one checker
|
if (produceDiagnostics) { // Only record types from one checker
|
||||||
tracing?.recordType(result);
|
tracingEnabled.recordType(result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -20209,6 +20210,24 @@ namespace ts {
|
||||||
return variances;
|
return variances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getVariancesUltra(type: GenericType, refid: number): { variances: string[], how: 'static' | 'check' | 'dump', refid: number, targetid: number } {
|
||||||
|
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
||||||
|
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
||||||
|
return { variances: arrayVariances.map(translateEnum), how: 'static', targetid: type.id, refid };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
how: type.variances ? 'check' : 'dump',
|
||||||
|
variances: getVariancesWorker(type.typeParameters, type, getMarkerTypeReference).map(translateEnum),
|
||||||
|
targetid: type.id,
|
||||||
|
refid,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function translateEnum(flag: VarianceFlags): string {
|
||||||
|
return flag.toString() // laters! (once I find out the distribution)
|
||||||
|
}
|
||||||
|
|
||||||
function getVariances(type: GenericType): VarianceFlags[] {
|
function getVariances(type: GenericType): VarianceFlags[] {
|
||||||
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
||||||
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
||||||
|
@ -40303,6 +40322,14 @@ namespace ts {
|
||||||
return diagnostics.getDiagnostics();
|
return diagnostics.getDiagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dumpVariances() {
|
||||||
|
tracingEnabled.iterTypes(t => {
|
||||||
|
if (getObjectFlags(t) & ObjectFlags.Reference) {
|
||||||
|
console.log(JSON.stringify(getVariancesUltra((t as TypeReference).target, t.id)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getGlobalDiagnostics(): Diagnostic[] {
|
function getGlobalDiagnostics(): Diagnostic[] {
|
||||||
throwIfNonDiagnosticsProducing();
|
throwIfNonDiagnosticsProducing();
|
||||||
return diagnostics.getGlobalDiagnostics();
|
return diagnostics.getGlobalDiagnostics();
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||||
// enable the above using startTracing()
|
// enable the above using startTracing()
|
||||||
|
|
||||||
// `tracingEnabled` should never be used directly, only through the above
|
// `tracingEnabled` should never be used directly, only through the above
|
||||||
namespace tracingEnabled { // eslint-disable-line one-namespace-per-file
|
export namespace tracingEnabled { // eslint-disable-line one-namespace-per-file
|
||||||
type Mode = "project" | "build" | "server";
|
type Mode = "project" | "build" | "server";
|
||||||
|
|
||||||
let fs: typeof import("fs");
|
let fs: typeof import("fs");
|
||||||
|
@ -103,6 +103,12 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function iterTypes(action: (t: Type) => void): void {
|
||||||
|
for (const t of typeCatalog) {
|
||||||
|
action(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const enum Phase {
|
export const enum Phase {
|
||||||
Parse = "parse",
|
Parse = "parse",
|
||||||
Program = "program",
|
Program = "program",
|
||||||
|
|
|
@ -4152,6 +4152,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TypeChecker {
|
export interface TypeChecker {
|
||||||
|
dumpVariances(): void;
|
||||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||||
getPropertiesOfType(type: Type): Symbol[];
|
getPropertiesOfType(type: Type): Symbol[];
|
||||||
|
|
|
@ -327,6 +327,7 @@ namespace ts {
|
||||||
|
|
||||||
if (allDiagnostics.length === configFileParsingDiagnosticsLength) {
|
if (allDiagnostics.length === configFileParsingDiagnosticsLength) {
|
||||||
addRange(allDiagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
|
addRange(allDiagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
|
||||||
|
(program as Program).getTypeChecker().dumpVariances();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue