Ignore:
Timestamp:
Mar 9, 2012, 4:06:48 AM (13 years ago)
Author:
[email protected]
Message:

Refactor code feature analysis in the parser
https://bugs.webkit.org/show_bug.cgi?id=79112

Reviewed by Geoffrey Garen.

This commit refactors the parser to more uniformly propagate flag
bits down and up the parse process, as the parser descends and
returns into nested blocks. Some flags get passed town to
subscopes, some apply to specific scopes only, and some get
unioned up after parsing subscopes.

The goal is to eventually be very precise with scoping
information, once we have block scopes: one block scope might use
`eval', which would require the emission of a symbol table within
that block and containing blocks, whereas another block in the
same function might not, allowing us to not emit a symbol table.

  • parser/Nodes.h:

(JSC::ScopeFlags): Rename from CodeFeatures.
(JSC::ScopeNode::addScopeFlags):
(JSC::ScopeNode::scopeFlags): New accessors for m_scopeFlags.
(JSC::ScopeNode::isStrictMode):
(JSC::ScopeNode::usesEval):
(JSC::ScopeNode::usesArguments):
(JSC::ScopeNode::setUsesArguments):
(JSC::ScopeNode::usesThis):
(JSC::ScopeNode::needsActivationForMoreThanVariables):
(JSC::ScopeNode::needsActivation): Refactor these accessors to
operate on the m_scopeFlags member.
(JSC::ScopeNode::source):
(JSC::ScopeNode::sourceURL):
(JSC::ScopeNode::sourceID): Shuffle these definitions around; no
semantic change.
(JSC::ScopeNode::ScopeNode)
(JSC::ProgramNode::ProgramNode)
(JSC::EvalNode::EvalNode)
(JSC::FunctionBodyNode::FunctionBodyNode): Have these constructors
take a ScopeFlags as an argument, instead of a bool inStrictContext.

  • parser/Nodes.cpp:

(JSC::ScopeNode::ScopeNode):
(JSC::ProgramNode::ProgramNode):
(JSC::ProgramNode::create):
(JSC::EvalNode::EvalNode):
(JSC::EvalNode::create):
(JSC::FunctionBodyNode::FunctionBodyNode):
(JSC::FunctionBodyNode::create): Adapt constructors to change.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::ASTBuilder):
(JSC::ASTBuilder::thisExpr):
(JSC::ASTBuilder::createResolve):
(JSC::ASTBuilder::createFunctionBody):
(JSC::ASTBuilder::createFuncDeclStatement):
(JSC::ASTBuilder::createTryStatement):
(JSC::ASTBuilder::createWithStatement):
(JSC::ASTBuilder::addVar):
(JSC::ASTBuilder::Scope::Scope):
(Scope):
(ASTBuilder):
(JSC::ASTBuilder::makeFunctionCallNode): Don't track scope
features here. Instead rely on the base Parser mechanism to track
features.

  • parser/NodeInfo.h (NodeInfo, NodeDeclarationInfo): "ScopeFlags".
  • parser/Parser.h:

(JSC::Scope::Scope): Manage scope through flags, not
bit-booleans. This lets us uniformly propagate them up and down.
(JSC::Scope::declareWrite):
(JSC::Scope::declareParameter):
(JSC::Scope::useVariable):
(JSC::Scope::collectFreeVariables):
(JSC::Scope::getCapturedVariables):
(JSC::Scope::saveFunctionInfo):
(JSC::Scope::restoreFunctionInfo):
(JSC::Parser::pushScope): Adapt to use scope flags and their
accessors instead of bit-booleans.

  • parser/Parser.cpp:

(JSC::::Parser):
(JSC::::parseInner):
(JSC::::didFinishParsing):
(JSC::::parseSourceElements):
(JSC::::parseVarDeclarationList):
(JSC::::parseConstDeclarationList):
(JSC::::parseWithStatement):
(JSC::::parseTryStatement):
(JSC::::parseFunctionBody):
(JSC::::parseFunctionInfo):
(JSC::::parseFunctionDeclaration):
(JSC::::parsePrimaryExpression): Hoist some of the flag handling
out of the "context" (ASTBuilder or SyntaxChecker) and to here.
Does not seem to have a performance impact.

  • parser/SourceProviderCacheItem.h (SourceProviderCacheItem):

Cache the scopeflags.

  • parser/SyntaxChecker.h: Remove evalCount() decl.
  • runtime/Executable.cpp:

(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::produceCodeBlockFor):

  • runtime/Executable.h:

(JSC::ScriptExecutable::ScriptExecutable):
(JSC::ScriptExecutable::usesEval):
(JSC::ScriptExecutable::usesArguments):
(JSC::ScriptExecutable::needsActivation):
(JSC::ScriptExecutable::isStrictMode):
(JSC::ScriptExecutable::recordParse):
(ScriptExecutable): ScopeFlags, not features.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r110268 r110287  
     12012-03-09  Andy Wingo  <[email protected]>
     2
     3        Refactor code feature analysis in the parser
     4        https://bugs.webkit.org/show_bug.cgi?id=79112
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        This commit refactors the parser to more uniformly propagate flag
     9        bits down and up the parse process, as the parser descends and
     10        returns into nested blocks.  Some flags get passed town to
     11        subscopes, some apply to specific scopes only, and some get
     12        unioned up after parsing subscopes.
     13
     14        The goal is to eventually be very precise with scoping
     15        information, once we have block scopes: one block scope might use
     16        `eval', which would require the emission of a symbol table within
     17        that block and containing blocks, whereas another block in the
     18        same function might not, allowing us to not emit a symbol table.
     19
     20        * parser/Nodes.h:
     21        (JSC::ScopeFlags): Rename from CodeFeatures.
     22        (JSC::ScopeNode::addScopeFlags):
     23        (JSC::ScopeNode::scopeFlags): New accessors for m_scopeFlags.
     24        (JSC::ScopeNode::isStrictMode):
     25        (JSC::ScopeNode::usesEval):
     26        (JSC::ScopeNode::usesArguments):
     27        (JSC::ScopeNode::setUsesArguments):
     28        (JSC::ScopeNode::usesThis):
     29        (JSC::ScopeNode::needsActivationForMoreThanVariables):
     30        (JSC::ScopeNode::needsActivation): Refactor these accessors to
     31        operate on the m_scopeFlags member.
     32        (JSC::ScopeNode::source):
     33        (JSC::ScopeNode::sourceURL):
     34        (JSC::ScopeNode::sourceID): Shuffle these definitions around; no
     35        semantic change.
     36        (JSC::ScopeNode::ScopeNode)
     37        (JSC::ProgramNode::ProgramNode)
     38        (JSC::EvalNode::EvalNode)
     39        (JSC::FunctionBodyNode::FunctionBodyNode): Have these constructors
     40        take a ScopeFlags as an argument, instead of a bool inStrictContext.
     41
     42        * parser/Nodes.cpp:
     43        (JSC::ScopeNode::ScopeNode):
     44        (JSC::ProgramNode::ProgramNode):
     45        (JSC::ProgramNode::create):
     46        (JSC::EvalNode::EvalNode):
     47        (JSC::EvalNode::create):
     48        (JSC::FunctionBodyNode::FunctionBodyNode):
     49        (JSC::FunctionBodyNode::create): Adapt constructors to change.
     50
     51        * parser/ASTBuilder.h:
     52        (JSC::ASTBuilder::ASTBuilder):
     53        (JSC::ASTBuilder::thisExpr):
     54        (JSC::ASTBuilder::createResolve):
     55        (JSC::ASTBuilder::createFunctionBody):
     56        (JSC::ASTBuilder::createFuncDeclStatement):
     57        (JSC::ASTBuilder::createTryStatement):
     58        (JSC::ASTBuilder::createWithStatement):
     59        (JSC::ASTBuilder::addVar):
     60        (JSC::ASTBuilder::Scope::Scope):
     61        (Scope):
     62        (ASTBuilder):
     63        (JSC::ASTBuilder::makeFunctionCallNode): Don't track scope
     64        features here.  Instead rely on the base Parser mechanism to track
     65        features.
     66
     67        * parser/NodeInfo.h (NodeInfo, NodeDeclarationInfo): "ScopeFlags".
     68
     69        * parser/Parser.h:
     70        (JSC::Scope::Scope): Manage scope through flags, not
     71        bit-booleans.  This lets us uniformly propagate them up and down.
     72        (JSC::Scope::declareWrite):
     73        (JSC::Scope::declareParameter):
     74        (JSC::Scope::useVariable):
     75        (JSC::Scope::collectFreeVariables):
     76        (JSC::Scope::getCapturedVariables):
     77        (JSC::Scope::saveFunctionInfo):
     78        (JSC::Scope::restoreFunctionInfo):
     79        (JSC::Parser::pushScope): Adapt to use scope flags and their
     80        accessors instead of bit-booleans.
     81        * parser/Parser.cpp:
     82        (JSC::::Parser):
     83        (JSC::::parseInner):
     84        (JSC::::didFinishParsing):
     85        (JSC::::parseSourceElements):
     86        (JSC::::parseVarDeclarationList):
     87        (JSC::::parseConstDeclarationList):
     88        (JSC::::parseWithStatement):
     89        (JSC::::parseTryStatement):
     90        (JSC::::parseFunctionBody):
     91        (JSC::::parseFunctionInfo):
     92        (JSC::::parseFunctionDeclaration):
     93        (JSC::::parsePrimaryExpression): Hoist some of the flag handling
     94        out of the "context" (ASTBuilder or SyntaxChecker) and to here.
     95        Does not seem to have a performance impact.
     96
     97        * parser/SourceProviderCacheItem.h (SourceProviderCacheItem):
     98        Cache the scopeflags.
     99        * parser/SyntaxChecker.h: Remove evalCount() decl.
     100
     101        * runtime/Executable.cpp:
     102        (JSC::EvalExecutable::compileInternal):
     103        (JSC::ProgramExecutable::compileInternal):
     104        (JSC::FunctionExecutable::produceCodeBlockFor):
     105        * runtime/Executable.h:
     106        (JSC::ScriptExecutable::ScriptExecutable):
     107        (JSC::ScriptExecutable::usesEval):
     108        (JSC::ScriptExecutable::usesArguments):
     109        (JSC::ScriptExecutable::needsActivation):
     110        (JSC::ScriptExecutable::isStrictMode):
     111        (JSC::ScriptExecutable::recordParse):
     112        (ScriptExecutable): ScopeFlags, not features.
     113
    11142012-03-08  Benjamin Poulain  <[email protected]>
    2115
Note: See TracChangeset for help on using the changeset viewer.