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