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