Skip to content

Commit

Permalink
Add CheckClsRGSoft IR
Browse files Browse the repository at this point in the history
Summary: This IR instruction allows us to be able to easily raising a warning or error depending on how many reified generics on a class are soft. This is needed by the corresponding bytecode (see D37256064) which in turn is needed because we plan to no longer pass the reified generics list to the bytecodes that create an object and were previously doing this check.

Reviewed By: oulgen

Differential Revision: D37255172

fbshipit-source-id: 85bc4f40ffe5cc02e9d31672dd25e1b6dee7b446
  • Loading branch information
mdko authored and facebook-github-bot committed Jul 6, 2022
1 parent b0e64ca commit 2049210
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions hphp/doc/ir.specification
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,11 @@ To string conversions:
Raises a runtime error unless whether each generic in S1 is reified or erased
matches exactly to the expectations of the cls in S0.

| CheckClsRGSoft, ND, S(Cls), NF

Raise a warning if all the reified generics on class S0 are soft,
otherwise raise an error. S0 must be a reified class.

| CheckFunReifiedGenericMismatch, ND, S(Func) S(Vec), LA

Raises a runtime error unless whether each generic in S1 is reified or erased
Expand Down
7 changes: 1 addition & 6 deletions hphp/runtime/base/object-data-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ NEVER_INLINE ObjectData* ObjectData::newInstanceSlow(Class* cls) {
raiseAbstractClassError(cls);
}
if (cls->hasReifiedGenerics()) {
if (areAllGenericsSoft(cls->getReifiedGenericsInfo())) {
raise_warning_for_soft_reified(0, false, cls->name());
} else {
raise_error("Cannot create a new instance of a reified class without "
"the reified generics");
}
checkClassReifiedGenericsSoft(cls);
}
auto obj = ObjectData::newInstanceImpl<Unlocked>(
cls,
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/vm/jit/dce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ bool canDCE(const IRInstruction& inst) {
case RaiseImplicitContextStateInvalidException:
case CheckClsMethFunc:
case CheckClsReifiedGenericMismatch:
case CheckClsRGSoft:
case CheckFunReifiedGenericMismatch:
case CheckInOutMismatch:
case CheckReadonlyMismatch:
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/vm/jit/ir-opcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ bool opcodeMayRaise(Opcode opc) {
case CGetPropQ:
case CheckClsMethFunc:
case CheckClsReifiedGenericMismatch:
case CheckClsRGSoft:
case CheckFunReifiedGenericMismatch:
case CheckInOutMismatch:
case CheckReadonlyMismatch:
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/vm/jit/irlower-exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ IMPL_OPCODE_CALL(RestoreErrorLevel)

IMPL_OPCODE_CALL(CheckClsMethFunc)
IMPL_OPCODE_CALL(CheckClsReifiedGenericMismatch)
IMPL_OPCODE_CALL(CheckClsRGSoft)
IMPL_OPCODE_CALL(CheckFunReifiedGenericMismatch)
IMPL_OPCODE_CALL(CheckInOutMismatch)
IMPL_OPCODE_CALL(CheckReadonlyMismatch)
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/vm/jit/memory-effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,7 @@ MemEffects memory_effects_impl(const IRInstruction& inst) {
case RaiseStrToClassNotice:
case CheckClsMethFunc:
case CheckClsReifiedGenericMismatch:
case CheckClsRGSoft:
case CheckFunReifiedGenericMismatch:
case CheckInOutMismatch:
case CheckReadonlyMismatch:
Expand Down
3 changes: 3 additions & 0 deletions hphp/runtime/vm/jit/native-calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ static CallMap s_callMap {
{CheckFunReifiedGenericMismatch, checkFunReifiedGenericMismatch,
DNone, SSync,
{{SSA, 0}, {SSA, 1}}},
{CheckClsRGSoft, checkClassReifiedGenericsSoft,
DNone, SSync,
{{SSA, 0}}},
{VerifyReifiedLocalType, VerifyReifiedLocalTypeImpl, DNone, SSync,
{{TV, 0}, {SSA, 1}, {SSA, 2},
extra(&FuncParamData::func),
Expand Down
9 changes: 9 additions & 0 deletions hphp/runtime/vm/reified-generics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ void raise_warning_for_soft_reified(size_t i, bool fun,
name->data());
}

void checkClassReifiedGenericsSoft(const Class* cls) {
assertx(cls->hasReifiedGenerics());
if (areAllGenericsSoft(cls->getReifiedGenericsInfo())) {
raise_warning_for_soft_reified(0, false, cls->name());
} else {
raise_error("Cannot create a new instance of a reified class without "
"the reified generics");
}
}


///////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions hphp/runtime/vm/reified-generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ bool areAllGenericsSoft(const ReifiedGenericsInfo& info);
// Raises warning for parameter at index i for function/class name
void raise_warning_for_soft_reified(size_t i, bool fun, const StringData *name);

// Raises warning if any reified generics on the class are not soft,
// otherwise throws an error
void checkClassReifiedGenericsSoft(const Class* cls);

///////////////////////////////////////////////////////////////////////////////

}
Expand Down

0 comments on commit 2049210

Please sign in to comment.