Fixed fwrite() error behaviour.

Closes #1909
Closes #1910
Github Author: Camillus Gerard Cai <cgcaiqxcg.net>

Reviewed By: @fredemmott

Differential Revision: D1210786
add could_include to Hack

I was going to kill this function, but @markw65 said it will be useful to the community if they don't have an autoloader. Lets open source it then.

Reviewed By: @elgenie

Differential Revision: D1218801
Enable ExtraOptPass when BytecodeControlFlow is on

This works as of D1233662.

Reviewed By: @ottoni

Differential Revision: D1234803
Dont use rAsm implicitly in x64Assembler

This removes the implicit uses of rAsm from X64Assembler,
and moves the definition to abi-x64.h.  Some mentions of
rAsm were hoisted, but most involved doing stores, so those
were converted to store two 32-bit immediates (without
using a scratch register) when possible.

The Immed wrapper class now only allows 32-bit immediates,
and a new Immed64 wrapper is available for immediates whose
compile-time-type (vm-compile time) is 64 bits.

Reviewed By: @ottoni

Differential Revision: D1224706
Fix a couple bugs with large immediates.

In one case we simply wrongly assumed that a TC address would
be in low memory, which is not guaranteed.

The other bug is when we have a CG function for an opcode, *and*
that opcode is in the native call table.  Typically the CG function
is emitting an inline fast path and falling back to a call.

mayUseConst was eagerly whitelisting such opcodes too soon; we
should get through the switch block for special cases before
whitelisting native call operands.

Reviewed By: @markw65

Differential Revision: D1241128
Fix return types for HNI functions

Using Type::Any for a return type meant that assigning the result
of a function to a variable had no effect on the type of that variable.
It needed to be Type::Variant. I would dig deeper and try to sort it out,
but hopefully we're just moving to hhbbc, and can drop it.

Reviewed By: @edwinsmith

Differential Revision: D1241620
Change method of running oss tests without jit

Adding it to the command line args put it in PHP_BINARY, which broke phpunit.

Given it's only used to disable the jit, remove the first arg from the function.

Reviewed By: @JoelMarcey

Differential Revision: D1242275
Increase JitPGOThreshold to 10

I was never happy with such a low threshold, but that's what made
perflab happiest at the time.  However, I've seen a couple of cases
where the profile-guided region selector was making a bad decision
because of limited profiling information, so I decided to try to
increase this again. I tried a few values, and 10 seems to show a
small improvement.

Reviewed By: @bertmaher

Differential Revision: D1241344
Fix a slew of bugs in the systemlibs

Reported in CodeError.js while I was working on D1241620

Reviewed By: @edwinsmith

Differential Revision: D1242050
Fix behavior of AttrDynamicInvoke on persistent functions

Solve it the way we do for fb_rename_function, although it
also seems fairly unfortunate that FuncEmitter::create has actual
logic in it instead of just deserializing data from the repo.

The problem was this: if you have a 'dynamic invoke' function (means
it can be used with fb_intercept and fb_rename_function) that is also
persistent, it would get allocated a persistent RDS handle.  After its
unit is merged, the information about how to define the func is
removed from the UnitMergeInfo in compactUnitMergeInfo, because we
expect it to be defined forever now.  Then if any thread uses
fb_rename_function on it, it will null out the persistent RDS handle.
Since it was AttrDynamicInvoke, calls to the function are compiled
with LdFuncCached, which checks if the RDS handle is null, and if so,
invokes autoload.  However, autoloading won't define the Func anymore
because it was removed from the unit merge info.

Reviewed By: @edwinsmith

Differential Revision: D1242770
Correctly support the cache File::m_buffer in UserFile::getc() and UserFile::seek()

This fixes `getimagesize()` when applied to user streams.
Closes #2140

Reviewed By: @fredemmott

Differential Revision: D1235554

Pulled By: @ptarjan
fix calling session_set_save_handler multiple times

Matches php5, brings slim back up to 100%

Reviewed By: @ptarjan

Differential Revision: D1242541
Partially implement PharFileInfo, implement Phar iterator behavior

Turns some composer test fatals into failures.

Reviewed By: @ptarjan

Differential Revision: D1239646
fix trait constructors

It looks like we implemented something that didn't end up in the final version. All tests were recorded from php5

Reviewed By: @elgenie

Differential Revision: D1227544
Make the gdb python tools Python 3 compatible

Fixes #2062
Closes #2119

Reviewed By: @markw65

Differential Revision: D1233593
Support auto_prepend_file and auto_append_file

Closes #2171

Reviewed By: @fredemmott

Differential Revision: D1238390

Pulled By: @ptarjan
EZC: Implement TSRM globals

* Implement TSRM globals properly, i.e. have different globals for
  different threads.
* Enable the ZTS macro. This is generally used by Zend extensions to
  know if they need to be thread-safe, so for HHVM best answer is yes,
  please do be thread-safe.
* Move ZendExtension to a separate header file, plus another for inline
  functions, to allow circular declarations. Having it in zend_modules.h
  didn't fit the recommended coding style in README.md.
* Implement functions in zend_virtual_cwd.cpp which are now used due to
  ZTS being defined. This is necessary to link the new version, and fixes
  some bugs due to HHVM's virtual CWD system not previously being used.
* Move zend_wrap_func() to the .cpp file so that TSRM.h can be included
  without giving duplicate macro definitions throughout the non-EZC
  codebase.
* Tested VCWD_REALPATH() by adding a wrapper ezc_realpath(), which has
  exactly the implementation of realpath() from PHP PHP. Copied in the
  realpath() tests, replacing realpath() with ezc_realpath().
* expand_filepath_with_mode() was naively copied from Zend and had a few
  problems with it. Reimplemented.

The major implementation difficulty is ensuring that the existing
macros can transmit relevant data to the implementation, and ensuring
that the extern macro does actually give access to the globals. I would
have liked to put each module's globals in its own __thread variable,
but there was no way to supply the name of it to the constructor's
caller. Obviously you can't take the address of a __thread variable in
the zend_module_entry static initializer.

The implementation here is quite close to the Zend implementation,
except with an HPHP::ThreadLocal used for underlying storage. TSRMLS_CC
etc. is used as it is in Zend ZTS mode, and should provide a slight
speedup over TLS, especially with dynamic linking.
Closes #2063

Reviewed By: @fredemmott

Differential Revision: D1240880

Pulled By: @ptarjan
EZC: fix bug in _zval_copy_ctor_func()

The type of the dest zval was copied from the source, but in the
KindOfStaticString case, the data of the dest zval is overwritten with a
plain string. This causes an assertion when the dest zval is used.

Enable the test which previously failed due to this bug.
Closes #2045

Reviewed By: @fredemmott

Differential Revision: D1240866

Pulled By: @ptarjan
Convert ext/mysql to HNI

Part of #1480

Also includes the commit in #2024

Closes facebook/hhvm#2027

https://github.com/facebook/hhvm/pull/2027

Reviewed By: @ptarjan

Differential Revision: D1220239

Pulled By: @fredemmott
Expand namespace "use" mappings even outside a namespace

The included test case would have its "use" dropped on the
floor since it applied outside of a namespace. Tweak the `elaborate_id`
function to always expand even outside a namespace, and remove a bunch
of special cases that tried to be too clever when outside a namespace.

Closes #2145

Reviewed By: @gabelevi

Differential Revision: D1240331