Copy code from ghc-7.8.2-release