Skip to content

Commit 83db399

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2js] Fix DictionaryTypeMask hashCode and == consistency.
The serializer uses these to cache instances of DictionaryTypeMask for indexing. If these produce inconsistent results we can end up with different caching patterns leading to different serialized outputs. Change-Id: I8550f6fc1cb2bb32a68b3274e6add2e7ee56930d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403483 Auto-Submit: Nate Biggs <[email protected]> Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Mayank Patke <[email protected]>
1 parent 85727ca commit 83db399

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/compiler/lib/src/inferrer/typemasks/dictionary_type_mask.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ class DictionaryTypeMask extends MapTypeMask {
144144
if (identical(this, other)) return true;
145145
if (other is! DictionaryTypeMask) return false;
146146
return super == other &&
147-
_typeMap.keys.every((k) => other._typeMap.containsKey(k)) &&
148-
other._typeMap.keys.every(
149-
(k) => _typeMap.containsKey(k) && _typeMap[k] == other._typeMap[k],
150-
);
147+
const MapEquality<String, TypeMask>().equals(_typeMap, other._typeMap);
151148
}
152149

153150
@override
154-
int get hashCode => Hashing.objectHash(_typeMap, super.hashCode);
151+
int get hashCode => Hashing.mixHashCodeBits(
152+
super.hashCode,
153+
const MapEquality<String, TypeMask>().hash(_typeMap),
154+
);
155155

156156
@override
157157
String toString() {

pkg/compiler/lib/src/inferrer/typemasks/masks.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library;
66

7+
import 'package:collection/collection.dart';
78
import 'package:js_shared/variance.dart';
89
import 'package:kernel/ast.dart' as ir;
910

@@ -141,7 +142,6 @@ class CommonMasks with AbstractValueDomain {
141142
_closedWorld,
142143
);
143144

144-
@override
145145
// TODO(50701): Use:
146146
//
147147
// TypeMask.nonNullSubtype(commonElements.recordClass, _closedWorld);
@@ -150,8 +150,8 @@ class CommonMasks with AbstractValueDomain {
150150
// subtypes of Record or (2) several live subtypes of Record. Everything
151151
// 'works' for the similar interface `Function` because there are multiple
152152
// live subclasses of `Closure`.
153-
late final TypeMask
154-
recordType = nonNullType;
153+
@override
154+
late final TypeMask recordType = nonNullType;
155155

156156
@override
157157
late final TypeMask listType = TypeMask.nonNullSubtype(

0 commit comments

Comments
 (0)