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

Unified Diff: pkg/dev_compiler/lib/src/compiler/type_utilities.dart

Issue 2969373002: fix #29028, understand promoted type parameters (Closed)
Patch Set: better fix Created 3 years, 5 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 | tests/language_strong/type_variable_promotion_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/type_utilities.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/type_utilities.dart b/pkg/dev_compiler/lib/src/compiler/type_utilities.dart
index 7632f08124f5eebde8a9a488025b40b4e8d656d0..1f1afa7b1513ac0b0e7f02b43e5ce7ce5198dd87 100644
--- a/pkg/dev_compiler/lib/src/compiler/type_utilities.dart
+++ b/pkg/dev_compiler/lib/src/compiler/type_utilities.dart
@@ -2,9 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'dart:collection' show HashMap, HashSet, LinkedHashMap;
-
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/src/dart/element/member.dart' show TypeParameterMember;
import 'package:analyzer/dart/element/type.dart';
import '../js_ast/js_ast.dart' as JS;
@@ -12,7 +11,7 @@ import '../js_ast/js_ast.dart' show js;
import 'js_names.dart' as JS;
Set<TypeParameterElement> freeTypeParameters(DartType t) {
- var result = new HashSet<TypeParameterElement>();
+ var result = new Set<TypeParameterElement>();
void find(DartType t) {
if (t is TypeParameterType) {
result.add(t.element);
@@ -37,7 +36,7 @@ class _CacheTable {
// Use a LinkedHashMap to maintain key insertion order so the generated code
// is stable under slight perturbation. (If this is not good enough we could
// sort by name to canonicalize order.)
- final _names = new LinkedHashMap<DartType, JS.TemporaryId>();
+ final _names = <DartType, JS.TemporaryId>{};
Iterable<DartType> get keys => _names.keys.toList();
JS.Statement _dischargeType(DartType type) {
@@ -120,7 +119,7 @@ class _CacheTable {
/// _GeneratorTable tracks types which have been
/// named and hoisted.
class _GeneratorTable extends _CacheTable {
- final _defs = new HashMap<DartType, JS.Expression>();
+ final _defs = <DartType, JS.Expression>{};
final JS.Identifier _runtimeModule;
@@ -167,8 +166,7 @@ class TypeTable {
/// cache/generator variables discharged at the binding site for the
/// type variable since the type definition depends on the type
/// parameter.
- final _scopeDependencies =
- new HashMap<TypeParameterElement, List<DartType>>();
+ final _scopeDependencies = <TypeParameterElement, List<DartType>>{};
TypeTable(JS.Identifier runtime)
: _generators = new _GeneratorTable(runtime),
@@ -191,22 +189,22 @@ class TypeTable {
/// Record the dependencies of the type on its free variables
bool recordScopeDependencies(DartType type) {
- var fvs = freeTypeParameters(type);
+ var freeVariables = freeTypeParameters(type);
// TODO(leafp): This is a hack to avoid trying to hoist out of
// generic functions and generic function types. This often degrades
// readability to little or no benefit. It would be good to do this
// when we know that we can hoist it to an outer scope, but for
// now we just disable it.
- if (fvs.any((i) => i.enclosingElement is FunctionTypedElement)) {
+ if (freeVariables.any((i) => i.enclosingElement is FunctionTypedElement)) {
return true;
}
- void addScope(TypeParameterElement i) {
- List<DartType> types = _scopeDependencies[i];
- if (types == null) _scopeDependencies[i] = types = [];
- types.add(type);
- }
- fvs.forEach(addScope);
+ for (var free in freeVariables) {
+ // If `free` is a promoted type parameter, get the original one so we can
+ // find it in our map.
+ var key = free is TypeParameterMember ? free.baseElement : free;
+ _scopeDependencies.putIfAbsent(key, () => []).add(type);
+ }
return false;
}
« no previous file with comments | « no previous file | tests/language_strong/type_variable_promotion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698