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

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

Issue 2748383003: Split MirrorsAnalysis (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen_listener.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 library js_backend.backend; 5 library js_backend.backend;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
10 10
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 398
399 /// Codegen support for tree-shaking entries of `LookupMap`. 399 /// Codegen support for tree-shaking entries of `LookupMap`.
400 LookupMapAnalysis _lookupMapAnalysis; 400 LookupMapAnalysis _lookupMapAnalysis;
401 401
402 /// Codegen support for typed JavaScript interop. 402 /// Codegen support for typed JavaScript interop.
403 JsInteropAnalysis jsInteropAnalysis; 403 JsInteropAnalysis jsInteropAnalysis;
404 404
405 /// Support for classifying `noSuchMethod` implementations. 405 /// Support for classifying `noSuchMethod` implementations.
406 NoSuchMethodRegistry noSuchMethodRegistry; 406 NoSuchMethodRegistry noSuchMethodRegistry;
407 407
408 /// Resolution and codegen support for computing reflectable elements. 408 /// Resolution support for computing reflectable elements.
409 MirrorsAnalysis mirrorsAnalysis; 409 MirrorsResolutionAnalysis _mirrorsResolutionAnalysis;
410
411 /// Codegen support for computing reflectable elements.
412 MirrorsCodegenAnalysis _mirrorsCodegenAnalysis;
410 413
411 /// Builds kernel representation for the program. 414 /// Builds kernel representation for the program.
412 KernelTask kernelTask; 415 KernelTask kernelTask;
413 416
414 /// The compiler task responsible for the compilation of constants for both 417 /// The compiler task responsible for the compilation of constants for both
415 /// the frontend and the backend. 418 /// the frontend and the backend.
416 final JavaScriptConstantTask constantCompilerTask; 419 final JavaScriptConstantTask constantCompilerTask;
417 420
418 /// Backend transformation methods for the world impacts. 421 /// Backend transformation methods for the world impacts.
419 ImpactTransformer impactTransformer; 422 ImpactTransformer impactTransformer;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 nativeBaseData, 529 nativeBaseData,
527 backendUsageBuilder); 530 backendUsageBuilder);
528 customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis( 531 customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis(
529 compiler.resolution, 532 compiler.resolution,
530 constantSystem, 533 constantSystem,
531 commonElements, 534 commonElements,
532 backendClasses, 535 backendClasses,
533 helpers, 536 helpers,
534 nativeBaseData); 537 nativeBaseData);
535 jsInteropAnalysis = new JsInteropAnalysis(this); 538 jsInteropAnalysis = new JsInteropAnalysis(this);
536 mirrorsAnalysis = new MirrorsAnalysis(this, compiler.resolution); 539 _mirrorsResolutionAnalysis =
540 new MirrorsResolutionAnalysisImpl(this, compiler.resolution);
537 lookupMapResolutionAnalysis = 541 lookupMapResolutionAnalysis =
538 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); 542 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment);
539 543
540 noSuchMethodRegistry = new NoSuchMethodRegistry(this); 544 noSuchMethodRegistry = new NoSuchMethodRegistry(this);
541 kernelTask = new KernelTask(compiler); 545 kernelTask = new KernelTask(compiler);
542 impactTransformer = new JavaScriptImpactTransformer( 546 impactTransformer = new JavaScriptImpactTransformer(
543 compiler.options, 547 compiler.options,
544 compiler.resolution, 548 compiler.resolution,
545 compiler.elementEnvironment, 549 compiler.elementEnvironment,
546 commonElements, 550 commonElements,
(...skipping 20 matching lines...) Expand all
567 DiagnosticReporter get reporter => compiler.reporter; 571 DiagnosticReporter get reporter => compiler.reporter;
568 572
569 CommonElements get commonElements => compiler.commonElements; 573 CommonElements get commonElements => compiler.commonElements;
570 574
571 Resolution get resolution => compiler.resolution; 575 Resolution get resolution => compiler.resolution;
572 576
573 Target get target => _target; 577 Target get target => _target;
574 578
575 /// Resolution analysis for tracking reflective access to type variables. 579 /// Resolution analysis for tracking reflective access to type variables.
576 TypeVariableResolutionAnalysis get typeVariableResolutionAnalysis { 580 TypeVariableResolutionAnalysis get typeVariableResolutionAnalysis {
577 assert(invariant(NO_LOCATION_SPANNABLE, _typeVariableCodegenAnalysis == null , 581 assert(invariant(
582 NO_LOCATION_SPANNABLE, _typeVariableCodegenAnalysis == null,
578 message: "TypeVariableHandler has already been created.")); 583 message: "TypeVariableHandler has already been created."));
579 return _typeVariableResolutionAnalysis; 584 return _typeVariableResolutionAnalysis;
580 } 585 }
581 586
582 /// Codegen handler for reflective access to type variables. 587 /// Codegen handler for reflective access to type variables.
583 TypeVariableCodegenAnalysis get typeVariableCodegenAnalysis { 588 TypeVariableCodegenAnalysis get typeVariableCodegenAnalysis {
584 assert(invariant(NO_LOCATION_SPANNABLE, _typeVariableCodegenAnalysis != null , 589 assert(invariant(
590 NO_LOCATION_SPANNABLE, _typeVariableCodegenAnalysis != null,
585 message: "TypeVariableHandler has not been created yet.")); 591 message: "TypeVariableHandler has not been created yet."));
586 return _typeVariableCodegenAnalysis; 592 return _typeVariableCodegenAnalysis;
587 } 593 }
588 594
589 MirrorsData get mirrorsData => _mirrorsData; 595 MirrorsData get mirrorsData => _mirrorsData;
590 596
591 MirrorsDataBuilder get mirrorsDataBuilder => _mirrorsData; 597 MirrorsDataBuilder get mirrorsDataBuilder => _mirrorsData;
592 598
599 /// Resolution support for computing reflectable elements.
600 MirrorsResolutionAnalysis get mirrorsResolutionAnalysis =>
601 _mirrorsResolutionAnalysis;
602
603 /// Codegen support for computing reflectable elements.
604 MirrorsCodegenAnalysis get mirrorsCodegenAnalysis {
605 assert(invariant(NO_LOCATION_SPANNABLE, _mirrorsCodegenAnalysis != null,
606 message: "MirrorsCodegenAnalysis has not been created yet."));
607 return _mirrorsCodegenAnalysis;
608 }
609
593 /// Codegen support for tree-shaking entries of `LookupMap`. 610 /// Codegen support for tree-shaking entries of `LookupMap`.
594 LookupMapAnalysis get lookupMapAnalysis { 611 LookupMapAnalysis get lookupMapAnalysis {
595 assert(invariant(NO_LOCATION_SPANNABLE, _lookupMapAnalysis != null, 612 assert(invariant(NO_LOCATION_SPANNABLE, _lookupMapAnalysis != null,
596 message: "LookupMapAnalysis has not been created yet.")); 613 message: "LookupMapAnalysis has not been created yet."));
597 return _lookupMapAnalysis; 614 return _lookupMapAnalysis;
598 } 615 }
599 616
600 InterceptorData get interceptorData { 617 InterceptorData get interceptorData {
601 assert(invariant(NO_LOCATION_SPANNABLE, _interceptorData != null, 618 assert(invariant(NO_LOCATION_SPANNABLE, _interceptorData != null,
602 message: "InterceptorData has not been computed yet.")); 619 message: "InterceptorData has not been computed yet."));
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 closedWorld, 823 closedWorld,
807 compiler.types, 824 compiler.types,
808 commonElements, 825 commonElements,
809 helpers, 826 helpers,
810 _backendUsage, 827 _backendUsage,
811 enableTypeAssertions: compiler.options.enableTypeAssertions); 828 enableTypeAssertions: compiler.options.enableTypeAssertions);
812 _interceptorData = 829 _interceptorData =
813 _interceptorDataBuilder.onResolutionComplete(closedWorld); 830 _interceptorDataBuilder.onResolutionComplete(closedWorld);
814 _oneShotInterceptorData = 831 _oneShotInterceptorData =
815 new OneShotInterceptorData(interceptorData, helpers); 832 new OneShotInterceptorData(interceptorData, helpers);
816 mirrorsAnalysis.onResolutionComplete(); 833 mirrorsResolutionAnalysis.onResolutionComplete();
817 } 834 }
818 835
819 void onTypeInferenceComplete() { 836 void onTypeInferenceComplete() {
820 noSuchMethodRegistry.onTypeInferenceComplete(); 837 noSuchMethodRegistry.onTypeInferenceComplete();
821 } 838 }
822 839
823 /// Register a runtime type variable bound tests between [typeArgument] and 840 /// Register a runtime type variable bound tests between [typeArgument] and
824 /// [bound]. 841 /// [bound].
825 void registerTypeVariableBoundsSubtypeCheck( 842 void registerTypeVariableBoundsSubtypeCheck(
826 ResolutionDartType typeArgument, ResolutionDartType bound) { 843 ResolutionDartType typeArgument, ResolutionDartType bound) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 impacts, 905 impacts,
889 backendClasses, 906 backendClasses,
890 nativeBaseData, 907 nativeBaseData,
891 _interceptorDataBuilder, 908 _interceptorDataBuilder,
892 _backendUsageBuilder, 909 _backendUsageBuilder,
893 _rtiNeedBuilder, 910 _rtiNeedBuilder,
894 mirrorsDataBuilder, 911 mirrorsDataBuilder,
895 noSuchMethodRegistry, 912 noSuchMethodRegistry,
896 customElementsResolutionAnalysis, 913 customElementsResolutionAnalysis,
897 lookupMapResolutionAnalysis, 914 lookupMapResolutionAnalysis,
898 mirrorsAnalysis, 915 mirrorsResolutionAnalysis,
899 typeVariableResolutionAnalysis, 916 typeVariableResolutionAnalysis,
900 _nativeResolutionEnqueuer), 917 _nativeResolutionEnqueuer),
901 new ElementResolutionWorldBuilder( 918 new ElementResolutionWorldBuilder(
902 this, compiler.resolution, const OpenWorldStrategy()), 919 this, compiler.resolution, const OpenWorldStrategy()),
903 new ResolutionWorkItemBuilder(compiler.resolution)); 920 new ResolutionWorkItemBuilder(compiler.resolution));
904 } 921 }
905 922
906 /// Creates an [Enqueuer] for code generation specific to this backend. 923 /// Creates an [Enqueuer] for code generation specific to this backend.
907 CodegenEnqueuer createCodegenEnqueuer( 924 CodegenEnqueuer createCodegenEnqueuer(
908 CompilerTask task, Compiler compiler, ClosedWorld closedWorld) { 925 CompilerTask task, Compiler compiler, ClosedWorld closedWorld) {
909 _typeVariableCodegenAnalysis = new TypeVariableCodegenAnalysis(this, helpers , mirrorsData); 926 _typeVariableCodegenAnalysis =
927 new TypeVariableCodegenAnalysis(this, helpers, mirrorsData);
910 _lookupMapAnalysis = new LookupMapAnalysis( 928 _lookupMapAnalysis = new LookupMapAnalysis(
911 reporter, 929 reporter,
912 constantSystem, 930 constantSystem,
913 constants, 931 constants,
914 compiler.elementEnvironment, 932 compiler.elementEnvironment,
915 commonElements, 933 commonElements,
916 helpers, 934 helpers,
917 backendClasses, 935 backendClasses,
918 lookupMapResolutionAnalysis); 936 lookupMapResolutionAnalysis);
937 _mirrorsCodegenAnalysis = mirrorsResolutionAnalysis.close();
919 return new CodegenEnqueuer( 938 return new CodegenEnqueuer(
920 task, 939 task,
921 compiler.options, 940 compiler.options,
922 const TreeShakingEnqueuerStrategy(), 941 const TreeShakingEnqueuerStrategy(),
923 new CodegenWorldBuilderImpl( 942 new CodegenWorldBuilderImpl(
924 nativeBaseData, closedWorld, constants, const TypeMaskStrategy()), 943 nativeBaseData, closedWorld, constants, const TypeMaskStrategy()),
925 new CodegenWorkItemBuilder(this, compiler.options), 944 new CodegenWorkItemBuilder(this, compiler.options),
926 new CodegenEnqueuerListener( 945 new CodegenEnqueuerListener(
927 compiler.elementEnvironment, 946 compiler.elementEnvironment,
928 commonElements, 947 commonElements,
929 helpers, 948 helpers,
930 impacts, 949 impacts,
931 backendClasses, 950 backendClasses,
932 backendUsage, 951 backendUsage,
933 rtiNeed, 952 rtiNeed,
934 customElementsCodegenAnalysis, 953 customElementsCodegenAnalysis,
935 typeVariableCodegenAnalysis, 954 typeVariableCodegenAnalysis,
936 lookupMapAnalysis, 955 lookupMapAnalysis,
937 mirrorsAnalysis, 956 mirrorsCodegenAnalysis,
938 _nativeCodegenEnqueuer)); 957 _nativeCodegenEnqueuer));
939 } 958 }
940 959
941 WorldImpact codegen(CodegenWorkItem work) { 960 WorldImpact codegen(CodegenWorkItem work) {
942 Element element = work.element; 961 Element element = work.element;
943 if (compiler.elementHasCompileTimeError(element)) { 962 if (compiler.elementHasCompileTimeError(element)) {
944 DiagnosticMessage message = 963 DiagnosticMessage message =
945 // If there's more than one error, the first is probably most 964 // If there's more than one error, the first is probably most
946 // informative, as the following errors may be side-effects of the 965 // informative, as the following errors may be side-effects of the
947 // first error. 966 // first error.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 /// Called to finalize the [RuntimeTypesChecks] information. 1055 /// Called to finalize the [RuntimeTypesChecks] information.
1037 void finalizeRti() { 1056 void finalizeRti() {
1038 _rtiChecks = rtiChecksBuilder.computeRequiredChecks(); 1057 _rtiChecks = rtiChecksBuilder.computeRequiredChecks();
1039 } 1058 }
1040 1059
1041 /// Generates the output and returns the total size of the generated code. 1060 /// Generates the output and returns the total size of the generated code.
1042 int assembleProgram(ClosedWorld closedWorld) { 1061 int assembleProgram(ClosedWorld closedWorld) {
1043 int programSize = emitter.assembleProgram(namer, closedWorld); 1062 int programSize = emitter.assembleProgram(namer, closedWorld);
1044 noSuchMethodRegistry.emitDiagnostic(); 1063 noSuchMethodRegistry.emitDiagnostic();
1045 int totalMethodCount = generatedCode.length; 1064 int totalMethodCount = generatedCode.length;
1046 if (totalMethodCount != mirrorsAnalysis.preMirrorsMethodCount) { 1065 if (totalMethodCount != mirrorsCodegenAnalysis.preMirrorsMethodCount) {
1047 int mirrorCount = 1066 int mirrorCount =
1048 totalMethodCount - mirrorsAnalysis.preMirrorsMethodCount; 1067 totalMethodCount - mirrorsCodegenAnalysis.preMirrorsMethodCount;
1049 double percentage = (mirrorCount / totalMethodCount) * 100; 1068 double percentage = (mirrorCount / totalMethodCount) * 100;
1050 DiagnosticMessage hint = 1069 DiagnosticMessage hint =
1051 reporter.createMessage(compiler.mainApp, MessageKind.MIRROR_BLOAT, { 1070 reporter.createMessage(compiler.mainApp, MessageKind.MIRROR_BLOAT, {
1052 'count': mirrorCount, 1071 'count': mirrorCount,
1053 'total': totalMethodCount, 1072 'total': totalMethodCount,
1054 'percentage': percentage.round() 1073 'percentage': percentage.round()
1055 }); 1074 });
1056 1075
1057 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; 1076 List<DiagnosticMessage> infos = <DiagnosticMessage>[];
1058 for (LibraryElement library in compiler.libraryLoader.libraries) { 1077 for (LibraryElement library in compiler.libraryLoader.libraries) {
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 return _backend.defaultSuperclass(element); 1619 return _backend.defaultSuperclass(element);
1601 } 1620 }
1602 1621
1603 @override 1622 @override
1604 bool isNativeClass(ClassEntity element) => 1623 bool isNativeClass(ClassEntity element) =>
1605 _backend.nativeBaseData.isNativeClass(element); 1624 _backend.nativeBaseData.isNativeClass(element);
1606 1625
1607 @override 1626 @override
1608 bool isForeign(Element element) => _backend.isForeign(element); 1627 bool isForeign(Element element) => _backend.isForeign(element);
1609 } 1628 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698