@@ -53,25 +53,24 @@ class FlatTypeMask implements TypeMask {
5353 /// Ensures that the generated mask is normalized, i.e., a call to
5454 /// [TypeMask.assertIsNormalized] with the factory's result returns `true` .
5555 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) {
5858 return FlatTypeMask .empty ();
5959 }
6060 if ((flags >> 1 ) == EMPTY || ((flags >> 1 ) == EXACT )) {
6161 return new FlatTypeMask ._(base , flags);
6262 }
6363 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 )) {
6666 flags = (flags & 0x1 ) | (SUBCLASS << 1 );
6767 }
6868 }
6969 if (((flags >> 1 ) == SUBCLASS ) &&
70- ! world .classHierarchy.hasAnyStrictSubclass (base )) {
70+ ! domain._closedWorld .classHierarchy.hasAnyStrictSubclass (base )) {
7171 flags = (flags & 0x1 ) | (EXACT << 1 );
7272 }
73- CommonMasks commonMasks = world.abstractValueDomain;
74- return commonMasks.getCachedMask (
73+ return domain.getCachedMask (
7574 base , flags, () => new FlatTypeMask ._(base , flags));
7675 }
7776
@@ -298,37 +297,38 @@ class FlatTypeMask implements TypeMask {
298297 }
299298
300299 @override
301- TypeMask union (TypeMask other, JClosedWorld closedWorld) {
300+ TypeMask union (TypeMask other, CommonMasks domain) {
301+ JClosedWorld closedWorld = domain._closedWorld;
302302 assert (other != null );
303303 assert (TypeMask .assertIsNormalized (this , closedWorld));
304304 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 );
306306 FlatTypeMask flatOther = other;
307307 if (isEmptyOrNull) {
308308 return isNullable ? flatOther.nullable () : flatOther;
309309 } else if (flatOther.isEmptyOrNull) {
310310 return flatOther.isNullable ? nullable () : this ;
311311 } else if (base == flatOther.base ) {
312- return unionSame (flatOther, closedWorld );
312+ return unionSame (flatOther, domain );
313313 } else if (closedWorld.classHierarchy.isSubclassOf (flatOther.base , base )) {
314- return unionStrictSubclass (flatOther, closedWorld );
314+ return unionStrictSubclass (flatOther, domain );
315315 } else if (closedWorld.classHierarchy.isSubclassOf (base , flatOther.base )) {
316- return flatOther.unionStrictSubclass (this , closedWorld );
316+ return flatOther.unionStrictSubclass (this , domain );
317317 } else if (closedWorld.classHierarchy.isSubtypeOf (flatOther.base , base )) {
318- return unionStrictSubtype (flatOther, closedWorld );
318+ return unionStrictSubtype (flatOther, domain );
319319 } else if (closedWorld.classHierarchy.isSubtypeOf (base , flatOther.base )) {
320- return flatOther.unionStrictSubtype (this , closedWorld );
320+ return flatOther.unionStrictSubtype (this , domain );
321321 } else {
322322 return new UnionTypeMask ._internal (
323323 < FlatTypeMask > [this .nonNullable (), flatOther.nonNullable ()],
324324 isNullable || other.isNullable);
325325 }
326326 }
327327
328- TypeMask unionSame (FlatTypeMask other, JClosedWorld closedWorld ) {
328+ TypeMask unionSame (FlatTypeMask other, CommonMasks domain ) {
329329 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 ));
332332 // The two masks share the base type, so we must chose the least
333333 // constraining kind (the highest) of the two. If either one of
334334 // the masks are nullable the result should be nullable too.
@@ -341,18 +341,18 @@ class FlatTypeMask implements TypeMask {
341341 } else if (other.flags == combined) {
342342 return other;
343343 } else {
344- return new FlatTypeMask .normalized (base , combined, closedWorld );
344+ return new FlatTypeMask .normalized (base , combined, domain );
345345 }
346346 }
347347
348- TypeMask unionStrictSubclass (FlatTypeMask other, JClosedWorld closedWorld ) {
348+ TypeMask unionStrictSubclass (FlatTypeMask other, CommonMasks domain ) {
349349 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 ));
353353 int combined;
354354 if ((isExact && other.isExact) ||
355- base == closedWorld .commonElements.objectClass) {
355+ base == domain .commonElements.objectClass) {
356356 // Since the other mask is a subclass of this mask, we need the
357357 // resulting union to be a subclass too. If either one of the
358358 // masks are nullable the result should be nullable too.
@@ -368,33 +368,33 @@ class FlatTypeMask implements TypeMask {
368368 // If we weaken the constraint on this type, we have to make sure that
369369 // the result is normalized.
370370 return (flags != combined)
371- ? new FlatTypeMask .normalized (base , combined, closedWorld )
371+ ? new FlatTypeMask .normalized (base , combined, domain )
372372 : this ;
373373 }
374374
375- TypeMask unionStrictSubtype (FlatTypeMask other, JClosedWorld closedWorld ) {
375+ TypeMask unionStrictSubtype (FlatTypeMask other, CommonMasks domain ) {
376376 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 ));
381381 // Since the other mask is a subtype of this mask, we need the
382382 // resulting union to be a subtype too. If either one of the masks
383383 // are nullable the result should be nullable too.
384384 int combined = (SUBTYPE << 1 ) | ((flags | other.flags) & 1 );
385385 // We know there is at least one subtype, [other.base], so no need
386386 // to normalize.
387387 return (flags != combined)
388- ? new FlatTypeMask .normalized (base , combined, closedWorld )
388+ ? new FlatTypeMask .normalized (base , combined, domain )
389389 : this ;
390390 }
391391
392392 @override
393- TypeMask intersection (TypeMask other, JClosedWorld closedWorld ) {
393+ TypeMask intersection (TypeMask other, CommonMasks domain ) {
394394 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 ));
398398 FlatTypeMask flatOther = other;
399399
400400 ClassEntity otherBase = flatOther.base ;
@@ -407,14 +407,12 @@ class FlatTypeMask implements TypeMask {
407407 return includeNull ? other : other.nonNullable ();
408408 }
409409
410- SubclassResult result = closedWorld .classHierarchy
410+ SubclassResult result = domain._closedWorld .classHierarchy
411411 .commonSubclasses (base , _classQuery, otherBase, flatOther._classQuery);
412412
413413 switch (result.kind) {
414414 case SubclassResultKind .EMPTY :
415- return includeNull
416- ? closedWorld.abstractValueDomain.nullType
417- : closedWorld.abstractValueDomain.emptyType;
415+ return includeNull ? domain.nullType : domain.emptyType;
418416 case SubclassResultKind .EXACT1 :
419417 assert (isExact);
420418 return includeNull ? this : nonNullable ();
@@ -436,20 +434,19 @@ class FlatTypeMask implements TypeMask {
436434 case SubclassResultKind .SET :
437435 default :
438436 if (result.classes.isEmpty) {
439- return includeNull
440- ? closedWorld.abstractValueDomain.nullType
441- : closedWorld.abstractValueDomain.emptyType;
437+ return includeNull ? domain.nullType : domain.emptyType;
442438 } else if (result.classes.length == 1 ) {
443439 ClassEntity cls = result.classes.first;
444440 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 );
447443 }
448444
449445 List <FlatTypeMask > masks = List .from (result.classes.map (
450- (ClassEntity cls) => TypeMask .nonNullSubclass (cls, closedWorld)));
446+ (ClassEntity cls) =>
447+ TypeMask .nonNullSubclass (cls, domain._closedWorld)));
451448 if (masks.length > UnionTypeMask .MAX_UNION_LENGTH ) {
452- return UnionTypeMask .flatten (masks, includeNull, closedWorld );
449+ return UnionTypeMask .flatten (masks, includeNull, domain );
453450 }
454451 return new UnionTypeMask ._internal (masks, includeNull);
455452 }
@@ -501,7 +498,7 @@ class FlatTypeMask implements TypeMask {
501498 return true ;
502499 }
503500
504- TypeMask intersectionSame (FlatTypeMask other, JClosedWorld closedWorld ) {
501+ TypeMask intersectionSame (FlatTypeMask other, CommonMasks domain ) {
505502 assert (base == other.base );
506503 // The two masks share the base type, so we must chose the most
507504 // constraining kind (the lowest) of the two. Only if both masks
@@ -515,14 +512,13 @@ class FlatTypeMask implements TypeMask {
515512 } else if (other.flags == combined) {
516513 return other;
517514 } else {
518- return new FlatTypeMask .normalized (base , combined, closedWorld );
515+ return new FlatTypeMask .normalized (base , combined, domain );
519516 }
520517 }
521518
522- TypeMask intersectionStrictSubclass (
523- FlatTypeMask other, JClosedWorld closedWorld) {
519+ TypeMask intersectionStrictSubclass (FlatTypeMask other, CommonMasks domain) {
524520 assert (base != other.base );
525- assert (closedWorld .classHierarchy.isSubclassOf (other.base , base ));
521+ assert (domain._closedWorld .classHierarchy.isSubclassOf (other.base , base ));
526522 // If this mask isn't at least a subclass mask, then the
527523 // intersection with the other mask is empty.
528524 if (isExact) return intersectionEmpty (other);
@@ -535,7 +531,7 @@ class FlatTypeMask implements TypeMask {
535531 if (other.flags == combined) {
536532 return other;
537533 } else {
538- return new FlatTypeMask .normalized (other.base , combined, closedWorld );
534+ return new FlatTypeMask .normalized (other.base , combined, domain );
539535 }
540536 }
541537
0 commit comments