[英]What are the default build option of Stack's package.yaml needed for?
创建新的Stack项目时,可执行文件会获得以下ghc-options
- -threaded
- -rtsopts
- -with-rtsopts=-N
看着man ghc
,我发现了以下内容:
-threaded
Use the threaded runtime
-rtsopts[=⟨none|some|all⟩]
Control whether the RTS behaviour can be tweaked via command-lineflags and the GHCRTS environment variable. Using none means no RTS
flags can be given; some means only a minimum of safe options can be given (the default), and all (or no argument at all) means
that all RTS flags are permitted.
-with-rtsopts=⟨opts⟩
Set the default RTS options to ⟨opts⟩.
这几乎没有告诉我任何事情。 线程运行时是指编译器的运行时还是生成的可执行文件的运行时? 这些rtsopts是做什么用的? 这些选择是否有益? 如果是,为什么它们不是默认值? 为什么可执行文件会得到它们,而库代码却没有:
library:
source-dirs: src
# notice no ghc-options field here!
它指的是生成的可执行文件的运行时。 这些选项允许最终程序运行多线程,即利用多核计算机上的并行或并发执行。 这对于性能尤其是交互式应用程序的响应性(尤其是一些不与线程化的运行时一起运行时实际上或实际上不可用)的响应性而言尤其有利。
运行时始终仅链接到可执行文件。 您可能会认为它类似于执行字节码程序的Java虚拟机,除了Haskell运行时被精简得多,并且不需要做太多的代码解释,它基本上只是处理内存需求并分配Haskell线程到OS线程。
因此,它没有链接到库,只有在最后在可执行文件中使用库时才链接到库。 这就是为什么该选项未出现在“ library
部分中的原因。 (虽然,它实际上是相当方便的,如果库有办法表示“当你使用这个在exectuable,它应该与螺纹运行时连接”,但是这会有后果,我不觉得有什么,允许这样的事情。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.