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

Unified Diff: lib/src/compiler/code_generator.dart

Issue 1958193002: optimize self-references in generic type definitions (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/codegen/language/generic_self_reference_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index f758d14bbcabe38bcf874d80a1988036442dae46..372f8157fb89c3c344950278dd983c3a3a38ccc0 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -1051,7 +1051,8 @@ class CodeGenerator extends GeneralizingAstVisitor
// TODO(jmesserly): we should really just extend Array in the first place.
newBaseClass = js.call('dart.global.#', [jsPeerName]);
} else if (_hasDeferredSupertype.contains(classElem)) {
- newBaseClass = _emitTypeName(classElem.type.superclass);
+ newBaseClass = _emitTypeName(classElem.type.superclass,
+ subClass: classElem, className: className);
}
if (newBaseClass != null) {
body.add(
@@ -2221,8 +2222,15 @@ class CodeGenerator extends GeneralizingAstVisitor
/// function type. Similarly if [lowerGeneric] is set, the `List$()` form
/// will be used instead of `List`. These flags are used when generating
/// the definitions for typedefs and generic types, respectively.
+ ///
+ /// If [subClass] is set, then we are setting the base class for the given
+ /// class and should emit the given [className], which will already be
+ /// defined.
JS.Expression _emitTypeName(DartType type,
- {bool lowerTypedef: false, bool lowerGeneric: false}) {
+ {bool lowerTypedef: false,
+ bool lowerGeneric: false,
+ ClassElement subClass,
Harry Terkelsen 2016/05/09 18:04:19 had to add 2 named args just for this one case :(
Jennifer Messerly 2016/05/09 18:16:36 Hmmm. You could pass it down as a function from `(
+ JS.Expression className}) {
// The void and dynamic types are not defined in core.
if (type.isVoid) {
return js.call('dart.void');
@@ -2252,11 +2260,16 @@ class CodeGenerator extends GeneralizingAstVisitor
return new JS.Identifier(name);
}
+ if (type == subClass?.type) {
+ return className;
+ }
+
if (type is ParameterizedType) {
var args = type.typeArguments;
Iterable jsArgs = null;
if (args.any((a) => !a.isDynamic)) {
- jsArgs = args.map(_emitTypeName);
+ jsArgs = args.map(
+ (x) => _emitTypeName(x, subClass: subClass, className: className));
} else if (lowerGeneric) {
jsArgs = [];
}
« no previous file with comments | « no previous file | test/codegen/language/generic_self_reference_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698