{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreihf4qzn6mq5ynploa4ewobzmi3cb4bcv5tvunf76xdoeb2ecurr7u",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mpmiy7kaoh72"
},
"path": "/t/can-noinline-fail-to-prevent-inlining/14324#post_14",
"publishedAt": "2026-07-01T20:23:50.000Z",
"site": "https://discourse.haskell.org",
"tags": [
"GHC proposal thread"
],
"textContent": "brandonchinn178:\n\n> If NOINLINE intentionally doesnt prevent inlining with regard to worker/wrapper, then there’s a semantic difference (not a bug) where NOINLINE might inline an unsafePerformIO CAF but OPAQUE doesnt.\n\nNo, the wrapper getting inlined only means that unsafePerformIO can get inlined if unsafePerformIO ends up in the wrapper, not the worker. And it doesn’t, since the wrapper only handles coercions and unboxings, and should not do any actual computation.\n\nOver at your GHC proposal thread you mentioned\n\n> My immediate motivation for this thread is me wanting to use top-level `unsafePerformIO` + `NOINLINE` at work, and hearing concerns about “we’ve seen it inlined in the past, so we don’t trust it”.\n\nI was going to ask: do we have actual evidence for this? Cargo-culting is not particularly helpful. But then I read the documentation for `unsafePerformIO`, which, in addition to requiring you add NOINLINE and set `-fno-cse -fno-full-laziness`, also says:\n\n> Note that these precautions are necessary for GHC, **but may not be sufficient** , and other compilers may require different precautions\n\n(emphasis mine). Since we’re entering GHC-specific land with unsafe functions anyway the latter part of the sentence is not so surprising, but the documentation clearly states that GHC will not guarantee the expected behaviour for this pattern even if you do all of these things!\n\nThis surprised me a lot, since I have multiple uses of this pattern in various places. Can a GHC expert chime in what this remark refers to? If it is the state hack, perhaps `-fno-state-hack` should be added to the unsafePerformIO documentation too!",
"title": "Can NOINLINE fail to prevent inlining?"
}