Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2194)

Unified Diff: pkg/compiler/lib/src/dump_info.dart

Issue 1301903002: Record information about constants in dump info (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart » ('j') | pkg/compiler/pubspec.yaml » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/dump_info.dart
diff --git a/pkg/compiler/lib/src/dump_info.dart b/pkg/compiler/lib/src/dump_info.dart
index 2f4a30403d4fee783628d060ce313cc1043fb2ed..307043a702df26464864e794de6421265348b8ba 100644
--- a/pkg/compiler/lib/src/dump_info.dart
+++ b/pkg/compiler/lib/src/dump_info.dart
@@ -11,6 +11,7 @@ import 'package:dart2js_info/info.dart';
import 'common/tasks.dart' show
CompilerTask;
+import 'constants/values.dart' show ConstantValue;
import 'compiler.dart' show
Compiler;
import 'diagnostics/messages.dart' show
@@ -37,11 +38,23 @@ class ElementInfoCollector extends BaseElementVisitor<Info, dynamic> {
final AllInfo result = new AllInfo();
final Map<Element, Info> _elementToInfo = <Element, Info>{};
+ final Map<ConstantValue, Info> _constantToInfo = <ConstantValue, Info>{};
final Map<OutputUnit, OutputUnitInfo> _outputToInfo = {};
ElementInfoCollector(this.compiler);
- void run() => compiler.libraryLoader.libraries.forEach(visit);
+ void run() {
+ compiler.dumpInfoTask._constantToNode.forEach((constant, node) {
+ // TODO(sigmund): add dependencies on other constants
+ var size = compiler.dumpInfoTask._nodeToSize[node];
+ var code = jsAst.prettyPrint(node, compiler).getText();
+ var info = new ConstantInfo(size: size, code: code);
+ _constantToInfo[constant] = info;
+ result.constants.add(info);
+
+ });
+ compiler.libraryLoader.libraries.forEach(visit);
+ }
Info visit(Element e, [_]) => e.accept(this, null);
@@ -115,17 +128,11 @@ class ElementInfoCollector extends BaseElementVisitor<Info, dynamic> {
TypeMask inferredType =
compiler.typesTask.getGuaranteedTypeOfElement(element);
// If a field has an empty inferred type it is never used.
- if (inferredType == null || inferredType.isEmpty || element.isConst) {
- return null;
- }
+ if (inferredType == null || inferredType.isEmpty) return null;
int size = compiler.dumpInfoTask.sizeOf(element);
- String code;
- StringBuffer emittedCode = compiler.dumpInfoTask.codeOf(element);
- if (emittedCode != null) {
- size += emittedCode.length;
- code = emittedCode.toString();
- }
+ String code = compiler.dumpInfoTask.codeOf(element);
+ if (code != null) size += code.length;
Siggi Cherem (dart-lang) 2015/08/19 04:21:08 FYI - these lines related to `codeOf` were just cl
FieldInfo info = new FieldInfo(
name: element.name,
@@ -136,8 +143,16 @@ class ElementInfoCollector extends BaseElementVisitor<Info, dynamic> {
inferredType: '$inferredType',
size: size,
code: code,
- outputUnit: _unitInfoForElement(element));
+ outputUnit: _unitInfoForElement(element),
+ isConst: element.isConst);
_elementToInfo[element] = info;
+ if (element.isConst) {
+ var value = compiler.backend.constantCompilerTask
+ .getConstantValueForVariable(element);
+ if (value != null) {
+ info.initializer = _constantToInfo[value];
+ }
+ }
List<FunctionInfo> nestedClosures = <FunctionInfo>[];
for (Element closure in element.nestedClosures) {
@@ -242,8 +257,7 @@ class ElementInfoCollector extends BaseElementVisitor<Info, dynamic> {
isConst: element.isConst,
isFactory: element.isFactoryConstructor,
isExternal: element.isPatched);
- StringBuffer emittedCode = compiler.dumpInfoTask.codeOf(element);
- String code = emittedCode == null ? null : '$emittedCode';
+ String code = compiler.dumpInfoTask.codeOf(element);
List<ParameterInfo> parameters = <ParameterInfo>[];
if (element.hasFunctionSignature) {
@@ -347,6 +361,8 @@ class DumpInfoTask extends CompilerTask {
// A mapping from Dart Elements to Javascript AST Nodes.
final Map<Element, List<jsAst.Node>> _elementToNodes =
<Element, List<jsAst.Node>>{};
+ final Map<ConstantValue, jsAst.Node> _constantToNode =
+ <ConstantValue, jsAst.Node>{};
// A mapping from Javascript AST Nodes to the size of their
// pretty-printed contents.
final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{};
@@ -426,6 +442,15 @@ class DumpInfoTask extends CompilerTask {
}
}
+ void registerConstantAst(ConstantValue constant, jsAst.Node code) {
+ if (compiler.dumpInfo) {
+ assert(_constantToNode[constant] == null ||
+ _constantToNode[constant] == code);
+ _constantToNode[constant] = code;
+ _tracking.add(code);
+ }
+ }
+
// Records the size of a dart AST node after it has been
// pretty-printed into the output buffer.
void recordAstSize(jsAst.Node node, int size) {
@@ -446,15 +471,9 @@ class DumpInfoTask extends CompilerTask {
}
}
- int sizeOfNode(jsAst.Node node) {
- if (_nodeToSize.containsKey(node)) {
- return _nodeToSize[node];
- } else {
- return 0;
- }
- }
+ int sizeOfNode(jsAst.Node node) => _nodeToSize[node] ?? 0;
- StringBuffer codeOf(Element element) {
+ String codeOf(Element element) {
List<jsAst.Node> code = _elementToNodes[element];
if (code == null) return null;
// Concatenate rendered ASTs.
@@ -462,7 +481,7 @@ class DumpInfoTask extends CompilerTask {
for (jsAst.Node ast in code) {
sb.writeln(jsAst.prettyPrint(ast, compiler).getText());
}
- return sb;
+ return sb.toString();
}
void collectInfo() {
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart » ('j') | pkg/compiler/pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698