Skip to content

Commit

Permalink
Merge pull request #2783 from Microsoft/symbolWriter2
Browse files Browse the repository at this point in the history
Split symbol baselines from type baselines.
  • Loading branch information
CyrusNajmabadi committed Apr 16, 2015
2 parents 0b13ca4 + 87b06f4 commit 4dfc518
Show file tree
Hide file tree
Showing 4,935 changed files with 243,637 additions and 87,924 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
60 changes: 43 additions & 17 deletions src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,53 @@ class CompilerBaselineRunner extends RunnerBase {
// These types are equivalent, but depend on what order the compiler observed
// certain parts of the program.

var fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
var pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
let allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));

var fullTypes = generateTypes(fullWalker);
var pullTypes = generateTypes(pullWalker);
let fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
let pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);

if (fullTypes !== pullTypes) {
Harness.Baseline.runBaseline('Correct full expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
Harness.Baseline.runBaseline('Correct pull expression types for ' + fileName, justName.replace(/\.ts/, '.types.pull'), () => pullTypes);
let fullResults: ts.Map<TypeWriterResult[]> = {};
let pullResults: ts.Map<TypeWriterResult[]> = {};

for (let sourceFile of allFiles) {
fullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
pullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
}
else {
Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);

// Produce baselines. The first gives the types for all expressions.
// The second gives symbols for all identifiers.
checkBaseLines(/*isSymbolBaseLine:*/ false);
checkBaseLines(/*isSymbolBaseLine:*/ true);

function checkBaseLines(isSymbolBaseLine: boolean) {
let fullBaseLine = generateBaseLine(fullResults, isSymbolBaseLine);
let pullBaseLine = generateBaseLine(pullResults, isSymbolBaseLine);

let fullExtension = isSymbolBaseLine ? '.symbols' : '.types';
let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull';

if (fullBaseLine !== pullBaseLine) {
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.ts/, pullExtension), () => pullBaseLine);
}
else {
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
}
}

