Permalink
Browse files

Split HAC CheckMisc into CheckArrayPlus and CheckArrayKeyCast

Summary: What it says on the tin--split these notices to be controlled by separate flags

Reviewed By: viratyosin

Differential Revision: D10222024

fbshipit-source-id: b4d4ec8f1cfd18e92bb4dba4d540e6c62aa0809b
  • Loading branch information...
jjgriego authored and hhvm-bot committed Oct 15, 2018
1 parent 2fb2a32 commit a8caa5c684452c1fc8ba6d97034b82eb15ac656d
Showing with 98 additions and 26 deletions.
  1. +2 −1 hphp/compiler/option.cpp
  2. +2 −1 hphp/hhbbc/main.cpp
  3. +6 −2 hphp/runtime/base/array-data-inl.h
  4. +2 −2 hphp/runtime/base/array-data.cpp
  5. +2 −1 hphp/runtime/base/array-data.h
  6. +4 −2 hphp/runtime/base/runtime-option.h
  7. +2 −2 hphp/runtime/base/tv-arith.cpp
  8. +1 −1 hphp/runtime/base/tv-conversions-inl.h
  9. +2 −2 hphp/runtime/base/type-array.cpp
  10. +2 −2 hphp/runtime/ext/array/ext_array.cpp
  11. +1 −1 hphp/runtime/server/source-root-info.cpp
  12. +1 −1 hphp/runtime/vm/jit/irgen-builtin.cpp
  13. +1 −1 hphp/runtime/vm/jit/translator-runtime.cpp
  14. +1 −1 hphp/runtime/vm/member-operations.h
  15. +1 −1 hphp/test/slow/array_functions/ake-object.php.opts
  16. +1 −1 hphp/test/slow/hack_arr_compat/add.php.opts
  17. +1 −1 hphp/test/slow/hack_arr_compat/implicit-key.php.opts
  18. +2 −1 hphp/test/slow/hack_arr_compat/scalars.php.opts
  19. +10 −0 hphp/test/slow/hack_arr_compat/split_misc_notices.php
  20. +19 −0 hphp/test/slow/hack_arr_compat/split_misc_notices.php.expectf
  21. +1 −0 hphp/test/slow/hack_arr_compat/split_misc_notices.php.hphp_opts
  22. +3 −0 hphp/test/slow/hack_arr_compat/split_misc_notices.php.opts
  23. +10 −0 hphp/test/slow/hack_arr_compat/split_misc_notices_2.php
  24. +15 −0 hphp/test/slow/hack_arr_compat/split_misc_notices_2.php.expectf
  25. +1 −0 hphp/test/slow/hack_arr_compat/split_misc_notices_2.php.hphp_opts
  26. +3 −0 hphp/test/slow/hack_arr_compat/split_misc_notices_2.php.opts
  27. +1 −1 hphp/test/slow/inline-interp-stack.php.hphp_opts
  28. +1 −1 hphp/test/slow/inline-interp-stack.php.opts
