GHC 不优化主模块以外的模块
我目前正在用 Haskell 编写一个多模块程序。我发现了一个奇怪的问题,即使我传递了 -O2
等,我的文件也没有得到正确优化。相关文件是共享 3D 矢量数学模块。当单独编译为 .o 时,这些模块会被正确优化。当使用 --make 编译为较大程序的一部分时,它们未正确优化。核心是完全不同的。
我已将一些简单的精简测试代码放入了 vector.hs 文件中:
data TestVector = TestVector !Double !Double !Double !Double
addVec :: TestVector -> TestVector -> TestVector
addVec (TestVector x1 y1 z1 w1) (TestVector x2 y2 z2 w2) =
TestVector (x1 + x2) (y1 + y2) (z1 + z2) (w1 + w2)
并从 main 导入它...
import Vector
此代码作为独立的 .hs 文件的编译方式与我使用 --make
我的命令行是:
ghc -tmpdir tmp -hidir hi -odir obj -fext-core -fexcess-precision -funbox-strict-fields -threaded -rtsopts -fwarn-missing-signatures -Wall -O2 Main.hs -o main
干杯
I'm currently writing a multi-module program in Haskell. I've found a strange problem where my files aren't being optimized properly, even though I'm passing in -O2
and so on. The files in question are shared 3D vector maths modules. When compiled individually to a .o, these modules are optimized correctly. When compiled as part of a larger program using --make, they are not optimized correctly. The core is quite different.
I've put in some simple stripped-down test code into a vector.hs file:
data TestVector = TestVector !Double !Double !Double !Double
addVec :: TestVector -> TestVector -> TestVector
addVec (TestVector x1 y1 z1 w1) (TestVector x2 y2 z2 w2) =
TestVector (x1 + x2) (y1 + y2) (z1 + z2) (w1 + w2)
And imported it from main...
import Vector
This code gets compiled differently as a standalone .hs file as opposed to when I build main.hs using --make
My command line is:
ghc -tmpdir tmp -hidir hi -odir obj -fext-core -fexcess-precision -funbox-strict-fields -threaded -rtsopts -fwarn-missing-signatures -Wall -O2 Main.hs -o main
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加到
主模块中。
如果调用者/被调用者不在同一模块中,GHC 需要在进行优化之前指示这种可能性。
Add
in main module.
GHC needs indication of that possibility before doing that optimization, if the invokator/invokated are not in the same modules.