function generateTypes(walker: TypeWriterWalker): string {
var allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
var typeLines: string[] = [];
var typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
function generateBaseLine(typeWriterResults: ts.Map<TypeWriterResult[]>, isSymbolBaseline: boolean): string {
let typeLines: string[] = [];
let typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};

allFiles.forEach(file => {
var codeLines = file.content.split('\n');
walker.getTypes(file.unitName).forEach(result => {
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + result.type;
typeWriterResults[file.unitName].forEach(result => {
if (isSymbolBaseline && !result.symbol) {
return;
}

var typeOrSymbolString = isSymbolBaseline ? result.symbol : result.type;
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + typeOrSymbolString;
if (!typeMap[file.unitName]) {
typeMap[file.unitName] = {};
}
Expand All @@ -316,11 +340,13 @@ class CompilerBaselineRunner extends RunnerBase {
typeLines.push('>' + ty + '\r\n');
});
if (i + 1 < codeLines.length && (codeLines[i + 1].match(/^\s*[{|}]\s*$/) || codeLines[i + 1].trim() === '')) {
} else {
}
else {
typeLines.push('\r\n');
}
}
} else {
}
else {
typeLines.push('No type information for this code.');
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/harness/typeWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface TypeWriterResult {
syntaxKind: number;
sourceText: string;
type: string;
symbol: string;
}

class TypeWriterWalker {
Expand All @@ -19,7 +20,7 @@ class TypeWriterWalker {
: program.getTypeChecker();
}

public getTypes(fileName: string): TypeWriterResult[] {
public getTypeAndSymbols(fileName: string): TypeWriterResult[] {
var sourceFile = this.program.getSourceFile(fileName);
this.currentSourceFile = sourceFile;
this.results = [];
Expand All @@ -45,8 +46,9 @@ class TypeWriterWalker {
var symbol = this.checker.getSymbolAtLocation(node);

var typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation);
var symbolString: string;
if (symbol) {
var symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
if (symbol.declarations) {
for (let declaration of symbol.declarations) {
symbolString += ", ";
Expand All @@ -56,15 +58,14 @@ class TypeWriterWalker {
}
}
symbolString += ")";

typeString += ", " + symbolString;
}

this.results.push({
line: lineAndCharacter.line,
syntaxKind: node.kind,
sourceText: sourceText,
type: typeString
type: typeString,
symbol: symbolString
});
}
}
38 changes: 38 additions & 0 deletions tests/baselines/reference/2dArrays.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=== tests/cases/compiler/2dArrays.ts ===
class Cell {
>Cell : Symbol(Cell, Decl(2dArrays.ts, 0, 0))
}

class Ship {
>Ship : Symbol(Ship, Decl(2dArrays.ts, 1, 1))

isSunk: boolean;
>isSunk : Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
}

class Board {
>Board : Symbol(Board, Decl(2dArrays.ts, 5, 1))

ships: Ship[];
>ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
>Ship : Symbol(Ship, Decl(2dArrays.ts, 1, 1))

cells: Cell[];
>cells : Symbol(cells, Decl(2dArrays.ts, 8, 18))
>Cell : Symbol(Cell, Decl(2dArrays.ts, 0, 0))

private allShipsSunk() {
>allShipsSunk : Symbol(allShipsSunk, Decl(2dArrays.ts, 9, 18))

return this.ships.every(function (val) { return val.isSunk; });
>this.ships.every : Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
>this.ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
>this : Symbol(Board, Decl(2dArrays.ts, 5, 1))
>ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
>every : Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
>val.isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
>isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
}
}
36 changes: 18 additions & 18 deletions tests/baselines/reference/2dArrays.types
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
=== tests/cases/compiler/2dArrays.ts ===
class Cell {
>Cell : Cell, Symbol(Cell, Decl(2dArrays.ts, 0, 0))
>Cell : Cell
}

class Ship {
>Ship : Ship, Symbol(Ship, Decl(2dArrays.ts, 1, 1))
>Ship : Ship

isSunk: boolean;
>isSunk : boolean, Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
>isSunk : boolean
}

class Board {
>Board : Board, Symbol(Board, Decl(2dArrays.ts, 5, 1))
>Board : Board

ships: Ship[];
>ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
>Ship : Ship, Symbol(Ship, Decl(2dArrays.ts, 1, 1))
>ships : Ship[]
>Ship : Ship

cells: Cell[];
>cells : Cell[], Symbol(cells, Decl(2dArrays.ts, 8, 18))
>Cell : Cell, Symbol(Cell, Decl(2dArrays.ts, 0, 0))
>cells : Cell[]
>Cell : Cell

private allShipsSunk() {
>allShipsSunk : () => boolean, Symbol(allShipsSunk, Decl(2dArrays.ts, 9, 18))
>allShipsSunk : () => boolean

return this.ships.every(function (val) { return val.isSunk; });
>this.ships.every(function (val) { return val.isSunk; }) : boolean
>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean, Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
>this.ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
>this : Board, Symbol(Board, Decl(2dArrays.ts, 5, 1))
>ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean, Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean
>this.ships : Ship[]
>this : Board
>ships : Ship[]
>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean
>function (val) { return val.isSunk; } : (val: Ship) => boolean
>val : Ship, Symbol(val, Decl(2dArrays.ts, 12, 42))
>val.isSunk : boolean, Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
>val : Ship, Symbol(val, Decl(2dArrays.ts, 12, 42))
>isSunk : boolean, Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
>val : Ship
>val.isSunk : boolean
>val : Ship
>isSunk : boolean
}
}
131 changes: 131 additions & 0 deletions tests/baselines/reference/APISample_compile.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
=== tests/cases/compiler/APISample_compile.ts ===

/*
* Note: This test is a public API sample. The sample sources can be found
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler
* Please log a "breaking change" issue for any API breaking change affecting this issue
*/

declare var process: any;
>process : Symbol(process, Decl(APISample_compile.ts, 7, 11))

declare var console: any;
>console : Symbol(console, Decl(APISample_compile.ts, 8, 11))

declare var os: any;
>os : Symbol(os, Decl(APISample_compile.ts, 9, 11))

import ts = require("typescript");
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))

export function compile(fileNames: string[], options: ts.CompilerOptions): void {
>compile : Symbol(compile, Decl(APISample_compile.ts, 11, 34))
>fileNames : Symbol(fileNames, Decl(APISample_compile.ts, 13, 24))
>options : Symbol(options, Decl(APISample_compile.ts, 13, 44))
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
>CompilerOptions : Symbol(ts.CompilerOptions, Decl(typescript.d.ts, 1074, 5))

var program = ts.createProgram(fileNames, options);
>program : Symbol(program, Decl(APISample_compile.ts, 14, 7))
>ts.createProgram : Symbol(ts.createProgram, Decl(typescript.d.ts, 1225, 113))
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
>createProgram : Symbol(ts.createProgram, Decl(typescript.d.ts, 1225, 113))
>fileNames : Symbol(fileNames, Decl(APISample_compile.ts, 13, 24))
>options : Symbol(options, Decl(APISample_compile.ts, 13, 44))

var emitResult = program.emit();
>emitResult : Symbol(emitResult, Decl(APISample_compile.ts, 15, 7))
>program.emit : Symbol(ts.Program.emit, Decl(typescript.d.ts, 767, 39))
>program : Symbol(program, Decl(APISample_compile.ts, 14, 7))
>emit : Symbol(ts.Program.emit, Decl(typescript.d.ts, 767, 39))

var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
>allDiagnostics : Symbol(allDiagnostics, Decl(APISample_compile.ts, 17, 7))
>ts.getPreEmitDiagnostics(program).concat : Symbol(Array.concat, Decl(lib.d.ts, 1025, 13), Decl(lib.d.ts, 1030, 46))
>ts.getPreEmitDiagnostics : Symbol(ts.getPreEmitDiagnostics, Decl(typescript.d.ts, 1223, 98))
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
>getPreEmitDiagnostics : Symbol(ts.getPreEmitDiagnostics, Decl(typescript.d.ts, 1223, 98))
>program : Symbol(program, Decl(APISample_compile.ts, 14, 7))
>concat : Symbol(Array.concat, Decl(lib.d.ts, 1025, 13), Decl(lib.d.ts, 1030, 46))
>emitResult.diagnostics : Symbol(ts.EmitResult.diagnostics, Decl(typescript.d.ts, 820, 29))
>emitResult : Symbol(emitResult, Decl(APISample_compile.ts, 15, 7))
>diagnostics : Symbol(ts.EmitResult.diagnostics, Decl(typescript.d.ts, 820, 29))

allDiagnostics.forEach(diagnostic => {
>allDiagnostics.forEach : Symbol(Array.forEach, Decl(lib.d.ts, 1108, 95))
>allDiagnostics : Symbol(allDiagnostics, Decl(APISample_compile.ts, 17, 7))
>forEach : Symbol(Array.forEach, Decl(lib.d.ts, 1108, 95))
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))

var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
>line : Symbol(line, Decl(APISample_compile.ts, 20, 13))
>character : Symbol(character, Decl(APISample_compile.ts, 20, 19))
>diagnostic.file.getLineAndCharacterOfPosition : Symbol(ts.SourceFile.getLineAndCharacterOfPosition, Decl(typescript.d.ts, 1286, 26))
>diagnostic.file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
>file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
>getLineAndCharacterOfPosition : Symbol(ts.SourceFile.getLineAndCharacterOfPosition, Decl(typescript.d.ts, 1286, 26))
>diagnostic.start : Symbol(ts.Diagnostic.start, Decl(typescript.d.ts, 1063, 25))
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
>start : Symbol(ts.Diagnostic.start, Decl(typescript.d.ts, 1063, 25))

var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
>message : Symbol(message, Decl(APISample_compile.ts, 21, 11))
>ts.flattenDiagnosticMessageText : Symbol(ts.flattenDiagnosticMessageText, Decl(typescript.d.ts, 1224, 67))
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
>flattenDiagnosticMessageText : Symbol(ts.flattenDiagnosticMessageText, Decl(typescript.d.ts, 1224, 67))
>diagnostic.messageText : Symbol(ts.Diagnostic.messageText, Decl(typescript.d.ts, 1065, 23))
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
>messageText : Symbol(ts.Diagnostic.messageText, Decl(typescript.d.ts, 1065, 23))

console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
>console : Symbol(console, Decl(APISample_compile.ts, 8, 11))
>diagnostic.file.fileName : Symbol(ts.SourceFile.fileName, Decl(typescript.d.ts, 743, 29))
>diagnostic.file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
>file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
>fileName : Symbol(ts.SourceFile.fileName, Decl(typescript.d.ts, 743, 29))
>line : Symbol(line, Decl(APISample_compile.ts, 20, 13))
>character : Symbol(character, Decl(APISample_compile.ts, 20, 19))
>message : Symbol(message, Decl(APISample_compile.ts, 21, 11))

});

var exitCode = emitResult.emitSkipped ? 1 : 0;
>exitCode : Symbol(exitCode, Decl(APISample_compile.ts, 25, 7))
>emitResult.emitSkipped : Symbol(ts.EmitResult.emitSkipped, Decl(typescript.d.ts, 819, 26))
>emitResult : Symbol(emitResult, Decl(APISample_compile.ts, 15, 7))
>emitSkipped : Symbol(ts.EmitResult.emitSkipped, Decl(typescript.d.ts, 819, 26))

console.log(`Process exiting with code '${exitCode}'.`);
>console : Symbol(console, Decl(APISample_compile.ts, 8, 11))
>exitCode : Symbol(exitCode, Decl(APISample_compile.ts, 25, 7))

process.exit(exitCode);
>process : Symbol(process, Decl(APISample_compile.ts, 7, 11))
>exitCode : Symbol(exitCode, Decl(APISample_compile.ts, 25, 7))
}

compile(process.argv.slice(2), {
>compile : Symbol(compile, Decl(APISample_compile.ts, 11, 34))
>process : Symbol(process, Decl(APISample_compile.ts, 7, 11))

noEmitOnError: true, noImplicitAny: true,
>noEmitOnError : Symbol(noEmitOnError, Decl(APISample_compile.ts, 30, 32))
>noImplicitAny : Symbol(noImplicitAny, Decl(APISample_compile.ts, 31, 24))

target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
>target : Symbol(target, Decl(APISample_compile.ts, 31, 45))
>ts.ScriptTarget.ES5 : Symbol(ts.ScriptTarget.ES5, Decl(typescript.d.ts, 1117, 16))
>ts.ScriptTarget : Symbol(ts.ScriptTarget, Decl(typescript.d.ts, 1115, 5))
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
>ScriptTarget : Symbol(ts.ScriptTarget, Decl(typescript.d.ts, 1115, 5))
>ES5 : Symbol(ts.ScriptTarget.ES5, Decl(typescript.d.ts, 1117, 16))
>module : Symbol(module, Decl(APISample_compile.ts, 32, 32))
>ts.ModuleKind.CommonJS : Symbol(ts.ModuleKind.CommonJS, Decl(typescript.d.ts, 1108, 17))
>ts.ModuleKind : Symbol(ts.ModuleKind, Decl(typescript.d.ts, 1106, 5))
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
>ModuleKind : Symbol(ts.ModuleKind, Decl(typescript.d.ts, 1106, 5))
>CommonJS : Symbol(ts.ModuleKind.CommonJS, Decl(typescript.d.ts, 1108, 17))

});
Loading

0 comments on commit 4dfc518

Please sign in to comment.