@@ -113,37 +113,6 @@ signature module DeltaSig {
113
113
}
114
114
115
115
signature module LangSig< DeltaSig D> {
116
- /** A reason for an inferred bound. */
117
- class SemReason {
118
- /**
119
- * Returns `this` if `reason` is not a `SemTypeReason`. Otherwise,
120
- * this predicate returns `SemTypeReason`.
121
- *
122
- * This predicate ensures that we propagate `SemTypeReason` all the way
123
- * to the top-level of a call to `semBounded` if the inferred bound is
124
- * based on type-information.
125
- */
126
- bindingset [ this , reason]
127
- SemReason combineWith ( SemReason reason ) ;
128
- }
129
-
130
- /**
131
- * A reason for an inferred bound that indicates that the bound is inferred
132
- * without going through a bounding condition.
133
- */
134
- class SemNoReason extends SemReason ;
135
-
136
- /** A reason for an inferred bound pointing to a condition. */
137
- class SemCondReason extends SemReason {
138
- SemGuard getCond ( ) ;
139
- }
140
-
141
- /**
142
- * A reason for an inferred bound that indicates that the bound is inferred
143
- * based on type-information.
144
- */
145
- class SemTypeReason extends SemReason ;
146
-
147
116
/**
148
117
* Holds if the specified expression should be excluded from the result of `ssaRead()`.
149
118
*
@@ -280,14 +249,6 @@ module RangeStage<
280
249
DeltaSig D, BoundSig< D > Bounds, OverflowSig< D > OverflowParam, LangSig< D > LangParam,
281
250
UtilSig< D > UtilParam>
282
251
{
283
- class SemReason = LangParam:: SemReason ;
284
-
285
- class SemCondReason = LangParam:: SemCondReason ;
286
-
287
- class SemNoReason = LangParam:: SemNoReason ;
288
-
289
- class SemTypeReason = LangParam:: SemTypeReason ;
290
-
291
252
private import Bounds
292
253
private import LangParam
293
254
private import UtilParam
@@ -548,6 +509,36 @@ module RangeStage<
548
509
)
549
510
}
550
511
512
+ private newtype TSemReason =
513
+ TSemNoReason ( ) or
514
+ TSemCondReason ( SemGuard guard ) { possibleReason ( guard ) }
515
+
516
+ /**
517
+ * A reason for an inferred bound. This can either be `CondReason` if the bound
518
+ * is due to a specific condition, or `NoReason` if the bound is inferred
519
+ * without going through a bounding condition.
520
+ */
521
+ abstract class SemReason extends TSemReason {
522
+ /** Gets a textual representation of this reason. */
523
+ abstract string toString ( ) ;
524
+ }
525
+
526
+ /**
527
+ * A reason for an inferred bound that indicates that the bound is inferred
528
+ * without going through a bounding condition.
529
+ */
530
+ class SemNoReason extends SemReason , TSemNoReason {
531
+ override string toString ( ) { result = "NoReason" }
532
+ }
533
+
534
+ /** A reason for an inferred bound pointing to a condition. */
535
+ class SemCondReason extends SemReason , TSemCondReason {
536
+ /** Gets the condition that is the reason for the bound. */
537
+ SemGuard getCond ( ) { this = TSemCondReason ( result ) }
538
+
539
+ override string toString ( ) { result = this .getCond ( ) .toString ( ) }
540
+ }
541
+
551
542
/**
552
543
* Holds if `e + delta` is a valid bound for `v` at `pos`.
553
544
* - `upper = true` : `v <= e + delta`
@@ -560,13 +551,13 @@ module RangeStage<
560
551
semSsaUpdateStep ( v , e , delta ) and
561
552
pos .hasReadOfVar ( v ) and
562
553
( upper = true or upper = false ) and
563
- reason instanceof SemNoReason
554
+ reason = TSemNoReason ( )
564
555
or
565
556
exists ( SemGuard guard , boolean testIsTrue |
566
557
pos .hasReadOfVar ( v ) and
567
558
guard = boundFlowCond ( v , e , delta , upper , testIsTrue ) and
568
559
semGuardDirectlyControlsSsaRead ( guard , pos , testIsTrue ) and
569
- reason . ( SemCondReason ) . getCond ( ) = guard
560
+ reason = TSemCondReason ( guard )
570
561
)
571
562
}
572
563
@@ -579,7 +570,7 @@ module RangeStage<
579
570
pos .hasReadOfVar ( v ) and
580
571
guard = semEqFlowCond ( v , e , delta , false , testIsTrue ) and
581
572
semGuardDirectlyControlsSsaRead ( guard , pos , testIsTrue ) and
582
- reason . ( SemCondReason ) . getCond ( ) = guard
573
+ reason = TSemCondReason ( guard )
583
574
)
584
575
}
585
576
@@ -709,7 +700,7 @@ module RangeStage<
709
700
// upper = true: v <= mid + d1 <= b + d1 + d2 = b + delta
710
701
// upper = false: v >= mid + d1 >= b + d1 + d2 = b + delta
711
702
delta = D:: fromFloat ( D:: toFloat ( d1 ) + D:: toFloat ( d2 ) ) and
712
- ( if r1 instanceof SemNoReason then reason = r2 else reason = r1 . combineWith ( r2 ) )
703
+ ( if r1 instanceof SemNoReason then reason = r2 else reason = r1 )
713
704
)
714
705
or
715
706
exists ( D:: Delta d , SemReason r1 , SemReason r2 |
@@ -723,9 +714,9 @@ module RangeStage<
723
714
upper = false and delta = D:: fromFloat ( D:: toFloat ( d ) + 1 )
724
715
) and
725
716
(
726
- reason = r1 . combineWith ( r2 )
717
+ reason = r1
727
718
or
728
- reason = r2 . combineWith ( r1 ) and not r2 instanceof SemNoReason
719
+ reason = r2 and not r2 instanceof SemNoReason
729
720
)
730
721
)
731
722
}
@@ -795,7 +786,7 @@ module RangeStage<
795
786
( upper = true or upper = false ) and
796
787
fromBackEdge0 = false and
797
788
origdelta = D:: fromFloat ( 0 ) and
798
- reason instanceof SemNoReason
789
+ reason = TSemNoReason ( )
799
790
|
800
791
if semBackEdge ( phi , inp , edge )
801
792
then
@@ -1053,13 +1044,13 @@ module RangeStage<
1053
1044
( upper = true or upper = false ) and
1054
1045
fromBackEdge = false and
1055
1046
origdelta = delta and
1056
- reason instanceof SemNoReason
1047
+ reason = TSemNoReason ( )
1057
1048
or
1058
1049
baseBound ( e , delta , upper ) and
1059
1050
b instanceof SemZeroBound and
1060
1051
fromBackEdge = false and
1061
1052
origdelta = delta and
1062
- reason instanceof SemNoReason
1053
+ reason = TSemNoReason ( )
1063
1054
or
1064
1055
exists ( SemSsaVariable v , SemSsaReadPositionBlock bb |
1065
1056
boundedSsa ( v , bb , b , delta , upper , fromBackEdge , origdelta , reason ) and
@@ -1113,9 +1104,9 @@ module RangeStage<
1113
1104
boundedConditionalExpr ( cond , b , upper , true , d1 , fbe1 , od1 , r1 ) and
1114
1105
boundedConditionalExpr ( cond , b , upper , false , d2 , fbe2 , od2 , r2 ) and
1115
1106
(
1116
- delta = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1 . combineWith ( r2 )
1107
+ delta = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1
1117
1108
or
1118
- delta = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2 . combineWith ( r1 )
1109
+ delta = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2
1119
1110
)
1120
1111
|
1121
1112
upper = true and delta = D:: fromFloat ( D:: toFloat ( d1 ) .maximum ( D:: toFloat ( d2 ) ) )
@@ -1141,15 +1132,9 @@ module RangeStage<
1141
1132
delta = D:: fromFloat ( D:: toFloat ( dLeft ) + D:: toFloat ( dRight ) ) and
1142
1133
fromBackEdge = fbeLeft .booleanOr ( fbeRight )
1143
1134
|
1144
- b = bLeft and
1145
- origdelta = odLeft and
1146
- reason = rLeft .combineWith ( rRight ) and
1147
- bRight instanceof SemZeroBound
1135
+ b = bLeft and origdelta = odLeft and reason = rLeft and bRight instanceof SemZeroBound
1148
1136
or
1149
- b = bRight and
1150
- origdelta = odRight and
1151
- reason = rRight .combineWith ( rLeft ) and
1152
- bLeft instanceof SemZeroBound
1137
+ b = bRight and origdelta = odRight and reason = rRight and bLeft instanceof SemZeroBound
1153
1138
)
1154
1139
or
1155
1140
exists (
@@ -1165,9 +1150,9 @@ module RangeStage<
1165
1150
(
1166
1151
if D:: toFloat ( d1 ) .abs ( ) > D:: toFloat ( d2 ) .abs ( )
1167
1152
then (
1168
- d_max = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1 . combineWith ( r2 )
1153
+ d_max = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1
1169
1154
) else (
1170
- d_max = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2 . combineWith ( r1 )
1155
+ d_max = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2
1171
1156
)
1172
1157
)
1173
1158
|
@@ -1183,14 +1168,11 @@ module RangeStage<
1183
1168
boundedMulOperand ( e , upper , true , dLeft , fbeLeft , odLeft , rLeft ) and
1184
1169
boundedMulOperand ( e , upper , false , dRight , fbeRight , odRight , rRight ) and
1185
1170
delta = D:: fromFloat ( D:: toFloat ( dLeft ) * D:: toFloat ( dRight ) ) and
1186
- fromBackEdge = fbeLeft .booleanOr ( fbeRight ) and
1187
- b instanceof SemZeroBound
1171
+ fromBackEdge = fbeLeft .booleanOr ( fbeRight )
1188
1172
|
1189
- origdelta = odLeft and
1190
- reason = rLeft .combineWith ( rRight )
1173
+ b instanceof SemZeroBound and origdelta = odLeft and reason = rLeft
1191
1174
or
1192
- origdelta = odRight and
1193
- reason = rRight .combineWith ( rLeft )
1175
+ b instanceof SemZeroBound and origdelta = odRight and reason = rRight
1194
1176
)
1195
1177
)
1196
1178
}
0 commit comments