Is there any reason not to use the INLINABLE pragma for a function?

后端 未结 1 1866
囚心锁ツ
囚心锁ツ 2021-01-31 15:04

The documentation states:

An {-# INLINABLE f #-} pragma on a function f has the following behaviour:

  • While INLINE says \"please in

相关标签:
1条回答
  • 2021-01-31 15:34

    There are three differences between using INLINABLE and not using a pragma at all:

    • Without INLINABLE, the definition that goes in the interface file is the code after optimisation, whereas with INLINABLE, it is the code you wrote (more or less). In particular, without INLINABLE, GHC might inline other functions into the function's definition.

    • Without INLINABLE, GHC will omit the definition from the interface file if it is too big. If some other function got inlined into the right-hand-side, this could easily push it over the limit.

    • INLINABLE also turns on some clever machinery that automatically specialises overloaded functions where they are used, and shares the specialised versions with other modules that transitively import the module in which the specialised version was created.

    0 讨论(0)
提交回复
热议问题