Skip to content

Commit 2bf19e8

Browse files
Speed up tests by not type-checking lib.d.ts unless the test asks for that.
1 parent 343a923 commit 2bf19e8

25 files changed

Lines changed: 139 additions & 106 deletions

Jakefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ function cleanTestDirs() {
506506
// used to pass data from jake command line directly to run.js
507507
function writeTestConfigFile(tests, testConfigFile) {
508508
console.log('Running test(s): ' + tests);
509-
var testConfigContents = '{\n' + '\ttest: [\'' + tests + '\']\n}';
509+
var testConfigContents = JSON.stringify({ test: [tests]});
510510
fs.writeFileSync('test.config', testConfigContents);
511511
}
512512

@@ -689,4 +689,4 @@ task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function
689689
complete();
690690
});
691691
ex.run();
692-
}, { async: true });
692+
}, { async: true });

src/compiler/checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11368,6 +11368,12 @@ module ts {
1136811368
function checkSourceFileWorker(node: SourceFile) {
1136911369
let links = getNodeLinks(node);
1137011370
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
11371+
links.flags |= NodeCheckFlags.TypeChecked;
11372+
11373+
if (node.isDefaultLib && compilerOptions.skipDefaultLibCheck) {
11374+
return;
11375+
}
11376+
1137111377
// Grammar checking
1137211378
checkGrammarSourceFile(node);
1137311379

@@ -11399,8 +11405,6 @@ module ts {
1139911405
if (emitParam) {
1140011406
links.flags |= NodeCheckFlags.EmitParam;
1140111407
}
11402-
11403-
links.flags |= NodeCheckFlags.TypeChecked;
1140411408
}
1140511409
}
1140611410

src/compiler/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ module ts {
391391
processImportedModules(file, basePath);
392392
}
393393
if (isDefaultLib) {
394+
file.isDefaultLib = true;
394395
files.unshift(file);
395396
}
396397
else {

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,8 @@ module ts {
11431143

11441144
// The first node that causes this file to be an external module
11451145
/* @internal */ externalModuleIndicator: Node;
1146-
1146+
1147+
/* @internal */ isDefaultLib: boolean;
11471148
/* @internal */ identifiers: Map<string>;
11481149
/* @internal */ nodeCount: number;
11491150
/* @internal */ identifierCount: number;
@@ -1823,6 +1824,7 @@ module ts {
18231824
experimentalDecorators?: boolean;
18241825
emitDecoratorMetadata?: boolean;
18251826
/* @internal */ stripInternal?: boolean;
1827+
/* @internal */ skipDefaultLibCheck?: boolean;
18261828
[option: string]: string | number | boolean;
18271829
}
18281830

src/harness/harness.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,17 @@ module Harness {
808808
}
809809
}
810810

811-
export function createSourceFileAndAssertInvariants(fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, assertInvariants = true) {
811+
export function createSourceFileAndAssertInvariants(
812+
fileName: string,
813+
sourceText: string,
814+
languageVersion: ts.ScriptTarget,
815+
assertInvariants: boolean,
816+
isDefaultLib: boolean) {
817+
812818
// Only set the parent nodes if we're asserting invariants. We don't need them otherwise.
813819
var result = ts.createSourceFile(fileName, sourceText, languageVersion, /*setParentNodes:*/ assertInvariants);
820+
result.isDefaultLib = isDefaultLib;
821+
814822
if (assertInvariants) {
815823
Utils.assertInvariants(result, /*parent:*/ undefined);
816824
}
@@ -821,8 +829,8 @@ module Harness {
821829
const lineFeed = "\n";
822830

823831
export var defaultLibFileName = 'lib.d.ts';
824-
export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
825-
export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest);
832+
export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*assertInvariants:*/ true, /*isDefaultLib:*/ true);
833+
export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*assertInvariants:*/ true, /*isDefaultLib:*/ true);
826834

827835
// Cache these between executions so we don't have to re-parse them for every test
828836
export var fourslashFileName = 'fourslash.ts';
@@ -832,13 +840,14 @@ module Harness {
832840
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
833841
}
834842

835-
export function createCompilerHost(inputFiles: { unitName: string; content: string; }[],
836-
writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void,
837-
scriptTarget: ts.ScriptTarget,
838-
useCaseSensitiveFileNames: boolean,
839-
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
840-
currentDirectory?: string,
841-
newLineKind?: ts.NewLineKind): ts.CompilerHost {
843+
export function createCompilerHost(
844+
inputFiles: { unitName: string; content: string; }[],
845+
writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void,
846+
scriptTarget: ts.ScriptTarget,
847+
useCaseSensitiveFileNames: boolean,
848+
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
849+
currentDirectory?: string,
850+
newLineKind?: ts.NewLineKind): ts.CompilerHost {
842851

843852
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
844853
function getCanonicalFileName(fileName: string): string {
@@ -852,7 +861,7 @@ module Harness {
852861
function register(file: { unitName: string; content: string; }) {
853862
if (file.content !== undefined) {
854863
var fileName = ts.normalizePath(file.unitName);
855-
filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget);
864+
filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget, /*assertInvariants:*/ true, /*isDefaultLib:*/ false);
856865
}
857866
};
858867
inputFiles.forEach(register);
@@ -875,7 +884,7 @@ module Harness {
875884
}
876885
else if (fn === fourslashFileName) {
877886
var tsFn = 'tests/cases/fourslash/' + fourslashFileName;
878-
fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget);
887+
fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget, /*assertInvariants:*/ true, /*isDefaultLib:*/ false);
879888
return fourslashSourceFile;
880889
}
881890
else {
@@ -964,7 +973,8 @@ module Harness {
964973
settingsCallback(null);
965974
}
966975

967-
var newLine = '\r\n';
976+
let newLine = '\r\n';
977+
options.skipDefaultLibCheck = true;
968978

969979
// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
970980
// Treat them as library files, so include them in build, but not in baselines.
@@ -1050,6 +1060,10 @@ module Harness {
10501060
options.outDir = setting.value;
10511061
break;
10521062

1063+
case 'skipdefaultlibcheck':
1064+
options.skipDefaultLibCheck = setting.value === "true";
1065+
break;
1066+
10531067
case 'sourceroot':
10541068
options.sourceRoot = setting.value;
10551069
break;
@@ -1134,9 +1148,11 @@ module Harness {
11341148
var fileOutputs: GeneratedFile[] = [];
11351149

11361150
var programFiles = inputFiles.concat(includeBuiltFiles).map(file => file.unitName);
1137-
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(includeBuiltFiles).concat(otherFiles),
1151+
var compilerHost = createCompilerHost(
1152+
inputFiles.concat(includeBuiltFiles).concat(otherFiles),
11381153
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
1139-
options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine));
1154+
options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine);
1155+
var program = ts.createProgram(programFiles, options, compilerHost);
11401156

11411157
var emitResult = program.emit();
11421158

@@ -1480,7 +1496,8 @@ module Harness {
14801496
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
14811497
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
14821498
"isolatedmodules", "inlinesourcemap", "maproot", "sourceroot",
1483-
"inlinesources", "emitdecoratormetadata", "experimentaldecorators"];
1499+
"inlinesources", "emitdecoratormetadata", "experimentaldecorators",
1500+
"skipdefaultlibcheck"];
14841501

14851502
function extractCompilerSettings(content: string): CompilerSetting[] {
14861503

src/harness/projectsRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class ProjectRunner extends RunnerBase {
174174
else {
175175
var text = getSourceFileText(fileName);
176176
if (text !== undefined) {
177-
sourceFile = Harness.Compiler.createSourceFileAndAssertInvariants(fileName, text, languageVersion);
177+
sourceFile = Harness.Compiler.createSourceFileAndAssertInvariants(fileName, text, languageVersion, /*assertInvariants:*/ true, /*isDefaultLib:*/ false);
178178
}
179179
}
180180

src/harness/runner.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,45 @@ var testConfigFile =
3838
(Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : '');
3939

4040
if (testConfigFile !== '') {
41-
// TODO: not sure why this is crashing mocha
42-
//var testConfig = JSON.parse(testConfigRaw);
43-
var testConfig = testConfigFile.match(/test:\s\['(.*)'\]/);
44-
var options = testConfig ? [testConfig[1]] : [];
45-
for (var i = 0; i < options.length; i++) {
46-
switch (options[i]) {
47-
case 'compiler':
48-
runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance));
49-
runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions));
50-
runners.push(new ProjectRunner());
51-
break;
52-
case 'conformance':
53-
runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance));
54-
break;
55-
case 'project':
56-
runners.push(new ProjectRunner());
57-
break;
58-
case 'fourslash':
59-
runners.push(new FourSlashRunner(FourSlashTestType.Native));
60-
break;
61-
case 'fourslash-shims':
62-
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
63-
break;
64-
case 'fourslash-server':
65-
runners.push(new FourSlashRunner(FourSlashTestType.Server));
66-
break;
67-
case 'fourslash-generated':
68-
runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native));
69-
break;
70-
case 'rwc':
71-
runners.push(new RWCRunner());
72-
break;
73-
case 'test262':
74-
runners.push(new Test262BaselineRunner());
75-
break;
41+
var testConfig = JSON.parse(testConfigFile);
42+
43+
if (testConfig.test && testConfig.test.length > 0) {
44+
for (let option of testConfig.test) {
45+
if (!option) {
46+
continue;
47+
}
48+
ts.sys.write("Option: " + option + "\r\n");
49+
switch (option) {
50+
case 'compiler':
51+
runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance));
52+
runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions));
53+
runners.push(new ProjectRunner());
54+
break;
55+
case 'conformance':
56+
runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance));
57+
break;
58+
case 'project':
59+
runners.push(new ProjectRunner());
60+
break;
61+
case 'fourslash':
62+
runners.push(new FourSlashRunner(FourSlashTestType.Native));
63+
break;
64+
case 'fourslash-shims':
65+
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
66+
break;
67+
case 'fourslash-server':
68+
runners.push(new FourSlashRunner(FourSlashTestType.Server));
69+
break;
70+
case 'fourslash-generated':
71+
runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native));
72+
break;
73+
case 'rwc':
74+
runners.push(new RWCRunner());
75+
break;
76+
case 'test262':
77+
runners.push(new Test262BaselineRunner());
78+
break;
79+
}
7680
}
7781
}
7882
}

