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

Side by Side Diff: pkg/compiler/lib/src/native/enqueue.dart

Issue 2045223002: Compute and cache element NativeBehavior during resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Temporarily skip compilation subtest Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'dart:collection' show Queue; 5 import 'dart:collection' show Queue;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/backend_api.dart' show ForeignResolver; 8 import '../common/backend_api.dart' show ForeignResolver;
9 import '../common/registry.dart' show Registry; 9 import '../common/registry.dart' show Registry;
10 import '../common/resolution.dart' show Resolution; 10 import '../common/resolution.dart' show Resolution;
(...skipping 16 matching lines...) Expand all
27 * This could be an abstract class but we use it as a stub for the dart_backend. 27 * This could be an abstract class but we use it as a stub for the dart_backend.
28 */ 28 */
29 class NativeEnqueuer { 29 class NativeEnqueuer {
30 /// Initial entry point to native enqueuer. 30 /// Initial entry point to native enqueuer.
31 void processNativeClasses(Iterable<LibraryElement> libraries) {} 31 void processNativeClasses(Iterable<LibraryElement> libraries) {}
32 32
33 /// Registers the [nativeBehavior]. Adds the liveness of its instantiated 33 /// Registers the [nativeBehavior]. Adds the liveness of its instantiated
34 /// types to the world. 34 /// types to the world.
35 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) {} 35 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) {}
36 36
37 /// Notification of a main Enqueuer worklist element. For methods, adds 37 // TODO(johnniwinther): Move [handleFieldAnnotations] and
38 /// information from metadata attributes, and computes types instantiated due 38 // [handleMethodAnnotations] to [JavaScriptBackend] or [NativeData].
39 /// to calling the method. 39 // TODO(johnniwinther): Change the return type to 'bool' and rename them to
40 void registerElement(Element element) {} 40 // something like `computeNativeField`.
41 41 /// Process the potentially native [field]. Adds information from metadata
42 /// Notification of native field. Adds information from metadata attributes. 42 /// attributes.
43 void handleFieldAnnotations(Element field) {} 43 void handleFieldAnnotations(Element field) {}
44 44
45 /// Computes types instantiated due to getting a native field. 45 /// Process the potentially native [method]. Adds information from metadata
46 void registerFieldLoad(Element field) {} 46 /// attributes.
47 47 void handleMethodAnnotations(Element method) {}
48 /// Computes types instantiated due to setting a native field.
49 void registerFieldStore(Element field) {}
50 48
51 /// Returns whether native classes are being used. 49 /// Returns whether native classes are being used.
52 bool hasInstantiatedNativeClasses() => false; 50 bool hasInstantiatedNativeClasses() => false;
53 51
54 /// Emits a summary information using the [log] function. 52 /// Emits a summary information using the [log] function.
55 void logSummary(log(message)) {} 53 void logSummary(log(message)) {}
56 54
57 // Do not use annotations in dart2dart. 55 // Do not use annotations in dart2dart.
58 ClassElement get annotationCreatesClass => null; 56 ClassElement get annotationCreatesClass => null;
59 ClassElement get annotationReturnsClass => null; 57 ClassElement get annotationReturnsClass => null;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // TODO(ahe): Is this really a global dependency? 362 // TODO(ahe): Is this really a global dependency?
365 classElement.ensureResolved(resolution); 363 classElement.ensureResolved(resolution);
366 compiler.backend.registerInstantiatedType( 364 compiler.backend.registerInstantiatedType(
367 classElement.rawType, world, compiler.globalDependencies); 365 classElement.rawType, world, compiler.globalDependencies);
368 366
369 if (firstTime) { 367 if (firstTime) {
370 queue.add(onFirstNativeClass); 368 queue.add(onFirstNativeClass);
371 } 369 }
372 } 370 }
373 371
374 registerElement(Element element) {
375 reporter.withCurrentElement(element, () {
376 if (element.isFunction ||
377 element.isFactoryConstructor ||
378 element.isGetter ||
379 element.isSetter) {
380 handleMethodAnnotations(element);
381 if (backend.isNative(element)) {
382 registerMethodUsed(element);
383 }
384 } else if (element.isField) {
385 handleFieldAnnotations(element);
386 if (backend.isNative(element)) {
387 registerFieldLoad(element);
388 registerFieldStore(element);
389 }
390 }
391 });
392 }
393
394 void handleFieldAnnotations(Element element) { 372 void handleFieldAnnotations(Element element) {
395 if (compiler.serialization.isDeserialized(element)) { 373 if (compiler.serialization.isDeserialized(element)) {
396 return; 374 return;
397 } 375 }
398 if (backend.isNative(element.enclosingElement)) { 376 if (backend.isNative(element.enclosingElement)) {
399 // Exclude non-instance (static) fields - they not really native and are 377 // Exclude non-instance (static) fields - they not really native and are
400 // compiled as isolate globals. Access of a property of a constructor 378 // compiled as isolate globals. Access of a property of a constructor
401 // function or a non-method property in the prototype chain, must be coded 379 // function or a non-method property in the prototype chain, must be coded
402 // using a JS-call. 380 // using a JS-call.
403 if (element.isInstanceMember) { 381 if (element.isInstanceMember) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (identical(token.stringValue, 'native')) return true; 446 if (identical(token.stringValue, 'native')) return true;
469 return false; 447 return false;
470 }); 448 });
471 } 449 }
472 450
473 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) { 451 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) {
474 processNativeBehavior(nativeBehavior, cause); 452 processNativeBehavior(nativeBehavior, cause);
475 flushQueue(); 453 flushQueue();
476 } 454 }
477 455
478 void registerMethodUsed(Element method) {
479 registerNativeBehavior(NativeBehavior.ofMethod(method, compiler), method);
480 }
481
482 void registerFieldLoad(Element field) {
483 registerNativeBehavior(NativeBehavior.ofFieldLoad(field, compiler), field);
484 }
485
486 void registerFieldStore(Element field) {
487 registerNativeBehavior(NativeBehavior.ofFieldStore(field, compiler), field);
488 }
489
490 processNativeBehavior(NativeBehavior behavior, cause) { 456 processNativeBehavior(NativeBehavior behavior, cause) {
491 // TODO(ahe): Is this really a global dependency? 457 // TODO(ahe): Is this really a global dependency?
492 Registry registry = compiler.globalDependencies; 458 Registry registry = compiler.globalDependencies;
493 bool allUsedBefore = unusedClasses.isEmpty; 459 bool allUsedBefore = unusedClasses.isEmpty;
494 for (var type in behavior.typesInstantiated) { 460 for (var type in behavior.typesInstantiated) {
495 if (matchedTypeConstraints.contains(type)) continue; 461 if (matchedTypeConstraints.contains(type)) continue;
496 matchedTypeConstraints.add(type); 462 matchedTypeConstraints.add(type);
497 if (type is SpecialType) { 463 if (type is SpecialType) {
498 if (type == SpecialType.JsObject) { 464 if (type == SpecialType.JsObject) {
499 backend.registerInstantiatedType( 465 backend.registerInstantiatedType(
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 List<Element> directSubtypes = 672 List<Element> directSubtypes =
707 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]); 673 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]);
708 directSubtypes.add(cls); 674 directSubtypes.add(cls);
709 } 675 }
710 676
711 void logSummary(log(message)) { 677 void logSummary(log(message)) {
712 log('Compiled ${registeredClasses.length} native classes, ' 678 log('Compiled ${registeredClasses.length} native classes, '
713 '${unusedClasses.length} native classes omitted.'); 679 '${unusedClasses.length} native classes omitted.');
714 } 680 }
715 } 681 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/native/behavior.dart ('k') | pkg/compiler/lib/src/resolution/registry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698