Add Template Haskell support for overloaded labels
[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
16 import Data.Data hiding ( Fixity )
17
18
19 {-
20 %************************************************************************
21 %* *
22 \subsection{Annotating the syntax}
23 %* *
24 %************************************************************************
25 -}
26
27 -- NB: These are intentionally open, allowing API consumers (like Haddock)
28 -- to declare new instances
29
30 -- | used as place holder in PostTc and PostRn values
31 data PlaceHolder = PlaceHolder
32 deriving (Data)
33
34 placeHolderKind :: PlaceHolder
35 placeHolderKind = PlaceHolder
36
37 placeHolderFixity :: PlaceHolder
38 placeHolderFixity = PlaceHolder
39
40 placeHolderType :: PlaceHolder
41 placeHolderType = PlaceHolder
42
43 placeHolderTypeTc :: Type
44 placeHolderTypeTc = panic "Evaluated the place holder for a PostTcType"
45
46 placeHolderNames :: PlaceHolder
47 placeHolderNames = PlaceHolder
48
49 placeHolderNamesTc :: NameSet
50 placeHolderNamesTc = emptyNameSet
51
52 placeHolderHsWrapper :: PlaceHolder
53 placeHolderHsWrapper = PlaceHolder
54
55 {-
56
57 Note [Pass sensitive types]
58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59 Since the same AST types are re-used through parsing,renaming and type
60 checking there are naturally some places in the AST that do not have
61 any meaningful value prior to the pass they are assigned a value.
62
63 Historically these have been filled in with place holder values of the form
64
65 panic "error message"
66
67 This has meant the AST is difficult to traverse using standard generic
68 programming techniques. The problem is addressed by introducing
69 pass-specific data types, implemented as a pair of open type families,
70 one for PostTc and one for PostRn. These are then explicitly populated
71 with a PlaceHolder value when they do not yet have meaning.
72
73 In terms of actual usage, we have the following
74
75 PostTc id Kind
76 PostTc id Type
77
78 PostRn id Fixity
79 PostRn id NameSet
80
81 TcId and Var are synonyms for Id
82
83 Unfortunately the type checker termination checking conditions fail for the
84 DataId constraint type based on this, so even though it is safe the
85 UndecidableInstances pragma is required where this is used.
86 -}
87
88
89 -- |Follow the @id@, but never beyond Name. This is used in a 'HsMatchContext',
90 -- for printing messages related to a 'Match'
91 type family NameOrRdrName id where
92 NameOrRdrName Id = Name
93 NameOrRdrName Name = Name
94 NameOrRdrName RdrName = RdrName