Add native signature type-checker
commit876679350fde83b73433c01e8e6329d2a41321bd
authorPaul Bissonnette <paulbiss@fb.com>
Tue, 10 Feb 2015 02:35:34 +0000 (9 18:35 -0800)
committerhhvm-bot <hhvm-bot@fb.com>
Mon, 16 Feb 2015 18:30:31 +0000 (16 10:30 -0800)
tree504eb4771e303f9dc5017a957391c7031298a80e
parent87f853d16db9fb0b443f856de1c5f28a6803b5c8
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
38 files changed:
hphp/compiler/analysis/emitter.cpp
hphp/runtime/base/annot-type.cpp
hphp/runtime/base/annot-type.h
hphp/runtime/ext/extension.h
hphp/runtime/ext/gmp/ext_gmp.cpp
hphp/runtime/ext/gmp/ext_gmp.php
hphp/runtime/ext/icu/ext_icu_date_fmt.cpp
hphp/runtime/ext/icu/ext_icu_date_fmt.php
hphp/runtime/ext/icu/ext_icu_timezone.cpp
hphp/runtime/ext/icu/ext_icu_uchar.cpp
hphp/runtime/ext/icu/ext_icu_uchar.php
hphp/runtime/ext/icu/ext_icu_uconverter.php
hphp/runtime/ext/imagick/ext_imagick.php
hphp/runtime/ext/mysql/ext_mysqli.cpp
hphp/runtime/ext/odbc/ext_odbc.cpp
hphp/runtime/ext/readline/ext_readline.cpp
hphp/runtime/ext/readline/ext_readline.php
hphp/runtime/ext/reflection/ext_reflection_hni.php
hphp/runtime/ext/sockets/ext_sockets.cpp
hphp/runtime/ext/sockets/ext_sockets.h
hphp/runtime/ext/sockets/ext_sockets.php
hphp/runtime/ext/std/ext_std_errorfunc.cpp
hphp/runtime/ext/std/ext_std_errorfunc.h
hphp/runtime/ext/std/ext_std_errorfunc.php
hphp/runtime/ext/std/ext_std_function.php
hphp/runtime/ext/std/ext_std_output.cpp
hphp/runtime/ext/std/ext_std_output.h
hphp/runtime/ext/std/ext_std_output.php
hphp/runtime/ext/stream/ext_stream.cpp
hphp/runtime/ext/stream/ext_stream.h
hphp/runtime/ext_zend_compat/hhvm/zend-extension.cpp
hphp/runtime/ext_zend_compat/php-src/Zend/zend_API.cpp
hphp/runtime/vm/func-emitter.cpp
hphp/runtime/vm/native.cpp
hphp/runtime/vm/native.h
hphp/runtime/vm/verifier/check.h
hphp/runtime/vm/verifier/check_func.cpp
hphp/runtime/vm/verifier/check_unit.cpp