-
Notifications
You must be signed in to change notification settings - Fork 21
/
CommonCHR.chs
169 lines (143 loc) · 7.5 KB
/
CommonCHR.chs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Shared between CHR+Pred and (in particular) Ty/FitsIn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Derived from work by Gerrit vd Geest.
This file exists to avoid module circularities.
%%[9 module {%{EH}Pred.CommonCHR} import({%{EH}CHR},{%{EH}CHR.Constraint}) export(module {%{EH}CHR},module {%{EH}CHR.Constraint})
%%]
%%[9 import(qualified Data.Map as Map,qualified Data.Set as Set)
%%]
%%[9 import(EH.Util.Pretty)
%%]
%%[9 import({%{EH}Base.Common})
%%]
%%[9 import({%{EH}Ty})
%%]
%%[9 import({%{EH}Base.CfgPP})
%%]
%%[99 import({%{EH}Base.ForceEval})
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Reduction info
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[9 export(RedHowAnnotation(..))
data RedHowAnnotation
= RedHow_ByInstance !HsName !Pred !PredScope -- inst name, for pred, in scope
| RedHow_BySuperClass !HsName !Int !CTag -- field name, offset, tag info of dict
| RedHow_ProveObl !UID !PredScope
| RedHow_Assumption !VarUIDHsName !PredScope
| RedHow_ByScope
%%[[10
| RedHow_ByLabel !Label !LabelOffset !PredScope
%%]]
%%[[13
| RedHow_Lambda !UID !PredScope
%%]]
%%[[16
| RedHow_ByEqSymmetry
| RedHow_ByEqTrans
| RedHow_ByEqCongr
| RedHow_ByEqTyReduction !Ty !Ty
| RedHow_ByPredSeqUnpack
| RedHow_ByEqFromAssume
%%]]
deriving (Eq, Ord)
%%]
%%[9
instance Show RedHowAnnotation where
show = showPP . pp
%%]
%%[9
instance PP RedHowAnnotation where
pp (RedHow_ByInstance s p sc) = "inst" >#< ppParensCommas [pp s, pp sc]
pp (RedHow_BySuperClass s _ _ ) = "super" >#< s
pp (RedHow_ProveObl i sc) = "prove" >#< i >#< sc
pp (RedHow_Assumption vun sc) = "assume" >#< ppParensCommas [pp vun, pp sc]
pp (RedHow_ByScope ) = pp "scope"
%%[[10
pp (RedHow_ByLabel l o sc) = "label" >#< l >|< "@" >|< o >|< sc
%%]]
%%[[13
pp (RedHow_Lambda i sc) = "lambda" >#< i >#< sc
%%]]
%%[[16
pp (RedHow_ByEqSymmetry) = pp "eqsym"
pp (RedHow_ByEqTrans ) = pp "eqtrans"
pp (RedHow_ByEqCongr ) = pp "eqcongr"
pp (RedHow_ByEqTyReduction ty1 ty2) = "eqtyred" >#< ty1 >#< "~>" >#< ty2
pp (RedHow_ByPredSeqUnpack) = pp "unpack"
pp (RedHow_ByEqFromAssume) = pp "eqassume"
%%]]
%%]
pp (RedHow_ByInstance s p sc) = "inst" >#< s >|< sc >#< "::" >#< p
%%[20
instance PPForHI RedHowAnnotation where
ppForHI (RedHow_ByInstance s p sc) = "redhowinst" >#< ppCurlysCommasBlock [ppForHI s, ppForHI p, ppForHI sc]
ppForHI (RedHow_BySuperClass s o tg) = "redhowsuper" >#< ppCurlysCommasBlock [ppForHI s, pp o, ppForHI tg]
ppForHI (RedHow_ProveObl i sc) = "redhowprove" >#< ppCurlysCommasBlock [ppForHI i, ppForHI sc]
ppForHI (RedHow_Assumption vun sc) = "redhowassume" >#< ppCurlysCommasBlock [ppForHI vun, ppForHI sc]
ppForHI (RedHow_ByScope ) = pp "redhowscope"
ppForHI (RedHow_ByLabel l o sc) = "redhowlabel" >#< ppCurlysCommasBlock [ppForHI l, ppForHI o, ppForHI sc]
ppForHI (RedHow_Lambda i sc) = "redhowlambda" >#< ppCurlysCommasBlock [ppForHI i, ppForHI sc]
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Constraint construction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[9 export(mkProveConstraint,mkAssumeConstraint,mkAssumeConstraint')
mkProveConstraint :: Pred -> UID -> PredScope -> (Constraint CHRPredOcc RedHowAnnotation,RedHowAnnotation)
mkProveConstraint pr i sc = (Prove (mkCHRPredOcc pr sc),RedHow_ProveObl i sc)
mkAssumeConstraint'' :: Pred -> VarUIDHsName -> PredScope -> (Constraint CHRPredOcc RedHowAnnotation,RedHowAnnotation)
mkAssumeConstraint'' pr vun sc = (Assume (mkCHRPredOcc pr sc),RedHow_Assumption vun sc)
mkAssumeConstraint' :: Pred -> UID -> HsName -> PredScope -> (Constraint CHRPredOcc RedHowAnnotation,RedHowAnnotation)
mkAssumeConstraint' pr i n sc = mkAssumeConstraint'' pr (VarUIDHs_Name i n) sc
mkAssumeConstraint :: Pred -> UID -> PredScope -> (Constraint CHRPredOcc RedHowAnnotation,RedHowAnnotation)
mkAssumeConstraint pr i sc = mkAssumeConstraint'' pr (VarUIDHs_UID i) sc
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Constraint to info map for CHRPredOcc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[9 export(CHRPredOccCnstrMp)
type CHRPredOccCnstrMp = ConstraintToInfoMap CHRPredOcc RedHowAnnotation
%%]
%%[9 export(gathPredLToProveCnstrMp,gathPredLToAssumeCnstrMp)
gathPredLToProveCnstrMp :: [PredOcc] -> CHRPredOccCnstrMp
gathPredLToProveCnstrMp l = cnstrMpFromList [ mkProveConstraint (poPr po) (poId po) (poScope po) | po <- l ]
gathPredLToAssumeCnstrMp :: [PredOcc] -> CHRPredOccCnstrMp
gathPredLToAssumeCnstrMp l = cnstrMpFromList [ mkAssumeConstraint (poPr po) (poId po) (poScope po) | po <- l ]
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ForceEval
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[99
instance ForceEval VarUIDHsName where
forceEval x@(VarUIDHs_Name i n) | forceEval i `seq` forceEval n `seq` True = x
forceEval x@(VarUIDHs_UID i ) | forceEval i `seq` True = x
forceEval x@(VarUIDHs_Var i ) | forceEval i `seq` True = x
%%[[101
fevCount (VarUIDHs_Name i n) = cm1 "VarUIDHs_Name" `cmUnion` fevCount i `cmUnion` fevCount n
fevCount (VarUIDHs_UID i ) = cm1 "VarUIDHs_UID" `cmUnion` fevCount i
fevCount (VarUIDHs_Var i ) = cm1 "VarUIDHs_Var" `cmUnion` fevCount i
%%]]
instance ForceEval RedHowAnnotation where
forceEval x@(RedHow_ByInstance _ p sc) | forceEval p `seq` forceEval sc `seq` True = x
forceEval x@(RedHow_ProveObl _ sc) | forceEval sc `seq` True = x
forceEval x@(RedHow_Assumption _ sc) | forceEval sc `seq` True = x
forceEval x@(RedHow_ByLabel l o sc) | forceEval l `seq` forceEval o `seq` forceEval sc `seq` True = x
forceEval x@(RedHow_Lambda _ sc) | forceEval sc `seq` True = x
forceEval x = x
%%[[101
fevCount (RedHow_ByInstance s p sc) = cm1 "RedHow_ByInstance" `cmUnion` fevCount s `cmUnion` fevCount p `cmUnion` fevCount sc
fevCount (RedHow_BySuperClass s o tg) = cm1 "RedHow_BySuperClass" `cmUnion` fevCount s `cmUnion` fevCount o `cmUnion` fevCount tg
fevCount (RedHow_ProveObl i sc) = cm1 "RedHow_ProveObl" `cmUnion` fevCount i `cmUnion` fevCount sc
fevCount (RedHow_Assumption vun sc) = cm1 "RedHow_Assumption" `cmUnion` fevCount vun `cmUnion` fevCount sc
fevCount (RedHow_ByScope ) = cm1 "RedHow_ByScope"
fevCount (RedHow_ByEqSymmetry ) = cm1 "RedHow_ByEqSymmetry"
fevCount (RedHow_ByEqTrans ) = cm1 "RedHow_ByEqTrans"
fevCount (RedHow_ByEqCongr ) = cm1 "RedHow_ByEqCongr"
fevCount (RedHow_ByEqTyReduction ty1 ty2) = cm1 "RedHow_ByEqTyReduction" `cmUnion` fevCount ty1 `cmUnion` fevCount ty2
fevCount (RedHow_ByPredSeqUnpack ) = cm1 "RedHow_ByPredSeqUnpack"
fevCount (RedHow_ByEqFromAssume ) = cm1 "RedHow_ByEqFromAssume"
fevCount (RedHow_ByLabel l o sc) = cm1 "RedHow_ByLabel" `cmUnion` fevCount l `cmUnion` fevCount o `cmUnion` fevCount sc
fevCount (RedHow_Lambda i sc) = cm1 "RedHow_Lambda" `cmUnion` fevCount i `cmUnion` fevCount sc
%%]]
%%]