Lexer: Suggest adding 'let' on unexpected '=' token
[ghc.git] / compiler / hsSyn / PlaceHolder.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE TypeFamilies #-}
3 {-# LANGUAGE ConstraintKinds #-}
4 {-# LANGUAGE FlexibleContexts #-}
5
6 module PlaceHolder where
7
8 import Type ( Type )
9 import Outputable
10 import Name
11 import NameSet
12 import RdrName
13 import Var
14 import Coercion
15
16 import Data.Data hiding ( Fixity )
17 import BasicTypes (Fixity)
18
19
20 {-
21 %************************************************************************
22 %* *
23 \subsection{Annotating the syntax}
24 %* *
25 %************************************************************************
26 -}
27
28 -- | used as place holder in PostTc and PostRn values
29 data PlaceHolder = PlaceHolder
30 deriving (Data,Typeable)
31
32 -- | Types that are not defined until after type checking
33 type family PostTc it ty :: * -- Note [Pass sensitive types]
34 type instance PostTc Id ty = ty
35 type instance PostTc Name ty = PlaceHolder
36 type instance PostTc RdrName ty = PlaceHolder
37
38 -- | Types that are not defined until after renaming
39 type family PostRn id ty :: * -- Note [Pass sensitive types]
40 type instance PostRn Id ty = ty
41 type instance PostRn Name ty = ty
42 type instance PostRn RdrName ty = PlaceHolder
43
44 placeHolderKind :: PlaceHolder
45 placeHolderKind = PlaceHolder
46
47 placeHolderFixity :: PlaceHolder
48 placeHolderFixity = PlaceHolder
49
50 placeHolderType :: PlaceHolder
51 placeHolderType = PlaceHolder
52
53 placeHolderTypeTc :: Type
54 placeHolderTypeTc = panic "Evaluated the place holder for a PostTcType"
55
56 placeHolderNames :: PlaceHolder
57 placeHolderNames = PlaceHolder
58
59 placeHolderNamesTc :: NameSet
60 placeHolderNamesTc = emptyNameSet
61
62 {-
63
64 Note [Pass sensitive types]
65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66 Since the same AST types are re-used through parsing,renaming and type
67 checking there are naturally some places in the AST that do not have
68 any meaningful value prior to the pass they are assigned a value.
69
70 Historically these have been filled in with place holder values of the form
71
72 panic "error message"
73
74 This has meant the AST is difficult to traverse using standed generic
75 programming techniques. The problem is addressed by introducing
76 pass-specific data types, implemented as a pair of open type families,
77 one for PostTc and one for PostRn. These are then explicitly populated
78 with a PlaceHolder value when they do not yet have meaning.
79
80 Since the required bootstrap compiler at this stage does not have
81 closed type families, an open type family had to be used, which
82 unfortunately forces the requirement for UndecidableInstances.
83
84 In terms of actual usage, we have the following
85
86 PostTc id Kind
87 PostTc id Type
88
89 PostRn id Fixity
90 PostRn id NameSet
91
92 TcId and Var are synonyms for Id
93 -}
94
95 type DataId id =
96 ( Data id
97 , Data (PostRn id NameSet)
98 , Data (PostRn id Fixity)
99 , Data (PostRn id Bool)
100 , Data (PostRn id Name)
101 , Data (PostRn id [Name])
102
103 , Data (PostTc id Type)
104 , Data (PostTc id Coercion)
105 )