Skip to content

Commit c72f01b

Browse files
committed
.
1 parent 36fa603 commit c72f01b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

zjit/src/hir_type/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,20 @@ impl Type {
453453
types::Empty
454454
}
455455

456+
/// Subtract `other` from `self`, preserving specialization if possible.
456457
pub fn subtract(&self, other: Type) -> Type {
458+
if self.is_subtype(other) { return types::Empty; }
459+
// If self's specialization is not a subtype of other's specialization (eg Int,Double or
460+
// Top,Int or Int,Empty or Int[5],Int[4]), subtracting has no effect.
461+
if !self.spec_is_subtype_of(other) {
462+
return *self;
463+
}
464+
// Now the specializations overlap: self's specialization is a subtype of other's
465+
// specialization (eg Int,Top or Int[4],Int[4], but NOT Empty,Int because that would mean
466+
// self is a subtype of other). Keep self's specialization.
467+
// Subtract the bits
457468
let bits = self.bits & !other.bits;
458-
if bits == bits::Empty { return types::Empty; }
459-
// TODO(max): See if we can preserve specialization
460-
Type { bits, spec: Specialization::Any }
469+
Type { bits, spec: self.spec }
461470
}
462471

463472
pub fn could_be(&self, other: Type) -> bool {

0 commit comments

Comments
 (0)