src/services/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ module ts {
743743
public parseDiagnostics: Diagnostic[];
744744
public bindDiagnostics: Diagnostic[];
745745

746+
public isDefaultLib: boolean;
746747
public hasNoDefaultLib: boolean;
747748
public externalModuleIndicator: Node; // The first node that causes this file to be an external module
748749
public nodeCount: number;

tests/baselines/reference/TypeGuardWithEnumUnion.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ function f1(x: Color | string) {
3535
}
3636

3737
function f2(x: Color | string | string[]) {
38-
>f2 : (x: string | string[] | Color) => void
39-
>x : string | string[] | Color
38+
>f2 : (x: string | Color | string[]) => void
39+
>x : string | Color | string[]
4040
>Color : Color
4141

4242
if (typeof x === "object") {
4343
>typeof x === "object" : boolean
4444
>typeof x : string
45-
>x : string | string[] | Color
45+
>x : string | Color | string[]
4646
>"object" : string
4747

4848
var y = x;
@@ -55,7 +55,7 @@ function f2(x: Color | string | string[]) {
5555
if (typeof x === "number") {
5656
>typeof x === "number" : boolean
5757
>typeof x : string
58-
>x : string | string[] | Color
58+
>x : string | Color | string[]
5959
>"number" : string
6060

6161
var z = x;
@@ -77,7 +77,7 @@ function f2(x: Color | string | string[]) {
7777
if (typeof x === "string") {
7878
>typeof x === "string" : boolean
7979
>typeof x : string
80-
>x : string | string[] | Color
80+
>x : string | Color | string[]
8181
>"string" : string
8282

8383
var a = x;
@@ -89,11 +89,11 @@ function f2(x: Color | string | string[]) {
8989
}
9090
else {
9191
var b = x;
92-
>b : string[] | Color
93-
>x : string[] | Color
92+
>b : Color | string[]
93+
>x : Color | string[]
9494

9595
var b: Color | string[];
96-
>b : string[] | Color
96+
>b : Color | string[]
9797
>Color : Color
9898
}
9999
}

tests/baselines/reference/arrayLiterals.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// Empty array literal with no contextual type has type Undefined[]
33

44
var arr1= [[], [1], ['']];
5-
>arr1 : (string[] | number[])[]
6-
>[[], [1], ['']] : (string[] | number[])[]
5+
>arr1 : (number[] | string[])[]
6+
>[[], [1], ['']] : (number[] | string[])[]
77
>[] : undefined[]
88
>[1] : number[]
99
>1 : number
1010
>[''] : string[]
1111
>'' : string
1212

1313
var arr2 = [[null], [1], ['']];
14-
>arr2 : (string[] | number[])[]
15-
>[[null], [1], ['']] : (string[] | number[])[]
14+
>arr2 : (number[] | string[])[]
15+
>[[null], [1], ['']] : (number[] | string[])[]
1616
>[null] : null[]
1717
>null : null
1818
>[1] : number[]

0 commit comments

Comments
 (0)