[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / interpreter / test / typechecker / t004.hs
1 --!!! Testing (one aspect of) the dictionary bug
2 {-
3 Hello,
4
5 Thanks for your reply and advice about the GC debugging. Before I got
6 it, (our mail server is slow and undeterministic for incoming mail,
7 and I have to call it up manually) I had boiled down my program to a
8 quite simple test example, and prepared a mail to send to you.
9
10 I don't know if the two problems are related. With my test program,
11 the bug occurs only after a (manual) GC. Each time. I have to
12 reload the script to get it going again.
13
14 The following is the mail I intended to send, with enclosed test
15 program:
16
17 Hi Alastair,
18
19 I have verified that there is a garbage collection related bug in
20 Hugs 1.01, both in the unpatched and the patched version, compiled
21 for Linux. The unpatched one had no changes to the source expect
22 SUNOS 0 and LINUX 1 in prelude.h
23
24 I have boiled it down to a simple test program.  The program won't
25 compile in either Gofer or Hugs 1.0!  This seems suspicious to me,
26 but maybe the program can be simplified further.
27
28 I still suspect it has something to do with the dictionaries not
29 being marked correctly.
30
31 Maybe this will be of some relevance for your new GC as well.
32
33 I don't know what / if there is a Hugs bug mailing list, maybe
34 you will forward this there or to Mark directly?
35
36 I'll tell you if I find out anything more specific.
37
38 It seems pretty certain the problem has nothing to do with that the
39 suspicious thing begins on Line 13, though...
40
41 Sverker
42
43 PS: Boiled down bug-provoking program enclosed, tbug.gs:
44
45 -}
46 module TestDicts where
47
48 class T a where                 -- Line 1
49         t :: Int ->  a
50
51 instance T Int where
52         t = id
53
54 instance (T a, T b) => T (a, b) where
55         t p = 
56             (t p, t p)
57
58
59 instance (T a, T b, T c) => T (a, b, c) where
60         t p =                           -- Line 13
61             (a, b, c) where
62                         (a, (b, c)) = t p
63 -- The following seems to give the same effect:
64 --      t p = 
65 --         case t (p + 3) of
66 --              (a, (b, c)) -> (a, b, c)
67 -- But the following seems to work:
68 --      t p = (t p, t p, t p)
69
70
71 t2:: Int -> (Int,Int)
72 t2 = t                  -- t2 has no problems
73
74 t3:: Int -> (Int,Int,Int)
75 t3 = t                  -- t3 has problems, see session transcript
76
77
78 {-
79
80 -- Gofer or Hugs 1.0 would not allow this program. Extract from Hugs 1.0:
81
82 ? :l /home/nilsson/ngof/simpleprims/src/tbug.gs
83 Reading script file "/home/nilsson/ngof/simpleprims/src/tbug.gs":
84 Type checking      
85 ERROR "/home/nilsson/ngof/simpleprims/src/tbug.gs" (line 13): Insufficient class constraints in instance member binding
86 *** Context  : (T a, T b, T c)
87 *** Required : T d
88
89 -- Hugs 1.01 allows it, as well as hacked.hugs. But in both the GC bug occurs.
90 -- Extract from Hugs 1.01:
91
92 Hugs session for:
93 /usr/local/lib/Hugs/hugs.prelude
94 tbug.gs
95 ? t3 14
96 (14,14,14)
97 ? :gc
98 Garbage collection recovered 94995 cells
99 ? t3 14
100 (
101
102 INTERNAL ERROR: Error in graph
103 ? t3 17
104 (
105 INTERNAL ERROR: Error in graph
106
107
108 -- Rewriting the tbug.gs file and reloading restores conditions.
109
110 Hugs session for:
111 /usr/local/lib/Hugs/hugs.prelude
112 tbug.gs
113 ? t3 14
114 (14,14,14)
115 ? :gc
116 Garbage collection recovered 94995 cells
117 ? t3 14
118 (
119 INTERNAL ERROR: Error in graph
120
121 -}
122