From 7035386a327dacb7135a8c9dd363effa96f10502 Mon Sep 17 00:00:00 2001 From: Yura Lazaryev Date: Thu, 25 Apr 2024 20:27:12 +0200 Subject: [PATCH] Golden test for evaluation result --- .../PureScript/Backend/Lua/Golden/Spec.hs | 45 +- test/ps/golden/Golden/ArrayOfUnits/Test.purs | 17 + .../Golden.ArrayOfUnits.Test/corefn.json | 1 + .../Golden.ArrayOfUnits.Test/eval/.gitignore | 1 + .../Golden.ArrayOfUnits.Test/eval/golden.txt | 4 + .../output/Golden.ArrayOfUnits.Test/golden.ir | 577 ++++++++++++++++++ .../Golden.ArrayOfUnits.Test/golden.lua | 151 +++++ .../output/Golden.HelloPrelude.Test/golden.ir | 4 +- .../Golden.HelloPrelude.Test/golden.lua | 2 +- test/ps/packages.dhall | 5 +- test/ps/spago.dhall | 2 +- 11 files changed, 796 insertions(+), 13 deletions(-) create mode 100644 test/ps/golden/Golden/ArrayOfUnits/Test.purs create mode 100644 test/ps/output/Golden.ArrayOfUnits.Test/corefn.json create mode 100644 test/ps/output/Golden.ArrayOfUnits.Test/eval/.gitignore create mode 100644 test/ps/output/Golden.ArrayOfUnits.Test/eval/golden.txt create mode 100644 test/ps/output/Golden.ArrayOfUnits.Test/golden.ir create mode 100644 test/ps/output/Golden.ArrayOfUnits.Test/golden.lua diff --git a/test/Language/PureScript/Backend/Lua/Golden/Spec.hs b/test/Language/PureScript/Backend/Lua/Golden/Spec.hs index 9958006..e712f35 100644 --- a/test/Language/PureScript/Backend/Lua/Golden/Spec.hs +++ b/test/Language/PureScript/Backend/Lua/Golden/Spec.hs @@ -19,7 +19,6 @@ import Language.PureScript.Backend.Lua.Optimizer (optimizeChunk) import Language.PureScript.Backend.Lua.Printer qualified as Printer import Language.PureScript.Backend.Types (AppOrModule (..)) import Language.PureScript.CoreFn.Reader qualified as CoreFn -import Language.PureScript.Names (ModuleName) import Language.PureScript.Names qualified as PS import Path ( Abs @@ -38,6 +37,7 @@ import Path ) import Path.IO ( AnyPath (makeRelativeToCurrentDir) + , doesFileExist , ensureDir , makeAbsolute , walkDirAccum @@ -111,14 +111,47 @@ spec = do } uberModule -- lua golden + let evalGolden = + modulePath $(mkRelDir "eval") $(mkRelFile "golden.txt") let luaGolden = modulePath $(mkRelFile "golden.lua") let luaActual = modulePath $(mkRelFile "actual.lua") luaTestName ← runIO do toFilePath <$> makeRelativeToCurrentDir luaGolden it luaTestName do defaultGolden luaGolden (Just luaActual) do - uberModule ← compileCorefn (Tagged (Rel psOutputPath)) moduleName - compileIr moduleName uberModule + appOrModule ← + (doesFileExist evalGolden) <&> \case + True → AsApplication moduleName (PS.Ident "main") + False → AsModule moduleName + cfn ← compileCorefn (Tagged (Rel psOutputPath)) moduleName + compileIr appOrModule cfn + + describe "golden files should evaluate" do + let + collectEvaluatableLuas ∷ MonadIO m ⇒ Path Rel Dir → m [Path Abs File] + collectEvaluatableLuas = walkDirAccum Nothing \_dir _subdirs files → + pure [file | file ← files, toFilePath (filename file) == "golden.txt"] + + luas ← runIO do collectEvaluatableLuas psOutputPath + for_ luas \lua → do + let evalDir = parent lua + let resActual = evalDir $(mkRelFile "actual.txt") + let resGolden = evalDir $(mkRelFile "golden.txt") + let luaGolden = parent evalDir $(mkRelFile "golden.lua") + luaTestName ← runIO do makeRelativeToCurrentDir lua + it (toFilePath luaTestName) do + defaultGolden resGolden (Just resActual) do + let process = fromString $ "lua " ++ toFilePath luaGolden + (exitCode, out) ← readProcessInterleaved process + let niceOut = + decodeUtf8 out + & lines + & fmap Text.stripStart + & filter (not . Text.null) + & unlines + & toString + exitCode `shouldBe` ExitSuccess `annotatingWith` niceOut + pure $ toText niceOut describe "golden files should typecheck" do luas ← runIO do collectLuas psOutputPath @@ -185,11 +218,11 @@ compileCorefn outputDir uberModuleName = do let uberModule = Linker.makeUberModule (LinkAsModule uberModuleName) modules pure $ optimizedUberModule uberModule -compileIr ∷ (MonadIO m, MonadMask m) ⇒ ModuleName → IR.UberModule → m Text -compileIr modname uberModule = withCurrentDir [reldir|test/ps|] do +compileIr ∷ (MonadIO m, MonadMask m) ⇒ AppOrModule → IR.UberModule → m Text +compileIr appOrModule uberModule = withCurrentDir [reldir|test/ps|] do foreignPath ← Tagged <$> makeAbsolute [reldir|foreign|] luaChunk ← - Lua.fromUberModule foreignPath (Tagged True) (AsModule modname) uberModule + Lua.fromUberModule foreignPath (Tagged True) appOrModule uberModule & handleLuaError & Oops.runOops & liftIO diff --git a/test/ps/golden/Golden/ArrayOfUnits/Test.purs b/test/ps/golden/Golden/ArrayOfUnits/Test.purs new file mode 100644 index 0000000..60d1b8c --- /dev/null +++ b/test/ps/golden/Golden/ArrayOfUnits/Test.purs @@ -0,0 +1,17 @@ +module Golden.ArrayOfUnits.Test where + +import Prelude (Unit, discard, unit) + +import Effect (Effect) +import Effect.Console (logShow) +import Data.Traversable (traverse_) +import Data.Foldable (length) + +main :: Effect Unit +main = do + let arr :: Array Unit + arr = [unit, unit, unit] + traverse_ logShow arr + let len :: Int + len = length arr + logShow len diff --git a/test/ps/output/Golden.ArrayOfUnits.Test/corefn.json b/test/ps/output/Golden.ArrayOfUnits.Test/corefn.json new file mode 100644 index 0000000..570b7a6 --- /dev/null +++ b/test/ps/output/Golden.ArrayOfUnits.Test/corefn.json @@ -0,0 +1 @@ +{"builtWith":"0.15.15","comments":[],"decls":[{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"bindType":"NonRec","expression":{"abstraction":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[16,19],"start":[16,13]}},"type":"Var","value":{"identifier":"length","moduleName":["Data","Foldable"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[16,23],"start":[16,13]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"foldableArray","moduleName":["Data","Foldable"]}},"type":"App"},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[16,23],"start":[16,13]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"semiringInt","moduleName":["Data","Semiring"]}},"type":"App"},"identifier":"length"},{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"bindType":"NonRec","expression":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[17,10],"start":[17,3]}},"type":"Var","value":{"identifier":"logShow","moduleName":["Effect","Console"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[17,14],"start":[17,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"showInt","moduleName":["Data","Show"]}},"type":"App"},"identifier":"logShow"},{"annotation":{"meta":null,"sourceSpan":{"end":[10,20],"start":[10,1]}},"bindType":"NonRec","expression":{"annotation":{"meta":null,"sourceSpan":{"end":[13,31],"start":[12,3]}},"binds":[{"annotation":{"meta":null,"sourceSpan":{"end":[12,24],"start":[12,7]}},"bindType":"NonRec","expression":{"annotation":{"meta":null,"sourceSpan":{"end":[13,31],"start":[13,13]}},"type":"Literal","value":{"literalType":"ArrayLiteral","value":[{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[13,18],"start":[13,14]}},"type":"Var","value":{"identifier":"unit","moduleName":["Data","Unit"]}},{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[13,24],"start":[13,20]}},"type":"Var","value":{"identifier":"unit","moduleName":["Data","Unit"]}},{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[13,30],"start":[13,26]}},"type":"Var","value":{"identifier":"unit","moduleName":["Data","Unit"]}}]}},"identifier":"arr"}],"expression":{"abstraction":{"abstraction":{"abstraction":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[14,24],"start":[14,3]}},"type":"Var","value":{"identifier":"discard","moduleName":["Control","Bind"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[14,24],"start":[14,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"discardUnit","moduleName":["Control","Bind"]}},"type":"App"},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[14,24],"start":[14,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"bindEffect","moduleName":["Effect"]}},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[14,24],"start":[14,3]}},"argument":{"abstraction":{"abstraction":{"abstraction":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[14,12],"start":[14,3]}},"type":"Var","value":{"identifier":"traverse_","moduleName":["Data","Foldable"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[14,20],"start":[14,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"applicativeEffect","moduleName":["Effect"]}},"type":"App"},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[14,20],"start":[14,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"foldableArray","moduleName":["Data","Foldable"]}},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[14,20],"start":[14,3]}},"argument":{"abstraction":{"annotation":{"meta":{"metaType":"IsForeign"},"sourceSpan":{"end":[14,20],"start":[14,13]}},"type":"Var","value":{"identifier":"logShow","moduleName":["Effect","Console"]}},"annotation":{"meta":{"metaType":"IsSyntheticApp"},"sourceSpan":{"end":[14,20],"start":[14,13]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"showUnit","moduleName":["Data","Show"]}},"type":"App"},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[14,24],"start":[14,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[14,24],"start":[14,21]}},"type":"Var","value":{"identifier":"arr","sourcePos":[12,7]}},"type":"App"},"type":"App"},"annotation":{"meta":null,"sourceSpan":{"end":[14,24],"start":[14,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[14,24],"start":[14,3]}},"argument":"$__unused","body":{"annotation":{"meta":null,"sourceSpan":{"end":[16,23],"start":[15,3]}},"binds":[{"annotation":{"meta":null,"sourceSpan":{"end":[15,17],"start":[15,7]}},"bindType":"NonRec","expression":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"length","moduleName":["Golden","ArrayOfUnits","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[16,23],"start":[16,13]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[16,23],"start":[16,20]}},"type":"Var","value":{"identifier":"arr","sourcePos":[12,7]}},"type":"App"},"identifier":"len"}],"expression":{"abstraction":{"annotation":{"meta":null,"sourceSpan":{"end":[0,0],"start":[0,0]}},"type":"Var","value":{"identifier":"logShow","moduleName":["Golden","ArrayOfUnits","Test"]}},"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[17,3]}},"argument":{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[17,11]}},"type":"Var","value":{"identifier":"len","sourcePos":[15,7]}},"type":"App"},"type":"Let"},"type":"Abs"},"type":"App"},"type":"Let"},"identifier":"main"}],"exports":["main"],"foreign":[],"imports":[{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Control","Bind"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Data","Foldable"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Data","Semiring"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Data","Show"]},{"annotation":{"meta":null,"sourceSpan":{"end":[7,36],"start":[7,1]}},"moduleName":["Data","Traversable"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Data","Unit"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Effect"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Effect","Console"]},{"annotation":{"meta":null,"sourceSpan":{"end":[3,37],"start":[3,1]}},"moduleName":["Prelude"]},{"annotation":{"meta":null,"sourceSpan":{"end":[17,14],"start":[1,1]}},"moduleName":["Prim"]}],"moduleName":["Golden","ArrayOfUnits","Test"],"modulePath":"golden/Golden/ArrayOfUnits/Test.purs","reExports":{},"sourceSpan":{"end":[17,14],"start":[1,1]}} \ No newline at end of file diff --git a/test/ps/output/Golden.ArrayOfUnits.Test/eval/.gitignore b/test/ps/output/Golden.ArrayOfUnits.Test/eval/.gitignore new file mode 100644 index 0000000..d2dc29b --- /dev/null +++ b/test/ps/output/Golden.ArrayOfUnits.Test/eval/.gitignore @@ -0,0 +1 @@ +actual.txt diff --git a/test/ps/output/Golden.ArrayOfUnits.Test/eval/golden.txt b/test/ps/output/Golden.ArrayOfUnits.Test/eval/golden.txt new file mode 100644 index 0000000..8786a2d --- /dev/null +++ b/test/ps/output/Golden.ArrayOfUnits.Test/eval/golden.txt @@ -0,0 +1,4 @@ +unit +unit +unit +3 diff --git a/test/ps/output/Golden.ArrayOfUnits.Test/golden.ir b/test/ps/output/Golden.ArrayOfUnits.Test/golden.ir new file mode 100644 index 0000000..52e2626 --- /dev/null +++ b/test/ps/output/Golden.ArrayOfUnits.Test/golden.ir @@ -0,0 +1,577 @@ +UberModule + { uberModuleBindings = + [ Standalone + ( QName + { qnameModuleName = ModuleName "Data.Unit", qnameName = Name "foreign" + }, ForeignImport Nothing + ( ModuleName "Data.Unit" ) ".spago/prelude/v7.2.0/src/Data/Unit.purs" + [ ( Just Always, Name "unit" ) ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Data.Semiring", qnameName = Name "foreign" + }, ForeignImport Nothing + ( ModuleName "Data.Semiring" ) ".spago/prelude/v7.2.0/src/Data/Semiring.purs" + [ ( Nothing, Name "intAdd" ), ( Nothing, Name "intMul" ) ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Data.Foldable", qnameName = Name "foreign" + }, ForeignImport Nothing + ( ModuleName "Data.Foldable" ) ".spago/foldable-traversable/v6.1.0/src/Data/Foldable.purs" + [ ( Nothing, Name "foldrArray" ), ( Nothing, Name "foldlArray" ) ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Effect", qnameName = Name "foreign" + }, ForeignImport Nothing + ( ModuleName "Effect" ) ".spago/effect/v4.1.0/src/Effect.purs" + [ ( Nothing, Name "pureE" ), ( Nothing, Name "bindE" ) ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Control.Semigroupoid", qnameName = Name "semigroupoidFn" + }, LiteralObject Nothing + [ + ( PropName "compose", Abs Nothing + ( ParamNamed Nothing ( Name "f" ) ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "g" ) ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "x" ) ) + ( App Nothing + ( Ref Nothing ( Local ( Name "f" ) ) 0 ) + ( App Nothing + ( Ref Nothing ( Local ( Name "g" ) ) 0 ) + ( Ref Nothing ( Local ( Name "x" ) ) 0 ) + ) + ) + ) + ) + ) + ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Data.Semiring", qnameName = Name "semiringInt" + }, LiteralObject Nothing + [ + ( PropName "add", ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Semiring" ) ( Name "foreign" ) ) 0 ) + ( PropName "intAdd" ) + ), + ( PropName "zero", LiteralInt Nothing 0 ), + ( PropName "mul", ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Semiring" ) ( Name "foreign" ) ) 0 ) + ( PropName "intMul" ) + ), + ( PropName "one", LiteralInt Nothing 1 ) + ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Control.Apply", qnameName = Name "apply" }, Abs Nothing + ( ParamNamed Nothing ( Name "dict" ) ) + ( ObjectProp Nothing ( Ref Nothing ( Local ( Name "dict" ) ) 0 ) ( PropName "apply" ) ) + ), Standalone + ( QName + { qnameModuleName = ModuleName "Control.Applicative", qnameName = Name "pure" + }, Abs Nothing + ( ParamNamed Nothing ( Name "dict" ) ) + ( ObjectProp Nothing ( Ref Nothing ( Local ( Name "dict" ) ) 0 ) ( PropName "pure" ) ) + ), Standalone + ( QName + { qnameModuleName = ModuleName "Control.Bind", qnameName = Name "bind" }, Abs Nothing + ( ParamNamed Nothing ( Name "dict" ) ) + ( ObjectProp Nothing ( Ref Nothing ( Local ( Name "dict" ) ) 0 ) ( PropName "bind" ) ) + ), Standalone + ( QName + { qnameModuleName = ModuleName "Data.Foldable", qnameName = Name "foldr" }, Abs Nothing + ( ParamNamed Nothing ( Name "dict" ) ) + ( ObjectProp Nothing ( Ref Nothing ( Local ( Name "dict" ) ) 0 ) ( PropName "foldr" ) ) + ), RecursiveGroup + ( + ( QName + { qnameModuleName = ModuleName "Data.Foldable", qnameName = Name "foldableArray" + }, LiteralObject Nothing + [ + ( PropName "foldr", ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Foldable" ) ( Name "foreign" ) ) 0 ) + ( PropName "foldrArray" ) + ), + ( PropName "foldl", ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Foldable" ) ( Name "foreign" ) ) 0 ) + ( PropName "foldlArray" ) + ), + ( PropName "foldMap", Abs Nothing + ( ParamNamed Nothing ( Name "dictMonoid" ) ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "f" ) ) + ( App Nothing + ( App Nothing + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Data.Foldable" ) ( Name "foldr" ) ) 0 + ) + ( Ref Nothing + ( Imported ( ModuleName "Data.Foldable" ) ( Name "foldableArray" ) ) 0 + ) + ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "x" ) ) + ( App Nothing + ( ObjectProp Nothing + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing ( Local ( Name "dictMonoid" ) ) 0 ) + ( PropName "Semigroup0" ) + ) + ( Ref Nothing + ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 + ) + ) + ( PropName "append" ) + ) + ( App Nothing + ( Ref Nothing ( Local ( Name "f" ) ) 0 ) + ( Ref Nothing ( Local ( Name "x" ) ) 0 ) + ) + ) + ) + ) + ( ObjectProp Nothing + ( Ref Nothing ( Local ( Name "dictMonoid" ) ) 0 ) + ( PropName "mempty" ) + ) + ) + ) + ) + ] + ) :| [] + ), RecursiveGroup + ( + ( QName + { qnameModuleName = ModuleName "Effect", qnameName = Name "monadEffect" + }, LiteralObject Nothing + [ + ( PropName "Applicative0", Abs Nothing ( ParamUnused Nothing ) + ( Ref Nothing ( Imported ( ModuleName "Effect" ) ( Name "applicativeEffect" ) ) 0 ) + ), + ( PropName "Bind1", Abs Nothing ( ParamUnused Nothing ) + ( Ref Nothing ( Imported ( ModuleName "Effect" ) ( Name "bindEffect" ) ) 0 ) + ) + ] + ) :| + [ + ( QName + { qnameModuleName = ModuleName "Effect", qnameName = Name "bindEffect" + }, LiteralObject Nothing + [ + ( PropName "bind", ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Effect" ) ( Name "foreign" ) ) 0 ) + ( PropName "bindE" ) + ), + ( PropName "Apply0", Abs Nothing ( ParamUnused Nothing ) + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "Lazy_applyEffect" ) ) 0 + ) + ( LiteralInt Nothing 0 ) + ) + ) + ] + ), + ( QName + { qnameModuleName = ModuleName "Effect", qnameName = Name "applicativeEffect" + }, LiteralObject Nothing + [ + ( PropName "pure", ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Effect" ) ( Name "foreign" ) ) 0 ) + ( PropName "pureE" ) + ), + ( PropName "Apply0", Abs Nothing ( ParamUnused Nothing ) + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "Lazy_applyEffect" ) ) 0 + ) + ( LiteralInt Nothing 0 ) + ) + ) + ] + ), + ( QName + { qnameModuleName = ModuleName "Effect", qnameName = Name "Lazy_functorEffect" + }, App Nothing + ( App Nothing + ( Ref Nothing ( Local ( Name "PSLUA_runtime_lazy" ) ) 0 ) + ( LiteralString Nothing "functorEffect" ) + ) + ( Abs Nothing ( ParamUnused Nothing ) + ( LiteralObject Nothing + [ + ( PropName "map", Abs Nothing + ( ParamNamed Nothing ( Name "f" ) ) + ( App Nothing + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Control.Apply" ) ( Name "apply" ) ) 0 + ) + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "applicativeEffect" ) ) 0 + ) + ( PropName "Apply0" ) + ) + ( Ref Nothing ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 ) + ) + ) + ( App Nothing + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Control.Applicative" ) ( Name "pure" ) ) 0 + ) + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "applicativeEffect" ) ) 0 + ) + ) + ( Ref Nothing ( Local ( Name "f" ) ) 0 ) + ) + ) + ) + ] + ) + ) + ), + ( QName + { qnameModuleName = ModuleName "Effect", qnameName = Name "Lazy_applyEffect" + }, App Nothing + ( App Nothing + ( Ref Nothing ( Local ( Name "PSLUA_runtime_lazy" ) ) 0 ) + ( LiteralString Nothing "applyEffect" ) + ) + ( Abs Nothing ( ParamUnused Nothing ) + ( LiteralObject Nothing + [ + ( PropName "apply", Let Nothing + ( Standalone + ( Nothing, Name "bind", App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Control.Bind" ) ( Name "bind" ) ) 0 + ) + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "monadEffect" ) ) 0 + ) + ( PropName "Bind1" ) + ) + ( Ref Nothing ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 ) + ) + ) :| [] + ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "f" ) ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "a" ) ) + ( App Nothing + ( App Nothing + ( Ref Nothing ( Local ( Name "bind" ) ) 0 ) + ( Ref Nothing ( Local ( Name "f" ) ) 0 ) + ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "f'" ) ) + ( App Nothing + ( App Nothing + ( Ref Nothing ( Local ( Name "bind" ) ) 0 ) + ( Ref Nothing ( Local ( Name "a" ) ) 0 ) + ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "a'" ) ) + ( App Nothing + ( App Nothing + ( Ref Nothing + ( Imported + ( ModuleName "Control.Applicative" ) + ( Name "pure" ) + ) 0 + ) + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported + ( ModuleName "Effect" ) + ( Name "monadEffect" ) + ) 0 + ) + ( PropName "Applicative0" ) + ) + ( Ref Nothing + ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 + ) + ) + ) + ( App Nothing + ( Ref Nothing ( Local ( Name "f'" ) ) 0 ) + ( Ref Nothing ( Local ( Name "a'" ) ) 0 ) + ) + ) + ) + ) + ) + ) + ) + ) + ), + ( PropName "Functor0", Abs Nothing ( ParamUnused Nothing ) + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "Lazy_functorEffect" ) ) 0 + ) + ( LiteralInt Nothing 0 ) + ) + ) + ] + ) + ) + ) + ] + ), Standalone + ( QName + { qnameModuleName = ModuleName "Effect.Console", qnameName = Name "logShow" }, Abs Nothing + ( ParamNamed Nothing ( Name "dictShow" ) ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "a" ) ) + ( App Nothing + ( ObjectProp ( Just Always ) + ( ForeignImport Nothing + ( ModuleName "Effect.Console" ) ".spago/console/v6.1.0/src/Effect/Console.purs" + [ ( Nothing, Name "log" ) ] + ) + ( PropName "log" ) + ) + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing ( Local ( Name "dictShow" ) ) 0 ) + ( PropName "show" ) + ) + ( Ref Nothing ( Local ( Name "a" ) ) 0 ) + ) + ) + ) + ) + ], uberModuleForeigns = [], uberModuleExports = + [ + ( Name "main", Let Nothing + ( Standalone + ( Nothing, Name "arr", LiteralArray Nothing + [ ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Unit" ) ( Name "foreign" ) ) 0 ) + ( PropName "unit" ), ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Unit" ) ( Name "foreign" ) ) 0 ) + ( PropName "unit" ), ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Unit" ) ( Name "foreign" ) ) 0 ) + ( PropName "unit" ) + ] + ) :| [] + ) + ( App Nothing + ( App Nothing + ( App Nothing + ( ObjectProp Nothing + ( LiteralObject Nothing + [ + ( PropName "discard", Ref Nothing + ( Imported ( ModuleName "Control.Bind" ) ( Name "bind" ) ) 0 + ) + ] + ) + ( PropName "discard" ) + ) + ( Ref Nothing ( Imported ( ModuleName "Effect" ) ( Name "bindEffect" ) ) 0 ) + ) + ( App Nothing + ( App Nothing + ( App Nothing + ( App Nothing + ( Ref Nothing ( Imported ( ModuleName "Data.Foldable" ) ( Name "foldr" ) ) 0 ) + ( Ref Nothing + ( Imported ( ModuleName "Data.Foldable" ) ( Name "foldableArray" ) ) 0 + ) + ) + ( App Nothing + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported + ( ModuleName "Control.Semigroupoid" ) + ( Name "semigroupoidFn" ) + ) 0 + ) + ( PropName "compose" ) + ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "a" ) ) + ( App Nothing + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Control.Apply" ) ( Name "apply" ) ) 0 + ) + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported + ( ModuleName "Effect" ) + ( Name "applicativeEffect" ) + ) 0 + ) + ( PropName "Apply0" ) + ) + ( Ref Nothing + ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 + ) + ) + ) + ( App Nothing + ( App Nothing + ( ObjectProp Nothing + ( App Nothing + ( ObjectProp Nothing + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported + ( ModuleName "Effect" ) + ( Name "applicativeEffect" ) + ) 0 + ) + ( PropName "Apply0" ) + ) + ( Ref Nothing + ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 + ) + ) + ( PropName "Functor0" ) + ) + ( Ref Nothing + ( Imported ( ModuleName "Prim" ) ( Name "undefined" ) ) 0 + ) + ) + ( PropName "map" ) + ) + ( Abs Nothing ( ParamUnused Nothing ) + ( ObjectProp Nothing + ( LiteralObject Nothing + [ + ( PropName "identity", Abs Nothing + ( ParamNamed Nothing ( Name "x" ) ) + ( Ref Nothing ( Local ( Name "x" ) ) 0 ) + ), + ( PropName "Semigroupoid0", Abs Nothing ( ParamUnused Nothing ) + ( Ref Nothing + ( Imported + ( ModuleName "Control.Semigroupoid" ) + ( Name "semigroupoidFn" ) + ) 0 + ) + ) + ] + ) + ( PropName "identity" ) + ) + ) + ) + ( Ref Nothing ( Local ( Name "a" ) ) 0 ) + ) + ) + ) + ) + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Effect.Console" ) ( Name "logShow" ) ) 0 + ) + ( LiteralObject Nothing + [ + ( PropName "show", Abs Nothing ( ParamUnused Nothing ) + ( LiteralString Nothing "unit" ) + ) + ] + ) + ) + ) + ) + ( App Nothing + ( App Nothing + ( Ref Nothing + ( Imported ( ModuleName "Control.Applicative" ) ( Name "pure" ) ) 0 + ) + ( Ref Nothing + ( Imported ( ModuleName "Effect" ) ( Name "applicativeEffect" ) ) 0 + ) + ) + ( ObjectProp ( Just Always ) + ( Ref Nothing ( Imported ( ModuleName "Data.Unit" ) ( Name "foreign" ) ) 0 ) + ( PropName "unit" ) + ) + ) + ) + ( Ref Nothing ( Local ( Name "arr" ) ) 0 ) + ) + ) + ( Abs Nothing ( ParamUnused Nothing ) + ( App Nothing + ( App Nothing + ( Ref Nothing ( Imported ( ModuleName "Effect.Console" ) ( Name "logShow" ) ) 0 ) + ( LiteralObject Nothing + [ + ( PropName "show", ObjectProp ( Just Always ) + ( ForeignImport Nothing + ( ModuleName "Data.Show" ) ".spago/prelude/v7.2.0/src/Data/Show.purs" + [ ( Nothing, Name "showIntImpl" ) ] + ) + ( PropName "showIntImpl" ) + ) + ] + ) + ) + ( App Nothing + ( App Nothing + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported ( ModuleName "Data.Foldable" ) ( Name "foldableArray" ) ) 0 + ) + ( PropName "foldl" ) + ) + ( Abs Nothing + ( ParamNamed Nothing ( Name "c" ) ) + ( Abs Nothing ( ParamUnused Nothing ) + ( App Nothing + ( App Nothing + ( ObjectProp Nothing + ( Ref Nothing + ( Imported ( ModuleName "Data.Semiring" ) ( Name "semiringInt" ) ) 0 + ) + ( PropName "add" ) + ) + ( ObjectProp Nothing + ( Ref Nothing + ( Imported ( ModuleName "Data.Semiring" ) ( Name "semiringInt" ) ) 0 + ) + ( PropName "one" ) + ) + ) + ( Ref Nothing ( Local ( Name "c" ) ) 0 ) + ) + ) + ) + ) + ( ObjectProp Nothing + ( Ref Nothing + ( Imported ( ModuleName "Data.Semiring" ) ( Name "semiringInt" ) ) 0 + ) + ( PropName "zero" ) + ) + ) + ( Ref Nothing ( Local ( Name "arr" ) ) 0 ) + ) + ) + ) + ) + ) + ] + } \ No newline at end of file diff --git a/test/ps/output/Golden.ArrayOfUnits.Test/golden.lua b/test/ps/output/Golden.ArrayOfUnits.Test/golden.lua new file mode 100644 index 0000000..b02e938 --- /dev/null +++ b/test/ps/output/Golden.ArrayOfUnits.Test/golden.lua @@ -0,0 +1,151 @@ +local function PSLUA_runtime_lazy(name) + return function(init) + return function() + local state = 0 + local val = nil + if state == 2 then + return val + else + if state == 1 then + return error(name .. " was needed before it finished initializing") + else + state = 1 + val = init() + state = 2 + return val + end + end + end + end +end +local M = {} +M.Data_Unit_foreign = { unit = {} } +M.Data_Semiring_foreign = { + intAdd = function(x) return function(y) return x + y end end, + intMul = function(x) return function(y) return x * y end end +} +M.Data_Foldable_foreign = { + foldrArray = function(f) + return function(init) + return function(xs) + local acc = init + local len = #xs + for i = len, 1, -1 do acc = f(xs[i])(acc) end + return acc + end + end + end, + foldlArray = function(f) + return function(init) + return function(xs) + local acc = init + local len = #xs + for i = 1, len do acc = f(acc)(xs[i]) end + return acc + end + end + end +} +M.Effect_foreign = { + pureE = function(a) + return function() + return a + end + end, + bindE = function(a) + return function(f) + return function() + return f(a())() + end + end + end +} +M.Control_Semigroupoid_semigroupoidFn = { + compose = function(f) + return function(g) return function(x) return f(g(x)) end end + end +} +M.Data_Semiring_semiringInt = { + add = M.Data_Semiring_foreign.intAdd, + zero = 0, + mul = M.Data_Semiring_foreign.intMul, + one = 1 +} +M.Control_Apply_apply = function(dict) return dict.apply end +M.Control_Applicative_pure = function(dict) return dict.pure end +M.Control_Bind_bind = function(dict) return dict.bind end +M.Data_Foldable_foldr = function(dict) return dict.foldr end +M.Data_Foldable_foldableArray = { + foldr = M.Data_Foldable_foreign.foldrArray, + foldl = M.Data_Foldable_foreign.foldlArray, + foldMap = function(dictMonoid) + return function(f) + return M.Data_Foldable_foldr(M.Data_Foldable_foldableArray)(function(x) + return (dictMonoid.Semigroup0()).append(f(x)) + end)(dictMonoid.mempty) + end + end +} +M.Effect_monadEffect = { + Applicative0 = function() return M.Effect_applicativeEffect end, + Bind1 = function() return M.Effect_bindEffect end +} +M.Effect_bindEffect = { + bind = M.Effect_foreign.bindE, + Apply0 = function() return M.Effect_Lazy_applyEffect(0) end +} +M.Effect_applicativeEffect = { + pure = M.Effect_foreign.pureE, + Apply0 = function() return M.Effect_Lazy_applyEffect(0) end +} +M.Effect_Lazy_functorEffect = PSLUA_runtime_lazy("functorEffect")(function() + return { + map = function(f) + return M.Control_Apply_apply(M.Effect_applicativeEffect.Apply0())(M.Control_Applicative_pure(M.Effect_applicativeEffect)(f)) + end + } +end) +M.Effect_Lazy_applyEffect = PSLUA_runtime_lazy("applyEffect")(function() + return { + apply = (function() + return function(f) + local bind = M.Control_Bind_bind(M.Effect_monadEffect.Bind1()) + return function(a) + return bind(f)(function(fPrime) + return bind(a)(function(aPrime) + return M.Control_Applicative_pure(M.Effect_monadEffect.Applicative0())(fPrime(aPrime)) + end) + end) + end + end + end)(), + Functor0 = function() return M.Effect_Lazy_functorEffect(0) end + } +end) +M.Effect_Console_logShow = function(dictShow) + return function(a) + return (function(s) return function() print(s) end end)(dictShow.show(a)) + end +end +return (function() + local arr = { + [1] = M.Data_Unit_foreign.unit, + [2] = M.Data_Unit_foreign.unit, + [3] = M.Data_Unit_foreign.unit + } + return M.Control_Bind_bind(M.Effect_bindEffect)(M.Data_Foldable_foldr(M.Data_Foldable_foldableArray)(M.Control_Semigroupoid_semigroupoidFn.compose(function( a ) + return M.Control_Apply_apply(M.Effect_applicativeEffect.Apply0())(((M.Effect_applicativeEffect.Apply0()).Functor0()).map(function( ) + return function(x) return x end + end)(a)) + end)(M.Effect_Console_logShow({ + show = function() return "unit" end + })))(M.Control_Applicative_pure(M.Effect_applicativeEffect)(M.Data_Unit_foreign.unit))(arr))(function( ) + return M.Effect_Console_logShow({ + show = function(n) return tostring(n) end + })(M.Data_Foldable_foldableArray.foldl(function(c) + return function() + return M.Data_Semiring_semiringInt.add(M.Data_Semiring_semiringInt.one)(c) + end + end)(M.Data_Semiring_semiringInt.zero)(arr)) + end) +end)()() diff --git a/test/ps/output/Golden.HelloPrelude.Test/golden.ir b/test/ps/output/Golden.HelloPrelude.Test/golden.ir index bc77225..e7afbf6 100644 --- a/test/ps/output/Golden.HelloPrelude.Test/golden.ir +++ b/test/ps/output/Golden.HelloPrelude.Test/golden.ir @@ -206,8 +206,8 @@ UberModule ) ( ObjectProp ( Just Always ) ( ForeignImport Nothing - ( ModuleName "Data.Unit" ) ".spago/prelude/v7.1.1/src/Data/Unit.purs" - [ ( Nothing, Name "unit" ) ] + ( ModuleName "Data.Unit" ) ".spago/prelude/v7.2.0/src/Data/Unit.purs" + [ ( Just Always, Name "unit" ) ] ) ( PropName "unit" ) ) diff --git a/test/ps/output/Golden.HelloPrelude.Test/golden.lua b/test/ps/output/Golden.HelloPrelude.Test/golden.lua index 37b7c0c..16977dd 100644 --- a/test/ps/output/Golden.HelloPrelude.Test/golden.lua +++ b/test/ps/output/Golden.HelloPrelude.Test/golden.lua @@ -70,4 +70,4 @@ M.Effect_Lazy_applyEffect = PSLUA_runtime_lazy("applyEffect")(function() Functor0 = function() return M.Effect_Lazy_functorEffect(0) end } end) -return { main = M.Control_Applicative_pure(M.Effect_applicativeEffect)(nil) } +return { main = M.Control_Applicative_pure(M.Effect_applicativeEffect)({}) } diff --git a/test/ps/packages.dhall b/test/ps/packages.dhall index 0327fc0..1a3ab9d 100644 --- a/test/ps/packages.dhall +++ b/test/ps/packages.dhall @@ -3,8 +3,7 @@ let upstream-ps = sha256:50c4ee579bf2c38671ac97df821c2cc4221fb3f6ad79c807bb6e4597ab6d1e95 let upstream-lua = - https://github.com/Unisay/purescript-lua-package-sets/releases/download/psc-0.15.15-20240416/packages.dhall - sha256:e68b7752ca4dee0f0578a2e40159caf6d1290a711777931b20d10d807823b52d + https://github.com/Unisay/purescript-lua-package-sets/releases/download/psc-0.15.15-20240425/packages.dhall + sha256:3721bc8a2f6681e16fb505b8b0256650d9fd47977755fde9947852343888f14b in upstream-ps // upstream-lua - diff --git a/test/ps/spago.dhall b/test/ps/spago.dhall index 6fbd3dc..d7992f0 100644 --- a/test/ps/spago.dhall +++ b/test/ps/spago.dhall @@ -1,5 +1,5 @@ { name = "test-project" -, dependencies = [ "console", "effect", "prelude" ] +, dependencies = [ "console", "effect", "foldable-traversable", "prelude" ] , packages = ./packages.dhall , sources = [ "golden/**/*.purs" ] }