From 6ff58e302875e1b25d1245209ce70a5b5d388ec8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 Dec 2014 12:41:59 -0800 Subject: [PATCH] Don't emit error flags in the 262 baselines unless the node actually had an error. This helps reduce clutter. --- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 14 +++++++++++--- src/compiler/utilities.ts | 10 +++++----- src/harness/test262Runner.ts | 11 +++++++++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e75b195d776..c7d05fc41c5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -856,7 +856,7 @@ module ts { // flag so that we don't mark any subsequent nodes. if (parseErrorBeforeNextFinishedNode) { parseErrorBeforeNextFinishedNode = false; - node.parserContextFlags |= ParserContextFlags.ContainsError; + node.parserContextFlags |= ParserContextFlags.ThisNodeHasError; } return node; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a77961da586..2c5376e744f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -317,14 +317,22 @@ module ts { // If the parser encountered an error when parsing the code that created this node. Note // the parser only sets this directly on the node it creates right after encountering the - // error. We then propagate that flag upwards to parent nodes during incremental parsing. - ContainsError = 1 << 4, + // error. + ThisNodeHasError = 1 << 4, + + // Context flags set directly by the parser. + ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | ThisNodeHasError, + + // Context flags computed by aggregating child flags upwards. + + // If this node, or any of it's children (transitively) contain an error. + ThisNodeOrAnySubNodesHasError = 1 << 5, // Used during incremental parsing to determine if we need to visit this node to see if // any of its children had an error. Once we compute that once, we can set this bit on the // node to know that we never have to do it again. From that point on, we can just check // the node directly for 'ContainsError'. - HasPropagatedChildContainsErrorFlag = 1 << 5 + HasComputedThisNodeOrAnySubNodesHasError = 1 << 6 } export interface Node extends TextRange { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 35e61a3a48e..d35364009b6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -68,25 +68,25 @@ module ts { // Returns true if this node contains a parse error anywhere underneath it. export function containsParseError(node: Node): boolean { - if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasPropagatedChildContainsErrorFlag)) { + if (!hasFlag(node.parserContextFlags, ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError)) { // A node is considered to contain a parse error if: // a) the parser explicitly marked that it had an error // b) any of it's children reported that it had an error. - var val = hasFlag(node.parserContextFlags, ParserContextFlags.ContainsError) || + var val = hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeHasError) || forEachChild(node, containsParseError); // If so, mark ourselves accordingly. if (val) { - node.parserContextFlags |= ParserContextFlags.ContainsError; + node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError; } // Also mark that we've propogated the child information to this node. This way we can // always consult the bit directly on this node without needing to check its children // again. - node.parserContextFlags |= ParserContextFlags.HasPropagatedChildContainsErrorFlag; + node.parserContextFlags |= ParserContextFlags.HasComputedThisNodeOrAnySubNodesHasError; } - return hasFlag(node.parserContextFlags, ParserContextFlags.ContainsError); + return hasFlag(node.parserContextFlags, ParserContextFlags.ThisNodeOrAnySubNodesHasError); } export function getSourceFileOfNode(node: Node): SourceFile { diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 8c39880a81c..2b5c2353095 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -51,7 +51,12 @@ class Test262BaselineRunner extends RunnerBase { } function getNodeFlagName(f: number) { return getFlagName((ts).NodeFlags, f); } - function getParserContextFlagName(f: number) { return getFlagName((ts).ParserContextFlags, f); } + function getParserContextFlagName(f: number) { + // Clear the flag that are produced by aggregating child values.. That is ephemeral + // data we don't care about in the dump. We only care what the parser set directly + // on the ast. + return getFlagName((ts).ParserContextFlags, f & ts.ParserContextFlags.ParserGeneratedFlags); + } function convertDiagnostics(diagnostics: ts.Diagnostic[]) { return diagnostics.map(convertDiagnostic); } @@ -68,7 +73,9 @@ class Test262BaselineRunner extends RunnerBase { function serializeNode(n: ts.Node): any { var o: any = { kind: getKindName(n.kind) }; - o.containsParseError = ts.containsParseError(n); + if (ts.containsParseError(n)) { + o.containsParseError = true; + } ts.forEach(Object.getOwnPropertyNames(n), propertyName => { switch (propertyName) {