@@ -21,10 +21,17 @@ import 'native_data.dart';
2121import 'runtime_types_codegen.dart' show RuntimeTypesSubstitutions;
2222import 'runtime_types_resolution.dart' show RuntimeTypesNeed;
2323
24+ class RecipeEncoding {
25+ final jsAst.Literal recipe;
26+ final Set <TypeVariableType > typeVariables;
27+
28+ const RecipeEncoding (this .recipe, this .typeVariables);
29+ }
30+
2431abstract class RecipeEncoder {
25- /// Returns a [jsAst.Literal ] representing the given [recipe] to be
32+ /// Returns a [RecipeEncoding ] representing the given [recipe] to be
2633 /// evaluated against a type environment with shape [structure] .
27- jsAst. Literal encodeRecipe (ModularEmitter emitter,
34+ RecipeEncoding encodeRecipe (ModularEmitter emitter,
2835 TypeEnvironmentStructure environmentStructure, TypeRecipe recipe);
2936
3037 jsAst.Literal encodeGroundRecipe (ModularEmitter emitter, TypeRecipe recipe);
@@ -67,22 +74,23 @@ class RecipeEncoderImpl implements RecipeEncoder {
6774 this ._elementEnvironment, this .commonElements, this ._rtiNeed);
6875
6976 @override
70- jsAst. Literal encodeRecipe (ModularEmitter emitter,
77+ RecipeEncoding encodeRecipe (ModularEmitter emitter,
7178 TypeEnvironmentStructure environmentStructure, TypeRecipe recipe) {
7279 return _RecipeGenerator (this , emitter, environmentStructure, recipe).run ();
7380 }
7481
7582 @override
7683 jsAst.Literal encodeGroundRecipe (ModularEmitter emitter, TypeRecipe recipe) {
77- return _RecipeGenerator (this , emitter, null , recipe).run ();
84+ return _RecipeGenerator (this , emitter, null , recipe).run ().recipe ;
7885 }
7986
8087 @override
8188 jsAst.Literal encodeRecipeWithVariablesReplaceByAny (
8289 ModularEmitter emitter, DartType dartType) {
8390 return _RecipeGenerator (this , emitter, null , TypeExpressionRecipe (dartType),
8491 hackTypeVariablesToAny: true )
85- .run ();
92+ .run ()
93+ .recipe;
8694 }
8795
8896 @override
@@ -94,7 +102,8 @@ class RecipeEncoderImpl implements RecipeEncoder {
94102 FullTypeEnvironmentStructure (classType: declaringType),
95103 TypeExpressionRecipe (supertypeArgument),
96104 indexTypeVariablesOnDeclaringClass: true )
97- .run ();
105+ .run ()
106+ .recipe;
98107 }
99108
100109 @override
@@ -125,6 +134,7 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
125134 final bool hackTypeVariablesToAny;
126135
127136 final List <FunctionTypeVariable > functionTypeVariables = [];
137+ final Set <TypeVariableType > typeVariables = {};
128138
129139 // Accumulated recipe.
130140 final List <jsAst.Literal > _fragments = [];
@@ -139,15 +149,19 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
139149 NativeBasicData get _nativeData => _encoder._nativeData;
140150 RuntimeTypesSubstitutions get _rtiSubstitutions => _encoder._rtiSubstitutions;
141151
142- jsAst.Literal run () {
152+ RecipeEncoding _finishEncoding (jsAst.Literal literal) =>
153+ RecipeEncoding (literal, typeVariables);
154+
155+ RecipeEncoding run () {
143156 _start (_recipe);
144157 assert (functionTypeVariables.isEmpty);
145158 if (_fragments.isEmpty) {
146- return js.string (String .fromCharCodes (_codes));
159+ return _finishEncoding ( js.string (String .fromCharCodes (_codes) ));
147160 }
148161 _flushCodes ();
149162 jsAst.LiteralString quote = jsAst.LiteralString ('"' );
150- return jsAst.StringConcatenation ([quote, ..._fragments, quote]);
163+ return _finishEncoding (
164+ jsAst.StringConcatenation ([quote, ..._fragments, quote]));
151165 }
152166
153167 void _start (TypeRecipe recipe) {
@@ -261,6 +275,7 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
261275 }
262276 jsAst.Name name = _emitter.typeVariableAccessNewRti (type.element);
263277 _emitName (name);
278+ typeVariables.add (type);
264279 return ;
265280 }
266281 // TODO(sra): Handle missing cases. This just emits some readable junk. The
@@ -449,9 +464,10 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
449464class _RulesetEntry {
450465 final InterfaceType _targetType;
451466 List <InterfaceType > _supertypes;
452- Map <TypeVariableType , DartType > _typeVariables = {} ;
467+ Map <TypeVariableType , DartType > _typeVariables;
453468
454- _RulesetEntry (this ._targetType, Iterable <InterfaceType > supertypes)
469+ _RulesetEntry (
470+ this ._targetType, Iterable <InterfaceType > supertypes, this ._typeVariables)
455471 : _supertypes = supertypes.toList ();
456472
457473 bool get isEmpty => _supertypes.isEmpty && _typeVariables.isEmpty;
@@ -463,8 +479,9 @@ class Ruleset {
463479 Ruleset (this ._entries);
464480 Ruleset .empty () : this ([]);
465481
466- void add (InterfaceType targetType, Iterable <InterfaceType > supertypes) =>
467- _entries.add (_RulesetEntry (targetType, supertypes));
482+ void add (InterfaceType targetType, Iterable <InterfaceType > supertypes,
483+ Map <TypeVariableType , DartType > typeVariables) =>
484+ _entries.add (_RulesetEntry (targetType, supertypes, typeVariables));
468485}
469486
470487class RulesetEncoder {
@@ -487,23 +504,9 @@ class RulesetEncoder {
487504
488505 bool _isObject (InterfaceType type) => identical (type.element, _objectClass);
489506
490- void _preprocessSupertype (_RulesetEntry entry, InterfaceType supertype) {
491- InterfaceType thisSupertype = _dartTypes.getThisType (supertype.element);
492- List <DartType > typeVariables = thisSupertype.typeArguments;
493- List <DartType > supertypeArguments = supertype.typeArguments;
494- int length = typeVariables.length;
495- assert (supertypeArguments.length == length);
496- for (int i = 0 ; i < length; i++ ) {
497- entry._typeVariables[typeVariables[i]] = supertypeArguments[i];
498- }
499- }
500-
501507 void _preprocessEntry (_RulesetEntry entry) {
502- entry._supertypes.removeWhere (_isObject);
503- entry._supertypes.forEach (
504- (InterfaceType supertype) => _preprocessSupertype (entry, supertype));
505- entry._supertypes.removeWhere (
506- (InterfaceType supertype) => identical (entry._targetType, supertype));
508+ entry._supertypes.removeWhere ((InterfaceType supertype) =>
509+ _isObject (supertype) || identical (entry._targetType, supertype));
507510 }
508511
509512 void _preprocessRuleset (Ruleset ruleset) {
0 commit comments