git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2560 from purescript/phil/2136

Fix inlining for negateInt

commitf2656f600e9df5548fa266b99435c694d6cc8cd2 authorPhil Freeman <paf31@cantab.net> dateFri 13 Jan 2017, 09:37 (10 years ago) parent966386785bb0f5
2 files changed+12−2
examples/passing/2136.purs+9 src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+3−2
examples/passing/2136.pursnew file+9
@@ -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+3−2
@@ -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
105108inlineCommonOperators :: 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