@@ -250,7 +250,8 @@ void Option::Load(const IniSetting::Map& ini, Hdf &config) {
BIND_HAC_OPTION(CheckRefBind, Notices)
BIND_HAC_OPTION(CheckFalseyPromote, Notices)
BIND_HAC_OPTION(CheckCompare, Notices)
BIND_HAC_OPTION(CheckMisc, Notices)
BIND_HAC_OPTION(CheckArrayKeyCast, Notices)
BIND_HAC_OPTION(CheckArrayPlus, Notices)
BIND_HAC_OPTION_SELF(IsArrayNotices)
BIND_HAC_OPTION_SELF(PromoteNotices)
BIND_HAC_OPTION_SELF(TypeHintNotices)
@@ -273,7 +273,8 @@ std::pair<std::vector<std::unique_ptr<UnitEmitter>>,
RuntimeOption::EvalHackArrCompatCheckRefBind =
RuntimeOption::EvalHackArrCompatCheckFalseyPromote =
RuntimeOption::EvalHackArrCompatCheckCompare =
RuntimeOption::EvalHackArrCompatCheckMisc =
RuntimeOption::EvalHackArrCompatCheckArrayPlus =
RuntimeOption::EvalHackArrCompatCheckArrayKeyCast =
gd.HackArrCompatNotices;
RuntimeOption::EvalAllowObjectDestructors = gd.AllowObjectDestructors;
RuntimeOption::EvalForbidDynamicCalls = gd.ForbidDynamicCalls;
@@ -331,9 +331,13 @@ ALWAYS_INLINE bool checkHACCompare() {
return RuntimeOption::EvalHackArrCompatNotices &&
RuntimeOption::EvalHackArrCompatCheckCompare;
}
ALWAYS_INLINE bool checkHACMisc() {
ALWAYS_INLINE bool checkHACArrayPlus() {
return RuntimeOption::EvalHackArrCompatNotices &&
RuntimeOption::EvalHackArrCompatCheckMisc;
RuntimeOption::EvalHackArrCompatCheckArrayPlus;
}
ALWAYS_INLINE bool checkHACArrayKeyCast() {
return RuntimeOption::EvalHackArrCompatNotices &&
RuntimeOption::EvalHackArrCompatCheckArrayKeyCast;
}
///////////////////////////////////////////////////////////////////////////////
@@ -1391,7 +1391,7 @@ void raiseHackArrCompatRefIter() {
}
void raiseHackArrCompatAdd() {
raise_hac_misc_notice("Using + operator on arrays");
raise_hac_array_plus_notice("Using + operator on arrays");
}
void raiseHackArrCompatArrMixedCmp() {
@@ -1425,7 +1425,7 @@ std::string makeHackArrCompatImplicitArrayKeyMsg(const TypedValue* key) {
}
void raiseHackArrCompatImplicitArrayKey(const TypedValue* key) {
raise_hac_misc_notice(makeHackArrCompatImplicitArrayKeyMsg(key));
raise_hac_array_key_cast_notice(makeHackArrCompatImplicitArrayKeyMsg(key));
}
///////////////////////////////////////////////////////////////////////////////
@@ -1030,7 +1030,8 @@ bool checkHACIntishCast();
bool checkHACRefBind();
bool checkHACFalseyPromote();
bool checkHACCompare();
bool checkHACMisc();
bool checkHACArrayPlus();
bool checkHACArrayKeyCast();
///////////////////////////////////////////////////////////////////////////////
@@ -554,7 +554,8 @@ struct RuntimeOption {
HC(RefBind, ref_bind) \
HC(FalseyPromote, falsey_promote) \
HC(Compare, compare) \
HC(Misc, misc)
HC(ArrayKeyCast, array_key_cast) \
HC(ArrayPlus, array_plus)
#define EVALFLAGS() \
/* F(type, name, defaultVal) */ \
@@ -917,7 +918,8 @@ struct RuntimeOption {
F(bool, HackArrCompatCheckRefBind, false) \
F(bool, HackArrCompatCheckFalseyPromote, false) \
F(bool, HackArrCompatCheckCompare, false) \
F(bool, HackArrCompatCheckMisc, false) \
F(bool, HackArrCompatCheckArrayPlus, false) \
F(bool, HackArrCompatCheckArrayKeyCast, false) \
/* Raise notices when is_array is called with any hack array */ \
F(bool, HackArrCompatIsArrayNotices, false) \
/* Raise notices when is_vec or is_dict is called with a v/darray */ \
@@ -204,7 +204,7 @@ struct Add {
ArrayData* operator()(ArrayData* a1, ArrayData* a2) const {
if (UNLIKELY(a1->isHackArray())) throwInvalidAdditionException(a1);
if (UNLIKELY(a2->isHackArray())) throwInvalidAdditionException(a2);
if (checkHACMisc()) raiseHackArrCompatAdd();
if (checkHACArrayPlus()) raiseHackArrCompatAdd();
a1->incRefCount(); // force COW
SCOPE_EXIT { a1->decRefCount(); };
return a1->plusEq(a2);
@@ -359,7 +359,7 @@ struct AddEq {
ArrayData* operator()(ArrayData* ad1, ArrayData* ad2) const {
if (UNLIKELY(ad1->isHackArray())) throwInvalidAdditionException(ad1);
if (UNLIKELY(ad2->isHackArray())) throwInvalidAdditionException(ad2);
if (checkHACMisc()) raiseHackArrCompatAdd();
if (checkHACArrayPlus()) raiseHackArrCompatAdd();
if (ad2->empty() || ad1 == ad2) return ad1;
if (ad1->empty()) {
ad2->incRefCount();
@@ -133,7 +133,7 @@ inline Cell cellToKey(Cell cell, const ArrayData* ad) {
if (!ad->useWeakKeys()) {
throwInvalidArrayKeyException(&cell, ad);
}
if (checkHACMisc()) {
if (checkHACArrayKeyCast()) {
raiseHackArrCompatImplicitArrayKey(&cell);
}
@@ -314,7 +314,7 @@ Array& Array::plusImpl(ArrayData *data) {
if (m_arr == nullptr || data == nullptr) {
throw_bad_array_merge();
}
if (checkHACMisc()) raiseHackArrCompatAdd();
if (checkHACArrayPlus()) raiseHackArrCompatAdd();
if (!data->empty()) {
if (m_arr->empty()) {
m_arr = data;
@@ -751,7 +751,7 @@ decltype(auto) elem(const Array& arr, Fn fn, bool is_key,
if (!ad->useWeakKeys()) {
throwInvalidArrayKeyException(&immutable_uninit_base, ad);
}
if (checkHACMisc()) {
if (checkHACArrayKeyCast()) {
raiseHackArrCompatImplicitArrayKey(&immutable_uninit_base);
}
return fn(make_tv<KindOfPersistentString>(staticEmptyString()),
@@ -335,7 +335,7 @@ bool HHVM_FUNCTION(array_key_exists,
switch (cell->m_type) {
case KindOfUninit:
case KindOfNull:
if (checkHACMisc() && ad->useWeakKeys()) {
if (checkHACArrayKeyCast() && ad->useWeakKeys()) {
raiseHackArrCompatImplicitArrayKey(cell);
}
return ad->useWeakKeys() && ad->exists(staticEmptyString());
@@ -357,7 +357,7 @@ bool HHVM_FUNCTION(array_key_exists,
case KindOfFunc:
case KindOfClass:
if (!ad->useWeakKeys()) throwInvalidArrayKeyException(cell, ad);
if (checkHACMisc()) {
if (checkHACArrayKeyCast()) {
raiseHackArrCompatImplicitArrayKey(cell);
}
raise_warning("Array key should be either a string or an integer");
@@ -227,7 +227,7 @@ Array SourceRootInfo::setServerVariables(Array server) const {
}
{
SuppressHACMiscNotices shacn;
SuppressHACArrayPlusNotices shacn;
if (!m_serverVars.empty()) {
server += m_serverVars;
}
@@ -2151,7 +2151,7 @@ void emitAKExists(IRGS& env) {
if (!arr->isA(TArr) && !arr->isA(TObj)) PUNT(AKExists_badArray);
if (key->isA(TInitNull)) {
if (checkHACMisc()) {
if (checkHACArrayKeyCast()) {
gen(
env,
RaiseHackArrCompatNotice,
@@ -167,7 +167,7 @@ ArrayData* arrayAdd(ArrayData* a1, ArrayData* a2) {
assertx(a1->isPHPArray());
assertx(a2->isPHPArray());
if (checkHACMisc()) raiseHackArrCompatAdd();
if (checkHACArrayPlus()) raiseHackArrCompatAdd();
if (!a2->empty()) {
if (a1->empty()) {
@@ -1643,7 +1643,7 @@ inline ArrayData* SetElemArrayPre(ArrayData* a,
a, const_cast<StringData*>(funcToStringHelper(key.m_data.pfunc)), value
);
}
if (checkHACMisc()) {
if (checkHACArrayKeyCast()) {
raiseHackArrCompatImplicitArrayKey(&key);
}
if (isNullType(key.m_type)) {
@@ -1,2 +1,2 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckMisc=1
-vEval.HackArrCompatCheckArrayKeyCast=1
@@ -1,2 +1,2 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckMisc=1
-vEval.HackArrCompatCheckArrayPlus=1
@@ -1,2 +1,2 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckMisc=1
-vEval.HackArrCompatCheckArrayKeyCast=1
@@ -1,4 +1,5 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckIntishCast=1
-vEval.HackArrCompatCheckCompare=1
-vEval.HackArrCompatCheckMisc=1
-vEval.HackArrCompatCheckArrayKeyCast=1
-vEval.HackArrCompatCheckArrayPlus=1
@@ -0,0 +1,10 @@
<?hh
<<__EntryPoint>>
function main () {
$a = darray["" => "empty string", 1 => "one", 0 => "zero"];
var_dump($a + darray["more stuff" => "yep"]);
var_dump($a[null]);
var_dump($a[true]);
var_dump($a[0.0]);
}
@@ -0,0 +1,19 @@
array(4) {
[""]=>
string(12) "empty string"
[1]=>
string(3) "one"
[0]=>
string(4) "zero"
["more stuff"]=>
string(3) "yep"
}
Notice: Hack Array Compat: Implicit conversion of null to array key in %s on line %d
string(12) "empty string"
Notice: Hack Array Compat: Implicit conversion of bool to array key in %s on line %d
string(3) "one"
Notice: Hack Array Compat: Implicit conversion of double to array key in %s on line %d
string(4) "zero"
@@ -0,0 +1 @@
-vRuntime.Eval.HackArrCompatNotices=true -d hhvm.php7.all=0
@@ -0,0 +1,3 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckArrayKeyCast=1
@@ -0,0 +1,10 @@
<?hh
<<__EntryPoint>>
function main () {
$a = darray["" => "empty string", 1 => "one", 0 => "zero"];
var_dump($a + darray["more stuff" => "yep"]);
var_dump($a[null]);
var_dump($a[true]);
var_dump($a[0.0]);
}
@@ -0,0 +1,15 @@
Notice: Hack Array Compat: Using + operator on arrays in %s on line %d
array(4) {
[""]=>
string(12) "empty string"
[1]=>
string(3) "one"
[0]=>
string(4) "zero"
["more stuff"]=>
string(3) "yep"
}
string(12) "empty string"
string(3) "one"
string(4) "zero"
@@ -0,0 +1 @@
-vRuntime.Eval.HackArrCompatNotices=true -d hhvm.php7.all=0
@@ -0,0 +1,3 @@
-vEval.HackArrCompatNotices=1
-vEval.HackArrCompatCheckArrayPlus=1
@@ -1 +1 @@
-vHackArrCompatNotices=1 -vHackArrCompatCheckMisc=1 -vJitEnableRenameFunction=0 -vRuntime.Hack.Lang.DisallowDynamicVarEnvFuncs=1 -vHackArrCompatCheckIntishCast=1
-vHackArrCompatNotices=1 -vHackArrCompatCheckArrayKeyCast=1 -vJitEnableRenameFunction=0 -vRuntime.Hack.Lang.DisallowDynamicVarEnvFuncs=1 -vHackArrCompatCheckIntishCast=1
@@ -1 +1 @@
-vEval.HackArrCompatNotices=1 -vEval.HackArrCompatCheckMisc=1 -vEval.JitEnableRenameFunction=0 -vHack.Lang.DisallowDynamicVarEnvFuncs=1 -vEval.HackArrCompatCheckIntishCast=1
-vEval.HackArrCompatNotices=1 -vEval.HackArrCompatCheckArrayKeyCast=1 -vEval.JitEnableRenameFunction=0 -vHack.Lang.DisallowDynamicVarEnvFuncs=1 -vEval.HackArrCompatCheckIntishCast=1

0 comments on commit a8caa5c

Please sign in to comment.