@@ -182,47 +182,26 @@ void PossibleContents::intersect(const PossibleContents& other) {
182
182
auto heapType = type.getHeapType ();
183
183
auto otherHeapType = otherType.getHeapType ();
184
184
185
- // If both inputs are nullable then the intersection is nullable as well.
186
- auto nullability =
187
- type.isNullable () && otherType.isNullable () ? Nullable : NonNullable;
185
+ // Intersect the types.
186
+ auto newType = Type::getGreatestLowerBound (type, otherType);
188
187
189
188
auto setNoneOrNull = [&]() {
190
- if (nullability == Nullable ) {
189
+ if (newType. isNullable () ) {
191
190
value = Literal::makeNull (heapType);
192
191
} else {
193
192
value = None ();
194
193
}
195
194
};
196
195
197
- // If the heap types are not compatible then they are in separate hierarchies
198
- // and there is no intersection, aside from possibly a null of the bottom
199
- // type.
200
- auto isSubType = HeapType::isSubType (heapType, otherHeapType);
201
- auto otherIsSubType = HeapType::isSubType (otherHeapType, heapType);
202
- if (!isSubType && !otherIsSubType) {
203
- if (heapType.getBottom () == otherHeapType.getBottom ()) {
204
- setNoneOrNull ();
205
- } else {
206
- value = None ();
207
- }
196
+ if (newType == Type::unreachable || newType.isNull ()) {
197
+ setNoneOrNull ();
208
198
return ;
209
199
}
210
200
211
201
// The heap types are compatible, so intersect the cones.
212
202
auto depthFromRoot = heapType.getDepth ();
213
203
auto otherDepthFromRoot = otherHeapType.getDepth ();
214
204
215
- // To compute the new cone, find the new heap type for it, and to compute its
216
- // depth, consider the adjustments to the existing depths that stem from the
217
- // choice of new heap type.
218
- HeapType newHeapType;
219
-
220
- if (depthFromRoot < otherDepthFromRoot) {
221
- newHeapType = otherHeapType;
222
- } else {
223
- newHeapType = heapType;
224
- }
225
-
226
205
// Note the global's information, if we started as a global. In that case, the
227
206
// code below will refine our type but we can remain a global, which we will
228
207
// accomplish by restoring our global status at the end.
@@ -231,8 +210,6 @@ void PossibleContents::intersect(const PossibleContents& other) {
231
210
globalName = getGlobal ();
232
211
}
233
212
234
- auto newType = Type (newHeapType, nullability);
235
-
236
213
// By assumption |other| has full depth. Consider the other cone in |this|.
237
214
if (hasFullCone ()) {
238
215
// Both are full cones, so the result is as well.
@@ -252,7 +229,7 @@ void PossibleContents::intersect(const PossibleContents& other) {
252
229
// E.g. if |this| is a cone of depth 10, and |otherHeapType| is an immediate
253
230
// subtype of |this|, then the new cone must be of depth 9.
254
231
auto newDepth = getCone ().depth ;
255
- if (newHeapType == otherHeapType) {
232
+ if (newType. getHeapType () == otherHeapType) {
256
233
assert (depthFromRoot <= otherDepthFromRoot);
257
234
auto reduction = otherDepthFromRoot - depthFromRoot;
258
235
if (reduction > newDepth) {
0 commit comments