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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compiler.dart

Issue 1259553002: Emit program and dependency information as relations in a Prolog database. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js; 5 part of dart2js;
6 6
7 // TODO(karlklose): move this to own library.
8
9 class CallSite {
10 final TreeElements context;
11 final Send node;
12 CallSite(this.context, this.node);
13 }
14
15 class Dependency {
16 final CallSite site;
17 final Element target;
18 Dependency(this.site, this.target);
19 }
20
7 /** 21 /**
8 * If true, print a warning for each method that was resolved, but not 22 * If true, print a warning for each method that was resolved, but not
9 * compiled. 23 * compiled.
10 */ 24 */
11 const bool REPORT_EXCESS_RESOLUTION = false; 25 const bool REPORT_EXCESS_RESOLUTION = false;
12 26
13 /** 27 /**
14 * Contains backend-specific data that is used throughout the compilation of 28 * Contains backend-specific data that is used throughout the compilation of
15 * one work item. 29 * one work item.
16 */ 30 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // TODO(johnniwinther): Split this class into interface and implementation. 64 // TODO(johnniwinther): Split this class into interface and implementation.
51 // TODO(johnniwinther): Move this implementation to the JS backend. 65 // TODO(johnniwinther): Move this implementation to the JS backend.
52 class CodegenRegistry extends Registry { 66 class CodegenRegistry extends Registry {
53 final Compiler compiler; 67 final Compiler compiler;
54 final TreeElements treeElements; 68 final TreeElements treeElements;
55 69
56 CodegenRegistry(this.compiler, this.treeElements); 70 CodegenRegistry(this.compiler, this.treeElements);
57 71
58 bool get isForResolution => false; 72 bool get isForResolution => false;
59 73
74 Element get currentElement => treeElements.currentElement;
75
60 // TODO(johnniwinther): Remove this getter when [Registry] creates a 76 // TODO(johnniwinther): Remove this getter when [Registry] creates a
61 // dependency node. 77 // dependency node.
62 Setlet<Element> get otherDependencies => treeElements.otherDependencies; 78 Setlet<Element> get otherDependencies => treeElements.otherDependencies;
63 79
64 CodegenEnqueuer get world => compiler.enqueuer.codegen; 80 CodegenEnqueuer get world => compiler.enqueuer.codegen;
65 js_backend.JavaScriptBackend get backend => compiler.backend; 81 js_backend.JavaScriptBackend get backend => compiler.backend;
66 82
67 void registerDependency(Element element) { 83 void registerDependency(Element element) {
68 treeElements.registerDependency(element); 84 treeElements.registerDependency(element);
69 } 85 }
70 86
71 void registerInstantiatedClass(ClassElement element) { 87 void registerInstantiatedClass(ClassElement element) {
72 world.registerInstantiatedClass(element, this); 88 world.registerInstantiatedClass(element, this);
73 } 89 }
74 90
75 void registerInstantiatedType(InterfaceType type) { 91 void registerInstantiatedType(InterfaceType type) {
76 world.registerInstantiatedType(type, this); 92 world.registerInstantiatedType(type, this);
77 } 93 }
78 94
79 void registerStaticUse(Element element) { 95 void registerStaticUse(Element element) {
80 world.registerStaticUse(element); 96 world.registerStaticUse(element);
81 } 97 }
82 98
83 void registerDynamicInvocation(Selector selector) { 99 void registerDynamicInvocation(Selector selector) {
84 world.registerDynamicInvocation(selector); 100 world.registerDynamicInvocation(currentElement, selector);
85 } 101 }
86 102
87 void registerDynamicSetter(Selector selector) { 103 void registerDynamicSetter(Selector selector) {
88 world.registerDynamicSetter(selector); 104 world.registerDynamicSetter(currentElement, selector);
89 } 105 }
90 106
91 void registerDynamicGetter(Selector selector) { 107 void registerDynamicGetter(Selector selector) {
92 world.registerDynamicGetter(selector); 108 world.registerDynamicGetter(currentElement, selector);
93 } 109 }
94 110
95 void registerGetterForSuperMethod(Element element) { 111 void registerGetterForSuperMethod(Element element) {
96 world.registerGetterForSuperMethod(element); 112 world.registerGetterForSuperMethod(element);
97 } 113 }
98 114
99 void registerFieldGetter(Element element) { 115 void registerFieldGetter(Element element) {
100 world.registerFieldGetter(element); 116 world.registerFieldGetter(element);
101 } 117 }
102 118
(...skipping 18 matching lines...) Expand all
121 137
122 void registerGenericClosure(FunctionElement element) { 138 void registerGenericClosure(FunctionElement element) {
123 backend.registerGenericClosure(element, world, this); 139 backend.registerGenericClosure(element, world, this);
124 } 140 }
125 141
126 void registerGetOfStaticFunction(FunctionElement element) { 142 void registerGetOfStaticFunction(FunctionElement element) {
127 world.registerGetOfStaticFunction(element); 143 world.registerGetOfStaticFunction(element);
128 } 144 }
129 145
130 void registerSelectorUse(Selector selector) { 146 void registerSelectorUse(Selector selector) {
131 world.registerSelectorUse(selector); 147 world.registerSelectorUse(currentElement, selector);
132 } 148 }
133 149
134 void registerFactoryWithTypeArguments() { 150 void registerFactoryWithTypeArguments() {
135 world.registerFactoryWithTypeArguments(this); 151 world.registerFactoryWithTypeArguments(this);
136 } 152 }
137 153
138 void registerConstSymbol(String name) { 154 void registerConstSymbol(String name) {
139 backend.registerConstSymbol(name, this); 155 backend.registerConstSymbol(name, this);
140 } 156 }
141 157
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 native.NativeEnqueuer nativeResolutionEnqueuer(world) { 248 native.NativeEnqueuer nativeResolutionEnqueuer(world) {
233 return new native.NativeEnqueuer(); 249 return new native.NativeEnqueuer();
234 } 250 }
235 native.NativeEnqueuer nativeCodegenEnqueuer(world) { 251 native.NativeEnqueuer nativeCodegenEnqueuer(world) {
236 return new native.NativeEnqueuer(); 252 return new native.NativeEnqueuer();
237 } 253 }
238 254
239 void assembleProgram(); 255 void assembleProgram();
240 List<CompilerTask> get tasks; 256 List<CompilerTask> get tasks;
241 257
242 void onResolutionComplete() {} 258 void onResolutionComplete() {
259 }
243 260
244 ItemCompilationContext createItemCompilationContext() { 261 ItemCompilationContext createItemCompilationContext() {
245 return new ItemCompilationContext(); 262 return new ItemCompilationContext();
246 } 263 }
247 264
248 bool classNeedsRti(ClassElement cls); 265 bool classNeedsRti(ClassElement cls);
249 bool methodNeedsRti(FunctionElement function); 266 bool methodNeedsRti(FunctionElement function);
250 267
251 268
252 /// Called during codegen when [constant] has been used. 269 /// Called during codegen when [constant] has been used.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 Registry registry) {} 361 Registry registry) {}
345 /** 362 /**
346 * Call this to register that the [:runtimeType:] property has been accessed. 363 * Call this to register that the [:runtimeType:] property has been accessed.
347 */ 364 */
348 void registerRuntimeType(Enqueuer enqueuer, Registry registry) {} 365 void registerRuntimeType(Enqueuer enqueuer, Registry registry) {}
349 366
350 /** 367 /**
351 * Call this method to enable [noSuchMethod] handling in the 368 * Call this method to enable [noSuchMethod] handling in the
352 * backend. 369 * backend.
353 */ 370 */
354 void enableNoSuchMethod(Enqueuer enqueuer) { 371 void enableNoSuchMethod(context, Enqueuer enqueuer) {
355 enqueuer.registerInvocation(compiler.noSuchMethodSelector); 372 // TODO(karlklose): add a context here.
373 enqueuer.registerInvocation(null, compiler.noSuchMethodSelector);
356 } 374 }
357 375
358 void registerRequiredType(DartType type, Element enclosingElement) {} 376 void registerRequiredType(DartType type, Element enclosingElement) {}
359 void registerClassUsingVariableExpression(ClassElement cls) {} 377 void registerClassUsingVariableExpression(ClassElement cls) {}
360 378
361 void registerConstSymbol(String name, Registry registry) {} 379 void registerConstSymbol(String name, Registry registry) {}
362 void registerNewSymbol(Registry registry) {} 380 void registerNewSymbol(Registry registry) {}
363 381
364 /// Called when resolving the `Symbol` constructor. 382 /// Called when resolving the `Symbol` constructor.
365 void onSymbolConstructor(Registry registry) {} 383 void onSymbolConstructor(Registry registry) {}
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 1330
1313 log('Compiling...'); 1331 log('Compiling...');
1314 phase = PHASE_COMPILING; 1332 phase = PHASE_COMPILING;
1315 // TODO(johnniwinther): Move these to [CodegenEnqueuer]. 1333 // TODO(johnniwinther): Move these to [CodegenEnqueuer].
1316 if (hasIsolateSupport()) { 1334 if (hasIsolateSupport()) {
1317 enqueuer.codegen.addToWorkList( 1335 enqueuer.codegen.addToWorkList(
1318 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); 1336 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE));
1319 enqueuer.codegen.registerGetOfStaticFunction(main); 1337 enqueuer.codegen.registerGetOfStaticFunction(main);
1320 } 1338 }
1321 if (enabledNoSuchMethod) { 1339 if (enabledNoSuchMethod) {
1322 backend.enableNoSuchMethod(enqueuer.codegen); 1340 backend.enableNoSuchMethod(null, enqueuer.codegen);
1323 } 1341 }
1324 if (compileAll) { 1342 if (compileAll) {
1325 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib, 1343 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib,
1326 enqueuer.codegen)); 1344 enqueuer.codegen));
1327 } 1345 }
1328 processQueue(enqueuer.codegen, main); 1346 processQueue(enqueuer.codegen, main);
1329 enqueuer.codegen.logSummary(log); 1347 enqueuer.codegen.logSummary(log);
1330 1348
1331 if (compilationFailed) return; 1349 if (compilationFailed) return;
1332 1350
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 static NullSink outputProvider(String name, String extension) { 1970 static NullSink outputProvider(String name, String extension) {
1953 return new NullSink('$name.$extension'); 1971 return new NullSink('$name.$extension');
1954 } 1972 }
1955 } 1973 }
1956 1974
1957 /// Information about suppressed warnings and hints for a given library. 1975 /// Information about suppressed warnings and hints for a given library.
1958 class SuppressionInfo { 1976 class SuppressionInfo {
1959 int warnings = 0; 1977 int warnings = 0;
1960 int hints = 0; 1978 int hints = 0;
1961 } 1979 }
1980
1981 // TODO(karlklose): rename to [CompilationInformation].
1982 class Relations {
1983 final String prefix;
1984
1985 Relations(Enqueuer enqueuer)
1986 : prefix = enqueuer.isResolutionQueue ? 'resolution' : 'codegen';
1987
1988 // General binary relations. Relation X Target -> Source
1989 Map<String, Map<dynamic, Set>> links = {};
1990
1991 Set<CallSite> callSites = new Set<CallSite>();
1992
1993 put(String relation, target, source) {
1994 links.putIfAbsent(relation, () => {})
1995 .putIfAbsent(target, () => new Set())
1996 .add(source);
1997 }
1998
1999 instantiates(InterfaceType type, Element source) {
2000 assert(source is FunctionElement || source is VariableElement);
2001 put('instantiates', type, source);
2002 }
2003
2004 registerCallSite(TreeElements context, Send node) {
2005 callSites.add(new CallSite(context, node));
2006 }
2007
2008 enqueues(Element function, Element source) {
2009 assert(source is Element || source is Element);
2010 put('enqueues', function, source);
2011 }
2012
2013 void finalizeInformation(Compiler compiler) {
2014 for (CallSite callSite in callSites) {
2015 TreeElements context = callSite.context;
2016 Selector selector = context.getSelector(callSite.node);
2017 Element source = context.currentElement;
2018 for (Element target in compiler.world.allFunctions.filter(selector)) {
2019 put('calls', source, target);
2020 }
2021 }
2022 }
2023 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/common.dart ('k') | sdk/lib/_internal/compiler/implementation/dart2jslib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698