@@ -141,8 +141,6 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
141
141
final List <jsAst.Literal > _fragments = [];
142
142
final List <int > _codes = [];
143
143
144
- RuntimeTypesNeed get _rtiNeed => _encoder._rtiNeed;
145
-
146
144
_RecipeGenerator (
147
145
this ._encoder, this ._emitter, this ._environment, this ._recipe,
148
146
{this .metadata = false , this .hackTypeVariablesToAny = false });
@@ -260,26 +258,14 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
260
258
}
261
259
}
262
260
if (environment is FullTypeEnvironmentStructure ) {
263
- int i = environment.bindings.indexOf (type);
264
- if (i >= 0 ) {
265
- // Indexes are 1-based since '0' encodes using the entire type for the
266
- // singleton structure.
267
- _emitInteger (i + 1 );
268
- return ;
269
- }
270
-
271
- int index = _indexIntoClassTypeVariables (type);
261
+ int index = indexTypeVariable (
262
+ _closedWorld, _rtiSubstitutions, environment, type,
263
+ metadata: metadata);
272
264
if (index != null ) {
273
- // We should only observe erased type arguments if we're generating
274
- // subtype metadata.
275
- assert (metadata ||
276
- _rtiNeed.classNeedsTypeArguments (environment.classType.element));
277
-
278
- // Indexed class type variables come after the bound function type
279
- // variables.
280
- _emitInteger (1 + environment.bindings.length + index);
265
+ _emitInteger (index);
281
266
return ;
282
267
}
268
+
283
269
jsAst.Name name = _emitter.typeVariableAccessNewRti (type.element);
284
270
_emitName (name);
285
271
typeVariables.add (type);
@@ -290,35 +276,6 @@ class _RecipeGenerator implements DartTypeVisitor<void, void> {
290
276
'`$type `' .codeUnits.forEach (_emitCode);
291
277
}
292
278
293
- int /*?*/ _indexIntoClassTypeVariables (TypeVariableType variable) {
294
- TypeVariableEntity element = variable.element;
295
- ClassEntity cls = element.typeDeclaration;
296
-
297
- if (metadata) {
298
- TypeEnvironmentStructure environment = _environment;
299
- if (environment is FullTypeEnvironmentStructure ) {
300
- if (identical (environment.classType.element, cls)) {
301
- return element.index;
302
- }
303
- }
304
- }
305
-
306
- // TODO(sra): We might be in a context where the class type variable has an
307
- // index, even though in the general case it is not at a specific index.
308
-
309
- ClassHierarchy classHierarchy = _closedWorld.classHierarchy;
310
- var test = mustCheckAllSubtypes (_closedWorld, cls)
311
- ? classHierarchy.anyStrictSubtypeOf
312
- : classHierarchy.anyStrictSubclassOf;
313
-
314
- if (test (cls, (ClassEntity subclass) {
315
- return ! _rtiSubstitutions.isTrivialSubstitution (subclass, cls);
316
- })) {
317
- return null ;
318
- }
319
- return element.index;
320
- }
321
-
322
279
@override
323
280
void visitFunctionTypeVariable (FunctionTypeVariable type, _) {
324
281
int position = functionTypeVariables.indexOf (type);
@@ -479,6 +436,49 @@ bool mustCheckAllSubtypes(JClosedWorld world, ClassEntity cls) =>
479
436
world.isUsedAsMixin (cls) ||
480
437
world.extractTypeArgumentsInterfacesNewRti.contains (cls);
481
438
439
+ int indexTypeVariable (
440
+ JClosedWorld world,
441
+ RuntimeTypesSubstitutions rtiSubstitutions,
442
+ FullTypeEnvironmentStructure environment,
443
+ TypeVariableType type,
444
+ {bool metadata = false }) {
445
+ int i = environment.bindings.indexOf (type);
446
+ if (i >= 0 ) {
447
+ // Indices are 1-based since '0' encodes using the entire type for the
448
+ // singleton structure.
449
+ return i + 1 ;
450
+ }
451
+
452
+ TypeVariableEntity element = type.element;
453
+ ClassEntity cls = element.typeDeclaration;
454
+
455
+ if (metadata) {
456
+ if (identical (environment.classType.element, cls)) {
457
+ // Indexed class type variables come after the bound function type
458
+ // variables.
459
+ return 1 + environment.bindings.length + element.index;
460
+ }
461
+ }
462
+
463
+ // TODO(sra): We might be in a context where the class type variable has an
464
+ // index, even though in the general case it is not at a specific index.
465
+
466
+ ClassHierarchy classHierarchy = world.classHierarchy;
467
+ var test = mustCheckAllSubtypes (world, cls)
468
+ ? classHierarchy.anyStrictSubtypeOf
469
+ : classHierarchy.anyStrictSubclassOf;
470
+ if (test (cls, (ClassEntity subclass) {
471
+ return ! rtiSubstitutions.isTrivialSubstitution (subclass, cls);
472
+ })) {
473
+ return null ;
474
+ }
475
+
476
+ assert (world.rtiNeed.classNeedsTypeArguments (environment.classType.element));
477
+ // Indexed class type variables come after the bound function type
478
+ // variables.
479
+ return 1 + environment.bindings.length + element.index;
480
+ }
481
+
482
482
class _RulesetEntry {
483
483
Set <InterfaceType > _supertypes = {};
484
484
Map <TypeVariableType , DartType > _typeVariables = {};
0 commit comments