-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Terei
committed
Jun 30, 2011
1 parent
0947668
commit 39e06ea
Showing
27 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module ControlMonadST where | ||
|
||
import Control.Monad | ||
import Control.Monad.ST | ||
-- import Control.Monad.ST.Unsafe | ||
import Data.STRef | ||
|
||
sumST :: Num a => [a] -> IO a | ||
sumST xs = unsafeSTToIO $ do | ||
n <- newSTRef 0 | ||
forM_ xs $ \x -> do | ||
modifySTRef n (+x) | ||
readSTRef n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module ControlMonadSTLazy where | ||
|
||
import Control.Monad | ||
import Control.Monad.ST.Lazy | ||
-- import Control.Monad.ST.Unsafe | ||
import Data.STRef.Lazy | ||
|
||
sumST :: Num a => [a] -> a | ||
sumST xs = runST $ do | ||
n <- newSTRef 0 | ||
forM_ xs $ \x -> do | ||
modifySTRef n (+x) | ||
readSTRef n | ||
|
||
badST :: () | ||
badST = runST $ unsafeIOToST $ putStrLn "Hello World" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Foreign2 where | ||
|
||
import Foreign | ||
|
||
bad :: IO a -> a | ||
bad = unsafePerformIO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module ForeignForeignPtr where | ||
|
||
import Foreign.Ptr | ||
import Foreign.ForeignPtr | ||
|
||
bad :: ForeignPtr a -> Ptr a | ||
bad = unsafeForeignPtrToPtr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module GHCArr where | ||
|
||
import GHC.Arr | ||
|
||
bad1 = unsafeArray | ||
|
||
bad2 = fill | ||
|
||
bad3 = done | ||
|
||
bad4 = unsafeThawSTArray | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module GHCConc where | ||
|
||
import GHC.Conc | ||
|
||
bad1 = unsafeIOToSTM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module GHCForeignPtr where | ||
|
||
import GHC.ForeignPtr | ||
|
||
bad1 = unsafeForeignPtrToPtr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module GHCIOArray where | ||
|
||
import GHC.IOArray | ||
|
||
bad1 = unsafeReadIOArray | ||
|
||
bad2 = unsafeWriteIOArray | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module GHCPtr where | ||
|
||
import GHC.Ptr | ||
|
||
bad1 = castFunPtrToPtr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module GHCST where | ||
|
||
import GHC.ST | ||
|
||
bad1 = liftST | ||
|
||
bad2 = unsafeInterleaveST | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{-# LANGUAGE Safe #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
module ImpSafe ( MyWord ) where | ||
|
||
-- Data.Word is safe so shouldn't requrie base be trusted. | ||
-- (No wrong as while Data.Word is safe it imports trustworthy | ||
-- modules in base, hence base needs to be trusted). | ||
-- Note: Worthwhile giving out better error messages for cases | ||
-- like this if I can. | ||
import Data.Word | ||
|
||
type MyWord = Word | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE Safe #-} | ||
module Main where | ||
|
||
import M_Terei | ||
|
||
main = do | ||
putStrLn $ show bigInt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE Safe #-} | ||
module Main where | ||
|
||
import M_Terei2 | ||
|
||
main = do | ||
putStrLn $ show bigInt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE Safe #-} | ||
module Main where | ||
|
||
import M_Terei3 | ||
|
||
main = do | ||
putStrLn $ show bigInt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE Safe #-} | ||
module ImpTrustworthy ( MyInt ) where | ||
|
||
-- Data.Int is trustworthy so we need to trust base | ||
import Data.Int | ||
|
||
type MyInt = Int | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{-# LANGUAGE Safe #-} | ||
module M_Terei where | ||
|
||
bigInt :: Int | ||
bigInt = 9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{-# LANGUAGE Trustworthy #-} | ||
module M_Terei2 where | ||
|
||
bigInt :: Int | ||
bigInt = 9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE Safe #-} | ||
module M_Terei3 where | ||
|
||
import qualified M_Terei2 as M2 | ||
|
||
bigInt :: Int | ||
bigInt = M2.bigInt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{-# LANGUAGE Safe #-} | ||
module M_Terei4 where | ||
|
||
import qualified M_Terei3 as M3 | ||
import Data.Word | ||
|
||
bigInt :: Int | ||
bigInt = M3.bigInt | ||
|
||
type MyWord = Word | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Distribution.Simple | ||
|
||
main = defaultMain | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Name: p | ||
Version: 1.0 | ||
Description: SafeHaskell Test Package | ||
License: BSD3 | ||
Author: David Terei | ||
Maintainer: davidterei@gmail.com | ||
Build-Type: Simple | ||
Cabal-Version: >= 1.2 | ||
|
||
Library { | ||
Build-Depends: base >= 4 | ||
Exposed-Modules: | ||
M_Terei | ||
M_Terei2 | ||
M_Terei3 | ||
M_Terei4 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{-# LANGUAGE Trustworthy #-} | ||
module A ( | ||
trace | ||
) where | ||
|
||
import qualified Debug.Trace as D | ||
import qualified Data.ByteString.Lazy.Char8 as BS | ||
|
||
-- | Allowed declasification | ||
trace :: String -> a -> a | ||
trace s = D.trace $ s ++ show a3 | ||
|
||
a3 :: BS.ByteString | ||
a3 = BS.take 3 $ BS.repeat 'a' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE Safe #-} | ||
module B where | ||
|
||
import A | ||
|
||
mainM :: Int -> Int | ||
mainM n = trace "Allowed Leak" $ n * 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE SafeImports #-} | ||
module C ( main' ) where | ||
|
||
import safe B | ||
|
||
main' = do | ||
let n = mainM 1 | ||
print $ n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{-# LANGUAGE SafeImports #-} | ||
module Main ( main ) where | ||
|
||
import C | ||
|
||
main = main' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Main where | ||
|
||
import B | ||
|
||
main = do | ||
let n = mainM 1 | ||
print $ n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
GHC=/home/davidt/Ghc/safeHaskell2/inplace/bin/ghc-stage2 | ||
|
||
# should fail as we don't trust the base package when compiling C | ||
# and so B isn't safe anymore since B imports a trustworthy | ||
# module from base. | ||
c: | ||
${GHC} -c -fforce-recomp A.hs | ||
${GHC} -c -fforce-recomp B.hs -trust base | ||
${GHC} -c -fforce-recomp C.hs | ||
echo "Should fail!" | ||
|
||
c2: | ||
${GHC} -c -fforce-recomp A.hs | ||
${GHC} -c -fforce-recomp B.hs -trust base | ||
${GHC} -c -fforce-recomp C.hs -trust base | ||
${GHC} -c -fforce-recomp C_2.hs -o C2 | ||
echo "Should succeed!" | ||
|
||
# should succeed as we do trust the base package when compiling C | ||
# and so B is safe still. | ||
c_trust: | ||
${GHC} -c -fforce-recomp A.hs | ||
${GHC} -c -fforce-recomp B.hs -trust base | ||
${GHC} -c -fforce-recomp C.hs -trust base | ||
echo "Should succeed!" | ||
|
||
## should succeed as we aren't importing B as a safe module | ||
d: | ||
${GHC} -c -fforce-recomp A.hs | ||
${GHC} -c -fforce-recomp B.hs -trust base | ||
${GHC} -c -fforce-recomp D.hs -o d | ||
echo "Should succeed!" | ||
|
||
clean: | ||
rm *.o | ||
rm *.hi | ||
rm C2 | ||
rm D | ||
|