class PureFunctionIdentifier extends java.lang.Object implements CompilerPass
Modifier and Type | Class and Description |
---|---|
(package private) static class |
PureFunctionIdentifier.Driver
A compiler pass that constructs a reference graph and drives
the PureFunctionIdentifier across it.
|
private class |
PureFunctionIdentifier.FunctionAnalyzer
Gather list of functions, functions with @nosideeffects
annotations, call sites, and functions that may mutate variables
not defined in the local scope.
|
private static class |
PureFunctionIdentifier.FunctionInformation
Keeps track of a function's known side effects by type and the
list of calls that appear in a function's body.
|
private static class |
PureFunctionIdentifier.SideEffectPropagationCallback
Callback that propagates side effect information across call sites.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<Node> |
allFunctionCalls |
private AbstractCompiler |
compiler |
private DefinitionProvider |
definitionProvider |
private Node |
externs |
private java.util.Map<Node,PureFunctionIdentifier.FunctionInformation> |
functionSideEffectMap |
(package private) static DiagnosticType |
INVALID_MODIFIES_ANNOTATION |
(package private) static DiagnosticType |
INVALID_NO_SIDE_EFFECT_ANNOTATION |
private Node |
root |
Constructor and Description |
---|
PureFunctionIdentifier(AbstractCompiler compiler,
DefinitionProvider definitionProvider) |
Modifier and Type | Method and Description |
---|---|
private static java.util.Collection<DefinitionsRemover.Definition> |
getCallableDefinitions(DefinitionProvider definitionProvider,
Node name)
Query the DefinitionProvider for the list of definitions that
correspond to a given qualified name subtree.
|
(package private) java.lang.String |
getDebugReport()
Compute debug report that includes:
- List of all pure functions.
|
private java.util.Collection<DefinitionsRemover.Definition> |
getGoogCacheCallableDefinitions(DefinitionProvider definitionProvider,
CodingConvention.Cache cacheCall) |
private static boolean |
isCallOrApply(Node callSite) |
private static boolean |
isIncDec(Node n) |
private static boolean |
isKnownLocalValue(Node value) |
private void |
markPureFunctionCalls()
Set no side effect property at pure-function call sites.
|
void |
process(Node externsAst,
Node srcAst)
Process the JS with root node root.
|
private void |
propagateSideEffects()
Propagate side effect information by building a graph based on
call site information stored in FunctionInformation and the
DefinitionProvider and then running GraphReachability to
determine the set of functions that have side effects.
|
static final DiagnosticType INVALID_NO_SIDE_EFFECT_ANNOTATION
static final DiagnosticType INVALID_MODIFIES_ANNOTATION
private final AbstractCompiler compiler
private final DefinitionProvider definitionProvider
private final java.util.Map<Node,PureFunctionIdentifier.FunctionInformation> functionSideEffectMap
private final java.util.List<Node> allFunctionCalls
private Node externs
private Node root
public PureFunctionIdentifier(AbstractCompiler compiler, DefinitionProvider definitionProvider)
public void process(Node externsAst, Node srcAst)
CompilerPass
process
in interface CompilerPass
externsAst
- Top of external JS treesrcAst
- Top of JS treejava.lang.String getDebugReport()
private static java.util.Collection<DefinitionsRemover.Definition> getCallableDefinitions(DefinitionProvider definitionProvider, Node name)
definitionProvider
- The name reference graphname
- Query nodeprivate void propagateSideEffects()
private void markPureFunctionCalls()
private java.util.Collection<DefinitionsRemover.Definition> getGoogCacheCallableDefinitions(DefinitionProvider definitionProvider, CodingConvention.Cache cacheCall)
private static boolean isIncDec(Node n)
private static boolean isKnownLocalValue(Node value)
private static boolean isCallOrApply(Node callSite)