@@ -53,25 +53,24 @@ class FlatTypeMask implements TypeMask {
53
53
/// Ensures that the generated mask is normalized, i.e., a call to
54
54
/// [TypeMask.assertIsNormalized] with the factory's result returns `true` .
55
55
factory FlatTypeMask .normalized (
56
- ClassEntity base , int flags, JClosedWorld world ) {
57
- if (base == world .commonElements.nullClass) {
56
+ ClassEntity base , int flags, CommonMasks domain ) {
57
+ if (base == domain .commonElements.nullClass) {
58
58
return FlatTypeMask .empty ();
59
59
}
60
60
if ((flags >> 1 ) == EMPTY || ((flags >> 1 ) == EXACT )) {
61
61
return new FlatTypeMask ._(base , flags);
62
62
}
63
63
if ((flags >> 1 ) == SUBTYPE ) {
64
- if (! world .classHierarchy.hasAnyStrictSubtype (base ) ||
65
- world .classHierarchy.hasOnlySubclasses (base )) {
64
+ if (! domain._closedWorld .classHierarchy.hasAnyStrictSubtype (base ) ||
65
+ domain._closedWorld .classHierarchy.hasOnlySubclasses (base )) {
66
66
flags = (flags & 0x1 ) | (SUBCLASS << 1 );
67
67
}
68
68
}
69
69
if (((flags >> 1 ) == SUBCLASS ) &&
70
- ! world .classHierarchy.hasAnyStrictSubclass (base )) {
70
+ ! domain._closedWorld .classHierarchy.hasAnyStrictSubclass (base )) {
71
71
flags = (flags & 0x1 ) | (EXACT << 1 );
72
72
}
73
- CommonMasks commonMasks = world.abstractValueDomain;
74
- return commonMasks.getCachedMask (
73
+ return domain.getCachedMask (
75
74
base , flags, () => new FlatTypeMask ._(base , flags));
76
75
}
77
76
@@ -298,37 +297,38 @@ class FlatTypeMask implements TypeMask {
298
297
}
299
298
300
299
@override
301
- TypeMask union (TypeMask other, JClosedWorld closedWorld) {
300
+ TypeMask union (TypeMask other, CommonMasks domain) {
301
+ JClosedWorld closedWorld = domain._closedWorld;
302
302
assert (other != null );
303
303
assert (TypeMask .assertIsNormalized (this , closedWorld));
304
304
assert (TypeMask .assertIsNormalized (other, closedWorld));
305
- if (other is ! FlatTypeMask ) return other.union (this , closedWorld );
305
+ if (other is ! FlatTypeMask ) return other.union (this , domain );
306
306
FlatTypeMask flatOther = other;
307
307
if (isEmptyOrNull) {
308
308
return isNullable ? flatOther.nullable () : flatOther;
309
309
} else if (flatOther.isEmptyOrNull) {
310
310
return flatOther.isNullable ? nullable () : this ;
311
311
} else if (base == flatOther.base ) {
312
- return unionSame (flatOther, closedWorld );
312
+ return unionSame (flatOther, domain );
313
313
} else if (closedWorld.classHierarchy.isSubclassOf (flatOther.base , base )) {
314
- return unionStrictSubclass (flatOther, closedWorld );
314
+ return unionStrictSubclass (flatOther, domain );
315
315
} else if (closedWorld.classHierarchy.isSubclassOf (base , flatOther.base )) {
316
- return flatOther.unionStrictSubclass (this , closedWorld );
316
+ return flatOther.unionStrictSubclass (this , domain );
317
317
} else if (closedWorld.classHierarchy.isSubtypeOf (flatOther.base , base )) {
318
- return unionStrictSubtype (flatOther, closedWorld );
318
+ return unionStrictSubtype (flatOther, domain );
319
319
} else if (closedWorld.classHierarchy.isSubtypeOf (base , flatOther.base )) {
320
- return flatOther.unionStrictSubtype (this , closedWorld );
320
+ return flatOther.unionStrictSubtype (this , domain );
321
321
} else {
322
322
return new UnionTypeMask ._internal (
323
323
< FlatTypeMask > [this .nonNullable (), flatOther.nonNullable ()],
324
324
isNullable || other.isNullable);
325
325
}
326
326
}
327
327
328
- TypeMask unionSame (FlatTypeMask other, JClosedWorld closedWorld ) {
328
+ TypeMask unionSame (FlatTypeMask other, CommonMasks domain ) {
329
329
assert (base == other.base );
330
- assert (TypeMask .assertIsNormalized (this , closedWorld ));
331
- assert (TypeMask .assertIsNormalized (other, closedWorld ));
330
+ assert (TypeMask .assertIsNormalized (this , domain._closedWorld ));
331
+ assert (TypeMask .assertIsNormalized (other, domain._closedWorld ));
332
332
// The two masks share the base type, so we must chose the least
333
333
// constraining kind (the highest) of the two. If either one of
334
334
// the masks are nullable the result should be nullable too.
@@ -341,18 +341,18 @@ class FlatTypeMask implements TypeMask {
341
341
} else if (other.flags == combined) {
342
342
return other;
343
343
} else {
344
- return new FlatTypeMask .normalized (base , combined, closedWorld );
344
+ return new FlatTypeMask .normalized (base , combined, domain );
345
345
}
346
346
}
347
347
348
- TypeMask unionStrictSubclass (FlatTypeMask other, JClosedWorld closedWorld ) {
348
+ TypeMask unionStrictSubclass (FlatTypeMask other, CommonMasks domain ) {
349
349
assert (base != other.base );
350
- assert (closedWorld .classHierarchy.isSubclassOf (other.base , base ));
351
- assert (TypeMask .assertIsNormalized (this , closedWorld ));
352
- assert (TypeMask .assertIsNormalized (other, closedWorld ));
350
+ assert (domain._closedWorld .classHierarchy.isSubclassOf (other.base , base ));
351
+ assert (TypeMask .assertIsNormalized (this , domain._closedWorld ));
352
+ assert (TypeMask .assertIsNormalized (other, domain._closedWorld ));
353
353
int combined;
354
354
if ((isExact && other.isExact) ||
355
- base == closedWorld .commonElements.objectClass) {
355
+ base == domain .commonElements.objectClass) {
356
356
// Since the other mask is a subclass of this mask, we need the
357
357
// resulting union to be a subclass too. If either one of the
358
358
// masks are nullable the result should be nullable too.
@@ -368,33 +368,33 @@ class FlatTypeMask implements TypeMask {
368
368
// If we weaken the constraint on this type, we have to make sure that
369
369
// the result is normalized.
370
370
return (flags != combined)
371
- ? new FlatTypeMask .normalized (base , combined, closedWorld )
371
+ ? new FlatTypeMask .normalized (base , combined, domain )
372
372
: this ;
373
373
}
374
374
375
- TypeMask unionStrictSubtype (FlatTypeMask other, JClosedWorld closedWorld ) {
375
+ TypeMask unionStrictSubtype (FlatTypeMask other, CommonMasks domain ) {
376
376
assert (base != other.base );
377
- assert (! closedWorld .classHierarchy.isSubclassOf (other.base , base ));
378
- assert (closedWorld .classHierarchy.isSubtypeOf (other.base , base ));
379
- assert (TypeMask .assertIsNormalized (this , closedWorld ));
380
- assert (TypeMask .assertIsNormalized (other, closedWorld ));
377
+ assert (! domain._closedWorld .classHierarchy.isSubclassOf (other.base , base ));
378
+ assert (domain._closedWorld .classHierarchy.isSubtypeOf (other.base , base ));
379
+ assert (TypeMask .assertIsNormalized (this , domain._closedWorld ));
380
+ assert (TypeMask .assertIsNormalized (other, domain._closedWorld ));
381
381
// Since the other mask is a subtype of this mask, we need the
382
382
// resulting union to be a subtype too. If either one of the masks
383
383
// are nullable the result should be nullable too.
384
384
int combined = (SUBTYPE << 1 ) | ((flags | other.flags) & 1 );
385
385
// We know there is at least one subtype, [other.base], so no need
386
386
// to normalize.
387
387
return (flags != combined)
388
- ? new FlatTypeMask .normalized (base , combined, closedWorld )
388
+ ? new FlatTypeMask .normalized (base , combined, domain )
389
389
: this ;
390
390
}
391
391
392
392
@override
393
- TypeMask intersection (TypeMask other, JClosedWorld closedWorld ) {
393
+ TypeMask intersection (TypeMask other, CommonMasks domain ) {
394
394
assert (other != null );
395
- if (other is ! FlatTypeMask ) return other.intersection (this , closedWorld );
396
- assert (TypeMask .assertIsNormalized (this , closedWorld ));
397
- assert (TypeMask .assertIsNormalized (other, closedWorld ));
395
+ if (other is ! FlatTypeMask ) return other.intersection (this , domain );
396
+ assert (TypeMask .assertIsNormalized (this , domain._closedWorld ));
397
+ assert (TypeMask .assertIsNormalized (other, domain._closedWorld ));
398
398
FlatTypeMask flatOther = other;
399
399
400
400
ClassEntity otherBase = flatOther.base ;
@@ -407,14 +407,12 @@ class FlatTypeMask implements TypeMask {
407
407
return includeNull ? other : other.nonNullable ();
408
408
}
409
409
410
- SubclassResult result = closedWorld .classHierarchy
410
+ SubclassResult result = domain._closedWorld .classHierarchy
411
411
.commonSubclasses (base , _classQuery, otherBase, flatOther._classQuery);
412
412
413
413
switch (result.kind) {
414
414
case SubclassResultKind .EMPTY :
415
- return includeNull
416
- ? closedWorld.abstractValueDomain.nullType
417
- : closedWorld.abstractValueDomain.emptyType;
415
+ return includeNull ? domain.nullType : domain.emptyType;
418
416
case SubclassResultKind .EXACT1 :
419
417
assert (isExact);
420
418
return includeNull ? this : nonNullable ();
@@ -436,20 +434,19 @@ class FlatTypeMask implements TypeMask {
436
434
case SubclassResultKind .SET :
437
435
default :
438
436
if (result.classes.isEmpty) {
439
- return includeNull
440
- ? closedWorld.abstractValueDomain.nullType
441
- : closedWorld.abstractValueDomain.emptyType;
437
+ return includeNull ? domain.nullType : domain.emptyType;
442
438
} else if (result.classes.length == 1 ) {
443
439
ClassEntity cls = result.classes.first;
444
440
return includeNull
445
- ? new TypeMask .subclass (cls, closedWorld )
446
- : new TypeMask .nonNullSubclass (cls, closedWorld );
441
+ ? new TypeMask .subclass (cls, domain._closedWorld )
442
+ : new TypeMask .nonNullSubclass (cls, domain._closedWorld );
447
443
}
448
444
449
445
List <FlatTypeMask > masks = List .from (result.classes.map (
450
- (ClassEntity cls) => TypeMask .nonNullSubclass (cls, closedWorld)));
446
+ (ClassEntity cls) =>
447
+ TypeMask .nonNullSubclass (cls, domain._closedWorld)));
451
448
if (masks.length > UnionTypeMask .MAX_UNION_LENGTH ) {
452
- return UnionTypeMask .flatten (masks, includeNull, closedWorld );
449
+ return UnionTypeMask .flatten (masks, includeNull, domain );
453
450
}
454
451
return new UnionTypeMask ._internal (masks, includeNull);
455
452
}
@@ -501,7 +498,7 @@ class FlatTypeMask implements TypeMask {
501
498
return true ;
502
499
}
503
500
504
- TypeMask intersectionSame (FlatTypeMask other, JClosedWorld closedWorld ) {
501
+ TypeMask intersectionSame (FlatTypeMask other, CommonMasks domain ) {
505
502
assert (base == other.base );
506
503
// The two masks share the base type, so we must chose the most
507
504
// constraining kind (the lowest) of the two. Only if both masks
@@ -515,14 +512,13 @@ class FlatTypeMask implements TypeMask {
515
512
} else if (other.flags == combined) {
516
513
return other;
517
514
} else {
518
- return new FlatTypeMask .normalized (base , combined, closedWorld );
515
+ return new FlatTypeMask .normalized (base , combined, domain );
519
516
}
520
517
}
521
518
522
- TypeMask intersectionStrictSubclass (
523
- FlatTypeMask other, JClosedWorld closedWorld) {
519
+ TypeMask intersectionStrictSubclass (FlatTypeMask other, CommonMasks domain) {
524
520
assert (base != other.base );
525
- assert (closedWorld .classHierarchy.isSubclassOf (other.base , base ));
521
+ assert (domain._closedWorld .classHierarchy.isSubclassOf (other.base , base ));
526
522
// If this mask isn't at least a subclass mask, then the
527
523
// intersection with the other mask is empty.
528
524
if (isExact) return intersectionEmpty (other);
@@ -535,7 +531,7 @@ class FlatTypeMask implements TypeMask {
535
531
if (other.flags == combined) {
536
532
return other;
537
533
} else {
538
- return new FlatTypeMask .normalized (other.base , combined, closedWorld );
534
+ return new FlatTypeMask .normalized (other.base , combined, domain );
539
535
}
540
536
}
541
537
0 commit comments