Skip to content

Commit f2656f6

Browse files
authored
Merge pull request purescript#2560 from purescript/phil/2136
Fix inlining for negateInt
2 parents 9663867 + 85bb0f5 commit f2656f6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

examples/passing/2136.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Main where
2+
3+
import Prelude
4+
import Control.Monad.Eff.Console (log)
5+
6+
main =
7+
if (negate (bottom :: Int) > top)
8+
then log "Fail"
9+
else log "Done"

src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ inlineCommonValues = everywhereOnJS convert
8686
| isDict' [semiringNumber, semiringInt] dict && isFn fnOne fn = JSNumericLiteral ss (Left 1)
8787
| isDict boundedBoolean dict && isFn fnBottom fn = JSBooleanLiteral ss False
8888
| isDict boundedBoolean dict && isFn fnTop fn = JSBooleanLiteral ss True
89+
convert (JSApp ss (JSApp _ fn [dict]) [x])
90+
| isDict ringInt dict && isFn fnNegate fn = JSBinary ss BitwiseOr (JSUnary ss Negate x) (JSNumericLiteral ss (Left 0))
8991
convert (JSApp ss (JSApp _ (JSApp _ fn [dict]) [x]) [y])
9092
| isDict semiringInt dict && isFn fnAdd fn = intOp ss Add x y
9193
| isDict semiringInt dict && isFn fnMultiply fn = intOp ss Multiply x y
@@ -100,6 +102,7 @@ inlineCommonValues = everywhereOnJS convert
100102
fnDivide = (C.dataEuclideanRing, C.div)
101103
fnMultiply = (C.dataSemiring, C.mul)
102104
fnSubtract = (C.dataRing, C.sub)
105+
fnNegate = (C.dataRing, C.negate)
103106
intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
104107

105108
inlineCommonOperators :: JS -> JS
@@ -109,8 +112,6 @@ inlineCommonOperators = applyAll $
109112

110113
, binary ringNumber opSub Subtract
111114
, unary ringNumber opNegate Negate
112-
, binary ringInt opSub Subtract
113-
, unary ringInt opNegate Negate
114115

115116
, binary euclideanRingNumber opDiv Divide
116117
, binary euclideanRingInt opMod Modulus

0 commit comments

Comments
 (0)