Hack generator should throw when required field is unset when reading

Summary:
A required field is non-nullable in Hack. Checking against null
(to check that a required field was set) is wrong. Fix by checking every
required field separately whether it was read.

Test Plan: Generated test code, used hphpd

Reviewed By: andrewcox@fb.com

Subscribers: trunkagent, alandau

FB internal diff: D1430277

Tasks: 4650708
bugfix when handling TApplicationException

Summary:
While helping troubleshoot a twisted thrift service, I noticed that bugs in the
server were silently swallowed: they weren't shown on the server side nor propagated back to the thrift client as exceptions. The reason being a
bug in the generated code :(

before:
@write_results_exception_callback
def write_results_exception_process(self, error, result):
try:
error.raiseException()
except InternalException as exc0:
reply_type = TMessageType.REPLY
result.ex_internal = exc0
except BackendSubmissionException as exc1:
reply_type = TMessageType.REPLY
result.ex_be_submission = exc1
except:
reply_type = TMessageType.EXCEPTION
ex = sys.exc_info()[1]
self._event_handler.handlerError(handler_ctx, 'process', ex)  <--- handler_ctx is not defined
result = Thrift.TApplicationException(message=str(ex))
return reply_type, result

after:

```
@write_results_exception_callback
-  def write_results_exception_process(self, error, result):
+  def write_results_exception_process(self, error, result, handler_ctx):

Test Plan: recompile thrift service, see bug gets propagated back to client

Reviewed By: andrewcox@fb.com

Subscribers: net-systems@, ruibalp, alandau, bmatheny, exa, andrewkr

FB internal diff: D1430800
thrift-py: Don't use python/ prefixed include paths for fastbinary

Summary:
It's general convention when implementing and building CPython
extensions that python's include dir is explicitly added to the include
path.  As a result, we should bring in Python.h and other python headers
as if they were installed directly to include/

Test Plan:
verified that fastbinary compilation fails in open source
fbthrift with both a brand new virtualenv and system python.  After this
change, compilation succeeds on both.  Internal builds that depend on
fastbinary.so continue to build successfully as well.

Reviewed By: fried@fb.com

Subscribers: doug, ruibalp, alandau, bmatheny

FB internal diff: D1418244
thrift-py: make fastbinary C90 compiler friendly

Summary:
setuptools-based distributions use the C compiler, while
internally, we build with the a C++ compiler.  This diff makes
fastbinary.c more C-compiler friendly for open source.

Test Plan:
verified fastbinary.c successfully compiles internally as well
as externally with python 2.6. 2.7, 3.3, and 3.4.

Reviewed By: haijunz@fb.com

Subscribers: doug, ruibalp, alandau, bmatheny

FB internal diff: D1420644
thrift-py: add thrift.util to setup.py

Summary:
fbthrift compiler generates python code that depends on
thrift.util, but the distutils build didn't include this module in the
modules to install.  Add it.

Test Plan:
Made this change in a virtualenv with external fbthrift.
Generated bindings now import and work without errors.

Reviewed By: andrewcox@fb.com

Subscribers: doug, ruibalp, alandau, bmatheny

FB internal diff: D1428641
Modified Haskell Thrift Compiler to conform to functional style

Summary: The way that the Thrift Compiler was originally written for Haskell made writing protocols very difficult.  Protocols had to be written in imperative style with mutable state to keep track of various details about the current state of a read or write.  I changed the compiler to allow protocols to be wirtten in functional style.  This ended up making the code much simpler (this diff is a net decrease in lines of code without loss of functionality).  I think this refactoring also improved performance, although I would have to set up real benchmark tests to make sure.

Test Plan: fbconfig -r thrift/lib/hs && fbmake runtests_dev

Reviewed By: smarlow@fb.com

Subscribers: alandau, bmatheny, jcoens, davejwatson

FB internal diff: D1425477

Tasks: 4678331
Add Type Info to Generated Code

Summary: Additional information about Thrift Types is needed to read/write with certain protocols

Test Plan: `fbconfig -r thrift/lib/hs && fbmake runtests_dev'

Reviewed By: smarlow@fb.com

Subscribers: bmatheny, alandau, jcoens, davejwatson

FB internal diff: D1428912

Tasks: 4678397
Improve Perf in Thrift Protocols

Summary: Because of the changes to the Thrift Compiler in D1425477, I was able to change the way that data is read and written to greatly increase performance.  I tested the performance with benchmark tests in which 1000 large randomly generated structs (from a common seed) where written and then read back.  The old code completed these tests in 87.5s and the new code completed the tests in 14.2s.  These changes increased performance by more than 6x :)

Test Plan: fbconfig -r thrift/lib/hs && fbmake runtests_dev

Reviewed By: smarlow@fb.com

Subscribers: alandau, bmatheny, jcoens, davejwatson, bnitka

FB internal diff: D1432263

Tasks: 4682195
Fix codegen for empty structs

Summary: The Thrift Compiler did not generate valid Haskell for Thrift Structs that had no fields.  Closes 4695697

Test Plan: fbconfig -r sigma/hax/datasources/coefficient2 && fbmake runtests_dev

Reviewed By: bnitka@fb.com

Subscribers: alandau, jcoens, smarlow, akr

FB internal diff: D1433297

Tasks: 4695697