Remove unnecessary externsScope field in GlobalNamespace
This is a very slight performance improvement (getRootNode() now only ever calls scope.getVar() once, but the cost of the extra calls was pretty low originally) and is generally less convoluted.
@@ -85,7 +85,6 @@ class GlobalNamespace
private final Node globalRoot = IR.root();
private final LinkedHashMap<Node, Boolean> spreadSiblingCache = new LinkedHashMap<>();
private SourceKind sourceKind;
- private Scope externsScope;
private boolean generated = false;
/**
@@ -207,9 +206,6 @@ class GlobalNamespace
private Node getRootNode(String name, Scope s) {
name = getTopVarName(name);
Var v = s.getVar(name);
- if (v == null && externsScope != null) {
- v = externsScope.getVar(name);
- }
if (v == null) {
Name providedName = nameMap.get(name);
return providedName != null && providedName.isProvided ? globalRoot : null;
@@ -346,15 +342,16 @@ class GlobalNamespace
/** Builds the namespace lazily. */
private void process() {
+ NodeTraversal.Builder traversal =
+ NodeTraversal.builder().setCompiler(compiler).setCallback(new BuildGlobalNamespace());
+
if (hasExternsRoot()) {
- sourceKind = SourceKind.EXTERN;
- NodeTraversal.traverse(compiler, externsRoot, new BuildGlobalNamespace());
+ traversal.traverseRoots(externsRoot, root);
+ } else {
+ traversal.traverse(root);
}
- sourceKind = SourceKind.CODE;
- NodeTraversal.traverse(compiler, root, new BuildGlobalNamespace());
generated = true;
- externsScope = null;
}
/**
@@ -426,16 +423,12 @@ class GlobalNamespace
if (n.isScript() && !shouldTraverseScript.test(n)) {
return false;
}
- if (hasExternsRoot()) {
- if (n == externsRoot) {
- // If we are traversing the externs, then we save a pointer to the scope
- // generated by them, so that we can do lookups in it later.
- externsScope = t.getScope();
- } else if (n.isScript()) {
+ if (hasExternsRoot() && n.isScript()) {
// When checking type-summary files, we want to consider them like normal code
// for some things (like alias inlining) but like externs for other things.
sourceKind = SourceKind.fromScriptNode(n);
- }
+ } else if (n == root) {
+ sourceKind = SourceKind.CODE;
}
if (n.isModuleBody() || NodeUtil.isBundledGoogModuleScopeRoot(n)) {
setupModuleMetadata(n);
