<div dir="ltr">I've always treated Safe Haskell as "Safe until you allow IO" -- in that all 'evil' things get tainted by an IO type that you can't get rid of by the usual means. So if you go to run pure Safe Haskell code in say, lambdabot, which doesn't give the user a means to execute IO, it can't segfault if all of the Trustworthy modules you depend upon actually are trustworthy.<div><br></div><div>Trying to shore up segfault safety under Safe in IO seems like a losing proposition.</div><div><br></div><div>-Edward</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 8, 2016 at 1:27 PM, Ryan Newton <span dir="ltr"><<a href="mailto:rrnewton@gmail.com" target="_blank">rrnewton@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">We're trying to spend some cycles pushing on Safe Haskell within the stackage packages.  (It's looking like a slog.)<div><br></div><div>But we're running up against some basic questions regarding the core packages and Safe Haskell guarantees.  <a href="https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/safe_haskell.html#safe-language" target="_blank">The manual currently says:</a></div><div><br></div><i>Functions in the IO monad are still allowed and behave as usual. <br></i><br>As usual?  So it is ok to segfault GHC?  Elsewhere it says "in the safe language you can trust the types", and I'd always assumed that meant Safe Haskell is a type safe language, even in the IO fragment.<div><br></div><div>Was there an explicit decision to allow segfaults and memory corruption?  This can happen not just with FFI calls but with uses of Ptrs within Haskell, for example the following:<br><div><br></div><div><br></div><div>```</div><div>







<p><span>{-# LANGUAGE Safe #-}</span></p>
<p>module Main where<br><span></span></p>
<p><span>import Foreign.Marshal.Alloc</span></p>
<p><span>import Foreign.Storable</span></p>
<p><span>import Foreign.Ptr</span></p>
<p><span>import System.Random</span></p>
<p><span></span><br></p>
<p><span>fn :: Ptr Int -> IO ()</span></p>
<p><span>fn p = do</span></p>
<p><span>  -- This is kosher:</span></p>
<p><span>  poke p 3</span></p>
<p><span>  print =<< peek p</span></p>
<p><span>  -- This should crash the system:</span></p>
<p><span>  ix <- randomIO</span></p>
<p><span>  pokeElemOff p ix 0xcc</span></p><p>      </p>
<p><span>main = alloca fn</span></p><p><span>```</span></p><span class="HOEnZb"><font color="#888888"><p><span><br></span></p><p><span>  -Ryan</span></p></font></span></div></div></div>
<br>______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>