Move TypeMask cache to CommonMasks

Change-Id: I908046245f822079dab41421b868a8cc786c9745
Reviewed-on: https://dart-review.googlesource.com/55463
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2018-05-17 08:05:42 +00:00 committed by commit-bot@chromium.org
parent 78f348b3d5
commit 54173bf293
3 changed files with 16 additions and 18 deletions

View file

@ -62,7 +62,8 @@ class FlatTypeMask implements TypeMask {
if (((flags >> 1) == SUBCLASS) && !world.hasAnyStrictSubclass(base)) {
flags = (flags & 0x1) | (EXACT << 1);
}
return world.getCachedMask(
CommonMasks commonMasks = world.abstractValueDomain;
return commonMasks.getCachedMask(
base, flags, () => new FlatTypeMask.internal(base, flags));
}

View file

@ -66,6 +66,19 @@ class CommonMasks implements AbstractValueDomain {
TypeMask _unmodifiableArrayType;
TypeMask _interceptorType;
/// Cache of [FlatTypeMask]s grouped by the 8 possible values of the
/// `FlatTypeMask.flags` property.
final List<Map<ClassEntity, TypeMask>> _canonicalizedTypeMasks =
new List<Map<ClassEntity, TypeMask>>.filled(8, null);
/// Return the cached mask for [base] with the given flags, or
/// calls [createMask] to create the mask and cache it.
TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask()) {
Map<ClassEntity, TypeMask> cachedMasks =
_canonicalizedTypeMasks[flags] ??= <ClassEntity, TypeMask>{};
return cachedMasks.putIfAbsent(base, createMask);
}
TypeMask get dynamicType => _dynamicType ??= new TypeMask.subclass(
_closedWorld.commonElements.objectClass, _closedWorld);

View file

@ -20,7 +20,7 @@ import 'js_backend/runtime_types.dart'
import 'ordered_typeset.dart';
import 'options.dart';
import 'types/abstract_value_domain.dart';
import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask;
import 'types/masks.dart' show CommonMasks, TypeMask;
import 'universe/class_set.dart';
import 'universe/function_set.dart' show FunctionSet;
import 'universe/selector.dart' show Selector;
@ -279,11 +279,6 @@ abstract class ClosedWorld implements World {
/// methods defined in [ClosedWorld].
ClassSet getClassSet(ClassEntity cls);
/// Return the cached mask for [base] with the given flags, or
/// calls [createMask] to create the mask and cache it.
// TODO(johnniwinther): Find a better strategy for caching these?
TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask());
/// Returns `true` if the field [element] is known to be effectively final.
bool fieldNeverChanges(MemberEntity element);
@ -514,21 +509,10 @@ abstract class ClosedWorldBase implements ClosedWorld, ClosedWorldRefiner {
@override
ClosedWorld get closedWorld => this;
/// Cache of [FlatTypeMask]s grouped by the 8 possible values of the
/// `FlatTypeMask.flags` property.
final List<Map<ClassEntity, TypeMask>> _canonicalizedTypeMasks =
new List<Map<ClassEntity, TypeMask>>.filled(8, null);
CommonMasks get abstractValueDomain {
return _commonMasks;
}
TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask()) {
Map<ClassEntity, TypeMask> cachedMasks =
_canonicalizedTypeMasks[flags] ??= <ClassEntity, TypeMask>{};
return cachedMasks.putIfAbsent(base, createMask);
}
bool checkEntity(covariant Entity element);
bool checkClass(covariant ClassEntity cls);