Skip to content

Commit c0f4fdd

Browse files
committed
merge with origin/master
2 parents 9cd5b46 + 57eac1b commit c0f4fdd

73 files changed

Lines changed: 528 additions & 268 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Jakefile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if (process.env.path !== undefined) {
3434

3535
var compilerSources = [
3636
"core.ts",
37+
"performance.ts",
3738
"sys.ts",
3839
"types.ts",
3940
"scanner.ts",
@@ -54,6 +55,7 @@ var compilerSources = [
5455

5556
var servicesSources = [
5657
"core.ts",
58+
"performance.ts",
5759
"sys.ts",
5860
"types.ts",
5961
"scanner.ts",

src/compiler/binder.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
/* @internal */
55
namespace ts {
6-
export let bindTime = 0;
7-
86
export const enum ModuleInstanceState {
97
NonInstantiated = 0,
108
Instantiated = 1,
@@ -91,9 +89,9 @@ namespace ts {
9189
const binder = createBinder();
9290

9391
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
94-
const start = new Date().getTime();
92+
const start = performance.mark();
9593
binder(file, options);
96-
bindTime += new Date().getTime() - start;
94+
performance.measure("Bind", start);
9795
}
9896

9997
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

src/compiler/checker.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ namespace ts {
1515
return node.id;
1616
}
1717

18-
export let checkTime = 0;
19-
2018
export function getSymbolId(symbol: Symbol): number {
2119
if (!symbol.id) {
2220
symbol.id = nextSymbolId;
@@ -976,7 +974,7 @@ namespace ts {
976974

977975
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
978976

979-
if (!isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
977+
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
980978
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
981979
}
982980
}
@@ -17026,11 +17024,11 @@ namespace ts {
1702617024
}
1702717025

1702817026
function checkSourceFile(node: SourceFile) {
17029-
const start = new Date().getTime();
17027+
const start = performance.mark();
1703017028

1703117029
checkSourceFileWorker(node);
1703217030

17033-
checkTime += new Date().getTime() - start;
17031+
performance.measure("Check", start);
1703417032
}
1703517033

1703617034
// Fully type check a source file and collect the relevant diagnostics.

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace ts {
2727
name: "diagnostics",
2828
type: "boolean",
2929
},
30+
{
31+
name: "extendedDiagnostics",
32+
type: "boolean",
33+
},
3034
{
3135
name: "emitBOM",
3236
type: "boolean"

src/compiler/core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/// <reference path="types.ts"/>
2+
/// <reference path="performance.ts" />
3+
24

35
/* @internal */
46
namespace ts {

src/compiler/emitter.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,14 +4571,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
45714571

45724572
function emitRestParameter(node: FunctionLikeDeclaration) {
45734573
if (languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node)) {
4574-
const restIndex = node.parameters.length - 1;
4575-
const restParam = node.parameters[restIndex];
4574+
const restParam = node.parameters[node.parameters.length - 1];
45764575

45774576
// A rest parameter cannot have a binding pattern, so let's just ignore it if it does.
45784577
if (isBindingPattern(restParam.name)) {
45794578
return;
45804579
}
45814580

4581+
const skipThisCount = node.parameters.length && (<Identifier>node.parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword ? 1 : 0;
4582+
const restIndex = node.parameters.length - 1 - skipThisCount;
45824583
const tempName = createTempVariable(TempFlags._i).text;
45834584
writeLine();
45844585
emitLeadingComments(restParam);
@@ -4726,7 +4727,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
47264727
write("(");
47274728
if (node) {
47284729
const parameters = node.parameters;
4729-
const skipCount = node.parameters.length && (<Identifier>node.parameters[0].name).text === "this" ? 1 : 0;
4730+
const skipCount = node.parameters.length && (<Identifier>node.parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword ? 1 : 0;
47304731
const omitCount = languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node) ? 1 : 0;
47314732
emitList(parameters, skipCount, parameters.length - omitCount - skipCount, /*multiLine*/ false, /*trailingComma*/ false);
47324733
}
@@ -6156,10 +6157,11 @@ const _super = (function (geti, seti) {
61566157

61576158
if (valueDeclaration) {
61586159
const parameters = valueDeclaration.parameters;
6160+
const skipThisCount = parameters.length && (<Identifier>parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword ? 1 : 0;
61596161
const parameterCount = parameters.length;
6160-
if (parameterCount > 0) {
6161-
for (let i = 0; i < parameterCount; i++) {
6162-
if (i > 0) {
6162+
if (parameterCount > skipThisCount) {
6163+
for (let i = skipThisCount; i < parameterCount; i++) {
6164+
if (i > skipThisCount) {
61636165
write(", ");
61646166
}
61656167

src/compiler/parser.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/// <reference path="scanner.ts"/>
33

44
namespace ts {
5-
/* @internal */ export let parseTime = 0;
6-
75
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
86
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
97
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
@@ -421,10 +419,10 @@ namespace ts {
421419
}
422420

423421
export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false, scriptKind?: ScriptKind): SourceFile {
424-
const start = new Date().getTime();
422+
const start = performance.mark();
425423
const result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind);
426424

427-
parseTime += new Date().getTime() - start;
425+
performance.measure("Parse", start);
428426
return result;
429427
}
430428

src/compiler/performance.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*@internal*/
2+
namespace ts {
3+
declare const performance: { now?(): number } | undefined;
4+
/** Gets a timestamp with (at least) ms resolution */
5+
export const timestamp = typeof performance !== "undefined" && performance.now ? performance.now : Date.now ? Date.now : () => +(new Date());
6+
}
7+
8+
/*@internal*/
9+
namespace ts.performance {
10+
/** Performance measurements for the compiler. */
11+
declare const onProfilerEvent: { (markName: string): void; profiler: boolean; };
12+
let profilerEvent: (markName: string) => void;
13+
let counters: Map<number>;
14+
let measures: Map<number>;
15+
16+
/**
17+
* Emit a performance event if ts-profiler is connected. This is primarily used
18+
* to generate heap snapshots.
19+
*
20+
* @param eventName A name for the event.
21+
*/
22+
export function emit(eventName: string) {
23+
if (profilerEvent) {
24+
profilerEvent(eventName);
25+
}
26+
}
27+
28+
/**
29+
* Increments a counter with the specified name.
30+
*
31+
* @param counterName The name of the counter.
32+
*/
33+
export function increment(counterName: string) {
34+
if (counters) {
35+
counters[counterName] = (getProperty(counters, counterName) || 0) + 1;
36+
}
37+
}
38+
39+
/**
40+
* Gets the value of the counter with the specified name.
41+
*
42+
* @param counterName The name of the counter.
43+
*/
44+
export function getCount(counterName: string) {
45+
return counters && getProperty(counters, counterName) || 0;
46+
}
47+
48+
/**
49+
* Marks the start of a performance measurement.
50+
*/
51+
export function mark() {
52+
return measures ? timestamp() : 0;
53+
}
54+
55+
/**
56+
* Adds a performance measurement with the specified name.
57+
*
58+
* @param measureName The name of the performance measurement.
59+
* @param marker The timestamp of the starting mark.
60+
*/
61+
export function measure(measureName: string, marker: number) {
62+
if (measures) {
63+
measures[measureName] = (getProperty(measures, measureName) || 0) + (timestamp() - marker);
64+
}
65+
}
66+
67+
/**
68+
* Iterate over each measure, performing some action
69+
*
70+
* @param cb The action to perform for each measure
71+
*/
72+
export function forEachMeasure(cb: (measureName: string, duration: number) => void) {
73+
return forEachKey(measures, key => cb(key, measures[key]));
74+
}
75+
76+
/**
77+
* Gets the total duration of all measurements with the supplied name.
78+
*
79+
* @param measureName The name of the measure whose durations should be accumulated.
80+
*/
81+
export function getDuration(measureName: string) {
82+
return measures && getProperty(measures, measureName) || 0;
83+
}
84+
85+
/** Enables (and resets) performance measurements for the compiler. */
86+
export function enable() {
87+
counters = { };
88+
measures = {
89+
"I/O Read": 0,
90+
"I/O Write": 0,
91+
"Program": 0,
92+
"Parse": 0,
93+
"Bind": 0,
94+
"Check": 0,
95+
"Emit": 0,
96+
};
97+
98+
profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true
99+
? onProfilerEvent
100+
: undefined;
101+
}
102+
103+
/** Disables (and clears) performance measurements for the compiler. */
104+
export function disable() {
105+
counters = undefined;
106+
measures = undefined;
107+
profilerEvent = undefined;
108+
}
109+
}

src/compiler/program.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
/// <reference path="core.ts" />
44

55
namespace ts {
6-
/* @internal */ export let programTime = 0;
7-
/* @internal */ export let emitTime = 0;
8-
/* @internal */ export let ioReadTime = 0;
9-
/* @internal */ export let ioWriteTime = 0;
10-
116
/** The version of the TypeScript compiler release */
127
export const version = "2.1.0";
138

@@ -865,9 +860,9 @@ namespace ts {
865860
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
866861
let text: string;
867862
try {
868-
const start = new Date().getTime();
863+
const start = performance.mark();
869864
text = sys.readFile(fileName, options.charset);
870-
ioReadTime += new Date().getTime() - start;
865+
performance.measure("I/O Read", start);
871866
}
872867
catch (e) {
873868
if (onError) {
@@ -934,7 +929,7 @@ namespace ts {
934929

935930
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
936931
try {
937-
const start = new Date().getTime();
932+
const start = performance.mark();
938933
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
939934

940935
if (isWatchSet(options) && sys.createHash && sys.getModifiedTime) {
@@ -944,7 +939,7 @@ namespace ts {
944939
sys.writeFile(fileName, data, writeByteOrderMark);
945940
}
946941

947-
ioWriteTime += new Date().getTime() - start;
942+
performance.measure("I/O Write", start);
948943
}
949944
catch (e) {
950945
if (onError) {
@@ -1121,7 +1116,7 @@ namespace ts {
11211116
// Track source files that are source files found by searching under node_modules, as these shouldn't be compiled.
11221117
const sourceFilesFoundSearchingNodeModules: Map<boolean> = {};
11231118

1124-
const start = new Date().getTime();
1119+
const start = performance.mark();
11251120

11261121
host = host || createCompilerHost(options);
11271122

@@ -1221,7 +1216,7 @@ namespace ts {
12211216

12221217
verifyCompilerOptions();
12231218

1224-
programTime += new Date().getTime() - start;
1219+
performance.measure("Program", start);
12251220

12261221
return program;
12271222

@@ -1468,14 +1463,14 @@ namespace ts {
14681463
// checked is to not pass the file to getEmitResolver.
14691464
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile);
14701465

1471-
const start = new Date().getTime();
1466+
const start = performance.mark();
14721467

14731468
const emitResult = emitFiles(
14741469
emitResolver,
14751470
getEmitHost(writeFileCallback),
14761471
sourceFile);
14771472

1478-
emitTime += new Date().getTime() - start;
1473+
performance.measure("Emit", start);
14791474
return emitResult;
14801475
}
14811476

src/compiler/sourcemap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ namespace ts {
240240
return;
241241
}
242242

243+
const start = performance.mark();
244+
243245
const sourceLinePos = getLineAndCharacterOfPosition(currentSourceFile, pos);
244246

245247
// Convert the location to be one-based.
@@ -279,6 +281,8 @@ namespace ts {
279281
}
280282

281283
updateLastEncodedAndRecordedSpans();
284+
285+
performance.measure("Source Map", start);
282286
}
283287

284288
function getStartPos(range: TextRange) {

0 commit comments

Comments
 (0)