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