Skip to content

Commit

Permalink
Fix Hack array specializations in JIT type system
Browse files Browse the repository at this point in the history
Summary:
The set of allowed bits for ArraySpec didn't include Hack arrays, which meant
the type-system would never make use of them (which is odd because I could
swear I've seen Hack array specializations before in IR dumps). Change the
allowed bits from Arr to ArrLike, and fix a few bugs this uncovered.

Reviewed By: mxw

Differential Revision: D13107383

fbshipit-source-id: 1d6baf94f85630bf920877c3fe3679dc9c9b9f48
  • Loading branch information
ricklavoie authored and hhvm-bot committed Nov 17, 2018
1 parent 2615f2f commit 1b01e01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions hphp/runtime/vm/jit/type-inl.h
Expand Up @@ -341,9 +341,11 @@ inline Type Type::dropConstVal() const {
if (!m_hasConstVal) return *this;
assertx(!isUnion());

if (*this <= TStaticArr) {
return Type::StaticArray(arrVal()->kind());
}
if (*this <= TStaticArr) return Type::StaticArray(arrVal()->kind());
if (*this <= TStaticVec) return TStaticVec;
if (*this <= TStaticDict) return TStaticDict;
if (*this <= TStaticKeyset) return TStaticKeyset;

return Type(m_bits, ptrKind(), memKind());
}

Expand Down Expand Up @@ -521,9 +523,8 @@ inline ArraySpec Type::arrSpec() const {
// all of them.
if (supports(SpecKind::Class)) return ArraySpec::Top;

if (m_hasConstVal) {
return ArraySpec(arrVal()->kind());
}
if (m_hasConstVal) return ArraySpec(m_arrVal->kind());

assertx(m_arrSpec != ArraySpec::Bottom);
return m_arrSpec;
}
Expand Down
4 changes: 2 additions & 2 deletions hphp/runtime/vm/jit/type.cpp
Expand Up @@ -621,11 +621,11 @@ bool Type::operator<=(Type rhs) const {
return true;
}

if (lhs.hasConstVal(TArr)) {
if (lhs.hasConstVal(TArrLike)) {
// Arrays can be specialized in different ways. Here, we check if the
// constant array fits the kind()/type() of the specialization of `rhs', if
// any.
auto const lhs_arr = lhs.arrVal();
auto const lhs_arr = lhs.m_arrVal;
auto const rhs_as = rhs.arrSpec();
return arrayFitsSpec(lhs_arr, rhs_as);
}
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/vm/jit/type.h
Expand Up @@ -479,7 +479,7 @@ struct Type {
kAnyDict = kDict | kBoxedDict,
kAnyKeyset = kKeyset | kBoxedKeyset,
kAnyArrLike = kAnyArr | kAnyVec | kAnyDict | kAnyKeyset,
kArrSpecBits = kAnyArr,
kArrSpecBits = kAnyArrLike,
kAnyObj = kObj | kBoxedObj,
kClsSpecBits = kAnyObj | kCls,
};
Expand Down

0 comments on commit 1b01e01

Please sign in to comment.