Add native signature type-checker
Summary: This diff adds a type-check step to the verifier for C++ builtins written using
HNI. The type checker uses some template magic inspired by @swtaarrs
and checks types.
I want to add this verifier pass because a lot of these mistakes can lead to
pretty nasty, pretty subtle bugs. I also think it would be nice to have a tool
like this around when @edwinsmith and @sgolemon rework our extension API
and the wrapper types it uses.
Currently 32 and 64-bit integers are allowed in signatures, I would like to
eventually have all of our extensions in a state where we can require 64-bit
signed integers (the extension can convert as necessary)- as that's how they
come in from the VM and allowing signatures with other intenger types opens the
door to all sorts of dangerous mistakes (in this diff I did remove the only
places 16 bit integers were used).
Most of the errors are verification errors, though it is possible to have errors
at compile time for particularly egregious mistakes and they can be cryptic
(yay template deduction errors), so it may be nice to make that more user
friendly.
Here are the compile-time errors I had to fix to get the diff to build:
differential/diff/
6438633/
Here are the verification errors before I fixed them:
Verification Error (unit systemlib.phpasync_mysql func getIterator): <<__Native>> function AsyncMysqlRowBlock::getIterator does not match C++ function signature (mixed AsyncMysqlRowBlock->getIterator(void)): Invalid return type detected
Verification Error (unit systemlib.phpasync_mysql func current): <<__Native>> function AsyncMysqlRowBlockIterator::current does not match C++ function signature (mixed AsyncMysqlRowBlockIterator->current(void)): Invalid return type detected
Verification Error (unit systemlib.phpasync_mysql func getIterator): <<__Native>> function AsyncMysqlRow::getIterator does not match C++ function signature (mixed AsyncMysqlRow->getIterator(void)): Invalid return type detected
Verification Error (unit systemlib.phpgmp func gmp_setbit): <<__Native>> function gmp_setbit does not match C++ function signature (void gmp_setbit(mixed&, int, bool)): Invalid argument type detected
Verification Error (unit systemlib.phpgmp func __debugInfo): <<__Native>> function GMP::__debugInfo does not match C++ function signature (array GMP->__debugInfo(mixed)): Invalid argument count detected
Verification Error (unit systemlib.phpimagick func setImageColormapColor): <<__Native>> function Imagick::setImageColormapColor does not match C++ function signature (bool Imagick->setImageColormapColor(int, object)): Invalid argument type detected
Verification Error (unit systemlib.phpicu_timezone func getUnknown): <<__Native>> function IntlTimeZone::getUnknown does not match C++ function signature (mixed IntlTimeZone::getUnknown(void)): Invalid return type detected
Verification Error (unit systemlib.phpicu_date_fmt func FormatObject): <<__Native>> function IntlDateFormatter::FormatObject does not match C++ function signature (string IntlDateFormatter::FormatObject(object, mixed, string)): Invalid argument type detected
Verification Error (unit systemlib.phpicu_uchar func getUnicodeVersion): <<__Native>> function IntlChar::getUnicodeVersion does not match C++ function signature (mixed IntlChar::getUnicodeVersion(void)): Invalid return type detected
Verification Error (unit systemlib.phpicu_uconverter func getDestinationEncoding): <<__Native>> function UConverter::getDestinationEncoding does not match C++ function signature (mixed UConverter->getDestinationEncoding(void)): Invalid return type detected
Verification Error (unit systemlib.phpicu_uconverter func getSourceEncoding): <<__Native>> function UConverter::getSourceEncoding does not match C++ function signature (mixed UConverter->getSourceEncoding(void)): Invalid return type detected
Verification Error (unit systemlib.phpicu_uconverter func setDestinationEncoding): <<__Native>> function UConverter::setDestinationEncoding does not match C++ function signature (bool UConverter->setDestinationEncoding(string)): Invalid return type detected
Verification Error (unit systemlib.phpmysqli func get_mysqli_conn_resource): <<__Native>> function mysqli_result::get_mysqli_conn_resource does not match C++ function signature (mixed mysqli_result->get_mysqli_conn_resource(mixed)): Invalid argument type detected
Verification Error (unit systemlib.phpmysqli func hh_init): <<__Native>> function mysqli_stmt::hh_init does not match C++ function signature (void mysqli_stmt->hh_init(mixed)): Invalid argument type detected
Verification Error (unit systemlib.phpodbc func odbc_connect): <<__Native>> function odbc_connect does not match C++ function signature (mixed odbc_connect(string, string, string)): Invalid argument count detected
Verification Error (unit systemlib.phpodbc func odbc_error): <<__Native>> function odbc_error does not match C++ function signature (string odbc_error(resource)): Invalid argument type detected
Verification Error (unit systemlib.phpodbc func odbc_errormsg): <<__Native>> function odbc_errormsg does not match C++ function signature (string odbc_errormsg(resource)): Invalid argument type detected
Verification Error (unit systemlib.phpodbc func odbc_exec): <<__Native>> function odbc_exec does not match C++ function signature (mixed odbc_exec(resource, string)): Invalid argument count detected
Verification Error (unit systemlib.phpodbc func odbc_execute): <<__Native>> function odbc_execute does not match C++ function signature (bool odbc_execute(resource, array)): Invalid argument type detected
Verification Error (unit systemlib.phpodbc func odbc_fetch_array): <<__Native>> function odbc_fetch_array does not match C++ function signature (mixed odbc_fetch_array(resource)): Invalid argument count detected
Verification Error (unit systemlib.phpreadline func readline_info): <<__Native>> function readline_info does not match C++ function signature (mixed readline_info(string, string)): Invalid argument type detected
Verification Error (unit systemlib.phpreadline func readline_read_history): <<__Native>> function readline_read_history does not match C++ function signature (bool readline_read_history(string)): Invalid argument type detected
Verification Error (unit systemlib.phpreadline func readline_write_history): <<__Native>> function readline_write_history does not match C++ function signature (bool readline_write_history(string)): Invalid argument type detected
Verification Error (unit systemlib.phpreadline func readline): <<__Native>> function readline does not match C++ function signature (mixed readline(string)): Invalid return type detected
Verification Error (unit systemlib.phpreflection_hni func __initClosure): <<__Native>> function ReflectionFunction::__initClosure does not match C++ function signature (bool ReflectionFunction->__initClosure(object)): Invalid return type detected
Verification Error (unit systemlib.phpsockets func socket_last_error): <<__Native>> function socket_last_error does not match C++ function signature (int socket_last_error(resource)): Invalid argument type detected
Verification Error (unit systemlib.phpsockets func socket_clear_error): <<__Native>> function socket_clear_error does not match C++ function signature (void socket_clear_error(resource)): Invalid argument type detected
Verification Error (unit systemlib.phpstd_errorfunc func error_log): <<__Native>> function error_log does not match C++ function signature (bool error_log(string, int, string, string)): Invalid argument type detected
Verification Error (unit systemlib.phpstd_output func hphp_set_hardware_events): <<__Native>> function hphp_set_hardware_events does not match C++ function signature (bool hphp_set_hardware_events(string)): Invalid argument type detected
Verification Error (unit systemlib.phpstd_function func func_get_args): <<__Native>> function func_get_args does not match C++ function signature (mixed func_get_args(void)): Invalid return type detected
{sync, type="parent", child="external", childrevid="33195", childdiffid="173475", parentdiffid="
6496593"}
Reviewed By: @markw65
Differential Revision:
D1837003