How does the GHC implement unsafePerformIO?

Starting with unsafePerformIOand ending with RTS, libc or OS API, how does GHC implement IO?


I am trying to understand how IO works in Haskell when the standard foreplay is not available (for example, if we ourselves used the standard foreplay for any reason).

I originally expected to find wrapped calls to C functions in GHC Haskell code, but that is not the case. unsafePerformIObuilt on top of runRW#where the heavy magic begins, and we begin to crumble into functions and types that are not implemented in Haskell and are instead built into the compiler. runRW#seems to be able to trigger an IO action in a real world state (i.e. a State# RealWorld).

Trying to go from another direction, I did not find a bridgehead in RTS. It does not seem to contain calls that I would expect functions like fread()and fwrite()or read()and write().

Where can I continue with IO implementation? What is the main roadmap from here onwards?

+4
source share
1 answer

As far as I remember, the type value is IO xreally a function of from RealWorld#to [strict] tuples RealWorld#and x. In other words, a simple state monad.

read() .. RTS; , Prelude FFI. , , base, RTS. ( RTS , pthread - . , , , mmap.)

, , , . , GHC, Haskell.

+2

Source: https://habr.com/ru/post/1691197/


All Articles