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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2640793007: Eliminate redundant signatures. (Closed)
Patch Set: Restore comment Created 3 years, 11 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 | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 var tInstanceSetters = <JS.Property>[]; 1797 var tInstanceSetters = <JS.Property>[];
1798 var sNames = <JS.Expression>[]; 1798 var sNames = <JS.Expression>[];
1799 for (MethodDeclaration node in methods) { 1799 for (MethodDeclaration node in methods) {
1800 var name = node.name.name; 1800 var name = node.name.name;
1801 var element = resolutionMap.elementDeclaredByMethodDeclaration(node); 1801 var element = resolutionMap.elementDeclaredByMethodDeclaration(node);
1802 // TODO(vsm): Clean up all the nasty duplication. 1802 // TODO(vsm): Clean up all the nasty duplication.
1803 if (node.isAbstract) { 1803 if (node.isAbstract) {
1804 continue; 1804 continue;
1805 } 1805 }
1806 1806
1807 List<JS.Property> tMember;
1808 Function getOverride;
1807 Function lookup; 1809 Function lookup;
1808 List<JS.Property> tMember; 1810 Function elementToType;
1809 if (node.isGetter) { 1811 if (node.isGetter) {
1810 lookup = classElem.lookUpInheritedConcreteGetter; 1812 elementToType = (ExecutableElement element) => element.type;
1813 getOverride = classElem.lookUpInheritedConcreteGetter;
1814 lookup = classElem.type.lookUpInheritedGetter;
1811 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; 1815 tMember = node.isStatic ? tStaticGetters : tInstanceGetters;
1812 } else if (node.isSetter) { 1816 } else if (node.isSetter) {
1813 lookup = classElem.lookUpInheritedConcreteSetter; 1817 elementToType = (ExecutableElement element) => element.type;
1818 getOverride = classElem.lookUpInheritedConcreteSetter;
1819 lookup = classElem.type.lookUpInheritedSetter;
1814 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; 1820 tMember = node.isStatic ? tStaticSetters : tInstanceSetters;
1815 } else { 1821 } else {
1816 // Method 1822 // Method
1817 lookup = classElem.lookUpInheritedConcreteMethod; 1823 // Swap in "Object" for parameter types that are covariant overrides.
1824 var objectType = context.typeProvider.objectType;
1825 elementToType =
1826 (MethodElement element) => element.getReifiedType(objectType);
1827 getOverride = classElem.lookUpInheritedConcreteMethod;
1828 lookup = classElem.type.lookUpInheritedMethod;
1818 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; 1829 tMember = node.isStatic ? tStaticMethods : tInstanceMethods;
1819 } 1830 }
1820 1831
1821 // Swap in "Object" for parameter types that are covariant overrides. 1832 DartType reifiedType = elementToType(element);
1822 var objectType = context.typeProvider.objectType;
1823 var reifiedType = element is MethodElement
1824 ? element.getReifiedType(objectType)
1825 : element.type;
1826 var type = _emitAnnotatedFunctionType(reifiedType, node.metadata, 1833 var type = _emitAnnotatedFunctionType(reifiedType, node.metadata,
1827 parameters: node.parameters?.parameters, 1834 parameters: node.parameters?.parameters,
1828 nameType: options.hoistSignatureTypes, 1835 nameType: options.hoistSignatureTypes,
1829 hoistType: options.hoistSignatureTypes, 1836 hoistType: options.hoistSignatureTypes,
1830 definite: true); 1837 definite: true);
1831 1838
1832 // Don't add redundant signatures for inherited methods whose signature 1839 // Don't add redundant signatures for inherited methods whose signature
1833 // did not change. 1840 // did not change. If we are not overriding, or if the thing we are
1834 var needsSignature = true; 1841 // overriding has a different reified type from ourselves, we must
1835 var inheritedElement = lookup(name, currentLibrary); 1842 // emit a signature on this class. Otherwise we will inherit the
1836 if (inheritedElement != null) { 1843 // signature from the superclass.
1837 if (inheritedElement is MethodElement) { 1844 var needsSignature = getOverride(name, currentLibrary) == null ||
1838 needsSignature = 1845 elementToType(
1839 inheritedElement.getReifiedType(objectType) != reifiedType; 1846 lookup(name, library: currentLibrary, thisType: false)) !=
1840 } else { 1847 reifiedType;
1841 needsSignature = inheritedElement.type != reifiedType;
1842 }
1843 }
1844 1848
1845 if (needsSignature) { 1849 if (needsSignature) {
1846 var memberName = _declareMemberName(element); 1850 var memberName = _declareMemberName(element);
1847 var property = new JS.Property(memberName, type); 1851 var property = new JS.Property(memberName, type);
1848 tMember.add(property); 1852 tMember.add(property);
1849 // TODO(vsm): Why do we need this? 1853 // TODO(vsm): Why do we need this?
1850 if (node.isStatic && !node.isGetter && !node.isSetter) { 1854 if (node.isStatic && !node.isGetter && !node.isSetter) {
1851 sNames.add(memberName); 1855 sNames.add(memberName);
1852 } 1856 }
1853 } 1857 }
(...skipping 3995 matching lines...) Expand 10 before | Expand all | Expand 10 after
5849 if (targetIdentifier.staticElement is! PrefixElement) return false; 5853 if (targetIdentifier.staticElement is! PrefixElement) return false;
5850 var prefix = targetIdentifier.staticElement as PrefixElement; 5854 var prefix = targetIdentifier.staticElement as PrefixElement;
5851 5855
5852 // The library the prefix is referring to must come from a deferred import. 5856 // The library the prefix is referring to must come from a deferred import.
5853 var containingLibrary = resolutionMap 5857 var containingLibrary = resolutionMap
5854 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5858 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5855 .library; 5859 .library;
5856 var imports = containingLibrary.getImportsWithPrefix(prefix); 5860 var imports = containingLibrary.getImportsWithPrefix(prefix);
5857 return imports.length == 1 && imports[0].isDeferred; 5861 return imports.length == 1 && imports[0].isDeferred;
5858 } 5862 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698