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

Side by Side Diff: pkg/compiler/lib/src/dart_backend/backend.dart

Issue 1424923004: Add StaticUse for more precise registration of statically known element use. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 1 month 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
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/deferred_load.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 dart_backend; 5 part of dart_backend;
6 6
7 // TODO(ahe): This class is simply wrong. This backend should use 7 // TODO(ahe): This class is simply wrong. This backend should use
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, 8 // elements when it can, not AST nodes. Perhaps a [Map<Element,
9 // TreeElements>] is what is needed. 9 // TreeElements>] is what is needed.
10 class ElementAst { 10 class ElementAst {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 final LITERAL_TYPE_NAMES = const [ 130 final LITERAL_TYPE_NAMES = const [
131 'Map', 'List', 'num', 'int', 'double', 'bool' 131 'Map', 'List', 'num', 'int', 'double', 'bool'
132 ]; 132 ];
133 final coreLibrary = compiler.coreLibrary; 133 final coreLibrary = compiler.coreLibrary;
134 for (final name in LITERAL_TYPE_NAMES) { 134 for (final name in LITERAL_TYPE_NAMES) {
135 ClassElement classElement = coreLibrary.findLocal(name); 135 ClassElement classElement = coreLibrary.findLocal(name);
136 classElement.ensureResolved(resolution); 136 classElement.ensureResolved(resolution);
137 } 137 }
138 // Enqueue the methods that the VM might invoke on user objects because 138 // Enqueue the methods that the VM might invoke on user objects because
139 // we don't trust the resolution to always get these included. 139 // we don't trust the resolution to always get these included.
140 world.registerInvocation(new UniverseSelector(Selectors.toString_, null)); 140 world.registerDynamicUse(new UniverseSelector(Selectors.toString_, null));
141 world.registerInvokedGetter( 141 world.registerDynamicUse(
142 new UniverseSelector(Selectors.hashCode_, null)); 142 new UniverseSelector(Selectors.hashCode_, null));
143 world.registerInvocation( 143 world.registerDynamicUse(
144 new UniverseSelector(new Selector.binaryOperator('=='), null)); 144 new UniverseSelector(new Selector.binaryOperator('=='), null));
145 world.registerInvocation( 145 world.registerDynamicUse(
146 new UniverseSelector(Selectors.compareTo, null)); 146 new UniverseSelector(Selectors.compareTo, null));
147 } 147 }
148 148
149 WorldImpact codegen(CodegenWorkItem work) { 149 WorldImpact codegen(CodegenWorkItem work) {
150 return const WorldImpact(); 150 return const WorldImpact();
151 } 151 }
152 152
153 /** 153 /**
154 * Tells whether we should output given element. Corelib classes like 154 * Tells whether we should output given element. Corelib classes like
155 * Object should not be in the resulting code. 155 * Object should not be in the resulting code.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 enqueuer.addToWorkList(getNameFunction); 258 enqueuer.addToWorkList(getNameFunction);
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 @override 263 @override
264 void registerInstantiatedType(InterfaceType type, 264 void registerInstantiatedType(InterfaceType type,
265 Enqueuer enqueuer, 265 Enqueuer enqueuer,
266 Registry registry, 266 Registry registry,
267 {bool mirrorUsage: false}) { 267 {bool mirrorUsage: false}) {
268 registerPlatformMembers(type, 268 registerPlatformMembers(type, registerUse: registry.registerDynamicUse);
269 registerGetter: registry.registerDynamicGetter,
270 registerSetter: registry.registerDynamicSetter,
271 registerInvocation: registry.registerDynamicInvocation);
272 super.registerInstantiatedType( 269 super.registerInstantiatedType(
273 type, enqueuer, registry, mirrorUsage: mirrorUsage); 270 type, enqueuer, registry, mirrorUsage: mirrorUsage);
274 } 271 }
275 272
276 /// Register dynamic access of members of [type] that implement members 273 /// Register dynamic access of members of [type] that implement members
277 /// of types defined in the platform libraries. 274 /// of types defined in the platform libraries.
278 void registerPlatformMembers( 275 void registerPlatformMembers(
279 InterfaceType type, 276 InterfaceType type,
280 {void registerGetter(UniverseSelector selector), 277 {void registerUse(UniverseSelector selector)}) {
281 void registerSetter(UniverseSelector selector),
282 void registerInvocation(UniverseSelector selector)}) {
283 278
284 // Without patching, dart2dart has no way of performing sound tree-shaking 279 // Without patching, dart2dart has no way of performing sound tree-shaking
285 // in face external functions. Therefore we employ another scheme: 280 // in face external functions. Therefore we employ another scheme:
286 // 281 //
287 // Based on the assumption that the platform code only relies on the 282 // Based on the assumption that the platform code only relies on the
288 // interfaces of it's own classes, we can approximate the semantics of 283 // interfaces of it's own classes, we can approximate the semantics of
289 // external functions by eagerly registering dynamic invocation of instance 284 // external functions by eagerly registering dynamic invocation of instance
290 // members defined the platform interfaces. 285 // members defined the platform interfaces.
291 // 286 //
292 // Since we only need to generate code for non-platform classes we can 287 // Since we only need to generate code for non-platform classes we can
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (_userImplementedPlatformClasses.add(superclass)) { 319 if (_userImplementedPlatformClasses.add(superclass)) {
325 // Register selectors for all instance methods since these might 320 // Register selectors for all instance methods since these might
326 // be called on user classes from within the platform 321 // be called on user classes from within the platform
327 // implementation. 322 // implementation.
328 superclass.forEachLocalMember((MemberElement element) { 323 superclass.forEachLocalMember((MemberElement element) {
329 if (element.isConstructor || element.isStatic) return; 324 if (element.isConstructor || element.isStatic) return;
330 325
331 FunctionElement function = element.asFunctionElement(); 326 FunctionElement function = element.asFunctionElement();
332 element.computeType(resolution); 327 element.computeType(resolution);
333 Selector selector = new Selector.fromElement(element); 328 Selector selector = new Selector.fromElement(element);
334 if (selector.isGetter) { 329 registerUse(
335 registerGetter( 330 new UniverseSelector(selector, null));
336 new UniverseSelector(selector, null));
337 } else if (selector.isSetter) {
338 registerSetter(
339 new UniverseSelector(selector, null));
340 } else {
341 registerInvocation(
342 new UniverseSelector(selector, null));
343 }
344 }); 331 });
345 } 332 }
346 } 333 }
347 } 334 }
348 } 335 }
349 } 336 }
350 337
351 @override 338 @override
352 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { 339 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) {
353 // TODO(sigurdm): Implement deferred loading for dart2dart. 340 // TODO(sigurdm): Implement deferred loading for dart2dart.
(...skipping 15 matching lines...) Expand all
369 for (DartType typeLiteral in worldImpact.typeLiterals) { 356 for (DartType typeLiteral in worldImpact.typeLiterals) {
370 if (typeLiteral.isInterfaceType) { 357 if (typeLiteral.isInterfaceType) {
371 backend.usedTypeLiterals.add(typeLiteral.element); 358 backend.usedTypeLiterals.add(typeLiteral.element);
372 } 359 }
373 } 360 }
374 for (InterfaceType instantiatedType in worldImpact.instantiatedTypes) { 361 for (InterfaceType instantiatedType in worldImpact.instantiatedTypes) {
375 // TODO(johnniwinther): Remove this when dependency tracking is done on 362 // TODO(johnniwinther): Remove this when dependency tracking is done on
376 // the world impact itself. 363 // the world impact itself.
377 transformed.registerInstantiatedType(instantiatedType); 364 transformed.registerInstantiatedType(instantiatedType);
378 backend.registerPlatformMembers(instantiatedType, 365 backend.registerPlatformMembers(instantiatedType,
379 registerGetter: transformed.registerDynamicGetter, 366 registerUse: transformed.registerDynamicUse);
380 registerSetter: transformed.registerDynamicSetter,
381 registerInvocation: transformed.registerDynamicInvocation);
382 } 367 }
383 return transformed; 368 return transformed;
384 } 369 }
385 } 370 }
386 371
387 class EmitterUnparser extends Unparser { 372 class EmitterUnparser extends Unparser {
388 final Map<Node, String> renames; 373 final Map<Node, String> renames;
389 374
390 EmitterUnparser(this.renames, {bool minify, bool stripTypes}) 375 EmitterUnparser(this.renames, {bool minify, bool stripTypes})
391 : super(minify: minify, stripTypes: stripTypes); 376 : super(minify: minify, stripTypes: stripTypes);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 543 }
559 544
560 // TODO(johnniwinther): Remove this when values are computed from the 545 // TODO(johnniwinther): Remove this when values are computed from the
561 // expressions. 546 // expressions.
562 @override 547 @override
563 void copyConstantValues(DartConstantTask task) { 548 void copyConstantValues(DartConstantTask task) {
564 constantCompiler.constantValueMap.addAll( 549 constantCompiler.constantValueMap.addAll(
565 task.constantCompiler.constantValueMap); 550 task.constantCompiler.constantValueMap);
566 } 551 }
567 } 552 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/deferred_load.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698