git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix unsafeIndex inliner issue https://github.com/andyarvanitis/purescript-native-go-ffi/issues/11
b5b1635Andy Arvanitis
src/CodeGen/IL/Common.hs+4
@@ -81,6 +81,7 @@ nameIsILBuiltIn name =
81 , "Fn"
81 , "Fn"
82 , "Foreign"
82 , "Foreign"
83 , "Get"
83 , "Get"
84+ , "Index"
84 , "Length"
85 , "Length"
85 , "Once"
86 , "Once"
86 , "Run"
87 , "Run"
@@ -184,6 +185,9 @@ string = "string"
184arrayLengthFn :: Text
185arrayLengthFn :: Text
185arrayLengthFn = "Length"
186arrayLengthFn = "Length"
186
187
188+indexFn :: Text
189+indexFn = "Index"
190+
187freshName' :: MonadSupply m => m Text
191freshName' :: MonadSupply m => m Text
188freshName' = do
192freshName' = do
189 name <- freshName
193 name <- freshName
src/CodeGen/IL/Optimizer/Inliner.hs+10−1
@@ -122,7 +122,7 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
122
122
123 , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> App Nothing f [x]
123 , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> App Nothing f [x]
124 , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> App Nothing f [x]
124 , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> App Nothing f [x]
125− , inlineNonClassFunction (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
125+ , inlineUnsafeIndex (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
126 ] ++
126 ] ++
127 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ] ++
127 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ] ++
128 [ fn | i <- [0..10], fn <- [ mkEffFn C.controlMonadEffUncurried C.mkEffFn i, runEffFn C.controlMonadEffUncurried C.runEffFn i ] ] ++
128 [ fn | i <- [0..10], fn <- [ mkEffFn C.controlMonadEffUncurried C.mkEffFn i, runEffFn C.controlMonadEffUncurried C.runEffFn i ] ] ++
@@ -211,6 +211,15 @@ inlineCommonOperators = everywhereTopDown $ applyAll $
211 convert (App _ (App _ op' [x]) [y]) | p op' = f x y
211 convert (App _ (App _ op' [x]) [y]) | p op' = f x y
212 convert other = other
212 convert other = other
213
213
214+ inlineUnsafeIndex :: (AST -> Bool) -> (AST -> AST -> AST) -> AST -> AST
215+ inlineUnsafeIndex p _ = convert where
216+ convert :: AST -> AST
217+ convert (App _ (App ss op' [x]) [y@NumericLiteral{}])
218+ | p op' = Indexer ss y x
219+ convert (App _ (App ss op' [x]) [y])
220+ | p op' = App ss (Var Nothing indexFn) [x, y]
221+ convert other = other
222+
214 isModFn :: (Text, PSString) -> AST -> Bool
223 isModFn :: (Text, PSString) -> AST -> Bool
215 isModFn (m, op) (Indexer _ (Var _ op') (Var _ m')) =
224 isModFn (m, op) (Indexer _ (Var _ op') (Var _ m')) =
216 m == m' && decodeString op == Just op'
225 m == m' && decodeString op == Just op'
src/CodeGen/IL/Printer.hs+6
@@ -106,6 +106,12 @@ literals = mkPattern' match'
106 , prettyPrintIL' arg
106 , prettyPrintIL' arg
107 , return $ emit ")"
107 , return $ emit ")"
108 ]
108 ]
109+ match (App _ (Var _ fn) args) | fn == indexFn = mconcat <$> sequence
110+ [ return $ emit fn
111+ , return $ emit "("
112+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
113+ , return $ emit ")"
114+ ]
109 match (App _ (Var _ fn) args) | fn == tcoLoop = mconcat <$> sequence
115 match (App _ (Var _ fn) args) | fn == tcoLoop = mconcat <$> sequence
110 [ return $ emit fn
116 [ return $ emit fn
111 , return $ emit "("
117 , return $ emit "("