git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Prevent unused arguments from being renamed
d96d4a0Gary Burgess
src/Language/PureScript/Constants.hs+3
@@ -201,6 +201,9 @@ main = "main"
201__superclass_ :: String
201__superclass_ :: String
202__superclass_ = "__superclass_"
202__superclass_ = "__superclass_"
203
203
204+__unused :: String
205+__unused = "__unused"
206+
204-- Modules
207-- Modules
205
208
206prim :: String
209prim :: String
src/Language/PureScript/Optimizer/Inliner.hs+2−2
@@ -49,8 +49,8 @@ etaConvert = everywhereOnJS convert
49 not (any (`isRebound` block) (map JSVar idents)) &&
49 not (any (`isRebound` block) (map JSVar idents)) &&
50 not (any (`isRebound` block) args)
50 not (any (`isRebound` block) args)
51 = JSBlock (map (replaceIdents (zip idents args)) body)
51 = JSBlock (map (replaceIdents (zip idents args)) body)
52− convert (JSFunction Nothing ["_"] (JSBlock [JSReturn (JSApp fn@JSVar{} [JSObjectLiteral []])]))
52+ convert (JSFunction Nothing [arg] (JSBlock [JSReturn (JSApp fn@JSVar{} [JSObjectLiteral []])]))
53− = fn
53+ | arg == C.__unused = fn
54 convert js = js
54 convert js = js
55
55
56unThunk :: JS -> JS
56unThunk :: JS -> JS
src/Language/PureScript/Optimizer/MagicDo.hs+1−1
@@ -60,7 +60,7 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
60 -- Desugar pure
60 -- Desugar pure
61 convert (JSApp (JSApp pure' [val]) []) | isPure pure' = val
61 convert (JSApp (JSApp pure' [val]) []) | isPure pure' = val
62 -- Desugar >>
62 -- Desugar >>
63− convert (JSApp (JSApp bind [m]) [JSFunction Nothing ["_"] (JSBlock js)]) | isBind bind && isJSReturn (last js) =
63+ convert (JSApp (JSApp bind [m]) [JSFunction Nothing [arg] (JSBlock js)]) | isBind bind && isJSReturn (last js) && arg == C.__unused =
64 let JSReturn ret = last js in
64 let JSReturn ret = last js in
65 JSFunction (Just fnName) [] $ JSBlock (JSApp m [] : init js ++ [JSReturn (JSApp ret [])] )
65 JSFunction (Just fnName) [] $ JSBlock (JSApp m [] : init js ++ [JSReturn (JSApp ret [])] )
66 -- Desugar >>=
66 -- Desugar >>=
src/Language/PureScript/Renamer.hs+4
@@ -28,6 +28,8 @@ import Language.PureScript.Environment
28import Language.PureScript.Names
28import Language.PureScript.Names
29import Language.PureScript.Traversals
29import Language.PureScript.Traversals
30
30
31+import qualified Language.PureScript.Constants as C
32+
31-- |
33-- |
32-- The state object used in this module
34-- The state object used in this module
33--
35--
@@ -69,6 +71,7 @@ newScope x = do
69-- unique name is generated and stored.
71-- unique name is generated and stored.
70--
72--
71updateScope :: Ident -> Rename Ident
73updateScope :: Ident -> Rename Ident
74+updateScope i@(Ident name) | name == C.__unused = return i
72updateScope name = do
75updateScope name = do
73 scope <- get
76 scope <- get
74 let name' = case name `S.member` rsUsedNames scope of
77 let name' = case name `S.member` rsUsedNames scope of
@@ -87,6 +90,7 @@ updateScope name = do
87-- Finds the new name to use for an ident.
90-- Finds the new name to use for an ident.
88--
91--
89lookupIdent :: Ident -> Rename Ident
92lookupIdent :: Ident -> Rename Ident
93+lookupIdent i@(Ident name) | name == C.__unused = return i
90lookupIdent name = do
94lookupIdent name = do
91 name' <- gets $ M.lookup name . rsBoundNames
95 name' <- gets $ M.lookup name . rsBoundNames
92 case name' of
96 case name' of
src/Language/PureScript/Sugar/DoNotation.hs+1−1
@@ -57,7 +57,7 @@ desugarDo d =
57 go [DoNotationValue val] = return val
57 go [DoNotationValue val] = return val
58 go (DoNotationValue val : rest) = do
58 go (DoNotationValue val : rest) = do
59 rest' <- go rest
59 rest' <- go rest
60− return $ App (App bind val) (Abs (Left (Ident "_")) rest')
60+ return $ App (App bind val) (Abs (Left (Ident C.__unused)) rest')
61 go [DoNotationBind _ _] = lift $ Left $ mkErrorStack "Bind statement cannot be the last statement in a do block" Nothing
61 go [DoNotationBind _ _] = lift $ Left $ mkErrorStack "Bind statement cannot be the last statement in a do block" Nothing
62 go (DoNotationBind NullBinder val : rest) = go (DoNotationValue val : rest)
62 go (DoNotationBind NullBinder val : rest) = go (DoNotationValue val : rest)
63 go (DoNotationBind (VarBinder ident) val : rest) = do
63 go (DoNotationBind (VarBinder ident) val : rest) = do
src/Language/PureScript/Sugar/TypeClasses.hs+2−2
@@ -239,7 +239,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
239 -- must be guarded by at least one function abstraction. For that reason, if the dictionary has no
239 -- must be guarded by at least one function abstraction. For that reason, if the dictionary has no
240 -- dependencies, we introduce an unnamed function parameter.
240 -- dependencies, we introduce an unnamed function parameter.
241 let superclasses =
241 let superclasses =
242− [ (fieldName, Abs (Left (Ident "_")) (SuperClassDictionary superclass tyArgs))
242+ [ (fieldName, Abs (Left (Ident C.__unused)) (SuperClassDictionary superclass tyArgs))
243 | (index, (superclass, suTyArgs)) <- zip [0..] implies
243 | (index, (superclass, suTyArgs)) <- zip [0..] implies
244 , let tyArgs = map (replaceAllTypeVars (zip args tys)) suTyArgs
244 , let tyArgs = map (replaceAllTypeVars (zip args tys)) suTyArgs
245 , let fieldName = mkSuperclassDictionaryName superclass index
245 , let fieldName = mkSuperclassDictionaryName superclass index
@@ -249,7 +249,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
249 dictTy = foldl TypeApp (TypeConstructor className) tys
249 dictTy = foldl TypeApp (TypeConstructor className) tys
250 constrainedTy = quantify (if null deps then function unit dictTy else ConstrainedType deps dictTy)
250 constrainedTy = quantify (if null deps then function unit dictTy else ConstrainedType deps dictTy)
251 dict = TypeClassDictionaryConstructorApp className memberNames'
251 dict = TypeClassDictionaryConstructorApp className memberNames'
252− dict' = if null deps then Abs (Left (Ident "_")) dict else dict
252+ dict' = if null deps then Abs (Left (Ident C.__unused)) dict else dict
253 result = ValueDeclaration name TypeInstanceDictionaryValue [] Nothing (TypedValue True dict' constrainedTy)
253 result = ValueDeclaration name TypeInstanceDictionaryValue [] Nothing (TypedValue True dict' constrainedTy)
254 return result
254 return result
255
255