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

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

Issue 2625913003: Defer all recursive mixins (Closed)
Patch Set: 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 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 return new JS.ClassExpression(new JS.Identifier(name), heritage, methods, 1241 return new JS.ClassExpression(new JS.Identifier(name), heritage, methods,
1242 typeParams: typeParams, fields: jsFields); 1242 typeParams: typeParams, fields: jsFields);
1243 } 1243 }
1244 1244
1245 JS.Expression _emitClassHeritage(ClassElement element) { 1245 JS.Expression _emitClassHeritage(ClassElement element) {
1246 var type = element.type; 1246 var type = element.type;
1247 if (type.isObject) return null; 1247 if (type.isObject) return null;
1248 1248
1249 _loader.startTopLevel(element); 1249 _loader.startTopLevel(element);
1250 1250
1251 // Find the super type 1251 // List of "direct" supertypes (supertype + mixins)
1252 JS.Expression heritage; 1252 var basetypes = [ type.superclass ]..addAll(type.mixins);
Jennifer Messerly 2017/01/11 18:11:47 nit: run dart format
vsm 2017/01/11 18:33:00 Done.
1253 var supertype = type.superclass; 1253
1254 if (_deferIfNeeded(supertype, element)) { 1254 // If any of these are recursive (via type parameter), defer setting
1255 // Fall back to raw type. 1255 // the real superclass.
1256 supertype = fillDynamicTypeArgs(supertype.element.type); 1256 if (basetypes.any((t) => _deferIfNeeded(t, element))) {
Jennifer Messerly 2017/01/11 18:11:47 alternatively, could do this: var baseTypes = <Da
vsm 2017/01/11 18:33:00 We also don't need to fill in dynamic for all type
1257 // Fall back to raw type
1258 basetypes = basetypes.map((t) => fillDynamicTypeArgs(t.element.type)).toLi st();
1257 _hasDeferredSupertype.add(element); 1259 _hasDeferredSupertype.add(element);
1258 } 1260 }
1259 // We could choose to name the superclasses, but it's
1260 // not clear that there's much benefit
1261 heritage = _emitType(supertype, nameType: false);
1262 1261
1263 if (type.mixins.isNotEmpty) { 1262 // List of "direct" JS superclasses
1264 var mixins = 1263 var baseclasses = basetypes.map((t) => _emitType(t, nameType: false)).toList ();
1265 type.mixins.map((t) => _emitType(t, nameType: false)).toList(); 1264 assert(baseclasses.isNotEmpty);
1266 mixins.insert(0, heritage); 1265 var heritage = (baseclasses.length == 1) ? baseclasses.first : _callHelper( 'mixin(#)', [baseclasses]);
1267 heritage = _callHelper('mixin(#)', [mixins]);
1268 }
1269 1266
1270 _loader.finishTopLevel(element); 1267 _loader.finishTopLevel(element);
1271 1268
1272 return heritage; 1269 return heritage;
1273 } 1270 }
1274 1271
1275 /// Provide Dart getters and setters that forward to the underlying native 1272 /// Provide Dart getters and setters that forward to the underlying native
1276 /// field. Note that the Dart names are always symbolized to avoid 1273 /// field. Note that the Dart names are always symbolized to avoid
1277 /// conflicts. They will be installed as extension methods on the underlying 1274 /// conflicts. They will be installed as extension methods on the underlying
1278 /// native type. 1275 /// native type.
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 JS.Statement _setBaseClass(ClassElement classElem, JS.Expression className, 1671 JS.Statement _setBaseClass(ClassElement classElem, JS.Expression className,
1675 List<String> jsPeerNames, List<JS.Statement> body) { 1672 List<String> jsPeerNames, List<JS.Statement> body) {
1676 var typeFormals = classElem.typeParameters; 1673 var typeFormals = classElem.typeParameters;
1677 if (jsPeerNames.isNotEmpty && typeFormals.isNotEmpty) { 1674 if (jsPeerNames.isNotEmpty && typeFormals.isNotEmpty) {
1678 for (var peer in jsPeerNames) { 1675 for (var peer in jsPeerNames) {
1679 // TODO(jmesserly): we should just extend Array in the first place 1676 // TODO(jmesserly): we should just extend Array in the first place
1680 var newBaseClass = _callHelper('global.#', [peer]); 1677 var newBaseClass = _callHelper('global.#', [peer]);
1681 body.add(_callHelperStatement( 1678 body.add(_callHelperStatement(
1682 'setExtensionBaseClass(#, #);', [className, newBaseClass])); 1679 'setExtensionBaseClass(#, #);', [className, newBaseClass]));
1683 } 1680 }
1684 } else if (_hasDeferredSupertype.contains(classElem)) { 1681 } else if (_hasDeferredSupertype.contains(classElem)) {
Jennifer Messerly 2017/01/11 18:11:47 incidentally ... this isn't caused by your change,
vsm 2017/01/11 18:33:00 Added a comment. _emitClassHeritage/_emitClassExp
1685 var newBaseClass = _emitType(classElem.type.superclass, 1682 var newBaseClass = _emitType(classElem.type.superclass,
1686 nameType: false, subClass: classElem, className: className); 1683 nameType: false, subClass: classElem, className: className);
1684 if (classElem.type.mixins.isNotEmpty) {
1685 var mixins =
1686 classElem.type.mixins.map((t) => _emitType(t, nameType: false)).toLi st();
1687 mixins.insert(0, newBaseClass);
1688 newBaseClass = _callHelper('mixin(#)', [mixins]);
1689 }
1687 var deferredBaseClass = _callHelperStatement( 1690 var deferredBaseClass = _callHelperStatement(
1688 'setBaseClass(#, #);', [className, newBaseClass]); 1691 'setBaseClass(#, #);', [className, newBaseClass]);
1689 if (typeFormals.isNotEmpty) return deferredBaseClass; 1692 if (typeFormals.isNotEmpty) return deferredBaseClass;
1690 body.add(deferredBaseClass); 1693 body.add(deferredBaseClass);
1691 } 1694 }
1692 return null; 1695 return null;
1693 } 1696 }
1694 1697
1695 void _defineNamedConstructors(List<ConstructorDeclaration> ctors, 1698 void _defineNamedConstructors(List<ConstructorDeclaration> ctors,
1696 List<JS.Statement> body, JS.Expression className, bool isCallable) { 1699 List<JS.Statement> body, JS.Expression className, bool isCallable) {
(...skipping 4116 matching lines...) Expand 10 before | Expand all | Expand 10 after
5813 if (targetIdentifier.staticElement is! PrefixElement) return false; 5816 if (targetIdentifier.staticElement is! PrefixElement) return false;
5814 var prefix = targetIdentifier.staticElement as PrefixElement; 5817 var prefix = targetIdentifier.staticElement as PrefixElement;
5815 5818
5816 // The library the prefix is referring to must come from a deferred import. 5819 // The library the prefix is referring to must come from a deferred import.
5817 var containingLibrary = resolutionMap 5820 var containingLibrary = resolutionMap
5818 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5821 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5819 .library; 5822 .library;
5820 var imports = containingLibrary.getImportsWithPrefix(prefix); 5823 var imports = containingLibrary.getImportsWithPrefix(prefix);
5821 return imports.length == 1 && imports[0].isDeferred; 5824 return imports.length == 1 && imports[0].isDeferred;
5822 } 5825 }
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