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

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

Issue 1896843002: Store and serialize NativeBehavior in TreeElements. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 8 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 30 matching lines...) Expand all
41 41
42 /// Notification of native field. Adds information from metadata attributes. 42 /// Notification of native field. Adds information from metadata attributes.
43 void handleFieldAnnotations(Element field) {} 43 void handleFieldAnnotations(Element field) {}
44 44
45 /// Computes types instantiated due to getting a native field. 45 /// Computes types instantiated due to getting a native field.
46 void registerFieldLoad(Element field) {} 46 void registerFieldLoad(Element field) {}
47 47
48 /// Computes types instantiated due to setting a native field. 48 /// Computes types instantiated due to setting a native field.
49 void registerFieldStore(Element field) {} 49 void registerFieldStore(Element field) {}
50 50
51 NativeBehavior getNativeBehaviorOf(Send node) => new NativeBehavior();
52
53 /// Returns whether native classes are being used. 51 /// Returns whether native classes are being used.
54 bool hasInstantiatedNativeClasses() => false; 52 bool hasInstantiatedNativeClasses() => false;
55 53
56 /// Emits a summary information using the [log] function. 54 /// Emits a summary information using the [log] function.
57 void logSummary(log(message)) {} 55 void logSummary(log(message)) {}
58 56
59 // Do not use annotations in dart2dart. 57 // Do not use annotations in dart2dart.
60 ClassElement get annotationCreatesClass => null; 58 ClassElement get annotationCreatesClass => null;
61 ClassElement get annotationReturnsClass => null; 59 ClassElement get annotationReturnsClass => null;
62 ClassElement get annotationJsNameClass => null; 60 ClassElement get annotationJsNameClass => null;
(...skipping 25 matching lines...) Expand all
88 * Records matched constraints ([SpecialType] or [DartType]). Once a type 86 * Records matched constraints ([SpecialType] or [DartType]). Once a type
89 * constraint has been matched, there is no need to match it again. 87 * constraint has been matched, there is no need to match it again.
90 */ 88 */
91 final Set matchedTypeConstraints = new Set(); 89 final Set matchedTypeConstraints = new Set();
92 90
93 /// Pending actions. Classes in [pendingClasses] have action thunks in 91 /// Pending actions. Classes in [pendingClasses] have action thunks in
94 /// [queue] to register the class. 92 /// [queue] to register the class.
95 final queue = new Queue(); 93 final queue = new Queue();
96 bool flushing = false; 94 bool flushing = false;
97 95
98 /// Maps JS foreign calls to their computed native behavior.
99 final Map<Node, NativeBehavior> nativeBehaviors =
100 new Map<Node, NativeBehavior>();
101
102 final Enqueuer world; 96 final Enqueuer world;
103 final Compiler compiler; 97 final Compiler compiler;
104 final bool enableLiveTypeAnalysis; 98 final bool enableLiveTypeAnalysis;
105 99
106 ClassElement _annotationCreatesClass; 100 ClassElement _annotationCreatesClass;
107 ClassElement _annotationReturnsClass; 101 ClassElement _annotationReturnsClass;
108 ClassElement _annotationJsNameClass; 102 ClassElement _annotationJsNameClass;
109 103
110 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. 104 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend.
111 NativeEnqueuerBase(this.world, Compiler compiler, this.enableLiveTypeAnalysis) 105 NativeEnqueuerBase(this.world, Compiler compiler, this.enableLiveTypeAnalysis)
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } 480 }
487 481
488 void registerFieldLoad(Element field) { 482 void registerFieldLoad(Element field) {
489 registerNativeBehavior(NativeBehavior.ofFieldLoad(field, compiler), field); 483 registerNativeBehavior(NativeBehavior.ofFieldLoad(field, compiler), field);
490 } 484 }
491 485
492 void registerFieldStore(Element field) { 486 void registerFieldStore(Element field) {
493 registerNativeBehavior(NativeBehavior.ofFieldStore(field, compiler), field); 487 registerNativeBehavior(NativeBehavior.ofFieldStore(field, compiler), field);
494 } 488 }
495 489
496 NativeBehavior getNativeBehaviorOf(Send node) => nativeBehaviors[node];
497
498 processNativeBehavior(NativeBehavior behavior, cause) { 490 processNativeBehavior(NativeBehavior behavior, cause) {
499 // TODO(ahe): Is this really a global dependency? 491 // TODO(ahe): Is this really a global dependency?
500 Registry registry = compiler.globalDependencies; 492 Registry registry = compiler.globalDependencies;
501 bool allUsedBefore = unusedClasses.isEmpty; 493 bool allUsedBefore = unusedClasses.isEmpty;
502 for (var type in behavior.typesInstantiated) { 494 for (var type in behavior.typesInstantiated) {
503 if (matchedTypeConstraints.contains(type)) continue; 495 if (matchedTypeConstraints.contains(type)) continue;
504 matchedTypeConstraints.add(type); 496 matchedTypeConstraints.add(type);
505 if (type is SpecialType) { 497 if (type is SpecialType) {
506 if (type == SpecialType.JsObject) { 498 if (type == SpecialType.JsObject) {
507 backend.registerInstantiatedType( 499 backend.registerInstantiatedType(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 598
607 /** 599 /**
608 * Handles JS-calls, which can be an instantiation point for types. 600 * Handles JS-calls, which can be an instantiation point for types.
609 * 601 *
610 * For example, the following code instantiates and returns native classes 602 * For example, the following code instantiates and returns native classes
611 * that are `_DOMWindowImpl` or a subtype. 603 * that are `_DOMWindowImpl` or a subtype.
612 * 604 *
613 * JS('_DOMWindowImpl', 'window') 605 * JS('_DOMWindowImpl', 'window')
614 * 606 *
615 */ 607 */
616 void registerJsCall(Send node, ForeignResolver resolver) { 608 NativeBehavior resolveJsCall(Send node, ForeignResolver resolver) {
617 NativeBehavior behavior = NativeBehavior.ofJsCall( 609 NativeBehavior behavior = NativeBehavior.ofJsCall(
618 node, reporter, compiler.parsingContext, compiler.coreTypes, resolver); 610 node, reporter, compiler.parsingContext, compiler.coreTypes, resolver);
611 // TODO(johnniwinther): Move registration to the world impact application.
619 registerNativeBehavior(behavior, node); 612 registerNativeBehavior(behavior, node);
620 nativeBehaviors[node] = behavior; 613 return behavior;
621 } 614 }
622 615
623 /** 616 /**
624 * Handles JS-embedded global calls, which can be an instantiation point for 617 * Handles JS-embedded global calls, which can be an instantiation point for
625 * types. 618 * types.
626 * 619 *
627 * For example, the following code instantiates and returns a String class 620 * For example, the following code instantiates and returns a String class
628 * 621 *
629 * JS_EMBEDDED_GLOBAL('String', 'foo') 622 * JS_EMBEDDED_GLOBAL('String', 'foo')
630 * 623 *
631 */ 624 */
632 void registerJsEmbeddedGlobalCall(Send node, ForeignResolver resolver) { 625 NativeBehavior resolveJsEmbeddedGlobalCall(
626 Send node, ForeignResolver resolver) {
633 NativeBehavior behavior = NativeBehavior.ofJsEmbeddedGlobalCall( 627 NativeBehavior behavior = NativeBehavior.ofJsEmbeddedGlobalCall(
634 node, reporter, compiler.parsingContext, compiler.coreTypes, resolver); 628 node, reporter, compiler.parsingContext, compiler.coreTypes, resolver);
629 // TODO(johnniwinther): Move registration to the world impact application.
635 registerNativeBehavior(behavior, node); 630 registerNativeBehavior(behavior, node);
636 nativeBehaviors[node] = behavior; 631 return behavior;
637 } 632 }
638 633
639 /** 634 /**
640 * Handles JS-compiler builtin calls, which can be an instantiation point for 635 * Handles JS-compiler builtin calls, which can be an instantiation point for
641 * types. 636 * types.
642 * 637 *
643 * For example, the following code instantiates and returns a String class 638 * For example, the following code instantiates and returns a String class
644 * 639 *
645 * JS_BUILTIN('String', 'int2string', 0) 640 * JS_BUILTIN('String', 'int2string', 0)
646 * 641 *
647 */ 642 */
648 void registerJsBuiltinCall(Send node, ForeignResolver resolver) { 643 NativeBehavior resolveJsBuiltinCall(Send node, ForeignResolver resolver) {
649 NativeBehavior behavior = NativeBehavior.ofJsBuiltinCall( 644 NativeBehavior behavior = NativeBehavior.ofJsBuiltinCall(
650 node, reporter, compiler.parsingContext, compiler.coreTypes, resolver); 645 node, reporter, compiler.parsingContext, compiler.coreTypes, resolver);
646 // TODO(johnniwinther): Move registration to the world impact application.
651 registerNativeBehavior(behavior, node); 647 registerNativeBehavior(behavior, node);
652 nativeBehaviors[node] = behavior; 648 return behavior;
653 } 649 }
654 } 650 }
655 651
656 class NativeCodegenEnqueuer extends NativeEnqueuerBase { 652 class NativeCodegenEnqueuer extends NativeEnqueuerBase {
657 final CodeEmitterTask emitter; 653 final CodeEmitterTask emitter;
658 654
659 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); 655 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>();
660 656
661 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) 657 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter)
662 : super(world, compiler, compiler.options.enableNativeLiveTypeAnalysis); 658 : super(world, compiler, compiler.options.enableNativeLiveTypeAnalysis);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 List<Element> directSubtypes = 704 List<Element> directSubtypes =
709 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]); 705 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]);
710 directSubtypes.add(cls); 706 directSubtypes.add(cls);
711 } 707 }
712 708
713 void logSummary(log(message)) { 709 void logSummary(log(message)) {
714 log('Compiled ${registeredClasses.length} native classes, ' 710 log('Compiled ${registeredClasses.length} native classes, '
715 '${unusedClasses.length} native classes omitted.'); 711 '${unusedClasses.length} native classes omitted.');
716 } 712 }
717 } 713 }
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