Hi,
while still trying to get Data.HashTable to work both in ST and
IO (I'll probably start complaining about optimizations not
performed once this is fixed ;), I bumped into the following
nastiness.
Comments interleaved with shell copy-paste-work.
% make clean
rm -f *.o *.hi a.out
% /var/tmp/ghc/bin/ghc --make -O Main.hs
Chasing modules from: Main.hs
Compiling MHashTable ( ./MHashTable.hs, ./MHashTable.o )
Compiling Main ( Main.hs, Main.o )
ghc-6.4.20050304: panic! (the `impossible' happened, GHC version
6.4.20050304):
cgPanic
zdfMutHashSTArray{v a1ip}
static binds for:
local binds for:
SRT labelghc-6.4.20050304: panic! (the `impossible' happened, GHC
version 6.4.20050304):
initC: srt
Okay, it dies. Almost any new change in the source makes this one
go away. The next panic is probably partly a consequence of this
one: MHashTable.o already exists and GHC can't cope with that for
some reason. That reason may of course be that MHashTable.o
contains garbage due to the previous bug.
% /var/tmp/ghc/bin/ghc --make -O Main.hs
Chasing modules from: Main.hs
Skipping MHashTable ( ./MHashTable.hs, ./MHashTable.o )
ghc-6.4.20050304: panic! (the `impossible' happened, GHC version
6.4.20050304):
tcIfaceGlobal (local): not found:
MHashTable.updateST{v r87}
[(rr, Identifier `MHashTable.zdfMutHashSTArray{v rr}'),
(rs, Type constructor `MHashTable.HT{tc rs}'),
(rt, Identifier `MHashTable.dir{v rt}'),
(ru, Data constructor `MHashTable.HT{d ru}'),
(rv, Identifier `MHashTable.HT{v rv}'),
(rw, Type constructor `MHashTable.HashTable{tc rw}'),
(rx, Data constructor `MHashTable.HashTable{d rx}'),
(ry, Identifier `MHashTable.zdWHashTable{v ry}'),
(rz, Type constructor `MHashTable.STHashTable{tc rz}'),
(rA, Class `MHashTable.MutHash{tc rA}'),
(rB, Type constructor `MHashTable.ZCTMutHash{tc rB}'),
(rC, Data constructor `MHashTable.ZCDMutHash{d rC}'),
(rD, Identifier `MHashTable.ZCDMutHash{v rD}'),
(rE, Identifier `MHashTable.newMHArray{v rE}'),
(rF, Identifier `MHashTable.readMHArray{v rF}'),
(rG, Identifier `MHashTable.writeMHArray{v rG}'),
(rH, Identifier `MHashTable.newMHRef{v rH}'),
(rI, Identifier `MHashTable.readMHRef{v rI}'),
(rJ, Identifier `MHashTable.writeMHRef{v rJ}'),
(rK, Identifier `MHashTable.zdp1MutHash{v rK}'),
(rL, Identifier `MHashTable.new{v rL}'),
(rM, Identifier `MHashTable.update{v rM}'),
(rN, Identifier `MHashTable.zdwpolyzuwriteMHArray{v rN}'),
(rO, Identifier `MHashTable.polyzuwriteMHArray{v rO}'),
(rP, Identifier `MHashTable.lit{v rP}'),
(rQ, Identifier `MHashTable.lvl{v rQ}'),
(rR, Identifier `MHashTable.zdwnew{v rR}')]
% make clean
rm -f *.o *.hi a.out
Removing all generated files: A Fresh Start with another
definition of "new" (see attachment):
% /var/tmp/ghc/bin/ghc --make -Dnew_undef -no-recomp -O Main.hs
Chasing modules from: Main.hs
Compiling MHashTable ( ./MHashTable.hs, ./MHashTable.o )
Compiling Main ( Main.hs, Main.o )
Linking ...
Main.o(.text+0x57): undefined reference to `MHashTable_updateST_closure'
Main.o(.rodata+0x0): undefined reference to `MHashTable_updateST_closure'
collect2: ld returned 1 exit status
Finally, executing the previous command again gives _another_
error, which is rather weird given that "-no-recomp" is given...
% /var/tmp/ghc/bin/ghc --make -Dnew_undef -no-recomp -O Main.hs
Chasing modules from: Main.hs
Compiling MHashTable ( ./MHashTable.hs, ./MHashTable.o )
Compiling Main ( Main.hs, Main.o )
ghc-6.4.20050304: panic! (the `impossible' happened, GHC version
6.4.20050304):
lookupVers1 MHashTable updateST{v}
Good night,
Remi
--
Nobody can be exactly like me. Even I have trouble doing it.
{-# OPTIONS -fglasgow-exts -cpp #-}
module MHashTable (STHashTable, new, update) where
import Data.Int (Int32)
import Control.Monad.ST (ST)
import Data.STRef (STRef)
import Data.Array.ST (STArray)
import Data.Array.MArray (writeArray)
class Monad m => MutHash arr ref m | arr -> m, ref -> m
, arr -> ref, ref -> arr where
newMHArray :: (Int32, Int32) -> a -> m (arr Int32 a)
readMHArray :: arr Int32 a -> Int32 -> m a
writeMHArray:: arr Int32 a -> Int32 -> a -> m ()
newMHRef :: a -> m (ref a)
readMHRef :: ref a -> m a
writeMHRef :: ref a -> a -> m ()
instance MutHash (STArray s) (STRef s) (ST s) where
newMHArray = undefined
readMHArray = undefined
writeMHArray= writeArray
newMHRef = undefined
readMHRef = undefined
writeMHRef = undefined
type STHashTable s key val = HashTable key val (STArray s) (STRef s) (ST s)
newtype HashTable key val arr ref m = HashTable (ref (HT key val arr ref m))
data HT key val arr (ref :: * -> *) (m :: * -> *) = HT { dir :: (arr Int32 (arr
Int32 [(key,val)])) }
new :: (MutHash arr ref m) => m (HashTable key val arr ref m)
#ifdef new_undef
new = undefined
#else
new = do
(dir::arr Int32 (arr Int32 [(key,val)])) <- newMHArray (0,0) undefined
(segment::arr Int32 [(key,val)]) <- return undefined
return (undefined :: HashTable key val arr ref m)
#endif
{-# RULES "update/ST" update = updateST #-}
updateST:: STHashTable s k v -> k -> v -> ST s Bool
updateST= update'
update :: (MutHash arr ref m)
=> HashTable key val arr ref m -> key -> val -> m Bool
update = update'
update' :: (MutHash arr ref m)
=> HashTable key val arr ref m -> key -> val -> m Bool
update' _ _ _ = return False
module Main (main) where
import MHashTable
import Control.Monad.ST
main= return $ runST (update (undefined :: STHashTable s Int Int) 0 0)
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs