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