use of com.google.javascript.rhino.jstype.JSTypeNative.UNKNOWN_TYPE in project closure-compiler by google.
the class TypeInferencePass method inferAllScopes.
/**
* Execute type inference running over part of the scope tree.
*
* @return the top scope, either newly created, or patched by this inference.
*/
TypedScope inferAllScopes(Node inferenceRoot) {
// order to propagate the type of ns.method in the outer scope.
try (JSTypeResolver.Closer closer = this.registry.getResolver().openForDefinition()) {
checkState(inferenceRoot.isRoot());
checkState(inferenceRoot.getParent() == null);
checkState(this.topScope == null);
this.topScope = scopeCreator.createScope(inferenceRoot, null);
NodeTraversal.builder().setCompiler(compiler).setCallback(new FirstScopeBuildingCallback()).setScopeCreator(scopeCreator).traverseWithScope(inferenceRoot, this.topScope);
scopeCreator.resolveWeakImportsPreResolution();
}
scopeCreator.finishAndFreeze();
NodeTraversal.builder().setCompiler(compiler).setCallback(new SecondScopeBuildingCallback()).setScopeCreator(scopeCreator).traverseWithScope(inferenceRoot, this.topScope);
// Normalize TypedVars to have the '?' type instead of null after inference is complete. This
// currently cannot be done any earlier because it breaks inference of variables assigned in
// local scopes.
// TODO(b/149843534): this should be a crash instead.
final JSType unknownType = this.registry.getNativeType(UNKNOWN_TYPE);
for (TypedVar var : this.scopeCreator.getAllSymbols()) {
if (var.getType() == null) {
var.setType(unknownType);
}
}
if (this.stepCountHistogram != null) {
try (LogFile histogram = this.compiler.createOrReopenLog(this.getClass(), "step_histogram.log")) {
histogram.log("step_count token population");
int[] totals = new int[] { 0, 0 };
this.stepCountHistogram.keySet().stream().sorted(Comparator.<Integer>naturalOrder().reversed()).forEach((stepCount) -> this.stepCountHistogram.get(stepCount).entrySet().stream().sorted(comparingInt(Multiset.Entry::getCount)).forEach((e) -> {
totals[0] += stepCount * e.getCount();
totals[1] += e.getCount();
histogram.log("%s %s %s", stepCount, e.getElement(), e.getCount());
}));
histogram.log("%s TOTAL %s", totals[0], totals[1]);
}
}
return this.topScope;
}
Aggregations