[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / docs / NOTES.import
1                 Notes on imports
2                 ~~~~~~~~~~~~~~~~
3                 SLPJ 15 March 91
4
5
6 Distinguish three kinds of things in interfaces:
7
8         - type, data, class, instance, value decls at top level
9
10         - the same but imported.  Syntax
11                 import B renaming C to D where
12                         data C = ...
13
14         - imports, which serve just to attach original names
15                 import B(X,Y)
16
17
18 The third group are syntactically stuck at the beginning; the second two
19 can be intermingled.
20
21 Pass 1
22 ~~~~~~
23 Process each imported interface, and the implementation being compiled,
24 scanning *headers of*
25
26         type, data and class decls (incl imported ones in interfaces)
27
28 giving the following environments for each
29
30         type/data info  {(ModStr,TyConStr) -> arity}
31         class info      {(ModStr,ClassStr)}
32
33 These are filtered (*but not renamed*) by the imports specified in the
34 impl (ignore dotdot parts and parts in parens), to give a grand
35 environment E1 of the same shape.  It gives the original names of in-scope
36 types and classes.
37
38 Pass 2
39 ~~~~~~
40 Process each imported interface and the implementation being compiled:
41         
42         - scan its imports and use them to filter and rename E1, to give
43
44                         {TyConStr -> arity}
45                         {ClassStr}
46
47         - scan type, data, class decls, headers of instance decls
48           and value type sigs in interfaces
49
50 giving for each:
51
52         class info (CE)         {ClassStr -> (ClassId, [ClassOpStr])}
53         inst info (GIE)         {(ClassId,TyConId) -> (Context, GlobalId)}
54                 (info from both class and instance decls)
55
56         type/data info (TCE)    {TyConStr -> (TyConId, [ConstrStr])}
57
58
59         value info (GVE)        {ValStr -> GlobalId}
60                 (info from value sigs, and constructors from data decls)
61
62 Filter and rename the environments gotten from each import to make a grand
63 environment E2. 
64
65 Pass 3
66 ~~~~~~
67 Check E2 for class cycles, and type synonym cycles.
68
69 Pass 4
70 ~~~~~~
71 Process the value decls in the impl, giving {ValStr -> GlobalId}, and some
72 code.
73
74 Pass 5
75 ~~~~~~
76 Process the bodies of instance decls, to generate code for methods.
77
78
79
80
81
82
83                 UNRESOLVED
84                 ~~~~~~~~~~
85 1. Who generates the interface?
86
87 2. Where is dependency analysis done?
88
89
90