From 4f41e04692b6bcbefaf05649739039c9248f2941 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Mon, 19 Dec 2022 00:17:03 +0100 Subject: [PATCH 01/34] implement basic benchmarks --- .gitignore | 1 + bench/Base.hs | 7 ++ bench/Compile.hs | 163 ++++++++++++++++++++++++++++++++++++++ bench/Main.hs | 41 ++++++++++ cabal.hie.yaml | 3 + package.yaml | 12 +++ src/Juvix/Prelude/Path.hs | 6 ++ 7 files changed, 233 insertions(+) create mode 100644 bench/Base.hs create mode 100644 bench/Compile.hs create mode 100644 bench/Main.hs diff --git a/.gitignore b/.gitignore index 9e60f2cee2..2623f48a73 100644 --- a/.gitignore +++ b/.gitignore @@ -86,4 +86,5 @@ docs/**/*.md docs/org/README.org # Binary files (produced by `make check`) examples/milestone/HelloWorld/HelloWorld +/.shake/ hie.yaml diff --git a/bench/Base.hs b/bench/Base.hs new file mode 100644 index 0000000000..2abd611104 --- /dev/null +++ b/bench/Base.hs @@ -0,0 +1,7 @@ +module Base where + +import Juvix.Extra.Paths +import Juvix.Prelude.Path as Path + +root :: Path Abs Dir +root = relToProject $(mkRelDir "tests/benchmark") diff --git a/bench/Compile.hs b/bench/Compile.hs new file mode 100644 index 0000000000..bec45a1238 --- /dev/null +++ b/bench/Compile.hs @@ -0,0 +1,163 @@ +module Compile where + +import Base +import Development.Shake +import Juvix.Extra.Paths +import Juvix.Prelude.Base +import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) + +dirs :: [Path Rel Dir] +dirs = + [ $(mkRelDir "ackermann"), + $(mkRelDir "combinations"), + $(mkRelDir "cps"), + $(mkRelDir "fibonacci"), + $(mkRelDir "fold"), + $(mkRelDir "mapfold"), + $(mkRelDir "mapfun"), + $(mkRelDir "maybe"), + $(mkRelDir "mergesort"), + $(mkRelDir "prime") + ] + +absDirs :: [Path Abs Dir] +absDirs = map (root Path.) dirs + +compile :: IO () +compile = shakeArgs opts $ do + phony "clean" $ do + putInfo "TODO: Cleaning... " + forM_ absDirs mkBenchMark + where + opts :: ShakeOptions + opts = shakeOptions + +recipe :: Path Abs File -> Action () -> Rules () +recipe out howto = toFilePath out %> const howto + +-- | e.g. dir = fibonacci +mkBenchMark :: Path Abs Dir -> Rules () +mkBenchMark dir = do + mkHaskell dir + mkOcaml dir + mkJuvix dir + mkJuvixRuntime dir + +-- mkClang dir FIXME + +-- | e.g. dir = fibonacci +mkHaskell :: Path Abs Dir -> Rules () +mkHaskell dir = do + action $ + whenM + (doesFileExist (toFilePath hsFile)) + (need [toFilePath exeFile, toFilePath sexeFile]) + let opts :: [String] = ["-O2", "-no-keep-hi-files", "-no-keep-o-files"] + recipe exeFile $ do + need [toFilePath hsFile] + command_ [] "ghc" (opts ++ ["-o", toFilePath exeFile, toFilePath hsFile]) + recipe sexeFile $ do + need [toFilePath hsFile] + command_ [] "ghc" (opts ++ ["-XStrict", "-o", toFilePath sexeFile, toFilePath hsFile]) + where + haskellDir :: Path Abs Dir + haskellDir = dir Path. $(mkRelDir "haskell") + hsFile :: Path Abs File + hsFile = addExtension' ".hs" (haskellDir Path. dirnameToFile dir) + exeFile :: Path Abs File + exeFile = replaceExtension' ".exe" hsFile + sexeFile :: Path Abs File + sexeFile = addExtension' ".exe" (replaceExtension' ".strict" hsFile) + +-- | e.g. dir = fibonacci +mkOcaml :: Path Abs Dir -> Rules () +mkOcaml dir = do + action $ + whenM + (doesFileExist (toFilePath mlFile)) + (need [toFilePath exeFile, toFilePath byteexeFile]) + recipe exeFile $ do + need [toFilePath mlFile] + command_ [] "ocamlopt" ["-O2", "-o", toFilePath exeFile, toFilePath mlFile] + recipe byteexeFile $ do + need [toFilePath mlFile] + command_ [] "ocamlc" ["-o", toFilePath byteexeFile, toFilePath mlFile] + where + ocamlDir :: Path Abs Dir + ocamlDir = dir Path. $(mkRelDir "ocaml") + mlFile :: Path Abs File + mlFile = addExtension' ".ml" (ocamlDir Path. dirnameToFile dir) + exeFile :: Path Abs File + exeFile = replaceExtension' ".exe" mlFile + byteexeFile :: Path Abs File + byteexeFile = addExtension' ".exe" (replaceExtension' ".byte" mlFile) + +-- | e.g. dir = fibonacci +mkJuvix :: Path Abs Dir -> Rules () +mkJuvix dir = do + action $ + whenM + (doesFileExist (toFilePath juvixFile)) + (need [toFilePath exeFile, toFilePath wasmFile]) + let opts :: [String] = ["compile"] + recipe exeFile $ do + need [toFilePath juvixFile] + command_ [] "juvix" (opts <> ["-o", toFilePath exeFile, toFilePath juvixFile]) + recipe wasmFile $ do + need [toFilePath juvixFile] + command_ [] "juvix" (opts <> ["--target=wasm", "-o", toFilePath wasmFile, toFilePath juvixFile]) + where + ocamlDir :: Path Abs Dir + ocamlDir = dir Path. $(mkRelDir "juvix") + juvixFile :: Path Abs File + juvixFile = addExtension' ".juvix" (ocamlDir Path. dirnameToFile dir) + exeFile :: Path Abs File + exeFile = replaceExtension' ".exe" juvixFile + wasmFile :: Path Abs File + wasmFile = replaceExtension' ".wasm" juvixFile + +-- | e.g. dir = fibonacci +mkJuvixRuntime :: Path Abs Dir -> Rules () +mkJuvixRuntime dir = do + action $ + whenM + (doesFileExist (toFilePath cFile)) + (need [toFilePath exeFile, toFilePath wasmFile]) + let opts :: [String] = ["dev", "runtime", "compile"] + recipe exeFile $ do + need [toFilePath cFile] + command_ [] "juvix" (opts <> ["-o", toFilePath exeFile, toFilePath cFile]) + recipe wasmFile $ do + need [toFilePath cFile] + command_ [] "juvix" (opts <> ["--target=wasm32-wasi", "-o", toFilePath wasmFile, toFilePath cFile]) + where + runtimeDir :: Path Abs Dir + runtimeDir = dir Path. $(mkRelDir "runtime") + cFile :: Path Abs File + cFile = addExtension' ".c" (runtimeDir Path. dirnameToFile dir) + exeFile :: Path Abs File + exeFile = replaceExtension' ".exe" cFile + wasmFile :: Path Abs File + wasmFile = replaceExtension' ".wasm" cFile + +mkClang :: Path Abs Dir -> Rules () +mkClang dir = do + action $ + whenM + (doesFileExist (toFilePath cFile)) + (need [toFilePath exeFile, toFilePath wasmFile]) + recipe exeFile $ do + need [toFilePath cFile] + command_ [] "clang" ["-O3", "-o", toFilePath exeFile, toFilePath cFile] + recipe wasmFile $ do + need [toFilePath cFile] + command_ [] "clang" ["-Os", "-nodefaultlibs", "--sysroot", "$WASI_SYSROOT_Path", "-lc", "--target=wasm32-wasi", "-o", toFilePath wasmFile, toFilePath cFile] + where + cDir :: Path Abs Dir + cDir = dir Path. $(mkRelDir "c") + cFile :: Path Abs File + cFile = addExtension' ".c" (cDir Path. dirnameToFile dir) + exeFile :: Path Abs File + exeFile = replaceExtension' ".exe" cFile + wasmFile :: Path Abs File + wasmFile = replaceExtension' ".wasm" cFile diff --git a/bench/Main.hs b/bench/Main.hs new file mode 100644 index 0000000000..ec7760a7ac --- /dev/null +++ b/bench/Main.hs @@ -0,0 +1,41 @@ +module Main where + +import Base +import Compile qualified +import Gauge.Benchmark +import Gauge.Main +import Juvix.Prelude +import Juvix.Prelude.Path as Path +import System.Process + +main :: IO () +main = do + Compile.compile + defaultMain benchmarks + +runExe :: Path Abs File -> IO () +runExe p = void (readProcess (toFilePath p) [] "") + +hsm :: Path Abs File +hsm = root Path. $(mkRelFile "mergesort/haskell/mergesort.exe") + +hssm :: Path Abs File +hssm = root Path. $(mkRelFile "mergesort/haskell/mergesort.strict.exe") + +cm :: Path Abs File +cm = root Path. $(mkRelFile "mergesort/c/mergesort.exe") + +mlm :: Path Abs File +mlm = root Path. $(mkRelFile "mergesort/ocaml/mergesort.exe") + +jm :: Path Abs File +jm = root Path. $(mkRelFile "mergesort/juvix/mergesort.exe") + +benchmarks :: [Benchmark] +benchmarks = + [ bench "haskell mergesort" (nfIO (runExe hsm)), + bench "haskell strict mergesort" (nfIO (runExe hssm)), + bench "c mergesort" (nfIO (runExe cm)), + bench "juvix mergesort" (nfIO (runExe jm)), + bench "ocaml mergesort" (nfIO (runExe mlm)) + ] diff --git a/cabal.hie.yaml b/cabal.hie.yaml index da79588bac..5c4ee7ab19 100644 --- a/cabal.hie.yaml +++ b/cabal.hie.yaml @@ -8,3 +8,6 @@ cradle: - path: "./test" component: "test:juvix-test" + + - path: "./bench" + component: "bench:juvix-bench" diff --git a/package.yaml b/package.yaml index b816700561..58cdd110d1 100644 --- a/package.yaml +++ b/package.yaml @@ -72,6 +72,9 @@ dependencies: - Diff == 0.4.* - pretty-show == 1.10.* +# benchmarks +- gauge == 0.2.* +- shake == 0.19.* ghc-options: # Warnings - -Weverything @@ -134,3 +137,12 @@ tests: - juvix verbatim: default-language: GHC2021 + +benchmarks: + juvix-bench: + main: Main.hs + source-dirs: bench + dependencies: + - juvix + verbatim: + default-language: GHC2021 diff --git a/src/Juvix/Prelude/Path.hs b/src/Juvix/Prelude/Path.hs index 00d2ff3947..1b9a4413ad 100644 --- a/src/Juvix/Prelude/Path.hs +++ b/src/Juvix/Prelude/Path.hs @@ -75,9 +75,15 @@ removeExtension = fmap fst . splitExtension removeExtension' :: Path b File -> Path b File removeExtension' = fst . fromJust . splitExtension +addExtension' :: String -> Path b File -> Path b File +addExtension' ext = fromJust . addExtension ext + replaceExtension' :: String -> Path b File -> Path b File replaceExtension' ext = fromJust . replaceExtension ext +dirnameToFile :: Path x Dir -> Path Rel File +dirnameToFile = relFile . dropTrailingPathSeparator . toFilePath . dirname + parents :: Path Abs a -> NonEmpty (Path Abs Dir) parents = go [] . parent where From a7ad2ff5b20a43527c4b9afda4642bfe36bcca47 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Mon, 19 Dec 2022 00:17:18 +0100 Subject: [PATCH 02/34] smaller input for mergesort --- tests/benchmark/mergesort/c/mergesort.c | 2 +- tests/benchmark/mergesort/core/mergesort.jvc | 2 +- tests/benchmark/mergesort/haskell/mergesort.hs | 2 +- tests/benchmark/mergesort/juvix/mergesort.juvix | 8 ++++---- tests/benchmark/mergesort/ocaml/mergesort.ml | 2 +- tests/benchmark/mergesort/runtime/mergesort.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/benchmark/mergesort/c/mergesort.c b/tests/benchmark/mergesort/c/mergesort.c index f538b938da..2a340e37b4 100644 --- a/tests/benchmark/mergesort/c/mergesort.c +++ b/tests/benchmark/mergesort/c/mergesort.c @@ -44,7 +44,7 @@ static bool sorted(int *tab, int size) { return true; } -#define N 2000000 +#define N 200000 int main() { int *tab = malloc(N * sizeof(int)); diff --git a/tests/benchmark/mergesort/core/mergesort.jvc b/tests/benchmark/mergesort/core/mergesort.jvc index 0b1d47ebd7..eab1e0d49c 100644 --- a/tests/benchmark/mergesort/core/mergesort.jvc +++ b/tests/benchmark/mergesort/core/mergesort.jvc @@ -51,4 +51,4 @@ def sorted := \xs def gen := \n \acc if n = 0 then acc else gen (n - 1) (cons n acc); -sorted (sort (gen 2000000 nil)) +sorted (sort (gen 200000 nil)) diff --git a/tests/benchmark/mergesort/haskell/mergesort.hs b/tests/benchmark/mergesort/haskell/mergesort.hs index 507573b768..8a798f08c5 100644 --- a/tests/benchmark/mergesort/haskell/mergesort.hs +++ b/tests/benchmark/mergesort/haskell/mergesort.hs @@ -30,4 +30,4 @@ gen 0 acc = acc gen n acc = gen (n - 1) (n : acc) main :: IO () -main = putStrLn (show (sorted (sort (gen 2000000 [])))) +main = putStrLn (show (sorted (sort (gen 200000 [])))) diff --git a/tests/benchmark/mergesort/juvix/mergesort.juvix b/tests/benchmark/mergesort/juvix/mergesort.juvix index d522094138..8342767737 100644 --- a/tests/benchmark/mergesort/juvix/mergesort.juvix +++ b/tests/benchmark/mergesort/juvix/mergesort.juvix @@ -44,12 +44,12 @@ terminating gen : Int -> List Int -> List Int; gen n acc := if (n Data.Int.Ops.== Int_0) acc (gen (n Data.Int.Ops.- Int_1) (n ∷ acc)); -axiom Int_2000000 : Int; -compile Int_2000000 { - c ↦ "2000000"; +axiom Int_200000 : Int; +compile Int_200000 { + c ↦ "200000"; }; main : IO; -main := if (sorted (sort (gen Int_2000000 nil))) (putStrLn "true") (putStrLn "false"); +main := if (sorted (sort (gen Int_200000 nil))) (putStrLn "true") (putStrLn "false"); end; diff --git a/tests/benchmark/mergesort/ocaml/mergesort.ml b/tests/benchmark/mergesort/ocaml/mergesort.ml index 9bde4af922..f712b37f8b 100644 --- a/tests/benchmark/mergesort/ocaml/mergesort.ml +++ b/tests/benchmark/mergesort/ocaml/mergesort.ml @@ -43,4 +43,4 @@ let rec gen n acc = if n = 0 then acc else gen (n - 1) (n :: acc) ;; -print_endline (if sorted (sort (gen 2000000 [])) then "true" else "false");; +print_endline (if sorted (sort (gen 200000 [])) then "true" else "false");; diff --git a/tests/benchmark/mergesort/runtime/mergesort.c b/tests/benchmark/mergesort/runtime/mergesort.c index fa0dcb40c7..b1f457c084 100644 --- a/tests/benchmark/mergesort/runtime/mergesort.c +++ b/tests/benchmark/mergesort/runtime/mergesort.c @@ -232,7 +232,7 @@ int main() { JUVIX_FUNCTION(juvix_function_main, 1); { ARG(1) = CONSTR_NIL; - ARG(0) = make_smallint(2000000); + ARG(0) = make_smallint(200000); CALL(0, gen, juvix_label_main_1); ARG(0) = juvix_result; CALL(0, sort, juvix_label_2); From 8a38ae49baf68abceae6e55f0a42f991c9730a80 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Mon, 19 Dec 2022 15:45:55 +0100 Subject: [PATCH 03/34] wip --- bench/Base.hs | 47 +++++++++++++++++++++++++ bench/Compile.hs | 1 - bench/Main.hs | 73 +++++++++++++++++++++++++++------------ src/Juvix/Prelude/Path.hs | 8 +++++ 4 files changed, 106 insertions(+), 23 deletions(-) diff --git a/bench/Base.hs b/bench/Base.hs index 2abd611104..657a027e33 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -2,6 +2,53 @@ module Base where import Juvix.Extra.Paths import Juvix.Prelude.Path as Path +import Juvix.Prelude +import Prelude (Show (show)) root :: Path Abs Dir root = relToProject $(mkRelDir "tests/benchmark") + +data Lang + = Ocaml + | Haskell + | C + | Juvix + | Runtime + | Core + +instance Show Lang where + show = \case + Ocaml -> "ocaml" + Haskell -> "haskell" + C -> "c" + Juvix -> "juvix" + Runtime -> "runtime" + Core -> "core" + +langPath :: Lang -> Path Rel Dir +langPath = relDir . Prelude.show + +langFile :: Lang -> Path Rel File +langFile = relFile . Prelude.show + +data Variant = Variant + { _variantTitle :: Maybe String, + _variantLanguage :: Lang, + _variantExtensions :: [String] + } + +data Bench = Bench + { _benchTitle :: String, + _benchVariants :: [Variant] + } + +makeLenses ''Bench +makeLenses ''Variant + +defaultVariant :: Lang -> Variant +defaultVariant l = + Variant + { _variantTitle = Nothing, + _variantLanguage = l, + _variantExtensions = [".exe"] + } diff --git a/bench/Compile.hs b/bench/Compile.hs index bec45a1238..704106957e 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -2,7 +2,6 @@ module Compile where import Base import Development.Shake -import Juvix.Extra.Paths import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) diff --git a/bench/Main.hs b/bench/Main.hs index ec7760a7ac..32fe0aa5e9 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -2,40 +2,69 @@ module Main where import Base import Compile qualified -import Gauge.Benchmark -import Gauge.Main +import Gauge import Juvix.Prelude -import Juvix.Prelude.Path as Path import System.Process main :: IO () main = do Compile.compile - defaultMain benchmarks + defaultMainWith config benchmarks runExe :: Path Abs File -> IO () runExe p = void (readProcess (toFilePath p) [] "") -hsm :: Path Abs File -hsm = root Path. $(mkRelFile "mergesort/haskell/mergesort.exe") +config :: Config +config = + defaultConfig + { timeLimit = Just 0.0, + quickMode = False, + csvFile = Just "results.csv" + } -hssm :: Path Abs File -hssm = root Path. $(mkRelFile "mergesort/haskell/mergesort.strict.exe") +defaultBench :: String -> Bench +defaultBench title = + Bench + { _benchTitle = title, + _benchVariants = + [ defaultVariant Haskell, + defaultVariant C, + defaultVariant Ocaml, + defaultVariant Runtime, + defaultVariant Juvix, + Variant + { _variantTitle = Just "strict", + _variantLanguage = Haskell, + _variantExtensions = [".strict", ".exe"] + }, + Variant + { _variantTitle = Just "byte", + _variantLanguage = Ocaml, + _variantExtensions = [".byte", ".exe"] + } + ] + } -cm :: Path Abs File -cm = root Path. $(mkRelFile "mergesort/c/mergesort.exe") +mergesort :: Bench +mergesort = defaultBench "mergesort" -mlm :: Path Abs File -mlm = root Path. $(mkRelFile "mergesort/ocaml/mergesort.exe") - -jm :: Path Abs File -jm = root Path. $(mkRelFile "mergesort/juvix/mergesort.exe") +fromBench :: Bench -> [Benchmark] +fromBench b = map go (b ^. benchVariants) + where + go :: Variant -> Benchmark + go v = bench title (nfIO (runExe exe)) + where + title :: String + title = b ^. benchTitle <> maybe "" (" " <>) (v ^. variantTitle) <> " - " <> show (v ^. variantLanguage) + exe :: Path Abs File + exe = + addExtensions' + (v ^. variantExtensions) + ( root + relDir (b ^. benchTitle) + langPath (v ^. variantLanguage) + relFile (b ^. benchTitle) + ) benchmarks :: [Benchmark] -benchmarks = - [ bench "haskell mergesort" (nfIO (runExe hsm)), - bench "haskell strict mergesort" (nfIO (runExe hssm)), - bench "c mergesort" (nfIO (runExe cm)), - bench "juvix mergesort" (nfIO (runExe jm)), - bench "ocaml mergesort" (nfIO (runExe mlm)) - ] +benchmarks = fromBench mergesort diff --git a/src/Juvix/Prelude/Path.hs b/src/Juvix/Prelude/Path.hs index 1b9a4413ad..bed5c3d9db 100644 --- a/src/Juvix/Prelude/Path.hs +++ b/src/Juvix/Prelude/Path.hs @@ -75,6 +75,14 @@ removeExtension = fmap fst . splitExtension removeExtension' :: Path b File -> Path b File removeExtension' = fst . fromJust . splitExtension +addExtensions :: MonadThrow m => [String] -> Path b File -> m (Path b File) +addExtensions ext p = case ext of + [] -> return p + (e : es) -> addExtension e p >>= addExtensions es + +addExtensions' :: [String] -> Path b File -> Path b File +addExtensions' ext = fromJust . addExtensions ext + addExtension' :: String -> Path b File -> Path b File addExtension' ext = fromJust . addExtension ext From 7b22b9d35cdc0873d2e482bece2f418fba1d98d9 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 20 Dec 2022 15:08:09 +0100 Subject: [PATCH 04/34] fix c benchmarks --- tests/benchmark/ackermann/c/ackermann.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/benchmark/ackermann/c/ackermann.c b/tests/benchmark/ackermann/c/ackermann.c index e476ee7b8d..e643dda7e8 100644 --- a/tests/benchmark/ackermann/c/ackermann.c +++ b/tests/benchmark/ackermann/c/ackermann.c @@ -2,17 +2,16 @@ #include #include +#include -typedef uintptr_t uint; - -typedef uint (*fun_t)(uint,uint); +typedef uintptr_t (*fun_t)(uintptr_t,uintptr_t); typedef struct{ - uint arg; + uintptr_t arg; fun_t f; } closure_t; -static uint iter(closure_t *cl, int n, uint x) { +static uintptr_t iter(closure_t *cl, int n, uintptr_t x) { while (n > 0) { x = cl->f(cl->arg, x); --n; @@ -20,18 +19,18 @@ static uint iter(closure_t *cl, int n, uint x) { return x; } -static uint step_2(uint f, uint n) { +static uintptr_t step_2(uintptr_t f, uintptr_t n) { return iter((closure_t*)f, n + 1, 1); } -static uint step(uint dummy, uint x) { +static uintptr_t step(uintptr_t dummy, uintptr_t x) { closure_t *cl = malloc(sizeof(closure_t)); cl->arg = x; cl->f = (fun_t)step_2; - return (uint)cl; + return (uintptr_t)cl; } -static uint plus(uint x, uint y) { +static uintptr_t plus(uintptr_t x, uintptr_t y) { return x + y; } @@ -42,7 +41,7 @@ static int ackermann(int m, int n) { closure_t *mystep = malloc(sizeof(closure_t)); mystep->arg = 0; mystep->f = step; - closure_t *cl = (closure_t *)iter(mystep, m, (uint)plus_one); + closure_t *cl = (closure_t *)iter(mystep, m, (uintptr_t)plus_one); return cl->f(cl->arg, n); } From fae5da95a7d0f502377fa7e7530563443d9b47aa Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 20 Dec 2022 16:48:23 +0100 Subject: [PATCH 05/34] Refactor hie.yaml and add entry in the readme (#1672) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2623f48a73..268a576bbf 100644 --- a/.gitignore +++ b/.gitignore @@ -86,5 +86,6 @@ docs/**/*.md docs/org/README.org # Binary files (produced by `make check`) examples/milestone/HelloWorld/HelloWorld +hie.yaml /.shake/ hie.yaml From d0a368393e4ffadd2235dd90468d99da50d24f51 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 20 Dec 2022 16:55:54 +0100 Subject: [PATCH 06/34] add Juivix.Prelude.Env --- bench/Base.hs | 1 - bench/Compile.hs | 7 ++++--- src/Juvix/Prelude/Env.hs | 30 ++++++++++++++++++++++++++++++ test/BackendC/Base.hs | 6 +----- test/Base.hs | 14 ++++++++------ test/Runtime/Base.hs | 6 +----- 6 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 src/Juvix/Prelude/Env.hs diff --git a/bench/Base.hs b/bench/Base.hs index 657a027e33..fccdf08367 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -1,7 +1,6 @@ module Base where import Juvix.Extra.Paths -import Juvix.Prelude.Path as Path import Juvix.Prelude import Prelude (Show (show)) diff --git a/bench/Compile.hs b/bench/Compile.hs index 704106957e..dd94661ba1 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -3,6 +3,7 @@ module Compile where import Base import Development.Shake import Juvix.Prelude.Base +import Juvix.Prelude.Env import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) dirs :: [Path Rel Dir] @@ -41,8 +42,7 @@ mkBenchMark dir = do mkOcaml dir mkJuvix dir mkJuvixRuntime dir - --- mkClang dir FIXME + mkClang dir -- | e.g. dir = fibonacci mkHaskell :: Path Abs Dir -> Rules () @@ -150,7 +150,8 @@ mkClang dir = do command_ [] "clang" ["-O3", "-o", toFilePath exeFile, toFilePath cFile] recipe wasmFile $ do need [toFilePath cFile] - command_ [] "clang" ["-Os", "-nodefaultlibs", "--sysroot", "$WASI_SYSROOT_Path", "-lc", "--target=wasm32-wasi", "-o", toFilePath wasmFile, toFilePath cFile] + wasipath <- getWasiSysrootPathStr + command_ [] "clang" ["-Os", "-nodefaultlibs", "--sysroot", wasipath, "-lc", "--target=wasm32-wasi", "-o", toFilePath wasmFile, toFilePath cFile] where cDir :: Path Abs Dir cDir = dir Path. $(mkRelDir "c") diff --git a/src/Juvix/Prelude/Env.hs b/src/Juvix/Prelude/Env.hs new file mode 100644 index 0000000000..c7fa1e369c --- /dev/null +++ b/src/Juvix/Prelude/Env.hs @@ -0,0 +1,30 @@ +module Juvix.Prelude.Env where + +import Juvix.Prelude.Base +import Juvix.Prelude.Path +import System.Environment + +-- | Environment variables relevant to Juvix +data EnvVar + = EnvWasiSysrootPath + deriving stock (Show, Eq) + +envVarString :: EnvVar -> String +envVarString = \case + EnvWasiSysrootPath -> "WASI_SYSROOT_PATH" + +envVarHint :: EnvVar -> Maybe String +envVarHint = \case + EnvWasiSysrootPath -> Just "Set to the location of the wasi-clib sysroot" + +getEnvVar :: MonadIO m => EnvVar -> m String +getEnvVar var = fromMaybeM (error (pack msg)) (liftIO (lookupEnv (envVarString var))) + where + msg :: String + msg = "Missing environment variable " <> envVarString var <> maybe "" (". " <>) (envVarHint var) + +getWasiSysrootPathStr :: MonadIO m => m String +getWasiSysrootPathStr = getEnvVar EnvWasiSysrootPath + +getWasiSysrootPath :: MonadIO m => m (Path Abs Dir) +getWasiSysrootPath = absDir <$> getEnvVar EnvWasiSysrootPath diff --git a/test/BackendC/Base.hs b/test/BackendC/Base.hs index 4a3f85640f..93ee568d5c 100644 --- a/test/BackendC/Base.hs +++ b/test/BackendC/Base.hs @@ -59,11 +59,7 @@ wasiClangAssertion stdlibMode mainFile expectedFile stdinText step = do assertCmdExists $(mkRelFile "wasmer") step "Lookup WASI_SYSROOT_PATH" - sysrootPath <- - absDir - <$> assertEnvVar - "Env var WASI_SYSROOT_PATH missing. Set to the location of the wasi-clib sysroot" - "WASI_SYSROOT_PATH" + sysrootPath <- getWasiSysrootPath root <- getCurrentDir step "C Generation" diff --git a/test/Base.hs b/test/Base.hs index acc5d29dc1..18164cc3cc 100644 --- a/test/Base.hs +++ b/test/Base.hs @@ -4,15 +4,16 @@ module Base module Juvix.Prelude, module Base, module Juvix.Extra.Paths, + module Juvix.Prelude.Env, ) where +import Juvix.Prelude.Env import Control.Monad.Extra as Monad import Data.Algorithm.Diff import Data.Algorithm.DiffOutput import Juvix.Extra.Paths import Juvix.Prelude -import System.Environment (lookupEnv) import Test.Tasty import Test.Tasty.HUnit import Text.Show.Pretty hiding (Html) @@ -34,10 +35,14 @@ newtype WASMInfo = WASMInfo makeLenses ''TestDescr -data StdlibMode = StdlibInclude | StdlibExclude +data StdlibMode = + StdlibInclude + | StdlibExclude deriving stock (Show, Eq) -data CompileMode = WASI StdlibMode | WASM WASMInfo +data CompileMode = + WASI StdlibMode + | WASM WASMInfo mkTest :: TestDescr -> TestTree mkTest TestDescr {..} = case _testAssertion of @@ -60,6 +65,3 @@ assertCmdExists cmd = assertBool ("Command: " <> toFilePath cmd <> " is not present on $PATH") . isJust =<< findExecutable cmd - -assertEnvVar :: String -> String -> IO String -assertEnvVar msg varName = fromMaybeM (assertFailure msg) (lookupEnv varName) diff --git a/test/Runtime/Base.hs b/test/Runtime/Base.hs index 729164c2b6..4634bf9808 100644 --- a/test/Runtime/Base.hs +++ b/test/Runtime/Base.hs @@ -31,11 +31,7 @@ clangAssertion inputFile expectedFile stdinText step = do assertCmdExists $(mkRelFile "wasmer") step "Lookup WASI_SYSROOT_PATH" - sysrootPath :: Path Abs Dir <- - absDir - <$> assertEnvVar - "Env var WASI_SYSROOT_PATH missing. Set to the location of the wasi-clib sysroot" - "WASI_SYSROOT_PATH" + sysrootPath :: Path Abs Dir <- getWasiSysrootPath expected <- TIO.readFile (toFilePath expectedFile) From bd09ff5b4072cd99cdf457ad3da7f491a93b54c0 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 00:32:04 +0100 Subject: [PATCH 07/34] add benchmark suites --- .gitignore | 2 +- bench/Base.hs | 69 ++++++++++--- bench/Compile.hs | 208 +++++++++++++------------------------- bench/Main.hs | 62 ------------ bench/Suites.hs | 31 ++++++ bench/Variants.hs | 173 +++++++++++++++++++++++++++++++ src/Juvix/Prelude/Path.hs | 9 ++ 7 files changed, 339 insertions(+), 215 deletions(-) create mode 100644 bench/Suites.hs create mode 100644 bench/Variants.hs diff --git a/.gitignore b/.gitignore index 268a576bbf..aaf2aa1a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -88,4 +88,4 @@ docs/org/README.org examples/milestone/HelloWorld/HelloWorld hie.yaml /.shake/ -hie.yaml +/.benchmark-results/ diff --git a/bench/Base.hs b/bench/Base.hs index fccdf08367..b8221c287b 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -3,10 +3,26 @@ module Base where import Juvix.Extra.Paths import Juvix.Prelude import Prelude (Show (show)) +import Development.Shake hiding (()) root :: Path Abs Dir root = relToProject $(mkRelDir "tests/benchmark") +resultsDir :: Path Abs Dir +resultsDir = relToProject $(mkRelDir ".benchmark-results") + +resultDirs :: [Path Abs Dir] +resultDirs = [binDir, plotDir, csvDir] + +binDir :: Path Abs Dir +binDir = resultsDir $(mkRelDir "bin") + +plotDir :: Path Abs Dir +plotDir = resultsDir $(mkRelDir "plot") + +csvDir :: Path Abs Dir +csvDir = resultsDir $(mkRelDir "csv") + data Lang = Ocaml | Haskell @@ -30,24 +46,53 @@ langPath = relDir . Prelude.show langFile :: Lang -> Path Rel File langFile = relFile . Prelude.show +langExtension :: Lang -> String +langExtension = \case + Ocaml -> ".ml" + Haskell -> ".hs" + C -> ".c" + Juvix -> ".juvix" + Runtime -> ".c" + Core -> ".jvc" + data Variant = Variant { _variantTitle :: Maybe String, _variantLanguage :: Lang, - _variantExtensions :: [String] + _variantExtensions :: [String], + _variantBuild :: BuildArgs -> Action () + } + +data BuildArgs = BuildArgs { + _buildSrc :: Path Abs File, + _buildOutDir :: Path Abs Dir } -data Bench = Bench - { _benchTitle :: String, - _benchVariants :: [Variant] +data Suite = Suite + { _suiteTitle :: String, + _suiteVariants :: [Variant] } -makeLenses ''Bench +makeLenses ''Suite +makeLenses ''BuildArgs makeLenses ''Variant -defaultVariant :: Lang -> Variant -defaultVariant l = - Variant - { _variantTitle = Nothing, - _variantLanguage = l, - _variantExtensions = [".exe"] - } +suiteCsvFile :: Suite -> Path Abs File +suiteCsvFile s = addExtension' ".csv" (csvDir suiteBaseFile s) + +suiteSrcDir :: Suite -> Path Abs Dir +suiteSrcDir s = root relDir (s ^. suiteTitle) + +suiteBaseFile :: Suite -> Path Rel File +suiteBaseFile s = relFile (s ^. suiteTitle) + +variantSrcDir :: Suite -> Variant -> Path Abs Dir +variantSrcDir s v = suiteSrcDir s langPath (v ^. variantLanguage) + +suitePath :: Suite -> Path Rel Dir +suitePath s = relDir (s ^. suiteTitle) + +variantBinDir :: Suite -> Variant -> Path Abs Dir +variantBinDir s v = binDir suitePath s langPath (v ^. variantLanguage) + +variantBinFile :: Suite -> Variant -> Path Abs File +variantBinFile s v = variantBinDir s v addExtensions' (v ^. variantExtensions) (suiteBaseFile s) diff --git a/bench/Compile.hs b/bench/Compile.hs index dd94661ba1..51564a133a 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -1,163 +1,91 @@ module Compile where import Base -import Development.Shake +import Gauge +import System.Process +import Development.Shake hiding (()) import Juvix.Prelude.Base -import Juvix.Prelude.Env import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) - -dirs :: [Path Rel Dir] -dirs = - [ $(mkRelDir "ackermann"), - $(mkRelDir "combinations"), - $(mkRelDir "cps"), - $(mkRelDir "fibonacci"), - $(mkRelDir "fold"), - $(mkRelDir "mapfold"), - $(mkRelDir "mapfun"), - $(mkRelDir "maybe"), - $(mkRelDir "mergesort"), - $(mkRelDir "prime") - ] - -absDirs :: [Path Abs Dir] -absDirs = map (root Path.) dirs +import Juvix.Prelude.Path qualified as Path +import Suites compile :: IO () -compile = shakeArgs opts $ do - phony "clean" $ do - putInfo "TODO: Cleaning... " - forM_ absDirs mkBenchMark +compile = shakeArgs opts compileRules where opts :: ShakeOptions opts = shakeOptions +compileRules :: Rules () +compileRules = do + phony "clean" $ do + putInfo "TODO: Cleaning... " + forM_ suites suiteRules + +suiteRules :: Suite -> Rules () +suiteRules s = do + forM_ (s ^. suiteVariants) (variantRules s) + csvRules s + recipe :: Path Abs File -> Action () -> Rules () recipe out howto = toFilePath out %> const howto --- | e.g. dir = fibonacci -mkBenchMark :: Path Abs Dir -> Rules () -mkBenchMark dir = do - mkHaskell dir - mkOcaml dir - mkJuvix dir - mkJuvixRuntime dir - mkClang dir - --- | e.g. dir = fibonacci -mkHaskell :: Path Abs Dir -> Rules () -mkHaskell dir = do +variantRules :: Suite -> Variant -> Rules () +variantRules s v = do action $ whenM - (doesFileExist (toFilePath hsFile)) - (need [toFilePath exeFile, toFilePath sexeFile]) - let opts :: [String] = ["-O2", "-no-keep-hi-files", "-no-keep-o-files"] + (doesFileExist (toFilePath srcFile)) + (need [toFilePath exeFile]) recipe exeFile $ do - need [toFilePath hsFile] - command_ [] "ghc" (opts ++ ["-o", toFilePath exeFile, toFilePath hsFile]) - recipe sexeFile $ do - need [toFilePath hsFile] - command_ [] "ghc" (opts ++ ["-XStrict", "-o", toFilePath sexeFile, toFilePath hsFile]) + need [toFilePath srcFile] + ensureDir outDir + (v ^. variantBuild) args where - haskellDir :: Path Abs Dir - haskellDir = dir Path. $(mkRelDir "haskell") - hsFile :: Path Abs File - hsFile = addExtension' ".hs" (haskellDir Path. dirnameToFile dir) + args :: BuildArgs + args = + BuildArgs + { _buildSrc = srcFile, + _buildOutDir = variantBinDir s v + } + srcDir :: Path Abs Dir + srcDir = suiteSrcDir s + srcFile :: Path Abs File + srcFile = addExtension' (langExtension (v ^. variantLanguage)) (srcDir Path. suiteBaseFile s) exeFile :: Path Abs File - exeFile = replaceExtension' ".exe" hsFile - sexeFile :: Path Abs File - sexeFile = addExtension' ".exe" (replaceExtension' ".strict" hsFile) + exeFile = replaceExtensions' (v ^. variantExtensions) srcFile --- | e.g. dir = fibonacci -mkOcaml :: Path Abs Dir -> Rules () -mkOcaml dir = do - action $ - whenM - (doesFileExist (toFilePath mlFile)) - (need [toFilePath exeFile, toFilePath byteexeFile]) - recipe exeFile $ do - need [toFilePath mlFile] - command_ [] "ocamlopt" ["-O2", "-o", toFilePath exeFile, toFilePath mlFile] - recipe byteexeFile $ do - need [toFilePath mlFile] - command_ [] "ocamlc" ["-o", toFilePath byteexeFile, toFilePath mlFile] - where - ocamlDir :: Path Abs Dir - ocamlDir = dir Path. $(mkRelDir "ocaml") - mlFile :: Path Abs File - mlFile = addExtension' ".ml" (ocamlDir Path. dirnameToFile dir) - exeFile :: Path Abs File - exeFile = replaceExtension' ".exe" mlFile - byteexeFile :: Path Abs File - byteexeFile = addExtension' ".exe" (replaceExtension' ".byte" mlFile) +csvRules :: Suite -> Rules () +csvRules s = do + let csv :: Path Abs File = suiteCsvFile s + recipe csv $ do + need [ toFilePath (variantBinFile s v) | v <- s ^. suiteVariants ] + ensureDir (parent csv) + whenM (Path.doesFileExist csv) (removeFile csv) + liftIO (runMode DefaultMode (config s) [] [fromSuite s]) --- | e.g. dir = fibonacci -mkJuvix :: Path Abs Dir -> Rules () -mkJuvix dir = do - action $ - whenM - (doesFileExist (toFilePath juvixFile)) - (need [toFilePath exeFile, toFilePath wasmFile]) - let opts :: [String] = ["compile"] - recipe exeFile $ do - need [toFilePath juvixFile] - command_ [] "juvix" (opts <> ["-o", toFilePath exeFile, toFilePath juvixFile]) - recipe wasmFile $ do - need [toFilePath juvixFile] - command_ [] "juvix" (opts <> ["--target=wasm", "-o", toFilePath wasmFile, toFilePath juvixFile]) - where - ocamlDir :: Path Abs Dir - ocamlDir = dir Path. $(mkRelDir "juvix") - juvixFile :: Path Abs File - juvixFile = addExtension' ".juvix" (ocamlDir Path. dirnameToFile dir) - exeFile :: Path Abs File - exeFile = replaceExtension' ".exe" juvixFile - wasmFile :: Path Abs File - wasmFile = replaceExtension' ".wasm" juvixFile - --- | e.g. dir = fibonacci -mkJuvixRuntime :: Path Abs Dir -> Rules () -mkJuvixRuntime dir = do - action $ - whenM - (doesFileExist (toFilePath cFile)) - (need [toFilePath exeFile, toFilePath wasmFile]) - let opts :: [String] = ["dev", "runtime", "compile"] - recipe exeFile $ do - need [toFilePath cFile] - command_ [] "juvix" (opts <> ["-o", toFilePath exeFile, toFilePath cFile]) - recipe wasmFile $ do - need [toFilePath cFile] - command_ [] "juvix" (opts <> ["--target=wasm32-wasi", "-o", toFilePath wasmFile, toFilePath cFile]) - where - runtimeDir :: Path Abs Dir - runtimeDir = dir Path. $(mkRelDir "runtime") - cFile :: Path Abs File - cFile = addExtension' ".c" (runtimeDir Path. dirnameToFile dir) - exeFile :: Path Abs File - exeFile = replaceExtension' ".exe" cFile - wasmFile :: Path Abs File - wasmFile = replaceExtension' ".wasm" cFile +runExe :: Path Abs File -> IO () +runExe p = void (readProcess (toFilePath p) [] "") -mkClang :: Path Abs Dir -> Rules () -mkClang dir = do - action $ - whenM - (doesFileExist (toFilePath cFile)) - (need [toFilePath exeFile, toFilePath wasmFile]) - recipe exeFile $ do - need [toFilePath cFile] - command_ [] "clang" ["-O3", "-o", toFilePath exeFile, toFilePath cFile] - recipe wasmFile $ do - need [toFilePath cFile] - wasipath <- getWasiSysrootPathStr - command_ [] "clang" ["-Os", "-nodefaultlibs", "--sysroot", wasipath, "-lc", "--target=wasm32-wasi", "-o", toFilePath wasmFile, toFilePath cFile] +fromSuite :: Suite -> Benchmark +fromSuite b = bgroup (b ^. suiteTitle) (map go (b ^. suiteVariants)) where - cDir :: Path Abs Dir - cDir = dir Path. $(mkRelDir "c") - cFile :: Path Abs File - cFile = addExtension' ".c" (cDir Path. dirnameToFile dir) - exeFile :: Path Abs File - exeFile = replaceExtension' ".exe" cFile - wasmFile :: Path Abs File - wasmFile = replaceExtension' ".wasm" cFile + go :: Variant -> Benchmark + go v = bench title (nfIO (runExe exe)) + where + title :: String + title = show (v ^. variantLanguage) <> maybe "" (" " <>) (v ^. variantTitle) + exe :: Path Abs File + exe = + addExtensions' + (v ^. variantExtensions) + ( root + relDir (b ^. suiteTitle) + langPath (v ^. variantLanguage) + relFile (b ^. suiteTitle) + ) +config :: Suite -> Config +config s = + defaultConfig + { timeLimit = Just 0.0, + quickMode = False, + csvFile = Just (toFilePath (suiteCsvFile s)) + } diff --git a/bench/Main.hs b/bench/Main.hs index 32fe0aa5e9..349fe71c5b 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -1,70 +1,8 @@ module Main where -import Base import Compile qualified -import Gauge import Juvix.Prelude -import System.Process main :: IO () main = do Compile.compile - defaultMainWith config benchmarks - -runExe :: Path Abs File -> IO () -runExe p = void (readProcess (toFilePath p) [] "") - -config :: Config -config = - defaultConfig - { timeLimit = Just 0.0, - quickMode = False, - csvFile = Just "results.csv" - } - -defaultBench :: String -> Bench -defaultBench title = - Bench - { _benchTitle = title, - _benchVariants = - [ defaultVariant Haskell, - defaultVariant C, - defaultVariant Ocaml, - defaultVariant Runtime, - defaultVariant Juvix, - Variant - { _variantTitle = Just "strict", - _variantLanguage = Haskell, - _variantExtensions = [".strict", ".exe"] - }, - Variant - { _variantTitle = Just "byte", - _variantLanguage = Ocaml, - _variantExtensions = [".byte", ".exe"] - } - ] - } - -mergesort :: Bench -mergesort = defaultBench "mergesort" - -fromBench :: Bench -> [Benchmark] -fromBench b = map go (b ^. benchVariants) - where - go :: Variant -> Benchmark - go v = bench title (nfIO (runExe exe)) - where - title :: String - title = b ^. benchTitle <> maybe "" (" " <>) (v ^. variantTitle) <> " - " <> show (v ^. variantLanguage) - exe :: Path Abs File - exe = - addExtensions' - (v ^. variantExtensions) - ( root - relDir (b ^. benchTitle) - langPath (v ^. variantLanguage) - relFile (b ^. benchTitle) - ) - -benchmarks :: [Benchmark] -benchmarks = fromBench mergesort diff --git a/bench/Suites.hs b/bench/Suites.hs new file mode 100644 index 0000000000..c117572cec --- /dev/null +++ b/bench/Suites.hs @@ -0,0 +1,31 @@ +module Suites where + +import Base +import Juvix.Prelude +import Variants + +suites :: [Suite] +suites = + map + defaultSuite + [ "mergesort", + "fibonacci" + ] + +-- "ackermann" +-- "combinations" +-- "cps" +-- "fibonacci" +-- "fold" +-- "mapfold" +-- "mapfun" +-- "maybe" +-- "mergesort" +-- "prime + +defaultSuite :: String -> Suite +defaultSuite title = + Suite + { _suiteTitle = title, + _suiteVariants = defaultVariants + } diff --git a/bench/Variants.hs b/bench/Variants.hs new file mode 100644 index 0000000000..a35afcc62d --- /dev/null +++ b/bench/Variants.hs @@ -0,0 +1,173 @@ +module Variants where + +import Base +import Development.Shake hiding (()) +import Juvix.Prelude +import Juvix.Prelude.Env + +defaultVariants :: [Variant] +defaultVariants = [ + ocamlExe, + ocamlByteExe, + juvixExe, + -- juvixWasm, + clangExe, + -- clangWasm, + runtimeExe, + -- runtimeWasm, + haskellExe, + haskellStrictExe + ] + +defaultExt :: [String] +defaultExt = [".exe"] + +outFile :: BuildArgs -> [String] -> Path Abs File +outFile args ext = args ^. buildOutDir replaceExtensions' ext (filename (args ^. buildSrc)) + +outOptions :: BuildArgs -> [String] -> [String] +outOptions args ext = ["-o", toFilePath (outFile args ext)] + +commonOptions :: BuildArgs -> [String] -> [String] +commonOptions args ext = toFilePath (args ^. buildSrc) : outOptions args ext + +ocamlExe :: Variant +ocamlExe = + Variant + { _variantTitle = Nothing, + _variantLanguage = Ocaml, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "ocamlc" (commonOptions args ext) + } + where + ext :: [String] + ext = defaultExt + +ocamlByteExe :: Variant +ocamlByteExe = + Variant + { _variantTitle = Just "byte", + _variantLanguage = Ocaml, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "ocamlopt" ("-O2" : commonOptions args ext) + } + where + ext :: [String] + ext = ".byte" : defaultExt + +haskellExe :: Variant +haskellExe = + Variant + { _variantTitle = Nothing, + _variantLanguage = Haskell, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "ghc" (haskellCommon ++ commonOptions args ext) + } + where + ext :: [String] + ext = defaultExt + +haskellCommon :: [String] +haskellCommon = ["-O2", "-no-keep-hi-files", "-no-keep-o-files"] + +haskellStrictExe :: Variant +haskellStrictExe = + Variant + { _variantTitle = Just "strict", + _variantLanguage = Haskell, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "ghc" (haskellCommon ++ ["-XStrict"] ++ commonOptions args ext) + } + where + ext :: [String] + ext = ".strict" : defaultExt + +juvixExe :: Variant +juvixExe = + Variant + { _variantTitle = Nothing, + _variantLanguage = Juvix, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "juvix" (juvixCommon ++ commonOptions args ext) + } + where + ext :: [String] + ext = defaultExt + +juvixCommon :: [String] +juvixCommon = ["compile"] + +-- TODO does not generate an executable +juvixWasm :: Variant +juvixWasm = + Variant + { _variantTitle = Just "wasm", + _variantLanguage = Juvix, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "juvix" (juvixCommon ++ ["--target=wasm"] ++ commonOptions args ext) + } + where + ext :: [String] + ext = [".wasm"] + +runtimeCommon :: [String] +runtimeCommon = ["dev", "runtime", "compile"] + +runtimeExe :: Variant +runtimeExe = + Variant + { _variantTitle = Nothing, + _variantLanguage = Runtime, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "juvix" (runtimeCommon ++ commonOptions args ext) + } + where + ext :: [String] + ext = defaultExt + +runtimeWasm :: Variant +runtimeWasm = + Variant + { _variantTitle = Nothing, + _variantLanguage = Runtime, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "juvix" (runtimeCommon ++ ["--target=wasm32-wasi"] ++ commonOptions args ext) + } + where + ext :: [String] + ext = [".wasm"] + +clangExe :: Variant +clangExe = + Variant + { _variantTitle = Nothing, + _variantLanguage = C, + _variantExtensions = ext, + _variantBuild = \args -> + command_ [] "clang" ("-O3" : commonOptions args ext) + } + where + ext :: [String] + ext = defaultExt + +clangWasm :: Variant +clangWasm = + Variant + { _variantTitle = Nothing, + _variantLanguage = C, + _variantExtensions = ext, + _variantBuild = \args -> do + wasipath <- getWasiSysrootPathStr + command_ [] "clang" (["-Os", "-nodefaultlibs", "--sysroot", wasipath, "-lc", "--target=wasm32-wasi"] ++ commonOptions args ext) + } + where + ext :: [String] + ext = defaultExt diff --git a/src/Juvix/Prelude/Path.hs b/src/Juvix/Prelude/Path.hs index bed5c3d9db..24c9e88b12 100644 --- a/src/Juvix/Prelude/Path.hs +++ b/src/Juvix/Prelude/Path.hs @@ -69,6 +69,9 @@ someBaseToAbs root = \case Rel r -> root r Abs a -> a +removeExtensions :: Path b File -> Path b File +removeExtensions p = maybe p removeExtensions (removeExtension p) + removeExtension :: Path b File -> Maybe (Path b File) removeExtension = fmap fst . splitExtension @@ -80,6 +83,12 @@ addExtensions ext p = case ext of [] -> return p (e : es) -> addExtension e p >>= addExtensions es +replaceExtensions :: MonadThrow m => [String] -> Path b File -> m (Path b File) +replaceExtensions ext = addExtensions ext . removeExtensions + +replaceExtensions' :: [String] -> Path b File -> Path b File +replaceExtensions' ext = fromJust . replaceExtensions ext + addExtensions' :: [String] -> Path b File -> Path b File addExtensions' ext = fromJust . addExtensions ext From 4d1f82737fdc01f0883993c208e12f0e4395e2e1 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 00:32:30 +0100 Subject: [PATCH 08/34] make fibonacci inpput smaller --- tests/benchmark/fibonacci/c/fibonacci.c | 2 +- tests/benchmark/fibonacci/core/fibonacci.jvc | 2 +- tests/benchmark/fibonacci/haskell/fibonacci.hs | 2 +- tests/benchmark/fibonacci/juvix/fibonacci.juvix | 8 ++++---- tests/benchmark/fibonacci/ocaml/fibonacci.ml | 2 +- tests/benchmark/fibonacci/runtime/fibonacci.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/benchmark/fibonacci/c/fibonacci.c b/tests/benchmark/fibonacci/c/fibonacci.c index c9e1aa8581..257965693f 100644 --- a/tests/benchmark/fibonacci/c/fibonacci.c +++ b/tests/benchmark/fibonacci/c/fibonacci.c @@ -14,6 +14,6 @@ static int fib(int k) { } int main() { - printf("%d\n", fib(100000000)); + printf("%d\n", fib(1000000)); return 0; } diff --git a/tests/benchmark/fibonacci/core/fibonacci.jvc b/tests/benchmark/fibonacci/core/fibonacci.jvc index 724dc71401..c6149cb5dc 100644 --- a/tests/benchmark/fibonacci/core/fibonacci.jvc +++ b/tests/benchmark/fibonacci/core/fibonacci.jvc @@ -9,4 +9,4 @@ def fib := \k in go k 0 1; -fib 100000000 +fib 1000000 diff --git a/tests/benchmark/fibonacci/haskell/fibonacci.hs b/tests/benchmark/fibonacci/haskell/fibonacci.hs index a5744794b1..6fc2a11445 100644 --- a/tests/benchmark/fibonacci/haskell/fibonacci.hs +++ b/tests/benchmark/fibonacci/haskell/fibonacci.hs @@ -8,4 +8,4 @@ fib n = go n 0 1 go k n m = go (k - 1) m ((n + m) `mod` (2 ^ 28)) main :: IO () -main = putStrLn (show (fib 100000000)) +main = putStrLn (show (fib 1000000)) diff --git a/tests/benchmark/fibonacci/juvix/fibonacci.juvix b/tests/benchmark/fibonacci/juvix/fibonacci.juvix index 2a1d7567c6..f0d9c742a3 100644 --- a/tests/benchmark/fibonacci/juvix/fibonacci.juvix +++ b/tests/benchmark/fibonacci/juvix/fibonacci.juvix @@ -20,12 +20,12 @@ go k n m := if (k Data.Int.Ops.== Int_0) fib : Int -> Int; fib n := go n Int_0 Int_1; -axiom Int_100000000 : Int; -compile Int_100000000 { - c ↦ "100000000"; +axiom Int_1000000 : Int; +compile Int_1000000 { + c ↦ "1000000"; }; main : IO; -main := printInt (fib Int_100000000); +main := printInt (fib Int_1000000); end; diff --git a/tests/benchmark/fibonacci/ocaml/fibonacci.ml b/tests/benchmark/fibonacci/ocaml/fibonacci.ml index f8c4ab0a36..0641ca9234 100644 --- a/tests/benchmark/fibonacci/ocaml/fibonacci.ml +++ b/tests/benchmark/fibonacci/ocaml/fibonacci.ml @@ -11,5 +11,5 @@ let fib k = ;; -print_int (fib 100000000); +print_int (fib 1000000); print_newline () diff --git a/tests/benchmark/fibonacci/runtime/fibonacci.c b/tests/benchmark/fibonacci/runtime/fibonacci.c index adfe6acbe7..482b803f4b 100644 --- a/tests/benchmark/fibonacci/runtime/fibonacci.c +++ b/tests/benchmark/fibonacci/runtime/fibonacci.c @@ -50,7 +50,7 @@ int main() { JUVIX_FUNCTION_NS(juvix_function_main); { - ARG(0) = make_smallint(100000000); + ARG(0) = make_smallint(1000000); TAIL_CALL_NS(0, fib); } From 0e744d9585b53f95e362bbc76c98d64776cec276 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 00:32:40 +0100 Subject: [PATCH 09/34] make mergesort input smaller --- tests/benchmark/mergesort/c/mergesort.c | 2 +- tests/benchmark/mergesort/haskell/mergesort.hs | 2 +- tests/benchmark/mergesort/juvix/mergesort.juvix | 8 ++++---- tests/benchmark/mergesort/ocaml/mergesort.ml | 2 +- tests/benchmark/mergesort/runtime/mergesort.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/benchmark/mergesort/c/mergesort.c b/tests/benchmark/mergesort/c/mergesort.c index 2a340e37b4..0a2ace1c24 100644 --- a/tests/benchmark/mergesort/c/mergesort.c +++ b/tests/benchmark/mergesort/c/mergesort.c @@ -44,7 +44,7 @@ static bool sorted(int *tab, int size) { return true; } -#define N 200000 +#define N 100000 int main() { int *tab = malloc(N * sizeof(int)); diff --git a/tests/benchmark/mergesort/haskell/mergesort.hs b/tests/benchmark/mergesort/haskell/mergesort.hs index 8a798f08c5..9004c76816 100644 --- a/tests/benchmark/mergesort/haskell/mergesort.hs +++ b/tests/benchmark/mergesort/haskell/mergesort.hs @@ -30,4 +30,4 @@ gen 0 acc = acc gen n acc = gen (n - 1) (n : acc) main :: IO () -main = putStrLn (show (sorted (sort (gen 200000 [])))) +main = putStrLn (show (sorted (sort (gen 100000 [])))) diff --git a/tests/benchmark/mergesort/juvix/mergesort.juvix b/tests/benchmark/mergesort/juvix/mergesort.juvix index 8342767737..ec18348fd0 100644 --- a/tests/benchmark/mergesort/juvix/mergesort.juvix +++ b/tests/benchmark/mergesort/juvix/mergesort.juvix @@ -44,12 +44,12 @@ terminating gen : Int -> List Int -> List Int; gen n acc := if (n Data.Int.Ops.== Int_0) acc (gen (n Data.Int.Ops.- Int_1) (n ∷ acc)); -axiom Int_200000 : Int; -compile Int_200000 { - c ↦ "200000"; +axiom N : Int; +compile N { + c ↦ "100000"; }; main : IO; -main := if (sorted (sort (gen Int_200000 nil))) (putStrLn "true") (putStrLn "false"); +main := if (sorted (sort (gen N nil))) (putStrLn "true") (putStrLn "false"); end; diff --git a/tests/benchmark/mergesort/ocaml/mergesort.ml b/tests/benchmark/mergesort/ocaml/mergesort.ml index f712b37f8b..d7a7183b11 100644 --- a/tests/benchmark/mergesort/ocaml/mergesort.ml +++ b/tests/benchmark/mergesort/ocaml/mergesort.ml @@ -43,4 +43,4 @@ let rec gen n acc = if n = 0 then acc else gen (n - 1) (n :: acc) ;; -print_endline (if sorted (sort (gen 200000 [])) then "true" else "false");; +print_endline (if sorted (sort (gen 100000 [])) then "true" else "false");; diff --git a/tests/benchmark/mergesort/runtime/mergesort.c b/tests/benchmark/mergesort/runtime/mergesort.c index b1f457c084..584507d8e7 100644 --- a/tests/benchmark/mergesort/runtime/mergesort.c +++ b/tests/benchmark/mergesort/runtime/mergesort.c @@ -232,7 +232,7 @@ int main() { JUVIX_FUNCTION(juvix_function_main, 1); { ARG(1) = CONSTR_NIL; - ARG(0) = make_smallint(200000); + ARG(0) = make_smallint(100000); CALL(0, gen, juvix_label_main_1); ARG(0) = juvix_result; CALL(0, sort, juvix_label_2); From a20c04242345bfc94db7784f61bfd1cc2d258069 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 00:48:40 +0100 Subject: [PATCH 10/34] fix some paths --- bench/Base.hs | 23 +++++++++++++---------- bench/Compile.hs | 26 +++++++++++++++++--------- bench/Variants.hs | 27 ++++++++++++--------------- src/Juvix/Prelude/Env.hs | 4 ++-- test/Base.hs | 10 +++++----- 5 files changed, 49 insertions(+), 41 deletions(-) diff --git a/bench/Base.hs b/bench/Base.hs index b8221c287b..620dbcf6dd 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -1,9 +1,9 @@ module Base where +import Development.Shake hiding (()) import Juvix.Extra.Paths import Juvix.Prelude import Prelude (Show (show)) -import Development.Shake hiding (()) root :: Path Abs Dir root = relToProject $(mkRelDir "tests/benchmark") @@ -48,12 +48,12 @@ langFile = relFile . Prelude.show langExtension :: Lang -> String langExtension = \case - Ocaml -> ".ml" - Haskell -> ".hs" - C -> ".c" - Juvix -> ".juvix" - Runtime -> ".c" - Core -> ".jvc" + Ocaml -> ".ml" + Haskell -> ".hs" + C -> ".c" + Juvix -> ".juvix" + Runtime -> ".c" + Core -> ".jvc" data Variant = Variant { _variantTitle :: Maybe String, @@ -62,9 +62,9 @@ data Variant = Variant _variantBuild :: BuildArgs -> Action () } -data BuildArgs = BuildArgs { - _buildSrc :: Path Abs File, - _buildOutDir :: Path Abs Dir +data BuildArgs = BuildArgs + { _buildSrc :: Path Abs File, + _buildOutDir :: Path Abs Dir } data Suite = Suite @@ -96,3 +96,6 @@ variantBinDir s v = binDir suitePath s langPath (v ^. variantLanguage) variantBinFile :: Suite -> Variant -> Path Abs File variantBinFile s v = variantBinDir s v addExtensions' (v ^. variantExtensions) (suiteBaseFile s) + +binFile :: BuildArgs -> [String] -> Path Abs File +binFile args ext = args ^. buildOutDir replaceExtensions' ext (filename (args ^. buildSrc)) diff --git a/bench/Compile.hs b/bench/Compile.hs index 51564a133a..52cd8783d3 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -1,13 +1,13 @@ module Compile where import Base -import Gauge -import System.Process import Development.Shake hiding (()) +import Gauge import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) import Juvix.Prelude.Path qualified as Path import Suites +import System.Process compile :: IO () compile = shakeArgs opts compileRules @@ -31,10 +31,11 @@ recipe out howto = toFilePath out %> const howto variantRules :: Suite -> Variant -> Rules () variantRules s v = do - action $ + action $ do whenM (doesFileExist (toFilePath srcFile)) (need [toFilePath exeFile]) + recipe exeFile $ do need [toFilePath srcFile] ensureDir outDir @@ -44,20 +45,26 @@ variantRules s v = do args = BuildArgs { _buildSrc = srcFile, - _buildOutDir = variantBinDir s v + _buildOutDir = outDir } - srcDir :: Path Abs Dir - srcDir = suiteSrcDir s + lang :: Lang + lang = v ^. variantLanguage srcFile :: Path Abs File - srcFile = addExtension' (langExtension (v ^. variantLanguage)) (srcDir Path. suiteBaseFile s) + srcFile = + addExtension' + (langExtension lang) + (suiteSrcDir s langPath lang suiteBaseFile s) exeFile :: Path Abs File - exeFile = replaceExtensions' (v ^. variantExtensions) srcFile + exeFile = outDir replaceExtensions' (v ^. variantExtensions) (filename srcFile) + outDir :: Path Abs Dir + outDir = variantBinDir s v csvRules :: Suite -> Rules () csvRules s = do let csv :: Path Abs File = suiteCsvFile s + want [toFilePath csv] recipe csv $ do - need [ toFilePath (variantBinFile s v) | v <- s ^. suiteVariants ] + need [toFilePath (variantBinFile s v) | v <- s ^. suiteVariants] ensureDir (parent csv) whenM (Path.doesFileExist csv) (removeFile csv) liftIO (runMode DefaultMode (config s) [] [fromSuite s]) @@ -82,6 +89,7 @@ fromSuite b = bgroup (b ^. suiteTitle) (map go (b ^. suiteVariants)) langPath (v ^. variantLanguage) relFile (b ^. suiteTitle) ) + config :: Suite -> Config config s = defaultConfig diff --git a/bench/Variants.hs b/bench/Variants.hs index a35afcc62d..15d1cade40 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -6,27 +6,24 @@ import Juvix.Prelude import Juvix.Prelude.Env defaultVariants :: [Variant] -defaultVariants = [ - ocamlExe, - ocamlByteExe, - juvixExe, - -- juvixWasm, - clangExe, - -- clangWasm, - runtimeExe, - -- runtimeWasm, - haskellExe, - haskellStrictExe +defaultVariants = + [ ocamlExe, + ocamlByteExe, + juvixExe, + -- juvixWasm, + clangExe, + -- clangWasm, + runtimeExe, + -- runtimeWasm, + haskellExe, + haskellStrictExe ] defaultExt :: [String] defaultExt = [".exe"] -outFile :: BuildArgs -> [String] -> Path Abs File -outFile args ext = args ^. buildOutDir replaceExtensions' ext (filename (args ^. buildSrc)) - outOptions :: BuildArgs -> [String] -> [String] -outOptions args ext = ["-o", toFilePath (outFile args ext)] +outOptions args ext = ["-o", toFilePath (binFile args ext)] commonOptions :: BuildArgs -> [String] -> [String] commonOptions args ext = toFilePath (args ^. buildSrc) : outOptions args ext diff --git a/src/Juvix/Prelude/Env.hs b/src/Juvix/Prelude/Env.hs index c7fa1e369c..358df8b662 100644 --- a/src/Juvix/Prelude/Env.hs +++ b/src/Juvix/Prelude/Env.hs @@ -20,8 +20,8 @@ envVarHint = \case getEnvVar :: MonadIO m => EnvVar -> m String getEnvVar var = fromMaybeM (error (pack msg)) (liftIO (lookupEnv (envVarString var))) where - msg :: String - msg = "Missing environment variable " <> envVarString var <> maybe "" (". " <>) (envVarHint var) + msg :: String + msg = "Missing environment variable " <> envVarString var <> maybe "" (". " <>) (envVarHint var) getWasiSysrootPathStr :: MonadIO m => m String getWasiSysrootPathStr = getEnvVar EnvWasiSysrootPath diff --git a/test/Base.hs b/test/Base.hs index 18164cc3cc..4ddb7fe13c 100644 --- a/test/Base.hs +++ b/test/Base.hs @@ -8,12 +8,12 @@ module Base ) where -import Juvix.Prelude.Env import Control.Monad.Extra as Monad import Data.Algorithm.Diff import Data.Algorithm.DiffOutput import Juvix.Extra.Paths import Juvix.Prelude +import Juvix.Prelude.Env import Test.Tasty import Test.Tasty.HUnit import Text.Show.Pretty hiding (Html) @@ -35,13 +35,13 @@ newtype WASMInfo = WASMInfo makeLenses ''TestDescr -data StdlibMode = - StdlibInclude +data StdlibMode + = StdlibInclude | StdlibExclude deriving stock (Show, Eq) -data CompileMode = - WASI StdlibMode +data CompileMode + = WASI StdlibMode | WASM WASMInfo mkTest :: TestDescr -> TestTree From 19037b038ba81dda828ffdec62767d48e224edac Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 11:18:36 +0100 Subject: [PATCH 11/34] swap build command for ocaml --- bench/Variants.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/Variants.hs b/bench/Variants.hs index 15d1cade40..5f9a4514d2 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -35,7 +35,7 @@ ocamlExe = _variantLanguage = Ocaml, _variantExtensions = ext, _variantBuild = \args -> - command_ [] "ocamlc" (commonOptions args ext) + command_ [] "ocamlopt" ("-O2" : commonOptions args ext) } where ext :: [String] @@ -48,7 +48,7 @@ ocamlByteExe = _variantLanguage = Ocaml, _variantExtensions = ext, _variantBuild = \args -> - command_ [] "ocamlopt" ("-O2" : commonOptions args ext) + command_ [] "ocamlc" (commonOptions args ext) } where ext :: [String] From 57f3251d0efab6df02cbbfec5bdfb4ed9e6cff72 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 11:25:26 +0100 Subject: [PATCH 12/34] match core/mergesort input size with others --- tests/benchmark/mergesort/core/mergesort.jvc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/benchmark/mergesort/core/mergesort.jvc b/tests/benchmark/mergesort/core/mergesort.jvc index eab1e0d49c..176d841c5e 100644 --- a/tests/benchmark/mergesort/core/mergesort.jvc +++ b/tests/benchmark/mergesort/core/mergesort.jvc @@ -51,4 +51,4 @@ def sorted := \xs def gen := \n \acc if n = 0 then acc else gen (n - 1) (cons n acc); -sorted (sort (gen 200000 nil)) +sorted (sort (gen 100000 nil)) From 5c6cbe20690c40b709dfccca43524c93019b3787 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 11:34:19 +0100 Subject: [PATCH 13/34] fix executable path --- bench/Compile.hs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/bench/Compile.hs b/bench/Compile.hs index 52cd8783d3..14b80015e0 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -73,22 +73,13 @@ runExe :: Path Abs File -> IO () runExe p = void (readProcess (toFilePath p) [] "") fromSuite :: Suite -> Benchmark -fromSuite b = bgroup (b ^. suiteTitle) (map go (b ^. suiteVariants)) +fromSuite s = bgroup (s ^. suiteTitle) (map go (s ^. suiteVariants)) where go :: Variant -> Benchmark - go v = bench title (nfIO (runExe exe)) + go v = bench title (nfIO (runExe (variantBinFile s v))) where title :: String title = show (v ^. variantLanguage) <> maybe "" (" " <>) (v ^. variantTitle) - exe :: Path Abs File - exe = - addExtensions' - (v ^. variantExtensions) - ( root - relDir (b ^. suiteTitle) - langPath (v ^. variantLanguage) - relFile (b ^. suiteTitle) - ) config :: Suite -> Config config s = From 354fda8d47523b71dde25d11df453bc36deb85e5 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 12:48:28 +0100 Subject: [PATCH 14/34] automatize plots --- bench/Base.hs | 7 +++++++ bench/Compile.hs | 37 +++++++++++++++++++++++++++++++++---- bench/Variants.hs | 16 +++++++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/bench/Base.hs b/bench/Base.hs index 620dbcf6dd..1497f4dcaf 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -59,6 +59,7 @@ data Variant = Variant { _variantTitle :: Maybe String, _variantLanguage :: Lang, _variantExtensions :: [String], + _variantColor :: Int, _variantBuild :: BuildArgs -> Action () } @@ -76,6 +77,12 @@ makeLenses ''Suite makeLenses ''BuildArgs makeLenses ''Variant +gnuplotFile :: Path Abs File +gnuplotFile = relToProject $(mkRelFile "gnuplot/bars.gp") + +suitePdfFile :: Suite -> Path Abs File +suitePdfFile s = addExtension' ".pdf" (plotDir suiteBaseFile s) + suiteCsvFile :: Suite -> Path Abs File suiteCsvFile s = addExtension' ".csv" (csvDir suiteBaseFile s) diff --git a/bench/Compile.hs b/bench/Compile.hs index 14b80015e0..ea44eb1547 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -2,6 +2,7 @@ module Compile where import Base import Development.Shake hiding (()) +import Data.Text qualified as Text import Gauge import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) @@ -25,6 +26,7 @@ suiteRules :: Suite -> Rules () suiteRules s = do forM_ (s ^. suiteVariants) (variantRules s) csvRules s + plotRules s recipe :: Path Abs File -> Action () -> Rules () recipe out howto = toFilePath out %> const howto @@ -59,21 +61,48 @@ variantRules s v = do outDir :: Path Abs Dir outDir = variantBinDir s v +plotRules :: Suite -> Rules () +plotRules s = do + let pdf :: Path Abs File = suitePdfFile s + csv :: Path Abs File = suiteCsvFile s + want [toFilePath pdf] + recipe pdf $ do + need [toFilePath csv, toFilePath gnuplotFile] + ensureDir (parent pdf) + command_ [] "gnuplot" ( + gpArg "name" (s ^. suiteTitle) + ++ gpArg "outfile" (toFilePath pdf) + ++ gpArg "csvfile" (toFilePath csv) + ++ [toFilePath gnuplotFile] + ) + where + gpArg :: String -> String -> [String] + gpArg arg val = ["-e", arg <> "='" <> val <> "'"] + + csvRules :: Suite -> Rules () csvRules s = do - let csv :: Path Abs File = suiteCsvFile s want [toFilePath csv] recipe csv $ do need [toFilePath (variantBinFile s v) | v <- s ^. suiteVariants] ensureDir (parent csv) whenM (Path.doesFileExist csv) (removeFile csv) - liftIO (runMode DefaultMode (config s) [] [fromSuite s]) + liftIO (runMode DefaultMode (config s) [] (fromSuite s)) + liftIO addColorColumn + where + csv :: Path Abs File = suiteCsvFile s + addColorColumn :: IO () + addColorColumn = do + header :| rows <- nonEmpty' . Text.lines <$> readFile (toFilePath csv) + let rows' = [ show (v ^. variantColor) <> "," <> r | (v, r) <- zipExact (s ^. suiteVariants) rows ] + header' = "Color," <> header + writeFile (toFilePath csv) (Text.unlines (header' : rows')) runExe :: Path Abs File -> IO () runExe p = void (readProcess (toFilePath p) [] "") -fromSuite :: Suite -> Benchmark -fromSuite s = bgroup (s ^. suiteTitle) (map go (s ^. suiteVariants)) +fromSuite :: Suite -> [Benchmark] +fromSuite s = map go (s ^. suiteVariants) where go :: Variant -> Benchmark go v = bench title (nfIO (runExe (variantBinFile s v))) diff --git a/bench/Variants.hs b/bench/Variants.hs index 5f9a4514d2..76cec91b41 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -34,6 +34,7 @@ ocamlExe = { _variantTitle = Nothing, _variantLanguage = Ocaml, _variantExtensions = ext, + _variantColor = 0, _variantBuild = \args -> command_ [] "ocamlopt" ("-O2" : commonOptions args ext) } @@ -47,6 +48,7 @@ ocamlByteExe = { _variantTitle = Just "byte", _variantLanguage = Ocaml, _variantExtensions = ext, + _variantColor = 1, _variantBuild = \args -> command_ [] "ocamlc" (commonOptions args ext) } @@ -54,12 +56,16 @@ ocamlByteExe = ext :: [String] ext = ".byte" : defaultExt +haskellCommon :: [String] +haskellCommon = ["-O2", "-no-keep-hi-files", "-no-keep-o-files"] + haskellExe :: Variant haskellExe = Variant { _variantTitle = Nothing, _variantLanguage = Haskell, _variantExtensions = ext, + _variantColor = 2, _variantBuild = \args -> command_ [] "ghc" (haskellCommon ++ commonOptions args ext) } @@ -67,15 +73,13 @@ haskellExe = ext :: [String] ext = defaultExt -haskellCommon :: [String] -haskellCommon = ["-O2", "-no-keep-hi-files", "-no-keep-o-files"] - haskellStrictExe :: Variant haskellStrictExe = Variant { _variantTitle = Just "strict", _variantLanguage = Haskell, _variantExtensions = ext, + _variantColor = 3, _variantBuild = \args -> command_ [] "ghc" (haskellCommon ++ ["-XStrict"] ++ commonOptions args ext) } @@ -89,6 +93,7 @@ juvixExe = { _variantTitle = Nothing, _variantLanguage = Juvix, _variantExtensions = ext, + _variantColor = 4, _variantBuild = \args -> command_ [] "juvix" (juvixCommon ++ commonOptions args ext) } @@ -106,6 +111,7 @@ juvixWasm = { _variantTitle = Just "wasm", _variantLanguage = Juvix, _variantExtensions = ext, + _variantColor = 5, _variantBuild = \args -> command_ [] "juvix" (juvixCommon ++ ["--target=wasm"] ++ commonOptions args ext) } @@ -122,6 +128,7 @@ runtimeExe = { _variantTitle = Nothing, _variantLanguage = Runtime, _variantExtensions = ext, + _variantColor = 6, _variantBuild = \args -> command_ [] "juvix" (runtimeCommon ++ commonOptions args ext) } @@ -135,6 +142,7 @@ runtimeWasm = { _variantTitle = Nothing, _variantLanguage = Runtime, _variantExtensions = ext, + _variantColor = 7, _variantBuild = \args -> command_ [] "juvix" (runtimeCommon ++ ["--target=wasm32-wasi"] ++ commonOptions args ext) } @@ -148,6 +156,7 @@ clangExe = { _variantTitle = Nothing, _variantLanguage = C, _variantExtensions = ext, + _variantColor = 8, _variantBuild = \args -> command_ [] "clang" ("-O3" : commonOptions args ext) } @@ -161,6 +170,7 @@ clangWasm = { _variantTitle = Nothing, _variantLanguage = C, _variantExtensions = ext, + _variantColor = 9, _variantBuild = \args -> do wasipath <- getWasiSysrootPathStr command_ [] "clang" (["-Os", "-nodefaultlibs", "--sysroot", wasipath, "-lc", "--target=wasm32-wasi"] ++ commonOptions args ext) From c8174e299131f7b7539fb3e5c4536dbfd203195a Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 13:11:26 +0100 Subject: [PATCH 15/34] add gnuplot script --- gnuplot/bars.gp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 gnuplot/bars.gp diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp new file mode 100644 index 0000000000..d4a124aaaf --- /dev/null +++ b/gnuplot/bars.gp @@ -0,0 +1,14 @@ +# arguments: name outfile csvfile +# usage: gnuplot -e "name='the title'" -e "outfile='out.pdf'" -e "csvfile='data.csv'" bars.gp +set terminal pdf +set output outfile +set title name +unset key +set style data histogram +set datafile separator "," +set boxwidth 2 +set xtic rotate by -20 scale 0 +set grid y +set ylabel "time (s)" +set style fill solid +plot csvfile using "Mean":"Color":xtic(2) title col lc variable From 5f0c40ed4cf891d03c154b8304f08508e994f2b5 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 15:06:54 +0100 Subject: [PATCH 16/34] produce svg --- bench/Base.hs | 8 +++++++- bench/Compile.hs | 14 +++++++++----- bench/Variants.hs | 19 +++++++++++++++++-- gnuplot/bars.gp | 11 ++++++++--- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/bench/Base.hs b/bench/Base.hs index 1497f4dcaf..216d26ecf8 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -80,8 +80,14 @@ makeLenses ''Variant gnuplotFile :: Path Abs File gnuplotFile = relToProject $(mkRelFile "gnuplot/bars.gp") +suitePlotFile :: Suite -> Path Abs File +suitePlotFile s = plotDir suiteBaseFile s + suitePdfFile :: Suite -> Path Abs File -suitePdfFile s = addExtension' ".pdf" (plotDir suiteBaseFile s) +suitePdfFile s = addExtension' ".pdf" (suitePlotFile s) + +suiteSvgFile :: Suite -> Path Abs File +suiteSvgFile s = addExtension' ".svg" (suitePlotFile s) suiteCsvFile :: Suite -> Path Abs File suiteCsvFile s = addExtension' ".csv" (csvDir suiteBaseFile s) diff --git a/bench/Compile.hs b/bench/Compile.hs index ea44eb1547..85a65001a4 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -28,6 +28,9 @@ suiteRules s = do csvRules s plotRules s +multiRecipe :: [Path Abs File] -> Action () -> Rules () +multiRecipe out howto = map toFilePath out &%> const howto + recipe :: Path Abs File -> Action () -> Rules () recipe out howto = toFilePath out %> const howto @@ -65,13 +68,15 @@ plotRules :: Suite -> Rules () plotRules s = do let pdf :: Path Abs File = suitePdfFile s csv :: Path Abs File = suiteCsvFile s - want [toFilePath pdf] - recipe pdf $ do + svg :: Path Abs File = suiteSvgFile s + out :: Path Abs File = suitePlotFile s + want [toFilePath pdf, toFilePath svg] + multiRecipe [pdf, svg] $ do need [toFilePath csv, toFilePath gnuplotFile] ensureDir (parent pdf) command_ [] "gnuplot" ( gpArg "name" (s ^. suiteTitle) - ++ gpArg "outfile" (toFilePath pdf) + ++ gpArg "outfile" (toFilePath out) ++ gpArg "csvfile" (toFilePath csv) ++ [toFilePath gnuplotFile] ) @@ -81,8 +86,7 @@ plotRules s = do csvRules :: Suite -> Rules () -csvRules s = do - want [toFilePath csv] +csvRules s = recipe csv $ do need [toFilePath (variantBinFile s v) | v <- s ^. suiteVariants] ensureDir (parent csv) diff --git a/bench/Variants.hs b/bench/Variants.hs index 76cec91b41..0418b9d01d 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -15,7 +15,8 @@ defaultVariants = -- clangWasm, runtimeExe, -- runtimeWasm, - haskellExe, + -- haskellExe, + -- coreJvc, haskellStrictExe ] @@ -156,7 +157,7 @@ clangExe = { _variantTitle = Nothing, _variantLanguage = C, _variantExtensions = ext, - _variantColor = 8, + _variantColor = 10, _variantBuild = \args -> command_ [] "clang" ("-O3" : commonOptions args ext) } @@ -178,3 +179,17 @@ clangWasm = where ext :: [String] ext = defaultExt + +coreJvc :: Variant +coreJvc = + Variant + { _variantTitle = Nothing, + _variantLanguage = Core, + _variantExtensions = ext, + _variantColor = 10, + _variantBuild = \args -> + command_ [] "cp" (map toFilePath [args ^. buildSrc, binFile args ext]) + } + where + ext :: [String] + ext = [langExtension Core] diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index d4a124aaaf..65681b4c34 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -1,7 +1,5 @@ # arguments: name outfile csvfile -# usage: gnuplot -e "name='the title'" -e "outfile='out.pdf'" -e "csvfile='data.csv'" bars.gp -set terminal pdf -set output outfile +# usage: gnuplot -e "name='the title'" -e "outfile='out'" -e "csvfile='data.csv'" bars.gp set title name unset key set style data histogram @@ -11,4 +9,11 @@ set xtic rotate by -20 scale 0 set grid y set ylabel "time (s)" set style fill solid + +set terminal pdf +set output outfile.'.pdf' plot csvfile using "Mean":"Color":xtic(2) title col lc variable + +set terminal svg enhanced mouse +set output outfile.'.svg' +replot From 2b32530e0bc76c49d0830f551b6e285e8cfbc588 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 21 Dec 2022 18:33:51 +0100 Subject: [PATCH 17/34] use fixed colours --- bench/Base.hs | 10 ++++++++-- bench/Compile.hs | 38 +++++++++++++++++++++----------------- bench/Variants.hs | 25 +++++++++++++------------ gnuplot/bars.gp | 3 ++- package.yaml | 1 + 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/bench/Base.hs b/bench/Base.hs index 216d26ecf8..755aaf8eea 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -1,9 +1,11 @@ module Base where +import Data.Colour +import Data.Colour.SRGB import Development.Shake hiding (()) import Juvix.Extra.Paths import Juvix.Prelude -import Prelude (Show (show)) +import Prelude (Double, Show (show)) root :: Path Abs Dir root = relToProject $(mkRelDir "tests/benchmark") @@ -23,6 +25,10 @@ plotDir = resultsDir $(mkRelDir "plot") csvDir :: Path Abs Dir csvDir = resultsDir $(mkRelDir "csv") +-- | e.g. 0xf0f8ff (format supported by gnuplot) +showColour :: Colour Double -> Text +showColour = pack . ("0x" <>) . dropExact 1 . sRGB24show + data Lang = Ocaml | Haskell @@ -59,7 +65,7 @@ data Variant = Variant { _variantTitle :: Maybe String, _variantLanguage :: Lang, _variantExtensions :: [String], - _variantColor :: Int, + _variantColor :: Colour Double, _variantBuild :: BuildArgs -> Action () } diff --git a/bench/Compile.hs b/bench/Compile.hs index 85a65001a4..0d24d1767d 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -1,8 +1,8 @@ module Compile where import Base -import Development.Shake hiding (()) import Data.Text qualified as Text +import Development.Shake hiding (()) import Gauge import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) @@ -74,16 +74,17 @@ plotRules s = do multiRecipe [pdf, svg] $ do need [toFilePath csv, toFilePath gnuplotFile] ensureDir (parent pdf) - command_ [] "gnuplot" ( - gpArg "name" (s ^. suiteTitle) - ++ gpArg "outfile" (toFilePath out) - ++ gpArg "csvfile" (toFilePath csv) - ++ [toFilePath gnuplotFile] - ) + command_ + [] + "gnuplot" + ( gpArg "name" (s ^. suiteTitle) + ++ gpArg "outfile" (toFilePath out) + ++ gpArg "csvfile" (toFilePath csv) + ++ [toFilePath gnuplotFile] + ) where - gpArg :: String -> String -> [String] - gpArg arg val = ["-e", arg <> "='" <> val <> "'"] - + gpArg :: String -> String -> [String] + gpArg arg val = ["-e", arg <> "='" <> val <> "'"] csvRules :: Suite -> Rules () csvRules s = @@ -94,13 +95,16 @@ csvRules s = liftIO (runMode DefaultMode (config s) [] (fromSuite s)) liftIO addColorColumn where - csv :: Path Abs File = suiteCsvFile s - addColorColumn :: IO () - addColorColumn = do - header :| rows <- nonEmpty' . Text.lines <$> readFile (toFilePath csv) - let rows' = [ show (v ^. variantColor) <> "," <> r | (v, r) <- zipExact (s ^. suiteVariants) rows ] - header' = "Color," <> header - writeFile (toFilePath csv) (Text.unlines (header' : rows')) + csv :: Path Abs File = suiteCsvFile s + addColorColumn :: IO () + addColorColumn = do + header :| rows <- nonEmpty' . Text.lines <$> readFile (toFilePath csv) + let rows' = + [ showColour (v ^. variantColor) <> "," <> r + | (v, r) <- zipExact (s ^. suiteVariants) rows + ] + header' = "Color," <> header + writeFile (toFilePath csv) (Text.unlines (header' : rows')) runExe :: Path Abs File -> IO () runExe p = void (readProcess (toFilePath p) [] "") diff --git a/bench/Variants.hs b/bench/Variants.hs index 0418b9d01d..bfb295ee30 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -1,6 +1,7 @@ module Variants where import Base +import Data.Colour.Names import Development.Shake hiding (()) import Juvix.Prelude import Juvix.Prelude.Env @@ -15,7 +16,7 @@ defaultVariants = -- clangWasm, runtimeExe, -- runtimeWasm, - -- haskellExe, + haskellExe, -- coreJvc, haskellStrictExe ] @@ -35,7 +36,7 @@ ocamlExe = { _variantTitle = Nothing, _variantLanguage = Ocaml, _variantExtensions = ext, - _variantColor = 0, + _variantColor = darkorange, _variantBuild = \args -> command_ [] "ocamlopt" ("-O2" : commonOptions args ext) } @@ -49,7 +50,7 @@ ocamlByteExe = { _variantTitle = Just "byte", _variantLanguage = Ocaml, _variantExtensions = ext, - _variantColor = 1, + _variantColor = orangered, _variantBuild = \args -> command_ [] "ocamlc" (commonOptions args ext) } @@ -66,7 +67,7 @@ haskellExe = { _variantTitle = Nothing, _variantLanguage = Haskell, _variantExtensions = ext, - _variantColor = 2, + _variantColor = purple, _variantBuild = \args -> command_ [] "ghc" (haskellCommon ++ commonOptions args ext) } @@ -80,7 +81,7 @@ haskellStrictExe = { _variantTitle = Just "strict", _variantLanguage = Haskell, _variantExtensions = ext, - _variantColor = 3, + _variantColor = powderblue, _variantBuild = \args -> command_ [] "ghc" (haskellCommon ++ ["-XStrict"] ++ commonOptions args ext) } @@ -94,7 +95,7 @@ juvixExe = { _variantTitle = Nothing, _variantLanguage = Juvix, _variantExtensions = ext, - _variantColor = 4, + _variantColor = plum, _variantBuild = \args -> command_ [] "juvix" (juvixCommon ++ commonOptions args ext) } @@ -112,7 +113,7 @@ juvixWasm = { _variantTitle = Just "wasm", _variantLanguage = Juvix, _variantExtensions = ext, - _variantColor = 5, + _variantColor = sandybrown, _variantBuild = \args -> command_ [] "juvix" (juvixCommon ++ ["--target=wasm"] ++ commonOptions args ext) } @@ -129,7 +130,7 @@ runtimeExe = { _variantTitle = Nothing, _variantLanguage = Runtime, _variantExtensions = ext, - _variantColor = 6, + _variantColor = navy, _variantBuild = \args -> command_ [] "juvix" (runtimeCommon ++ commonOptions args ext) } @@ -143,7 +144,7 @@ runtimeWasm = { _variantTitle = Nothing, _variantLanguage = Runtime, _variantExtensions = ext, - _variantColor = 7, + _variantColor = turquoise, _variantBuild = \args -> command_ [] "juvix" (runtimeCommon ++ ["--target=wasm32-wasi"] ++ commonOptions args ext) } @@ -157,7 +158,7 @@ clangExe = { _variantTitle = Nothing, _variantLanguage = C, _variantExtensions = ext, - _variantColor = 10, + _variantColor = black, _variantBuild = \args -> command_ [] "clang" ("-O3" : commonOptions args ext) } @@ -171,7 +172,7 @@ clangWasm = { _variantTitle = Nothing, _variantLanguage = C, _variantExtensions = ext, - _variantColor = 9, + _variantColor = palevioletred, _variantBuild = \args -> do wasipath <- getWasiSysrootPathStr command_ [] "clang" (["-Os", "-nodefaultlibs", "--sysroot", wasipath, "-lc", "--target=wasm32-wasi"] ++ commonOptions args ext) @@ -186,7 +187,7 @@ coreJvc = { _variantTitle = Nothing, _variantLanguage = Core, _variantExtensions = ext, - _variantColor = 10, + _variantColor = orchid, _variantBuild = \args -> command_ [] "cp" (map toFilePath [args ^. buildSrc, binFile args ext]) } diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index 65681b4c34..0a8c0fa8af 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -12,7 +12,8 @@ set style fill solid set terminal pdf set output outfile.'.pdf' -plot csvfile using "Mean":"Color":xtic(2) title col lc variable +set yrange [0 : *] +plot csvfile using "Mean":"Color":xtic(2) title col lc rgbcolor variable set terminal svg enhanced mouse set output outfile.'.svg' diff --git a/package.yaml b/package.yaml index 58cdd110d1..b8d3ed39f0 100644 --- a/package.yaml +++ b/package.yaml @@ -75,6 +75,7 @@ dependencies: # benchmarks - gauge == 0.2.* - shake == 0.19.* +- colour == 2.3.* ghc-options: # Warnings - -Weverything From 7ff05df34c11c93945dd34c5020cf3c3dba5b862 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 22 Dec 2022 16:31:19 +0100 Subject: [PATCH 18/34] use nicer colors and add stddev plot --- bench/Base.hs | 3 +- bench/Compile.hs | 9 +-- bench/Suites.hs | 2 +- bench/Variants.hs | 112 +++++++++++++++++++++++++++----------- gnuplot/bars.gp | 39 ++++++++++--- package.yaml | 1 + src/Juvix/Prelude/Base.hs | 2 + 7 files changed, 118 insertions(+), 50 deletions(-) diff --git a/bench/Base.hs b/bench/Base.hs index 755aaf8eea..968ca56713 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -5,7 +5,7 @@ import Data.Colour.SRGB import Development.Shake hiding (()) import Juvix.Extra.Paths import Juvix.Prelude -import Prelude (Double, Show (show)) +import Prelude (Show (show)) root :: Path Abs Dir root = relToProject $(mkRelDir "tests/benchmark") @@ -66,6 +66,7 @@ data Variant = Variant _variantLanguage :: Lang, _variantExtensions :: [String], _variantColor :: Colour Double, + _variantRun :: Path Abs File -> IO (), _variantBuild :: BuildArgs -> Action () } diff --git a/bench/Compile.hs b/bench/Compile.hs index 0d24d1767d..1a2fc8c762 100644 --- a/bench/Compile.hs +++ b/bench/Compile.hs @@ -8,7 +8,6 @@ import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) import Juvix.Prelude.Path qualified as Path import Suites -import System.Process compile :: IO () compile = shakeArgs opts compileRules @@ -19,7 +18,8 @@ compile = shakeArgs opts compileRules compileRules :: Rules () compileRules = do phony "clean" $ do - putInfo "TODO: Cleaning... " + putInfo ("Deleting " <> toFilePath resultsDir) + removePathForcibly resultsDir forM_ suites suiteRules suiteRules :: Suite -> Rules () @@ -106,14 +106,11 @@ csvRules s = header' = "Color," <> header writeFile (toFilePath csv) (Text.unlines (header' : rows')) -runExe :: Path Abs File -> IO () -runExe p = void (readProcess (toFilePath p) [] "") - fromSuite :: Suite -> [Benchmark] fromSuite s = map go (s ^. suiteVariants) where go :: Variant -> Benchmark - go v = bench title (nfIO (runExe (variantBinFile s v))) + go v = bench title (nfIO ((v ^. variantRun) (variantBinFile s v))) where title :: String title = show (v ^. variantLanguage) <> maybe "" (" " <>) (v ^. variantTitle) diff --git a/bench/Suites.hs b/bench/Suites.hs index c117572cec..ad3c026ae9 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -27,5 +27,5 @@ defaultSuite :: String -> Suite defaultSuite title = Suite { _suiteTitle = title, - _suiteVariants = defaultVariants + _suiteVariants = allVariants } diff --git a/bench/Variants.hs b/bench/Variants.hs index bfb295ee30..31875fab28 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -1,29 +1,65 @@ module Variants where import Base -import Data.Colour.Names +import Data.Colour +import Data.Colour.Palette.BrewerSet import Development.Shake hiding (()) import Juvix.Prelude import Juvix.Prelude.Env - -defaultVariants :: [Variant] -defaultVariants = - [ ocamlExe, - ocamlByteExe, - juvixExe, - -- juvixWasm, - clangExe, - -- clangWasm, - runtimeExe, - -- runtimeWasm, - haskellExe, - -- coreJvc, - haskellStrictExe - ] +import System.Process + +allVariants :: [Variant] +allVariants = map getVariant allElements + +data VariantId + = OcamlExe + | OcamlByte + | HaskellExe + | HaskellStrict + | JuvixExe + | JuvixWasm + | ClangExe + | ClangWasm + | RuntimeExe + | RuntimeWasm + | CoreEval + deriving stock (Bounded, Enum, Eq, Ord) + +getVariantIx :: VariantId -> Int +getVariantIx = fromEnum + +-- | Note that only 12 colors are available +getVariantColor :: VariantId -> Colour Double +getVariantColor v + | i < 12 = brewerSet Paired 12 !! i + | otherwise = error "not enough colors. Please extend the palette" + where + i :: Int + i = getVariantIx v + +getVariant :: VariantId -> Variant +getVariant = \case + OcamlExe -> ocamlExe + OcamlByte -> ocamlByteExe + HaskellExe -> haskellExe + HaskellStrict -> haskellStrictExe + JuvixExe -> juvixExe + JuvixWasm -> juvixWasm + ClangExe -> clangExe + ClangWasm -> clangWasm + RuntimeExe -> runtimeExe + RuntimeWasm -> runtimeWasm + CoreEval -> coreEval defaultExt :: [String] defaultExt = [".exe"] +runWasm :: Path Abs File -> IO () +runWasm p = void (readProcess "wasmer" [toFilePath p, "--disable-cache"] "") + +runExe :: Path Abs File -> IO () +runExe p = void (readProcess (toFilePath p) [] "") + outOptions :: BuildArgs -> [String] -> [String] outOptions args ext = ["-o", toFilePath (binFile args ext)] @@ -36,7 +72,8 @@ ocamlExe = { _variantTitle = Nothing, _variantLanguage = Ocaml, _variantExtensions = ext, - _variantColor = darkorange, + _variantColor = getVariantColor OcamlExe, + _variantRun = runExe, _variantBuild = \args -> command_ [] "ocamlopt" ("-O2" : commonOptions args ext) } @@ -50,7 +87,8 @@ ocamlByteExe = { _variantTitle = Just "byte", _variantLanguage = Ocaml, _variantExtensions = ext, - _variantColor = orangered, + _variantColor = getVariantColor OcamlByte, + _variantRun = runExe, _variantBuild = \args -> command_ [] "ocamlc" (commonOptions args ext) } @@ -67,7 +105,8 @@ haskellExe = { _variantTitle = Nothing, _variantLanguage = Haskell, _variantExtensions = ext, - _variantColor = purple, + _variantColor = getVariantColor HaskellExe, + _variantRun = runExe, _variantBuild = \args -> command_ [] "ghc" (haskellCommon ++ commonOptions args ext) } @@ -81,7 +120,8 @@ haskellStrictExe = { _variantTitle = Just "strict", _variantLanguage = Haskell, _variantExtensions = ext, - _variantColor = powderblue, + _variantColor = getVariantColor HaskellStrict, + _variantRun = runExe, _variantBuild = \args -> command_ [] "ghc" (haskellCommon ++ ["-XStrict"] ++ commonOptions args ext) } @@ -95,7 +135,8 @@ juvixExe = { _variantTitle = Nothing, _variantLanguage = Juvix, _variantExtensions = ext, - _variantColor = plum, + _variantColor = getVariantColor JuvixExe, + _variantRun = runExe, _variantBuild = \args -> command_ [] "juvix" (juvixCommon ++ commonOptions args ext) } @@ -106,14 +147,14 @@ juvixExe = juvixCommon :: [String] juvixCommon = ["compile"] --- TODO does not generate an executable juvixWasm :: Variant juvixWasm = Variant { _variantTitle = Just "wasm", _variantLanguage = Juvix, _variantExtensions = ext, - _variantColor = sandybrown, + _variantColor = getVariantColor JuvixWasm, + _variantRun = runWasm, _variantBuild = \args -> command_ [] "juvix" (juvixCommon ++ ["--target=wasm"] ++ commonOptions args ext) } @@ -130,7 +171,8 @@ runtimeExe = { _variantTitle = Nothing, _variantLanguage = Runtime, _variantExtensions = ext, - _variantColor = navy, + _variantColor = getVariantColor RuntimeExe, + _variantRun = runExe, _variantBuild = \args -> command_ [] "juvix" (runtimeCommon ++ commonOptions args ext) } @@ -141,10 +183,11 @@ runtimeExe = runtimeWasm :: Variant runtimeWasm = Variant - { _variantTitle = Nothing, + { _variantTitle = Just "wasm", _variantLanguage = Runtime, _variantExtensions = ext, - _variantColor = turquoise, + _variantColor = getVariantColor RuntimeWasm, + _variantRun = runWasm, _variantBuild = \args -> command_ [] "juvix" (runtimeCommon ++ ["--target=wasm32-wasi"] ++ commonOptions args ext) } @@ -158,7 +201,8 @@ clangExe = { _variantTitle = Nothing, _variantLanguage = C, _variantExtensions = ext, - _variantColor = black, + _variantColor = getVariantColor ClangExe, + _variantRun = runExe, _variantBuild = \args -> command_ [] "clang" ("-O3" : commonOptions args ext) } @@ -169,25 +213,27 @@ clangExe = clangWasm :: Variant clangWasm = Variant - { _variantTitle = Nothing, + { _variantTitle = Just "wasm", _variantLanguage = C, _variantExtensions = ext, - _variantColor = palevioletred, + _variantColor = getVariantColor ClangWasm, + _variantRun = runWasm, _variantBuild = \args -> do wasipath <- getWasiSysrootPathStr command_ [] "clang" (["-Os", "-nodefaultlibs", "--sysroot", wasipath, "-lc", "--target=wasm32-wasi"] ++ commonOptions args ext) } where ext :: [String] - ext = defaultExt + ext = [".wasm"] -coreJvc :: Variant -coreJvc = +coreEval :: Variant +coreEval = Variant { _variantTitle = Nothing, _variantLanguage = Core, _variantExtensions = ext, - _variantColor = orchid, + _variantColor = getVariantColor CoreEval, + _variantRun = \src -> void (readProcess "juvix" ["dev", "core", "eval", toFilePath src] ""), _variantBuild = \args -> command_ [] "cp" (map toFilePath [args ^. buildSrc, binFile args ext]) } diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index 0a8c0fa8af..5d6aa5dbb9 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -1,20 +1,41 @@ # arguments: name outfile csvfile # usage: gnuplot -e "name='the title'" -e "outfile='out'" -e "csvfile='data.csv'" bars.gp -set title name -unset key + +meanCol = 'Mean' +colorCol = 'Color' +stddevCol = 'Stddev' +targets = meanCol . ' ' . stddevCol + +set terminal pdf size 18cm, 26cm +set output outfile.'.pdf' +set tmargin 3 set style data histogram set datafile separator "," set boxwidth 2 -set xtic rotate by -20 scale 0 +set xtic rotate by -20 scale 0 font ",16" +set ytic scale 0 font ",16" set grid y -set ylabel "time (s)" +set ylabel "execution time (s)" font ", 20" set style fill solid - -set terminal pdf -set output outfile.'.pdf' +unset key set yrange [0 : *] -plot csvfile using "Mean":"Color":xtic(2) title col lc rgbcolor variable -set terminal svg enhanced mouse +set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 +do for [target in targets] { + set title target font ",20" + plot csvfile \ + using target:colorCol:xtic(2) notitle column(2) lc rgbcolor variable, \ + '' using 0:target:(sprintf("%1.4f",column(target))) with labels font ",13" center offset 0, 0.4 title target, \ + +} + +unset multiplot + +set terminal svg enhanced mouse size 600, 1100 set output outfile.'.svg' +set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 +do for [target in targets] { +set key outside replot +} +unset multiplot diff --git a/package.yaml b/package.yaml index b8d3ed39f0..373bc47c46 100644 --- a/package.yaml +++ b/package.yaml @@ -76,6 +76,7 @@ dependencies: - gauge == 0.2.* - shake == 0.19.* - colour == 2.3.* +- palette == 0.3.* ghc-options: # Warnings - -Weverything diff --git a/src/Juvix/Prelude/Base.hs b/src/Juvix/Prelude/Base.hs index 32adf88bdc..75148fcb8e 100644 --- a/src/Juvix/Prelude/Base.hs +++ b/src/Juvix/Prelude/Base.hs @@ -32,6 +32,7 @@ module Juvix.Prelude.Base module Data.Monoid, module Data.Ord, module Data.Semigroup, + module Prelude, module Data.Singletons, module Data.Singletons.Sigma, module Data.Singletons.TH, @@ -178,6 +179,7 @@ import System.IO hiding import System.IO.Error import Text.Show (Show) import Text.Show qualified as Show +import Prelude (Double) -------------------------------------------------------------------------------- From 69d7fc7ee8483896f5008afa74f612afc971ea29 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 22 Dec 2022 16:33:13 +0100 Subject: [PATCH 19/34] add suites --- bench/Suites.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bench/Suites.hs b/bench/Suites.hs index ad3c026ae9..a3362d7277 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -9,19 +9,17 @@ suites = map defaultSuite [ "mergesort", - "fibonacci" + "fibonacci", + "ackermann", + "combinations", + "cps", + "fold", + "mapfold", + "mapfun", + "maybe", + "prime" ] --- "ackermann" --- "combinations" --- "cps" --- "fibonacci" --- "fold" --- "mapfold" --- "mapfun" --- "maybe" --- "mergesort" --- "prime defaultSuite :: String -> Suite defaultSuite title = From 7c888b2790242be1c3d204f71c2c2a1b392ceafe Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 22 Dec 2022 16:33:55 +0100 Subject: [PATCH 20/34] Revert "make mergesort input smaller" This reverts commit 84589ed9283d2931d2083a9aec465fb86463218f. --- tests/benchmark/mergesort/c/mergesort.c | 2 +- tests/benchmark/mergesort/haskell/mergesort.hs | 2 +- tests/benchmark/mergesort/juvix/mergesort.juvix | 8 ++++---- tests/benchmark/mergesort/ocaml/mergesort.ml | 2 +- tests/benchmark/mergesort/runtime/mergesort.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/benchmark/mergesort/c/mergesort.c b/tests/benchmark/mergesort/c/mergesort.c index 0a2ace1c24..2a340e37b4 100644 --- a/tests/benchmark/mergesort/c/mergesort.c +++ b/tests/benchmark/mergesort/c/mergesort.c @@ -44,7 +44,7 @@ static bool sorted(int *tab, int size) { return true; } -#define N 100000 +#define N 200000 int main() { int *tab = malloc(N * sizeof(int)); diff --git a/tests/benchmark/mergesort/haskell/mergesort.hs b/tests/benchmark/mergesort/haskell/mergesort.hs index 9004c76816..8a798f08c5 100644 --- a/tests/benchmark/mergesort/haskell/mergesort.hs +++ b/tests/benchmark/mergesort/haskell/mergesort.hs @@ -30,4 +30,4 @@ gen 0 acc = acc gen n acc = gen (n - 1) (n : acc) main :: IO () -main = putStrLn (show (sorted (sort (gen 100000 [])))) +main = putStrLn (show (sorted (sort (gen 200000 [])))) diff --git a/tests/benchmark/mergesort/juvix/mergesort.juvix b/tests/benchmark/mergesort/juvix/mergesort.juvix index ec18348fd0..8342767737 100644 --- a/tests/benchmark/mergesort/juvix/mergesort.juvix +++ b/tests/benchmark/mergesort/juvix/mergesort.juvix @@ -44,12 +44,12 @@ terminating gen : Int -> List Int -> List Int; gen n acc := if (n Data.Int.Ops.== Int_0) acc (gen (n Data.Int.Ops.- Int_1) (n ∷ acc)); -axiom N : Int; -compile N { - c ↦ "100000"; +axiom Int_200000 : Int; +compile Int_200000 { + c ↦ "200000"; }; main : IO; -main := if (sorted (sort (gen N nil))) (putStrLn "true") (putStrLn "false"); +main := if (sorted (sort (gen Int_200000 nil))) (putStrLn "true") (putStrLn "false"); end; diff --git a/tests/benchmark/mergesort/ocaml/mergesort.ml b/tests/benchmark/mergesort/ocaml/mergesort.ml index d7a7183b11..f712b37f8b 100644 --- a/tests/benchmark/mergesort/ocaml/mergesort.ml +++ b/tests/benchmark/mergesort/ocaml/mergesort.ml @@ -43,4 +43,4 @@ let rec gen n acc = if n = 0 then acc else gen (n - 1) (n :: acc) ;; -print_endline (if sorted (sort (gen 100000 [])) then "true" else "false");; +print_endline (if sorted (sort (gen 200000 [])) then "true" else "false");; diff --git a/tests/benchmark/mergesort/runtime/mergesort.c b/tests/benchmark/mergesort/runtime/mergesort.c index 584507d8e7..b1f457c084 100644 --- a/tests/benchmark/mergesort/runtime/mergesort.c +++ b/tests/benchmark/mergesort/runtime/mergesort.c @@ -232,7 +232,7 @@ int main() { JUVIX_FUNCTION(juvix_function_main, 1); { ARG(1) = CONSTR_NIL; - ARG(0) = make_smallint(100000); + ARG(0) = make_smallint(200000); CALL(0, gen, juvix_label_main_1); ARG(0) = juvix_result; CALL(0, sort, juvix_label_2); From 798dce18c562477e54b327d7be7cf320333b9287 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 22 Dec 2022 16:34:06 +0100 Subject: [PATCH 21/34] Revert "make fibonacci inpput smaller" This reverts commit d7206150b0adfede43575ecefeb6d1c6fb9ff0ec. --- tests/benchmark/fibonacci/c/fibonacci.c | 2 +- tests/benchmark/fibonacci/core/fibonacci.jvc | 2 +- tests/benchmark/fibonacci/haskell/fibonacci.hs | 2 +- tests/benchmark/fibonacci/juvix/fibonacci.juvix | 8 ++++---- tests/benchmark/fibonacci/ocaml/fibonacci.ml | 2 +- tests/benchmark/fibonacci/runtime/fibonacci.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/benchmark/fibonacci/c/fibonacci.c b/tests/benchmark/fibonacci/c/fibonacci.c index 257965693f..c9e1aa8581 100644 --- a/tests/benchmark/fibonacci/c/fibonacci.c +++ b/tests/benchmark/fibonacci/c/fibonacci.c @@ -14,6 +14,6 @@ static int fib(int k) { } int main() { - printf("%d\n", fib(1000000)); + printf("%d\n", fib(100000000)); return 0; } diff --git a/tests/benchmark/fibonacci/core/fibonacci.jvc b/tests/benchmark/fibonacci/core/fibonacci.jvc index c6149cb5dc..724dc71401 100644 --- a/tests/benchmark/fibonacci/core/fibonacci.jvc +++ b/tests/benchmark/fibonacci/core/fibonacci.jvc @@ -9,4 +9,4 @@ def fib := \k in go k 0 1; -fib 1000000 +fib 100000000 diff --git a/tests/benchmark/fibonacci/haskell/fibonacci.hs b/tests/benchmark/fibonacci/haskell/fibonacci.hs index 6fc2a11445..a5744794b1 100644 --- a/tests/benchmark/fibonacci/haskell/fibonacci.hs +++ b/tests/benchmark/fibonacci/haskell/fibonacci.hs @@ -8,4 +8,4 @@ fib n = go n 0 1 go k n m = go (k - 1) m ((n + m) `mod` (2 ^ 28)) main :: IO () -main = putStrLn (show (fib 1000000)) +main = putStrLn (show (fib 100000000)) diff --git a/tests/benchmark/fibonacci/juvix/fibonacci.juvix b/tests/benchmark/fibonacci/juvix/fibonacci.juvix index f0d9c742a3..2a1d7567c6 100644 --- a/tests/benchmark/fibonacci/juvix/fibonacci.juvix +++ b/tests/benchmark/fibonacci/juvix/fibonacci.juvix @@ -20,12 +20,12 @@ go k n m := if (k Data.Int.Ops.== Int_0) fib : Int -> Int; fib n := go n Int_0 Int_1; -axiom Int_1000000 : Int; -compile Int_1000000 { - c ↦ "1000000"; +axiom Int_100000000 : Int; +compile Int_100000000 { + c ↦ "100000000"; }; main : IO; -main := printInt (fib Int_1000000); +main := printInt (fib Int_100000000); end; diff --git a/tests/benchmark/fibonacci/ocaml/fibonacci.ml b/tests/benchmark/fibonacci/ocaml/fibonacci.ml index 0641ca9234..f8c4ab0a36 100644 --- a/tests/benchmark/fibonacci/ocaml/fibonacci.ml +++ b/tests/benchmark/fibonacci/ocaml/fibonacci.ml @@ -11,5 +11,5 @@ let fib k = ;; -print_int (fib 1000000); +print_int (fib 100000000); print_newline () diff --git a/tests/benchmark/fibonacci/runtime/fibonacci.c b/tests/benchmark/fibonacci/runtime/fibonacci.c index 482b803f4b..adfe6acbe7 100644 --- a/tests/benchmark/fibonacci/runtime/fibonacci.c +++ b/tests/benchmark/fibonacci/runtime/fibonacci.c @@ -50,7 +50,7 @@ int main() { JUVIX_FUNCTION_NS(juvix_function_main); { - ARG(0) = make_smallint(1000000); + ARG(0) = make_smallint(100000000); TAIL_CALL_NS(0, fib); } From 94b6512bfbadd486166818927b224ac9c3d1eff2 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 22 Dec 2022 16:37:35 +0100 Subject: [PATCH 22/34] revert input changes --- tests/benchmark/mergesort/c/mergesort.c | 2 +- tests/benchmark/mergesort/core/mergesort.jvc | 2 +- tests/benchmark/mergesort/haskell/mergesort.hs | 2 +- tests/benchmark/mergesort/juvix/mergesort.juvix | 8 ++++---- tests/benchmark/mergesort/ocaml/mergesort.ml | 2 +- tests/benchmark/mergesort/runtime/mergesort.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/benchmark/mergesort/c/mergesort.c b/tests/benchmark/mergesort/c/mergesort.c index 2a340e37b4..f538b938da 100644 --- a/tests/benchmark/mergesort/c/mergesort.c +++ b/tests/benchmark/mergesort/c/mergesort.c @@ -44,7 +44,7 @@ static bool sorted(int *tab, int size) { return true; } -#define N 200000 +#define N 2000000 int main() { int *tab = malloc(N * sizeof(int)); diff --git a/tests/benchmark/mergesort/core/mergesort.jvc b/tests/benchmark/mergesort/core/mergesort.jvc index 176d841c5e..0b1d47ebd7 100644 --- a/tests/benchmark/mergesort/core/mergesort.jvc +++ b/tests/benchmark/mergesort/core/mergesort.jvc @@ -51,4 +51,4 @@ def sorted := \xs def gen := \n \acc if n = 0 then acc else gen (n - 1) (cons n acc); -sorted (sort (gen 100000 nil)) +sorted (sort (gen 2000000 nil)) diff --git a/tests/benchmark/mergesort/haskell/mergesort.hs b/tests/benchmark/mergesort/haskell/mergesort.hs index 8a798f08c5..507573b768 100644 --- a/tests/benchmark/mergesort/haskell/mergesort.hs +++ b/tests/benchmark/mergesort/haskell/mergesort.hs @@ -30,4 +30,4 @@ gen 0 acc = acc gen n acc = gen (n - 1) (n : acc) main :: IO () -main = putStrLn (show (sorted (sort (gen 200000 [])))) +main = putStrLn (show (sorted (sort (gen 2000000 [])))) diff --git a/tests/benchmark/mergesort/juvix/mergesort.juvix b/tests/benchmark/mergesort/juvix/mergesort.juvix index 8342767737..d522094138 100644 --- a/tests/benchmark/mergesort/juvix/mergesort.juvix +++ b/tests/benchmark/mergesort/juvix/mergesort.juvix @@ -44,12 +44,12 @@ terminating gen : Int -> List Int -> List Int; gen n acc := if (n Data.Int.Ops.== Int_0) acc (gen (n Data.Int.Ops.- Int_1) (n ∷ acc)); -axiom Int_200000 : Int; -compile Int_200000 { - c ↦ "200000"; +axiom Int_2000000 : Int; +compile Int_2000000 { + c ↦ "2000000"; }; main : IO; -main := if (sorted (sort (gen Int_200000 nil))) (putStrLn "true") (putStrLn "false"); +main := if (sorted (sort (gen Int_2000000 nil))) (putStrLn "true") (putStrLn "false"); end; diff --git a/tests/benchmark/mergesort/ocaml/mergesort.ml b/tests/benchmark/mergesort/ocaml/mergesort.ml index f712b37f8b..9bde4af922 100644 --- a/tests/benchmark/mergesort/ocaml/mergesort.ml +++ b/tests/benchmark/mergesort/ocaml/mergesort.ml @@ -43,4 +43,4 @@ let rec gen n acc = if n = 0 then acc else gen (n - 1) (n :: acc) ;; -print_endline (if sorted (sort (gen 200000 [])) then "true" else "false");; +print_endline (if sorted (sort (gen 2000000 [])) then "true" else "false");; diff --git a/tests/benchmark/mergesort/runtime/mergesort.c b/tests/benchmark/mergesort/runtime/mergesort.c index b1f457c084..fa0dcb40c7 100644 --- a/tests/benchmark/mergesort/runtime/mergesort.c +++ b/tests/benchmark/mergesort/runtime/mergesort.c @@ -232,7 +232,7 @@ int main() { JUVIX_FUNCTION(juvix_function_main, 1); { ARG(1) = CONSTR_NIL; - ARG(0) = make_smallint(200000); + ARG(0) = make_smallint(2000000); CALL(0, gen, juvix_label_main_1); ARG(0) = juvix_result; CALL(0, sort, juvix_label_2); From 4cb930af37a0d773bfe47b41e4234c1e44bbd88b Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 22 Dec 2022 17:22:54 +0100 Subject: [PATCH 23/34] do not use core --- bench/Suites.hs | 3 +-- bench/Variants.hs | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bench/Suites.hs b/bench/Suites.hs index a3362d7277..c54e369007 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -20,10 +20,9 @@ suites = "prime" ] - defaultSuite :: String -> Suite defaultSuite title = Suite { _suiteTitle = title, - _suiteVariants = allVariants + _suiteVariants = defaultVariants } diff --git a/bench/Variants.hs b/bench/Variants.hs index 31875fab28..4f1e62bf03 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -11,6 +11,9 @@ import System.Process allVariants :: [Variant] allVariants = map getVariant allElements +defaultVariants :: [Variant] +defaultVariants = map getVariant (delete CoreEval allElements) + data VariantId = OcamlExe | OcamlByte From 2d85fa42fce746735828b97e103ae8cfc5688342 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Fri, 23 Dec 2022 10:48:29 +0100 Subject: [PATCH 24/34] percentual stddev --- bench/Suites.hs | 4 ++-- gnuplot/bars.gp | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bench/Suites.hs b/bench/Suites.hs index c54e369007..405892c5a5 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -10,8 +10,8 @@ suites = defaultSuite [ "mergesort", "fibonacci", - "ackermann", - "combinations", + "ackermann", -- juvix crashes + "combinations", -- juvix crashes: out of call stack "cps", "fold", "mapfold", diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index 5d6aa5dbb9..30797f8dfe 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -21,21 +21,28 @@ unset key set yrange [0 : *] set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 -do for [target in targets] { - set title target font ",20" - plot csvfile \ - using target:colorCol:xtic(2) notitle column(2) lc rgbcolor variable, \ - '' using 0:target:(sprintf("%1.4f",column(target))) with labels font ",13" center offset 0, 0.4 title target, \ -} +set title meanCol font ",20" +plot csvfile \ + using meanCol:colorCol:xtic(2) notitle linecolor rgbcolor variable, \ + '' using 0:meanCol:(sprintf("%1.4f",column(meanCol))) with labels font ",13" center offset 0, 0.4 title meanCol, \ + + +set title "Standard deviation" font ",20" +unset ylabel + +f(x) = column(stddevCol)*100/column(meanCol) +plot csvfile \ + using (f('')):colorCol:xtic(2) notitle linecolor rgbcolor variable, \ + '' using 0:(f('')):(sprintf("%1.2f%",(f('')))) with labels font ",13" center offset -9,0.4 notitle unset multiplot set terminal svg enhanced mouse size 600, 1100 set output outfile.'.svg' set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 -do for [target in targets] { set key outside +do for [target in targets] { replot } unset multiplot From 5c642ead2890252c2c7a04e19145a590eba21ea8 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 3 Jan 2023 09:45:34 +0100 Subject: [PATCH 25/34] wip --- bench/Base.hs | 1 + bench/Compile.hs | 124 ---------------------------------------------- bench/Main.hs | 123 +++++++++++++++++++++++++++++++++++++++++++-- bench/Suites.hs | 18 ++++--- bench/Variants.hs | 6 ++- gnuplot/bars.gp | 1 + 6 files changed, 136 insertions(+), 137 deletions(-) delete mode 100644 bench/Compile.hs diff --git a/bench/Base.hs b/bench/Base.hs index 968ca56713..50770d9f2a 100644 --- a/bench/Base.hs +++ b/bench/Base.hs @@ -36,6 +36,7 @@ data Lang | Juvix | Runtime | Core + deriving stock (Eq) instance Show Lang where show = \case diff --git a/bench/Compile.hs b/bench/Compile.hs deleted file mode 100644 index 1a2fc8c762..0000000000 --- a/bench/Compile.hs +++ /dev/null @@ -1,124 +0,0 @@ -module Compile where - -import Base -import Data.Text qualified as Text -import Development.Shake hiding (()) -import Gauge -import Juvix.Prelude.Base -import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) -import Juvix.Prelude.Path qualified as Path -import Suites - -compile :: IO () -compile = shakeArgs opts compileRules - where - opts :: ShakeOptions - opts = shakeOptions - -compileRules :: Rules () -compileRules = do - phony "clean" $ do - putInfo ("Deleting " <> toFilePath resultsDir) - removePathForcibly resultsDir - forM_ suites suiteRules - -suiteRules :: Suite -> Rules () -suiteRules s = do - forM_ (s ^. suiteVariants) (variantRules s) - csvRules s - plotRules s - -multiRecipe :: [Path Abs File] -> Action () -> Rules () -multiRecipe out howto = map toFilePath out &%> const howto - -recipe :: Path Abs File -> Action () -> Rules () -recipe out howto = toFilePath out %> const howto - -variantRules :: Suite -> Variant -> Rules () -variantRules s v = do - action $ do - whenM - (doesFileExist (toFilePath srcFile)) - (need [toFilePath exeFile]) - - recipe exeFile $ do - need [toFilePath srcFile] - ensureDir outDir - (v ^. variantBuild) args - where - args :: BuildArgs - args = - BuildArgs - { _buildSrc = srcFile, - _buildOutDir = outDir - } - lang :: Lang - lang = v ^. variantLanguage - srcFile :: Path Abs File - srcFile = - addExtension' - (langExtension lang) - (suiteSrcDir s langPath lang suiteBaseFile s) - exeFile :: Path Abs File - exeFile = outDir replaceExtensions' (v ^. variantExtensions) (filename srcFile) - outDir :: Path Abs Dir - outDir = variantBinDir s v - -plotRules :: Suite -> Rules () -plotRules s = do - let pdf :: Path Abs File = suitePdfFile s - csv :: Path Abs File = suiteCsvFile s - svg :: Path Abs File = suiteSvgFile s - out :: Path Abs File = suitePlotFile s - want [toFilePath pdf, toFilePath svg] - multiRecipe [pdf, svg] $ do - need [toFilePath csv, toFilePath gnuplotFile] - ensureDir (parent pdf) - command_ - [] - "gnuplot" - ( gpArg "name" (s ^. suiteTitle) - ++ gpArg "outfile" (toFilePath out) - ++ gpArg "csvfile" (toFilePath csv) - ++ [toFilePath gnuplotFile] - ) - where - gpArg :: String -> String -> [String] - gpArg arg val = ["-e", arg <> "='" <> val <> "'"] - -csvRules :: Suite -> Rules () -csvRules s = - recipe csv $ do - need [toFilePath (variantBinFile s v) | v <- s ^. suiteVariants] - ensureDir (parent csv) - whenM (Path.doesFileExist csv) (removeFile csv) - liftIO (runMode DefaultMode (config s) [] (fromSuite s)) - liftIO addColorColumn - where - csv :: Path Abs File = suiteCsvFile s - addColorColumn :: IO () - addColorColumn = do - header :| rows <- nonEmpty' . Text.lines <$> readFile (toFilePath csv) - let rows' = - [ showColour (v ^. variantColor) <> "," <> r - | (v, r) <- zipExact (s ^. suiteVariants) rows - ] - header' = "Color," <> header - writeFile (toFilePath csv) (Text.unlines (header' : rows')) - -fromSuite :: Suite -> [Benchmark] -fromSuite s = map go (s ^. suiteVariants) - where - go :: Variant -> Benchmark - go v = bench title (nfIO ((v ^. variantRun) (variantBinFile s v))) - where - title :: String - title = show (v ^. variantLanguage) <> maybe "" (" " <>) (v ^. variantTitle) - -config :: Suite -> Config -config s = - defaultConfig - { timeLimit = Just 0.0, - quickMode = False, - csvFile = Just (toFilePath (suiteCsvFile s)) - } diff --git a/bench/Main.hs b/bench/Main.hs index 349fe71c5b..565788cfce 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -1,8 +1,123 @@ module Main where -import Compile qualified -import Juvix.Prelude +import Base +import Data.Text qualified as Text +import Development.Shake hiding (()) +import Gauge +import Juvix.Prelude.Base +import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) +import Juvix.Prelude.Path qualified as Path +import Suites main :: IO () -main = do - Compile.compile +main = shakeArgs opts compileRules + where + opts :: ShakeOptions + opts = shakeOptions + +compileRules :: Rules () +compileRules = do + phony "clean" $ do + putInfo ("Deleting " <> toFilePath resultsDir) + removePathForcibly resultsDir + forM_ suites suiteRules + +suiteRules :: Suite -> Rules () +suiteRules s = do + forM_ (s ^. suiteVariants) (variantRules s) + csvRules s + plotRules s + +multiRecipe :: [Path Abs File] -> Action () -> Rules () +multiRecipe out howto = map toFilePath out &%> const howto + +recipe :: Path Abs File -> Action () -> Rules () +recipe out howto = toFilePath out %> const howto + +variantRules :: Suite -> Variant -> Rules () +variantRules s v = do + action $ do + whenM + (doesFileExist (toFilePath srcFile)) + (need [toFilePath exeFile]) + + recipe exeFile $ do + need [toFilePath srcFile] + ensureDir outDir + (v ^. variantBuild) args + where + args :: BuildArgs + args = + BuildArgs + { _buildSrc = srcFile, + _buildOutDir = outDir + } + lang :: Lang + lang = v ^. variantLanguage + srcFile :: Path Abs File + srcFile = + addExtension' + (langExtension lang) + (suiteSrcDir s langPath lang suiteBaseFile s) + exeFile :: Path Abs File + exeFile = outDir replaceExtensions' (v ^. variantExtensions) (filename srcFile) + outDir :: Path Abs Dir + outDir = variantBinDir s v + +plotRules :: Suite -> Rules () +plotRules s = do + let pdf :: Path Abs File = suitePdfFile s + csv :: Path Abs File = suiteCsvFile s + svg :: Path Abs File = suiteSvgFile s + out :: Path Abs File = suitePlotFile s + want [toFilePath pdf, toFilePath svg] + multiRecipe [pdf, svg] $ do + need [toFilePath csv, toFilePath gnuplotFile] + ensureDir (parent pdf) + command_ + [] + "gnuplot" + ( gpArg "name" (s ^. suiteTitle) + ++ gpArg "outfile" (toFilePath out) + ++ gpArg "csvfile" (toFilePath csv) + ++ [toFilePath gnuplotFile] + ) + where + gpArg :: String -> String -> [String] + gpArg arg val = ["-e", arg <> "='" <> val <> "'"] + +csvRules :: Suite -> Rules () +csvRules s = + recipe csv $ do + need [toFilePath (variantBinFile s v) | v <- s ^. suiteVariants] + ensureDir (parent csv) + whenM (Path.doesFileExist csv) (removeFile csv) + liftIO (runMode DefaultMode (config s) [] (fromSuite s) >> addColorColumn) + where + csv :: Path Abs File = suiteCsvFile s + addColorColumn :: IO () + addColorColumn = do + header :| rows <- nonEmpty' . Text.lines <$> readFile (toFilePath csv) + let rows' = + [ showColour (v ^. variantColor) <> "," <> r + | (v, r) <- zipExact (s ^. suiteVariants) rows + ] + header' = "Color," <> header + writeFile (toFilePath csv) (Text.unlines (header' : rows')) + +fromSuite :: Suite -> [Benchmark] +fromSuite s = map go (s ^. suiteVariants) + where + go :: Variant -> Benchmark + go v = bench title (nfIO ((v ^. variantRun) (variantBinFile s v))) + where + title :: String + title = show (v ^. variantLanguage) <> maybe "" (" " <>) (v ^. variantTitle) + +config :: Suite -> Config +config s = + defaultConfig + { quickMode = False, + csvFile = Just (toFilePath (suiteCsvFile s)), + timeLimit = Just 30 + } diff --git a/bench/Suites.hs b/bench/Suites.hs index 405892c5a5..6bf1074622 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -10,15 +10,17 @@ suites = defaultSuite [ "mergesort", "fibonacci", - "ackermann", -- juvix crashes - "combinations", -- juvix crashes: out of call stack - "cps", - "fold", - "mapfold", - "mapfun", - "maybe", - "prime" + "maybe" ] + <> [ Suite "fold" (allVariantsExcept [C] [CoreEval]), + Suite "mapfold" (allVariantsExcept [C] [CoreEval]), + Suite "mapfun" (allVariantsExcept [C] [CoreEval]) + ] + +-- "ackermann", -- juvix crashes +-- "combinations", -- juvix crashes: call stack exhausted +-- "cps", call stack exhausted +-- "prime" -- Address boundary error defaultSuite :: String -> Suite defaultSuite title = diff --git a/bench/Variants.hs b/bench/Variants.hs index 4f1e62bf03..e56b4df62b 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -8,11 +8,15 @@ import Juvix.Prelude import Juvix.Prelude.Env import System.Process +allVariantsExcept :: [Lang] -> [VariantId] -> [Variant] +allVariantsExcept ls vs = filter (\v -> (v ^. variantLanguage) `notElem` ls) + (map getVariant (filter (`notElem` vs) allElements)) + allVariants :: [Variant] allVariants = map getVariant allElements defaultVariants :: [Variant] -defaultVariants = map getVariant (delete CoreEval allElements) +defaultVariants = allVariantsExcept [] [CoreEval] data VariantId = OcamlExe diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index 30797f8dfe..cb0f63e409 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -19,6 +19,7 @@ set ylabel "execution time (s)" font ", 20" set style fill solid unset key set yrange [0 : *] +set offsets graph 0,0.5 set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 From 1d0dad75afa40ae0979060d9cf73b4867a05980a Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 3 Jan 2023 17:31:31 +0100 Subject: [PATCH 26/34] switch to criterion --- bench/Main.hs | 11 ++++++----- bench/Suites.hs | 8 ++++---- bench/Variants.hs | 6 ++++-- package.yaml | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bench/Main.hs b/bench/Main.hs index 565788cfce..b63fc166d3 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -1,9 +1,11 @@ module Main where import Base +import Criterion.Main +import Criterion.Main.Options hiding (config) +import Criterion.Types import Data.Text qualified as Text import Development.Shake hiding (()) -import Gauge import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) import Juvix.Prelude.Path qualified as Path @@ -92,7 +94,7 @@ csvRules s = need [toFilePath (variantBinFile s v) | v <- s ^. suiteVariants] ensureDir (parent csv) whenM (Path.doesFileExist csv) (removeFile csv) - liftIO (runMode DefaultMode (config s) [] (fromSuite s) >> addColorColumn) + liftIO (runMode (Run (config s) Glob []) (fromSuite s) >> addColorColumn) where csv :: Path Abs File = suiteCsvFile s addColorColumn :: IO () @@ -117,7 +119,6 @@ fromSuite s = map go (s ^. suiteVariants) config :: Suite -> Config config s = defaultConfig - { quickMode = False, - csvFile = Just (toFilePath (suiteCsvFile s)), - timeLimit = Just 30 + { csvFile = Just (toFilePath (suiteCsvFile s)), + timeLimit = 30 } diff --git a/bench/Suites.hs b/bench/Suites.hs index 6bf1074622..80be3370e8 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -13,14 +13,14 @@ suites = "maybe" ] <> [ Suite "fold" (allVariantsExcept [C] [CoreEval]), - Suite "mapfold" (allVariantsExcept [C] [CoreEval]), - Suite "mapfun" (allVariantsExcept [C] [CoreEval]) + Suite "mapfold" (allVariantsExcept [C] [CoreEval]) ] +-- "mapfun" -- juvix crashes: Address boundary error -- "ackermann", -- juvix crashes -- "combinations", -- juvix crashes: call stack exhausted --- "cps", call stack exhausted --- "prime" -- Address boundary error +-- "cps", juvix: call stack exhausted +-- "prime" -- juvix: Address boundary error defaultSuite :: String -> Suite defaultSuite title = diff --git a/bench/Variants.hs b/bench/Variants.hs index e56b4df62b..33d4b5efe6 100644 --- a/bench/Variants.hs +++ b/bench/Variants.hs @@ -9,8 +9,10 @@ import Juvix.Prelude.Env import System.Process allVariantsExcept :: [Lang] -> [VariantId] -> [Variant] -allVariantsExcept ls vs = filter (\v -> (v ^. variantLanguage) `notElem` ls) - (map getVariant (filter (`notElem` vs) allElements)) +allVariantsExcept ls vs = + filter + (\v -> (v ^. variantLanguage) `notElem` ls) + (map getVariant (filter (`notElem` vs) allElements)) allVariants :: [Variant] allVariants = map getVariant allElements diff --git a/package.yaml b/package.yaml index 373bc47c46..d9691bdaa7 100644 --- a/package.yaml +++ b/package.yaml @@ -73,10 +73,11 @@ dependencies: - pretty-show == 1.10.* # benchmarks -- gauge == 0.2.* +- criterion == 1.5.* - shake == 0.19.* - colour == 2.3.* - palette == 0.3.* + ghc-options: # Warnings - -Weverything From 045ec4bb77b492cfd99d1384e6bd610a0c8d4b17 Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Tue, 3 Jan 2023 13:49:04 +0100 Subject: [PATCH 27/34] Change syntax for ind. data types and forbid the empty data type (#1684) Closes #1644 #1635 --- .../validity-predicates/PolyFungibleToken.org | 22 +++---- docs/org/language-reference/builtins.org | 5 +- .../org/language-reference/foreign-blocks.org | 5 +- .../inductive-data-types.org | 27 ++++---- docs/org/notes/builtins.org | 10 ++- docs/org/notes/monomorphization.org | 5 +- .../notes/strictly-positive-data-types.org | 63 +++++++------------ examples/milestone/Hanoi/Hanoi.juvix | 13 ++-- .../milestone/TicTacToe/Logic/Board.juvix | 3 +- .../milestone/TicTacToe/Logic/GameState.juvix | 12 ++-- .../milestone/TicTacToe/Logic/Square.juvix | 10 +-- .../milestone/TicTacToe/Logic/Symbol.juvix | 5 +- .../milestone/TicTacToe/Web/TicTacToe.juvix | 9 ++- juvix-stdlib | 2 +- .../Abstract/Translation/FromConcrete.hs | 2 +- .../Backend/Html/Translation/FromTyped.hs | 4 +- src/Juvix/Compiler/Concrete/Keywords.hs | 2 + src/Juvix/Compiler/Concrete/Language.hs | 2 +- src/Juvix/Compiler/Concrete/Pretty/Base.hs | 30 ++++++--- .../Concrete/Translation/FromSource.hs | 21 ++++--- src/Juvix/Data/Keyword/All.hs | 3 + src/Juvix/Extra/Strings.hs | 2 +- test/Termination/Negative.hs | 6 -- test/Termination/Positive.hs | 4 -- tests/Asm/negative/test002.jva | 2 +- tests/Asm/negative/test003.jva | 2 +- tests/Asm/negative/vtest008.jva | 2 +- tests/Asm/negative/vtest009.jva | 2 +- tests/Asm/positive/test009.jva | 2 +- tests/Asm/positive/test014.jva | 2 +- tests/Asm/positive/test028.jva | 2 +- tests/Asm/positive/test029.jva | 2 +- tests/Asm/positive/test031.jva | 2 +- tests/Asm/positive/test032.jva | 2 +- tests/Asm/positive/test035.jva | 2 +- tests/Asm/positive/test036.jva | 2 +- tests/Core/positive/test007.jvc | 2 +- tests/Core/positive/test012.jvc | 2 +- tests/Core/positive/test023.jvc | 2 +- tests/Core/positive/test024.jvc | 2 +- tests/Core/positive/test026.jvc | 2 +- tests/Core/positive/test028.jvc | 4 +- tests/Core/positive/test029.jvc | 2 +- tests/Core/positive/test030.jvc | 4 +- tests/Core/positive/test033.jvc | 2 +- tests/Core/positive/test035.jvc | 4 +- tests/Core/positive/test037.jvc | 2 +- tests/Core/positive/test039.jvc | 2 +- tests/Core/positive/test041.jvc | 4 +- tests/Core/positive/test042.jvc | 2 +- tests/Core/positive/test045.jvc | 2 +- tests/Core/positive/test046.jvc | 2 +- .../positive/FunctionReturnConstructor.juvix | 3 +- tests/Internal/positive/FunctionType.juvix | 3 +- tests/Internal/positive/Inductive.juvix | 3 +- .../Internal/positive/MatchConstructor.juvix | 5 +- tests/benchmark/fold/core/fold.jvc | 2 +- tests/benchmark/mapfold/core/mapfold.jvc | 2 +- tests/benchmark/mapfun/core/mapfun.jvc | 2 +- tests/benchmark/maybe/core/maybe.jvc | 4 +- tests/benchmark/maybe/juvix/maybe.juvix | 5 +- tests/benchmark/mergesort/core/mergesort.jvc | 4 +- tests/benchmark/prime/core/prime.jvc | 2 +- tests/negative/230/Foo/Data/Bool.juvix | 5 +- tests/negative/258/M.juvix | 5 +- tests/negative/265/M.juvix | 10 ++- tests/negative/AmbiguousConstructor.juvix | 6 +- tests/negative/AmbiguousExport.juvix | 3 +- tests/negative/AmbiguousSymbol.juvix | 4 +- tests/negative/BindGroupConflict/Clause.juvix | 5 +- tests/negative/BindGroupConflict/Lambda.juvix | 4 +- .../CompileBlocks/Sample/Definitions.juvix | 5 +- .../DuplicateInductiveParameterName.juvix | 2 +- tests/negative/InfixErrorP.juvix | 5 +- .../Internal/ExpectedExplicitArgument.juvix | 3 +- .../Internal/ExpectedExplicitPattern.juvix | 3 +- .../Internal/ExpectedFunctionType.juvix | 6 +- tests/negative/Internal/FunctionApplied.juvix | 3 +- tests/negative/Internal/FunctionPattern.juvix | 3 +- .../Internal/LhsTooManyPatterns.juvix | 3 +- tests/negative/Internal/MultiWrongType.juvix | 6 +- .../Internal/PatternConstructor.juvix | 6 +- tests/negative/Internal/Positivity/E1.juvix | 3 +- tests/negative/Internal/Positivity/E10.juvix | 7 +-- tests/negative/Internal/Positivity/E11.juvix | 6 +- tests/negative/Internal/Positivity/E2.juvix | 3 +- tests/negative/Internal/Positivity/E3.juvix | 3 +- tests/negative/Internal/Positivity/E4.juvix | 8 +-- tests/negative/Internal/Positivity/E5.juvix | 9 +-- tests/negative/Internal/Positivity/E6.juvix | 3 +- tests/negative/Internal/Positivity/E7.juvix | 6 +- tests/negative/Internal/Positivity/E8.juvix | 3 +- tests/negative/Internal/Positivity/E9.juvix | 6 +- .../Internal/Positivity/NegParam.juvix | 3 +- .../negative/Internal/Positivity/errorE5.test | 4 +- .../negative/Internal/Positivity/errorE9.test | 2 +- .../negative/Internal/TooManyArguments.juvix | 3 +- tests/negative/Internal/UnsolvedMeta.juvix | 3 +- .../Internal/WrongConstructorArity.juvix | 3 +- tests/negative/Internal/WrongReturnType.juvix | 3 +- .../Internal/WrongReturnTypeParameters.juvix | 3 +- .../WrongReturnTypeTooFewArguments.juvix | 3 +- .../WrongReturnTypeTooManyArguments.juvix | 3 +- tests/negative/Internal/WrongType.juvix | 6 +- tests/negative/Termination/Data/Bool.juvix | 5 +- tests/negative/Termination/Data/Nat.juvix | 5 +- .../negative/Termination/Data/QuickSort.juvix | 5 +- tests/negative/Termination/Data/Tree.juvix | 5 +- tests/negative/Termination/Ord.juvix | 7 +-- tests/negative/Termination/ToEmpty.juvix | 6 -- tests/negative/issue1337/Braces.juvix | 5 +- tests/negative/issue1344/M.juvix | 3 +- tests/negative/issue1344/Other.juvix | 3 +- tests/negative/issue1344/U.juvix | 4 +- tests/positive/265/M.juvix | 10 ++- tests/positive/272/M.juvix | 20 +++--- tests/positive/BuiltinsBool.juvix | 7 +-- tests/positive/BuiltinsMultiImport/Nat.juvix | 7 +-- .../BuiltinsMultiOpenImport/Nat.juvix | 7 +-- .../MonoSimpleFungibleToken.juvix | 25 +++----- .../SimpleFungibleTokenImplicit.juvix | 22 +++---- tests/positive/Imports/A.juvix | 3 +- tests/positive/Inductive.juvix | 5 +- tests/positive/Internal/AsPattern.juvix | 8 +-- tests/positive/Internal/Box.juvix | 6 +- tests/positive/Internal/HoleInSignature.juvix | 8 +-- tests/positive/Internal/Implicit.juvix | 25 +++----- tests/positive/Internal/Lambda.juvix | 27 ++++---- tests/positive/Internal/LiteralInt.juvix | 9 +-- tests/positive/Internal/LiteralString.juvix | 6 +- tests/positive/Internal/Mutual.juvix | 14 ++--- tests/positive/Internal/Positivity/E5.juvix | 9 +-- tests/positive/Internal/Simple.juvix | 18 +++--- tests/positive/Judoc.juvix | 4 +- .../positive/MiniC/AxiomNoCompile/Input.juvix | 3 +- tests/positive/MiniC/Builtins/Input.juvix | 12 ++-- tests/positive/MiniC/ClosureEnv/Input.juvix | 7 +-- tests/positive/MiniC/ClosureNoEnv/Input.juvix | 7 +-- tests/positive/MiniC/HigherOrder/Input.juvix | 12 ++-- tests/positive/MiniC/Lib/Data/Bool.juvix | 7 +-- tests/positive/MiniC/Lib/Data/Nat.juvix | 7 +-- tests/positive/MiniC/Lib/Data/Pair.juvix | 3 +- .../MiniC/MultiModules/Data/Bool.juvix | 7 +-- .../MiniC/MultiModules/Data/Nat.juvix | 7 +-- .../MiniC/MultiModules/Data/Pair.juvix | 3 +- .../MiniC/MutuallyRecursive/Data/Bool.juvix | 7 +-- .../MiniC/MutuallyRecursive/Data/Nat.juvix | 7 +-- .../MiniC/MutuallyRecursive/Data/Pair.juvix | 3 +- tests/positive/MiniC/Nat/Input.juvix | 14 ++--- tests/positive/MiniC/NestedList/Input.juvix | 10 ++- .../MiniC/PolymorphicAxioms/Input.juvix | 3 +- .../MiniC/PolymorphicTarget/Input.juvix | 3 +- tests/positive/MiniC/Polymorphism/Input.juvix | 10 ++- .../MiniC/PolymorphismHoles/Input.juvix | 10 ++- .../SimpleFungibleTokenImplicit/Input.juvix | 22 +++---- tests/positive/MiniHaskell/HelloWorld.juvix | 10 ++- tests/positive/Polymorphism.juvix | 18 +++--- tests/positive/PolymorphismHoles.juvix | 18 +++--- tests/positive/QualifiedConstructor/M.juvix | 3 +- tests/positive/Reachability/Data/Bool.juvix | 5 +- tests/positive/Reachability/Data/Maybe.juvix | 5 +- tests/positive/Reachability/Data/Nat.juvix | 5 +- tests/positive/Reachability/Data/Ord.juvix | 7 +-- .../positive/Reachability/Data/Product.juvix | 3 +- tests/positive/Reachability/N.juvix | 3 +- tests/positive/StdlibImport/A.juvix | 4 +- tests/positive/StdlibList/Data/Bool.juvix | 5 +- tests/positive/StdlibList/Data/List.juvix | 7 +-- tests/positive/StdlibList/Data/Maybe.juvix | 5 +- tests/positive/StdlibList/Data/Nat.juvix | 5 +- tests/positive/StdlibList/Data/Ord.juvix | 7 +-- tests/positive/StdlibList/Data/Product.juvix | 3 +- tests/positive/Termination/Data/Bool.juvix | 5 +- tests/positive/Termination/Data/List.juvix | 5 +- tests/positive/Termination/Data/Nat.juvix | 5 +- tests/positive/Termination/Fib.juvix | 7 +-- tests/positive/Termination/ToEmpty.juvix | 7 --- tests/positive/TypeAlias.juvix | 9 +-- tests/positive/issue1333/M.juvix | 3 +- tests/positive/issue1466/M.juvix | 5 +- 180 files changed, 470 insertions(+), 687 deletions(-) delete mode 100644 tests/negative/Termination/ToEmpty.juvix delete mode 100644 tests/positive/Termination/ToEmpty.juvix diff --git a/docs/org/examples/validity-predicates/PolyFungibleToken.org b/docs/org/examples/validity-predicates/PolyFungibleToken.org index 6899afb261..0e5f435552 100644 --- a/docs/org/examples/validity-predicates/PolyFungibleToken.org +++ b/docs/org/examples/validity-predicates/PolyFungibleToken.org @@ -12,10 +12,9 @@ foreign ghc { -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; infixr 2 ||; || : Bool → Bool → Bool; @@ -139,10 +138,9 @@ infix 4 ==String; -------------------------------------------------------------------------------- infixr 5 ∷; -inductive List (A : Type) { - nil : List A; - ∷ : A → List A → List A; -}; +type List (A : Type) := + nil : List A + | ∷ : A → List A → List A; elem : {A : Type} → (A → A → Bool) → A → List A → Bool; elem _ _ nil := false; @@ -158,18 +156,16 @@ foldl f z (h ∷ hs) := foldl f (f z h) hs; infixr 4 ,; infixr 2 ×; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; -------------------------------------------------------------------------------- -- Maybe -------------------------------------------------------------------------------- -inductive Maybe (A : Type) { - nothing : Maybe A; +type Maybe (A : Type) := + nothing : Maybe A | just : A → Maybe A; -}; from-int : Int → Maybe Int; from-int i := if (i < 0) nothing (just i); diff --git a/docs/org/language-reference/builtins.org b/docs/org/language-reference/builtins.org index 5495a1450b..40470ab516 100755 --- a/docs/org/language-reference/builtins.org +++ b/docs/org/language-reference/builtins.org @@ -7,10 +7,9 @@ Juvix has support for the built-in natural type and a few functions that are com #+begin_example builtin nat - inductive Nat { - zero : Nat; + type Nat := + zero : Nat | suc : Nat → Nat; - }; #+end_example 2. Builtin function definitions. diff --git a/docs/org/language-reference/foreign-blocks.org b/docs/org/language-reference/foreign-blocks.org index c603a78b52..5cbe4edb68 100644 --- a/docs/org/language-reference/foreign-blocks.org +++ b/docs/org/language-reference/foreign-blocks.org @@ -19,10 +19,9 @@ foreign c { \} }; -inductive Bool { - true : Bool; +type Bool := + true : Bool | false : Bool; -}; infix 4 <'; axiom <' : Int -> Int -> Bool; diff --git a/docs/org/language-reference/inductive-data-types.org b/docs/org/language-reference/inductive-data-types.org index 00f3df26bb..53f8403d04 100755 --- a/docs/org/language-reference/inductive-data-types.org +++ b/docs/org/language-reference/inductive-data-types.org @@ -1,15 +1,16 @@ * Inductive data types The =inductive= keyword is reserved for declaring inductive data types. An -inductive type declaration requires a unique name for its type and its -constructors, functions for building its terms. Constructors can be used as -normal identifiers and also in patterns. As shown later, one can also provide -type parameters to widen the family of inductive types one can define in Juvix. +inductive type declaration requires a unique name for its type and a non-empty +list of constructor declarations, functions for building the terms of the +inductive data type. Constructors can be used as normal identifiers and also in +patterns. As shown later, one can also provide type parameters to widen the +family of inductive types one can define in Juvix. -The simplest inductive type is the =Empty= type with no constructors. +The simplest inductive type is the =Unit= type with one constructor called =unit=. #+begin_example -inductive Empty {}; +type Unit := unit : Unit; #+end_example In the following example, we declare the inductive type =Nat=, the unary @@ -18,10 +19,9 @@ namely =zero= and =suc=. A term of the type =Nat= is the number one, represented by =suc zero= or the number two represented by =suc (suc zero)=, etc. #+begin_example -inductive Nat { - zero : Nat; - suc : Nat -> Nat; -}; +type Nat := + zero : Nat + | suc : Nat -> Nat; #+end_example The way to use inductive types is by declaring functions by pattern matching. @@ -43,10 +43,9 @@ the following type taken from the Juvix standard library: #+begin_example infixr 5 ∷; -inductive List (A : Type) { - nil : List A; - ∷ : A -> List A -> List A; -}; +type List (A : Type) := + nil : List A + | ∷ : A -> List A -> List A; elem : {A : Type} -> (A -> A -> Bool) -> A -> List A -> Bool; elem _ _ nil := false; diff --git a/docs/org/notes/builtins.org b/docs/org/notes/builtins.org index ad546469d5..7e0a189c8e 100644 --- a/docs/org/notes/builtins.org +++ b/docs/org/notes/builtins.org @@ -10,10 +10,9 @@ of definitions: 1. Builtin inductive definitions. For example: #+begin_example builtin nat - inductive Nat { - zero : Nat; + type Nat := + zero : Nat | suc : Nat → Nat; - }; #+end_example We will call this the canonical definition of natural numbers. @@ -41,10 +40,9 @@ what are the terms that refer to them. For instance, imagine that we find this definitions in a juvix module: #+begin_src text builtin nat -inductive MyNat { - z : MyNat; +type MyNat := + z : MyNat | s : MyNat → MyNat; -}; #+end_src We need to take care of the following: 1. Check that the definition =MyInt= is up to renaming equal to the canonical diff --git a/docs/org/notes/monomorphization.org b/docs/org/notes/monomorphization.org index e845f10689..aa972768e0 100644 --- a/docs/org/notes/monomorphization.org +++ b/docs/org/notes/monomorphization.org @@ -31,10 +31,9 @@ * More examples ** Mutual recursion #+begin_src juvix -inductive List (A : Type) { - nil : List A; +type List (A : Type) := + nil : List A | cons : A → List A → List A; -}; even : (A : Type) → List A → Bool; even A nil := true ; diff --git a/docs/org/notes/strictly-positive-data-types.org b/docs/org/notes/strictly-positive-data-types.org index 628dbf15f8..4419e1840f 100644 --- a/docs/org/notes/strictly-positive-data-types.org +++ b/docs/org/notes/strictly-positive-data-types.org @@ -2,27 +2,28 @@ We follow a syntactic description of strictly positive inductive data types. -An inductive type is said to be _strictly positive_ if it does not occur or occurs -strictly positively in the types of the arguments of its constructors. A name -qualified as strictly positive for an inductive type if it never occurs at a negative -position in the types of the arguments of its constructors. We refer to a negative -position as those occurrences on the left of an arrow in a type constructor argument. +An inductive type is said to be _strictly positive_ if it does not occur or +occurs strictly positively in the types of the arguments of its constructors. A +name qualified as strictly positive for an inductive type if it never occurs at +a negative position in the types of the arguments of its constructors. We refer +to a negative position as those occurrences on the left of an arrow in a type +constructor argument. -In the example below, the type =X= occurs strictly positive in =c0= and negatively at -the constructor =c1=. Therefore, =X= is not strictly positive. +In the example below, the type =X= occurs strictly positive in =c0= and +negatively at the constructor =c1=. Therefore, =X= is not strictly positive. #+begin_src minijuvix axiom B : Type; -inductive X { - c0 : (B -> X) -> X; - c1 : (X -> X) -> X; -}; +type X := + c0 : (B -> X) -> X + | c1 : (X -> X) -> X; #+end_src -We could also refer to positive parameters as such parameters occurring in no negative positions. -For example, the type =B= in the =c0= constructor above is on the left of the arrow =B->X=. -Then, =B= is at a negative position. Negative parameters need to be considered when checking strictly -positive data types as they may allow to define non-strictly positive data types. +We could also refer to positive parameters as such parameters occurring in no +negative positions. For example, the type =B= in the =c0= constructor above is +on the left of the arrow =B->X=. Then, =B= is at a negative position. Negative +parameters need to be considered when checking strictly positive data types as +they may allow to define non-strictly positive data types. In the example below, the type =T0= is strictly positive. However, the type =T1= is not. Only after unfolding the type application =T0 (T1 A)= in the data constructor =c1=, we can @@ -30,13 +31,9 @@ find out that =T1= occurs at a negative position because of =T0=. More precisely the type parameter =A= of =T0= is negative. #+begin_src minijuvix -inductive T0 (A : Type) { - c0 : (A -> T0 A) -> T0 A; -}; +type T0 (A : Type) := c0 : (A -> T0 A) -> T0 A; -inductive T1 { - c1 : T0 T1 -> T1; -}; +type T1 := c1 : T0 T1 -> T1; #+end_src @@ -50,37 +47,25 @@ when typechecking a =Juvix= File. $ cat tests/negative/MicroJuvix/NoStrictlyPositiveDataTypes/E5.mjuvix module E5; positive - inductive T0 (A : Type){ + type T0 (A : Type) := c0 : (T0 A -> A) -> T0 A; - }; end; #+end_example ** Examples of non-strictly data types -- =NSPos= is at a negative position in =c=. - #+begin_src minijuvix - inductive Empty {}; - inductive NSPos { - c : ((NSPos -> Empty) -> NSPos) -> NSPos; - }; - #+end_src - - =Bad= is not strictly positive beceause of the negative parameter =A= of =Tree=. #+begin_src minijuvix - inductive Tree (A : Type) { - leaf : Tree A; - node : (A -> Tree A) -> Tree A; - }; + type Tree (A : Type) := + leaf : Tree A + | node : (A -> Tree A) -> Tree A; - inductive Bad { + type Bad := bad : Tree Bad -> Bad; - }; #+end_src - =A= is a negative parameter. #+begin_src minijuvix - inductive B (A : Type) { + type B (A : Type) := b : (A -> B (B A -> A)) -> B A; - }; #+end_src diff --git a/examples/milestone/Hanoi/Hanoi.juvix b/examples/milestone/Hanoi/Hanoi.juvix index 93de2ada39..fd0032b638 100644 --- a/examples/milestone/Hanoi/Hanoi.juvix +++ b/examples/milestone/Hanoi/Hanoi.juvix @@ -43,11 +43,10 @@ showList : List Nat → String; showList xs := "[" ++str intercalate "," (map natToStr xs) ++str "]"; --- A Peg represents a peg in the towers of Hanoi game -inductive Peg { - left : Peg; - middle : Peg; - right : Peg; -}; +type Peg := + left : Peg + | middle : Peg + | right : Peg; showPeg : Peg → String; showPeg left := "left"; @@ -56,9 +55,7 @@ showPeg right := "right"; --- A Move represents a move between pegs -inductive Move { - move : Peg → Peg → Move; -}; +type Move := move : Peg → Peg → Move; showMove : Move → String; showMove (move from to) := showPeg from ++str " -> " ++str showPeg to; diff --git a/examples/milestone/TicTacToe/Logic/Board.juvix b/examples/milestone/TicTacToe/Logic/Board.juvix index c5a297a756..725481bec3 100644 --- a/examples/milestone/TicTacToe/Logic/Board.juvix +++ b/examples/milestone/TicTacToe/Logic/Board.juvix @@ -6,9 +6,8 @@ open import Logic.Symbol public; open import Logic.Extra; --- A 3x3 grid of ;Square;s -inductive Board { +type Board := board : List (List Square) → Board; -}; --- Returns the list of numbers corresponding to the empty ;Square;s possibleMoves : List Square → List Nat; diff --git a/examples/milestone/TicTacToe/Logic/GameState.juvix b/examples/milestone/TicTacToe/Logic/GameState.juvix index d9b6cd9976..21d5eb1fff 100644 --- a/examples/milestone/TicTacToe/Logic/GameState.juvix +++ b/examples/milestone/TicTacToe/Logic/GameState.juvix @@ -4,18 +4,16 @@ open import Stdlib.Prelude; open import Logic.Extra; open import Logic.Board; -inductive Error { +type Error := --- no error occurred - noError : Error; + noError : Error | --- a non-fatal error occurred - continue : String → Error; +continue : String → Error | --- a fatal occurred - terminate : String → Error; -}; +terminate : String → Error; -inductive GameState { +type GameState := state : Board → Symbol → Error → GameState; -}; --- Textual representation of a ;GameState; showGameState : GameState → String; diff --git a/examples/milestone/TicTacToe/Logic/Square.juvix b/examples/milestone/TicTacToe/Logic/Square.juvix index f1953dd981..5439b375bb 100644 --- a/examples/milestone/TicTacToe/Logic/Square.juvix +++ b/examples/milestone/TicTacToe/Logic/Square.juvix @@ -6,12 +6,12 @@ open import Stdlib.Data.Nat.Ord; open import Logic.Extra; --- A square is each of the holes in a board -inductive Square { +type Square := --- An empty square has a ;Nat; that uniquely identifies it - empty : Nat → Square; - --- An occupied square has a ;Symbol; in it - occupied : Symbol → Square; -}; + empty : Nat → Square + -- TODO: Check the line below using Judoc + -- - An occupied square has a ;Symbol; in it + | occupied : Symbol → Square; --- Equality for ;Square;s ==Square : Square → Square → Bool; diff --git a/examples/milestone/TicTacToe/Logic/Symbol.juvix b/examples/milestone/TicTacToe/Logic/Symbol.juvix index eb6ab5cdaf..a1a243ec68 100644 --- a/examples/milestone/TicTacToe/Logic/Symbol.juvix +++ b/examples/milestone/TicTacToe/Logic/Symbol.juvix @@ -4,12 +4,11 @@ module Logic.Symbol; open import Stdlib.Prelude; --- A symbol represents a token that can be placed in a square -inductive Symbol { +type Symbol := --- The circle token - O : Symbol; + O : Symbol | --- The cross token X : Symbol; -}; --- Equality for ;Symbol;s ==Symbol : Symbol → Symbol → Bool; diff --git a/examples/milestone/TicTacToe/Web/TicTacToe.juvix b/examples/milestone/TicTacToe/Web/TicTacToe.juvix index 80efc21bea..07d8c3290d 100644 --- a/examples/milestone/TicTacToe/Web/TicTacToe.juvix +++ b/examples/milestone/TicTacToe/Web/TicTacToe.juvix @@ -93,11 +93,10 @@ lightBackgroundColor := "#c7737a"; -- Rendering -inductive Align { - left : Align; - right : Align; - center : Align; -}; +type Align := + left : Align + | right : Align + | center : Align; alignNum : Align → Nat; alignNum left := zero; diff --git a/juvix-stdlib b/juvix-stdlib index a2790ca49c..bdcf1ef088 160000 --- a/juvix-stdlib +++ b/juvix-stdlib @@ -1 +1 @@ -Subproject commit a2790ca49ceeb569559224abe1587305ea1861fa +Subproject commit bdcf1ef0889a08de1ec334a598efbbf622607884 diff --git a/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs b/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs index 826fb1e420..4a45b76a97 100644 --- a/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs +++ b/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs @@ -279,7 +279,7 @@ goInductive ty@InductiveDef {..} = do _inductiveBuiltin = _inductiveBuiltin, _inductiveName = goSymbol _inductiveName, _inductiveType = fromMaybe (Abstract.ExpressionUniverse (smallUniverse loc)) _inductiveType', - _inductiveConstructors = _inductiveConstructors', + _inductiveConstructors = toList _inductiveConstructors', _inductiveExamples = _inductiveExamples', _inductivePositive = ty ^. inductivePositive } diff --git a/src/Juvix/Compiler/Backend/Html/Translation/FromTyped.hs b/src/Juvix/Compiler/Backend/Html/Translation/FromTyped.hs index 6bd13aacc3..872dd51288 100644 --- a/src/Juvix/Compiler/Backend/Html/Translation/FromTyped.hs +++ b/src/Juvix/Compiler/Backend/Html/Translation/FromTyped.hs @@ -411,9 +411,9 @@ goInductive def = do inductiveHeader = runReader defaultOptions (ppInductiveSignature def) >>= ppCodeHtml -goConstructors :: forall r. Members '[Reader HtmlOptions, Reader NormalizedTable] r => [InductiveConstructorDef 'Scoped] -> Sem r Html +goConstructors :: forall r. Members '[Reader HtmlOptions, Reader NormalizedTable] r => NonEmpty (InductiveConstructorDef 'Scoped) -> Sem r Html goConstructors cc = do - tbl' <- table . tbody <$> mconcatMapM goConstructor cc + tbl' <- table . tbody <$> mconcatMapM goConstructor (toList cc) return $ Html.div ! Attr.class_ "subs constructors" $ (p ! Attr.class_ "caption" $ "Constructors") diff --git a/src/Juvix/Compiler/Concrete/Keywords.hs b/src/Juvix/Compiler/Concrete/Keywords.hs index f5f68eaaf5..c8215d4248 100644 --- a/src/Juvix/Compiler/Concrete/Keywords.hs +++ b/src/Juvix/Compiler/Concrete/Keywords.hs @@ -36,6 +36,7 @@ import Juvix.Data.Keyword.All kwMapsTo, kwModule, kwOpen, + kwPipe, kwPositive, kwPostfix, kwPublic, @@ -76,6 +77,7 @@ allKeywords = kwLet, kwModule, kwOpen, + kwPipe, kwPostfix, kwPublic, kwRightArrow, diff --git a/src/Juvix/Compiler/Concrete/Language.hs b/src/Juvix/Compiler/Concrete/Language.hs index a384560378..5f4ebbc7b8 100644 --- a/src/Juvix/Compiler/Concrete/Language.hs +++ b/src/Juvix/Compiler/Concrete/Language.hs @@ -249,7 +249,7 @@ data InductiveDef (s :: Stage) = InductiveDef _inductiveName :: InductiveName s, _inductiveParameters :: [InductiveParameter s], _inductiveType :: Maybe (ExpressionType s), - _inductiveConstructors :: [InductiveConstructorDef s], + _inductiveConstructors :: NonEmpty (InductiveConstructorDef s), _inductivePositive :: Bool } diff --git a/src/Juvix/Compiler/Concrete/Pretty/Base.hs b/src/Juvix/Compiler/Concrete/Pretty/Base.hs index bb7101c635..f4d59b4ea2 100644 --- a/src/Juvix/Compiler/Concrete/Pretty/Base.hs +++ b/src/Juvix/Compiler/Concrete/Pretty/Base.hs @@ -108,13 +108,16 @@ groupStatements = reverse . map reverse . uncurry cons . foldl' aux ([], []) symbolParsed sym = case sing :: SStage s of SParsed -> sym SScoped -> sym ^. S.nameConcrete + syms :: InductiveDef s -> [Symbol] - syms InductiveDef {..} = case sing :: SStage s of - SParsed -> _inductiveName : map (^. constructorName) _inductiveConstructors - SScoped -> - _inductiveName - ^. S.nameConcrete - : map (^. constructorName . S.nameConcrete) _inductiveConstructors + syms InductiveDef {..} = + let constructors = toList _inductiveConstructors + in case sing :: SStage s of + SParsed -> _inductiveName : map (^. constructorName) constructors + SScoped -> + _inductiveName + ^. S.nameConcrete + : map (^. constructorName . S.nameConcrete) constructors instance SingI s => PrettyCode [Statement s] where ppCode ss = vsep2 <$> mapM (fmap vsep . mapM (fmap endSemicolon . ppCode)) (groupStatements ss) @@ -288,8 +291,19 @@ instance SingI s => PrettyCode (InductiveDef s) where ppCode d@InductiveDef {..} = do doc' <- mapM ppCode _inductiveDoc sig' <- ppInductiveSignature d - inductiveConstructors' <- ppBlock _inductiveConstructors - return $ doc' ?<> sig' <+> inductiveConstructors' + inductiveConstructors' <- ppConstructorBlock _inductiveConstructors + return $ + doc' ?<> sig' + <+> kwAssign + <> line + <> (indent' . align) inductiveConstructors' + where + ppConstructorBlock :: + NonEmpty (InductiveConstructorDef s) -> Sem r (Doc Ann) + ppConstructorBlock cs = + do + concatWith (\x y -> x <> softline <> kwPipe <+> y) + <$> mapM ppCode (toList cs) dotted :: Foldable f => f (Doc Ann) -> Doc Ann dotted = concatWith (surround kwDot) diff --git a/src/Juvix/Compiler/Concrete/Translation/FromSource.hs b/src/Juvix/Compiler/Concrete/Translation/FromSource.hs index 81fa70595d..63f47313d5 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromSource.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromSource.hs @@ -496,10 +496,16 @@ inductiveDef _inductiveBuiltin = do _inductivePositive <- isJust <$> optional (kw kwPositive) kw kwInductive _inductiveDoc <- getJudoc - _inductiveName <- symbol - _inductiveParameters <- P.many inductiveParam - _inductiveType <- optional (kw kwColon >> parseExpressionAtoms) - _inductiveConstructors <- braces $ P.sepEndBy constructorDef (kw kwSemicolon) + _inductiveName <- symbol P. "" + _inductiveParameters <- + P.many inductiveParam + P. "" + _inductiveType <- + optional (kw kwColon >> parseExpressionAtoms) + P. "" + kw kwAssign P. " ParsecS r (InductiveParameter 'Parsed) @@ -512,9 +518,10 @@ inductiveParam = parens $ do constructorDef :: Members '[InfoTableBuilder, JudocStash, NameIdGen] r => ParsecS r (InductiveConstructorDef 'Parsed) constructorDef = do _constructorDoc <- optional stashJudoc >> getJudoc - _constructorName <- symbol - kw kwColon - _constructorType <- parseExpressionAtoms + _constructorName <- symbol P. "" + _constructorType <- + kw kwColon >> parseExpressionAtoms + P. "" return InductiveConstructorDef {..} wildcard :: Members '[InfoTableBuilder, JudocStash, NameIdGen] r => ParsecS r Wildcard diff --git a/src/Juvix/Data/Keyword/All.hs b/src/Juvix/Data/Keyword/All.hs index 58c92992f2..95680e9e97 100644 --- a/src/Juvix/Data/Keyword/All.hs +++ b/src/Juvix/Data/Keyword/All.hs @@ -94,6 +94,9 @@ kwRightArrow = unicodeKw Str.toAscii Str.toUnicode kwSemicolon :: Keyword kwSemicolon = asciiKw Str.semicolon +kwPipe :: Keyword +kwPipe = asciiKw Str.pipe + kwType :: Keyword kwType = asciiKw Str.type_ diff --git a/src/Juvix/Extra/Strings.hs b/src/Juvix/Extra/Strings.hs index e2f43c5ec8..f57a9ae96e 100644 --- a/src/Juvix/Extra/Strings.hs +++ b/src/Juvix/Extra/Strings.hs @@ -33,7 +33,7 @@ in_ :: IsString s => s in_ = "in" inductive :: IsString s => s -inductive = "inductive" +inductive = "type" function :: IsString s => s function = "function" diff --git a/test/Termination/Negative.hs b/test/Termination/Negative.hs index 7e3207fb06..203750618b 100644 --- a/test/Termination/Negative.hs +++ b/test/Termination/Negative.hs @@ -65,12 +65,6 @@ tests = $(mkRelFile "TerminatingG.juvix") $ \case ErrNoLexOrder {} -> Nothing, - NegTest - "f x := f x is not terminating" - $(mkRelDir ".") - $(mkRelFile "ToEmpty.juvix") - $ \case - ErrNoLexOrder {} -> Nothing, NegTest "Tree" $(mkRelDir ".") diff --git a/test/Termination/Positive.hs b/test/Termination/Positive.hs index f2c7976fd8..c39522b25c 100644 --- a/test/Termination/Positive.hs +++ b/test/Termination/Positive.hs @@ -71,10 +71,6 @@ tests = testsWithKeyword :: [PosTest] testsWithKeyword = [ PosTest - "terminating added to fx:=fx" - $(mkRelDir ".") - $(mkRelFile "ToEmpty.juvix"), - PosTest "terminating for all functions in the mutual block" $(mkRelDir ".") $(mkRelFile "Mutual.juvix"), diff --git a/tests/Asm/negative/test002.jva b/tests/Asm/negative/test002.jva index 7ba2658217..9b1e15defa 100644 --- a/tests/Asm/negative/test002.jva +++ b/tests/Asm/negative/test002.jva @@ -1,6 +1,6 @@ -- invalid memory access -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/negative/test003.jva b/tests/Asm/negative/test003.jva index acbec90a8b..0a0e7ebffa 100644 --- a/tests/Asm/negative/test003.jva +++ b/tests/Asm/negative/test003.jva @@ -1,6 +1,6 @@ -- no matching case branch -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/negative/vtest008.jva b/tests/Asm/negative/vtest008.jva index 079c5cb6c0..bdbbe97659 100644 --- a/tests/Asm/negative/vtest008.jva +++ b/tests/Asm/negative/vtest008.jva @@ -1,6 +1,6 @@ -- case stack height mismatch -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/negative/vtest009.jva b/tests/Asm/negative/vtest009.jva index c2ae98db32..ce8346a8e3 100644 --- a/tests/Asm/negative/vtest009.jva +++ b/tests/Asm/negative/vtest009.jva @@ -1,6 +1,6 @@ -- case type mismatch -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/positive/test009.jva b/tests/Asm/positive/test009.jva index 99246965fa..b0d2311477 100644 --- a/tests/Asm/positive/test009.jva +++ b/tests/Asm/positive/test009.jva @@ -1,6 +1,6 @@ -- case -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/positive/test014.jva b/tests/Asm/positive/test014.jva index 365329577b..b53cc516d2 100644 --- a/tests/Asm/positive/test014.jva +++ b/tests/Asm/positive/test014.jva @@ -1,6 +1,6 @@ -- trees -inductive tree { +type tree { node1 : tree -> tree; node2 : tree -> tree -> tree; node3 : tree -> tree -> tree -> tree; diff --git a/tests/Asm/positive/test028.jva b/tests/Asm/positive/test028.jva index 689f49cb23..d31536c2e6 100644 --- a/tests/Asm/positive/test028.jva +++ b/tests/Asm/positive/test028.jva @@ -1,6 +1,6 @@ -- lists -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/positive/test029.jva b/tests/Asm/positive/test029.jva index 0bf551012f..6e142f5951 100644 --- a/tests/Asm/positive/test029.jva +++ b/tests/Asm/positive/test029.jva @@ -1,6 +1,6 @@ -- structural equality -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/positive/test031.jva b/tests/Asm/positive/test031.jva index 91a91f033f..aafeab721c 100644 --- a/tests/Asm/positive/test031.jva +++ b/tests/Asm/positive/test031.jva @@ -1,6 +1,6 @@ -- temporary stack with branching -inductive tree { +type tree { leaf : tree; node : tree -> tree -> tree; } diff --git a/tests/Asm/positive/test032.jva b/tests/Asm/positive/test032.jva index 0e0fd67185..cee8c6f04b 100644 --- a/tests/Asm/positive/test032.jva +++ b/tests/Asm/positive/test032.jva @@ -1,6 +1,6 @@ -- Church numerals -inductive Pair { +type Pair { pair : * -> * -> Pair; } diff --git a/tests/Asm/positive/test035.jva b/tests/Asm/positive/test035.jva index cd007b4f4d..336a7db97e 100644 --- a/tests/Asm/positive/test035.jva +++ b/tests/Asm/positive/test035.jva @@ -1,6 +1,6 @@ -- Nested lists -inductive list { +type list { nil : list; cons : * -> list -> list; } diff --git a/tests/Asm/positive/test036.jva b/tests/Asm/positive/test036.jva index 86a6b194e7..3489a79107 100644 --- a/tests/Asm/positive/test036.jva +++ b/tests/Asm/positive/test036.jva @@ -1,6 +1,6 @@ -- streams without memoization -inductive stream { +type stream { cons : integer -> (unit -> stream) -> stream; } diff --git a/tests/Core/positive/test007.jvc b/tests/Core/positive/test007.jvc index df7c8c03d7..e50190ccc0 100644 --- a/tests/Core/positive/test007.jvc +++ b/tests/Core/positive/test007.jvc @@ -1,6 +1,6 @@ -- case -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/Core/positive/test012.jvc b/tests/Core/positive/test012.jvc index 4db37ab409..00105ab6d7 100644 --- a/tests/Core/positive/test012.jvc +++ b/tests/Core/positive/test012.jvc @@ -1,6 +1,6 @@ -- trees -inductive tree : Type { +type tree : Type { node1 : tree -> tree; node2 : tree -> tree -> tree; node3 : tree -> tree -> tree -> tree; diff --git a/tests/Core/positive/test023.jvc b/tests/Core/positive/test023.jvc index 022c2df224..ee5f2f0fd7 100644 --- a/tests/Core/positive/test023.jvc +++ b/tests/Core/positive/test023.jvc @@ -1,6 +1,6 @@ -- lists -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/Core/positive/test024.jvc b/tests/Core/positive/test024.jvc index e6b5821a0e..9e10662bd8 100644 --- a/tests/Core/positive/test024.jvc +++ b/tests/Core/positive/test024.jvc @@ -1,6 +1,6 @@ -- structural equality -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/Core/positive/test026.jvc b/tests/Core/positive/test026.jvc index 6df367440a..9fb6a62ebd 100644 --- a/tests/Core/positive/test026.jvc +++ b/tests/Core/positive/test026.jvc @@ -1,6 +1,6 @@ -- nested case, let & if -inductive tree { +type tree { leaf : tree; node : tree -> tree -> tree; }; diff --git a/tests/Core/positive/test028.jvc b/tests/Core/positive/test028.jvc index 4b3e61f623..804699802f 100644 --- a/tests/Core/positive/test028.jvc +++ b/tests/Core/positive/test028.jvc @@ -1,6 +1,6 @@ -- functional queues -inductive list { +type list { nil : list; cons : any -> list -> list; }; @@ -15,7 +15,7 @@ def rev' := \l \acc case l of { def rev := \l rev' l nil; -inductive Queue { +type Queue { queue : list -> list -> Queue; }; diff --git a/tests/Core/positive/test029.jvc b/tests/Core/positive/test029.jvc index 6d66a13c87..bdecb6e6c9 100644 --- a/tests/Core/positive/test029.jvc +++ b/tests/Core/positive/test029.jvc @@ -1,6 +1,6 @@ -- Church numerals -inductive Pair { +type Pair { pair : any -> any -> Pair; }; diff --git a/tests/Core/positive/test030.jvc b/tests/Core/positive/test030.jvc index fc9ada197a..342d3a0b2f 100644 --- a/tests/Core/positive/test030.jvc +++ b/tests/Core/positive/test030.jvc @@ -1,10 +1,10 @@ -- streams without memoization -inductive Unit { +type Unit { unit : Unit; }; -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/Core/positive/test033.jvc b/tests/Core/positive/test033.jvc index de73119a05..82f0bd291d 100644 --- a/tests/Core/positive/test033.jvc +++ b/tests/Core/positive/test033.jvc @@ -1,6 +1,6 @@ -- nested lists -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/Core/positive/test035.jvc b/tests/Core/positive/test035.jvc index e7764f654a..0fb89d3c93 100644 --- a/tests/Core/positive/test035.jvc +++ b/tests/Core/positive/test035.jvc @@ -1,11 +1,11 @@ -- merge sort -inductive list { +type list { nil : list; cons : any -> list -> list; }; -inductive product { +type product { pair : any -> any -> product; }; diff --git a/tests/Core/positive/test037.jvc b/tests/Core/positive/test037.jvc index 8cf99e062c..925a9c2d71 100644 --- a/tests/Core/positive/test037.jvc +++ b/tests/Core/positive/test037.jvc @@ -1,6 +1,6 @@ -- global variables -inductive Unit { +type Unit { unit : Unit; }; diff --git a/tests/Core/positive/test039.jvc b/tests/Core/positive/test039.jvc index 108e29a216..bb535aac70 100644 --- a/tests/Core/positive/test039.jvc +++ b/tests/Core/positive/test039.jvc @@ -1,6 +1,6 @@ -- eta-expansion of builtins and constructors -inductive stream { +type stream { cons : any -> any -> stream; }; diff --git a/tests/Core/positive/test041.jvc b/tests/Core/positive/test041.jvc index e48a889087..133f30283c 100644 --- a/tests/Core/positive/test041.jvc +++ b/tests/Core/positive/test041.jvc @@ -1,6 +1,6 @@ -- match -inductive list { +type list { cons : any -> list -> list; nil : list; }; @@ -14,7 +14,7 @@ def sum2 := \x { } }; -inductive tree { +type tree { leaf : tree; node : tree -> tree -> tree; }; diff --git a/tests/Core/positive/test042.jvc b/tests/Core/positive/test042.jvc index e5c2b569bb..bbde6ef523 100644 --- a/tests/Core/positive/test042.jvc +++ b/tests/Core/positive/test042.jvc @@ -1,6 +1,6 @@ -- type annotations -inductive list : Π A : Type, Type { +type list : Π A : Type, Type { cons : Π A : Type, A → list A → list A; nil : Π A : Type, list A; }; diff --git a/tests/Core/positive/test045.jvc b/tests/Core/positive/test045.jvc index 8a564189ca..efc1ad41db 100644 --- a/tests/Core/positive/test045.jvc +++ b/tests/Core/positive/test045.jvc @@ -1,6 +1,6 @@ -- type application and abstraction -inductive list : Π A : Type, Type { +type list : Π A : Type, Type { cons : Π A : Type, A → list A → list A; nil : Π A : Type, list A; }; diff --git a/tests/Core/positive/test046.jvc b/tests/Core/positive/test046.jvc index ef40570253..bc43ea4b86 100644 --- a/tests/Core/positive/test046.jvc +++ b/tests/Core/positive/test046.jvc @@ -1,6 +1,6 @@ -- applications with lets and cases in function position -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/Internal/positive/FunctionReturnConstructor.juvix b/tests/Internal/positive/FunctionReturnConstructor.juvix index fd1bd7ab94..9c5d8a764c 100644 --- a/tests/Internal/positive/FunctionReturnConstructor.juvix +++ b/tests/Internal/positive/FunctionReturnConstructor.juvix @@ -1,8 +1,7 @@ module FunctionReturnConstructor; -inductive Foo { +type Foo := foo : Foo; -}; main : Foo; main := foo; diff --git a/tests/Internal/positive/FunctionType.juvix b/tests/Internal/positive/FunctionType.juvix index 3fb27629d7..8bfce45c30 100644 --- a/tests/Internal/positive/FunctionType.juvix +++ b/tests/Internal/positive/FunctionType.juvix @@ -1,8 +1,7 @@ module FunctionType; -inductive A { +type A := a : A; -}; main : Type; main := (A : Type) -> (B : Type) -> A -> B; diff --git a/tests/Internal/positive/Inductive.juvix b/tests/Internal/positive/Inductive.juvix index 5430f40f32..401c147ac7 100644 --- a/tests/Internal/positive/Inductive.juvix +++ b/tests/Internal/positive/Inductive.juvix @@ -1,8 +1,7 @@ module Inductive; -inductive A (B : Type) { +type A (B : Type) := a : A B; -}; main : Type -> Type; main := A; diff --git a/tests/Internal/positive/MatchConstructor.juvix b/tests/Internal/positive/MatchConstructor.juvix index 5573e63b24..40dd42395a 100644 --- a/tests/Internal/positive/MatchConstructor.juvix +++ b/tests/Internal/positive/MatchConstructor.juvix @@ -2,10 +2,9 @@ module MatchConstructor; open import Stdlib.Prelude; -inductive Foo { - foo1 : Nat → Foo; +type Foo := + foo1 : Nat → Foo | foo2 : Foo; -}; toNat : Foo → Nat; toNat (foo1 n) := n; diff --git a/tests/benchmark/fold/core/fold.jvc b/tests/benchmark/fold/core/fold.jvc index aa088a84b3..882f398771 100644 --- a/tests/benchmark/fold/core/fold.jvc +++ b/tests/benchmark/fold/core/fold.jvc @@ -1,6 +1,6 @@ -- fold a list of N integers -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/benchmark/mapfold/core/mapfold.jvc b/tests/benchmark/mapfold/core/mapfold.jvc index 865f70d5e2..b570bfe824 100644 --- a/tests/benchmark/mapfold/core/mapfold.jvc +++ b/tests/benchmark/mapfold/core/mapfold.jvc @@ -1,6 +1,6 @@ -- map and fold a list of N integers K times -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/benchmark/mapfun/core/mapfun.jvc b/tests/benchmark/mapfun/core/mapfun.jvc index 043f0aef5f..1b69f780c3 100644 --- a/tests/benchmark/mapfun/core/mapfun.jvc +++ b/tests/benchmark/mapfun/core/mapfun.jvc @@ -1,6 +1,6 @@ -- successively map K functions to a list of N integers -inductive list { +type list { nil : list; cons : * -> list -> list; }; diff --git a/tests/benchmark/maybe/core/maybe.jvc b/tests/benchmark/maybe/core/maybe.jvc index c1535bb093..adf12794cf 100644 --- a/tests/benchmark/maybe/core/maybe.jvc +++ b/tests/benchmark/maybe/core/maybe.jvc @@ -1,11 +1,11 @@ -- optionally sum N integers from a binary tree K times -inductive tree { +type tree { node : int -> tree -> tree -> tree; leaf : tree; }; -inductive maybe { +type maybe { just : any -> maybe; nothing : maybe; }; diff --git a/tests/benchmark/maybe/juvix/maybe.juvix b/tests/benchmark/maybe/juvix/maybe.juvix index 4abea502dd..0aa44162d8 100644 --- a/tests/benchmark/maybe/juvix/maybe.juvix +++ b/tests/benchmark/maybe/juvix/maybe.juvix @@ -6,10 +6,9 @@ open import Stdlib.Prelude; open import Data.Int; open import Data.Int.Ops; -inductive Tree { - leaf : Tree; +type Tree := + leaf : Tree | node : Int -> Tree -> Tree -> Tree; -}; mknode : Int -> Tree -> Tree; mknode n t := node n t t; diff --git a/tests/benchmark/mergesort/core/mergesort.jvc b/tests/benchmark/mergesort/core/mergesort.jvc index 0b1d47ebd7..9a33c6d115 100644 --- a/tests/benchmark/mergesort/core/mergesort.jvc +++ b/tests/benchmark/mergesort/core/mergesort.jvc @@ -1,11 +1,11 @@ -- merge sort -inductive list { +type list { nil : list; cons : any -> list -> list; }; -inductive product { +type product { pair : any -> any -> product; }; diff --git a/tests/benchmark/prime/core/prime.jvc b/tests/benchmark/prime/core/prime.jvc index dd9d8fb001..aac8b56c91 100644 --- a/tests/benchmark/prime/core/prime.jvc +++ b/tests/benchmark/prime/core/prime.jvc @@ -1,6 +1,6 @@ -- Compute the Nth prime -inductive list { +type list { nil : list; cons : any -> list -> list; }; diff --git a/tests/negative/230/Foo/Data/Bool.juvix b/tests/negative/230/Foo/Data/Bool.juvix index 730dac79ab..0c36f1ea3e 100644 --- a/tests/negative/230/Foo/Data/Bool.juvix +++ b/tests/negative/230/Foo/Data/Bool.juvix @@ -2,10 +2,9 @@ module Foo.Data.Bool; import Stdlib.Data.Bool; - inductive Bool { - true : Bool; + type Bool := + true : Bool | false : Bool; - }; not : Bool → Bool; not true := false; diff --git a/tests/negative/258/M.juvix b/tests/negative/258/M.juvix index 79feec3bc6..53a4d3dc5b 100644 --- a/tests/negative/258/M.juvix +++ b/tests/negative/258/M.juvix @@ -1,9 +1,8 @@ module M; -inductive Nat { - O : Nat; +type Nat := + O : Nat | S : Nat -> Nat; -}; fun : Nat -> Nat; fun (S {S {x}}) := x; diff --git a/tests/negative/265/M.juvix b/tests/negative/265/M.juvix index 6a7f2c10a3..a00a6274d5 100644 --- a/tests/negative/265/M.juvix +++ b/tests/negative/265/M.juvix @@ -1,13 +1,11 @@ module M; -inductive Bool { - false : Bool; - true : Bool; -}; +type Bool := + true : Bool + | false : Bool; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; f : _ → _; f (mkPair false true) := true; diff --git a/tests/negative/AmbiguousConstructor.juvix b/tests/negative/AmbiguousConstructor.juvix index 46ef6a91f7..e54d48d38f 100644 --- a/tests/negative/AmbiguousConstructor.juvix +++ b/tests/negative/AmbiguousConstructor.juvix @@ -1,14 +1,12 @@ module AmbiguousConstructor; module M; - inductive T1 { + type T1 := A : T1; - }; end; module N; - inductive T2 { + type T2 := A : T2; - }; end; open M; diff --git a/tests/negative/AmbiguousExport.juvix b/tests/negative/AmbiguousExport.juvix index 4e5fa58829..fdf0d6ed59 100644 --- a/tests/negative/AmbiguousExport.juvix +++ b/tests/negative/AmbiguousExport.juvix @@ -2,9 +2,8 @@ module AmbiguousExport; module N; module O; - inductive T { + type T := A : T; - }; end; end; diff --git a/tests/negative/AmbiguousSymbol.juvix b/tests/negative/AmbiguousSymbol.juvix index 9d58d531a2..f6d85c3e09 100644 --- a/tests/negative/AmbiguousSymbol.juvix +++ b/tests/negative/AmbiguousSymbol.juvix @@ -3,9 +3,7 @@ module AmbiguousSymbol; axiom A : Type; module O; - inductive T { - A : T; - }; + type T := A : T; end; open O; diff --git a/tests/negative/BindGroupConflict/Clause.juvix b/tests/negative/BindGroupConflict/Clause.juvix index 5660d10537..4e7533c3a8 100644 --- a/tests/negative/BindGroupConflict/Clause.juvix +++ b/tests/negative/BindGroupConflict/Clause.juvix @@ -1,8 +1,7 @@ module Clause; - inductive Pair (a : Type) (b : Type) { - mkPair : a → b → Pair a b - }; + type Pair (a : Type) (b : Type) := + mkPair : a → b → Pair a b; fst : (a : Type) → (b : Type) → Pair a b → a ; fst _ _ (mkPair _ _ x x) := x; diff --git a/tests/negative/BindGroupConflict/Lambda.juvix b/tests/negative/BindGroupConflict/Lambda.juvix index ea502e7256..87bf252df0 100644 --- a/tests/negative/BindGroupConflict/Lambda.juvix +++ b/tests/negative/BindGroupConflict/Lambda.juvix @@ -1,8 +1,6 @@ module Lambda; - inductive Pair (a : Type) (b : Type) { - mkPair : a → b → Pair a b - }; + type Pair (a : Type) (b : Type) := mkPair : a → b → Pair a b; fst : (a : Type) → (b : Type) → Pair a b → a ; fst := λ { _ _ (mkPair _ _ x x) := x }; diff --git a/tests/negative/CompileBlocks/Sample/Definitions.juvix b/tests/negative/CompileBlocks/Sample/Definitions.juvix index 2487064b14..6ebf0e48f3 100644 --- a/tests/negative/CompileBlocks/Sample/Definitions.juvix +++ b/tests/negative/CompileBlocks/Sample/Definitions.juvix @@ -2,10 +2,9 @@ module Sample.Definitions; axiom A : Type; -inductive Nat { -zero : Nat; +type Nat := +zero : Nat | suc : Nat -> Nat; -}; f : A -> Nat; f a := zero; diff --git a/tests/negative/DuplicateInductiveParameterName.juvix b/tests/negative/DuplicateInductiveParameterName.juvix index a84c418c46..2575900fb6 100644 --- a/tests/negative/DuplicateInductiveParameterName.juvix +++ b/tests/negative/DuplicateInductiveParameterName.juvix @@ -1,5 +1,5 @@ module DuplicateInductiveParameterName; -inductive T (A : Type) (B : Type) (A : Type) {}; +type T (A : Type) (B : Type) (A : Type) := c : T A B A; end; \ No newline at end of file diff --git a/tests/negative/InfixErrorP.juvix b/tests/negative/InfixErrorP.juvix index b6f428c900..af156bc96f 100644 --- a/tests/negative/InfixErrorP.juvix +++ b/tests/negative/InfixErrorP.juvix @@ -2,9 +2,8 @@ module InfixErrorP; infix 5 , ; - inductive Pair { - , : Type → Type → Pair - }; + type Pair := + , : Type → Type → Pair; fst : Pair → Type; fst (x , ) := x; diff --git a/tests/negative/Internal/ExpectedExplicitArgument.juvix b/tests/negative/Internal/ExpectedExplicitArgument.juvix index 355d1fc92e..f23d98fbc8 100644 --- a/tests/negative/Internal/ExpectedExplicitArgument.juvix +++ b/tests/negative/Internal/ExpectedExplicitArgument.juvix @@ -1,7 +1,6 @@ module ExpectedExplicitArgument; - inductive T (A : Type) { + type T (A : Type) := c : A → T A; - }; f : {A : Type} → A → T A; f {A} a := c {A} {a}; diff --git a/tests/negative/Internal/ExpectedExplicitPattern.juvix b/tests/negative/Internal/ExpectedExplicitPattern.juvix index a0ef395fa9..06e406e24b 100644 --- a/tests/negative/Internal/ExpectedExplicitPattern.juvix +++ b/tests/negative/Internal/ExpectedExplicitPattern.juvix @@ -1,7 +1,6 @@ module ExpectedExplicitPattern; - inductive T (A : Type) { + type T (A : Type) := c : A → T A; - }; f : {A : Type} → T A → A; f {_} {c a} := a; diff --git a/tests/negative/Internal/ExpectedFunctionType.juvix b/tests/negative/Internal/ExpectedFunctionType.juvix index 749da537e0..c156b10f6b 100644 --- a/tests/negative/Internal/ExpectedFunctionType.juvix +++ b/tests/negative/Internal/ExpectedFunctionType.juvix @@ -1,11 +1,9 @@ module ExpectedFunctionType; - inductive Pair (A : Type) { + type Pair (A : Type) := mkPair : A → A → Pair A; - }; - inductive B { + type B := b : B; - }; f : Pair B → Pair B; f (mkPair a b) := a b; diff --git a/tests/negative/Internal/FunctionApplied.juvix b/tests/negative/Internal/FunctionApplied.juvix index 1f37c1e677..dc2ffd8ab6 100644 --- a/tests/negative/Internal/FunctionApplied.juvix +++ b/tests/negative/Internal/FunctionApplied.juvix @@ -1,7 +1,6 @@ module FunctionApplied; - inductive T (A : Type) { + type T (A : Type) := c : A → T A; - }; f : {A : Type} → A → T A; f {A} a := c {(A → A) A} a; diff --git a/tests/negative/Internal/FunctionPattern.juvix b/tests/negative/Internal/FunctionPattern.juvix index bc36be117a..f0e9ab8f78 100644 --- a/tests/negative/Internal/FunctionPattern.juvix +++ b/tests/negative/Internal/FunctionPattern.juvix @@ -1,7 +1,6 @@ module FunctionPattern; - inductive T { + type T := A : T; - }; f : (T → T) → T; f A := A; diff --git a/tests/negative/Internal/LhsTooManyPatterns.juvix b/tests/negative/Internal/LhsTooManyPatterns.juvix index 5fcd4be9b6..4dd3489a8d 100644 --- a/tests/negative/Internal/LhsTooManyPatterns.juvix +++ b/tests/negative/Internal/LhsTooManyPatterns.juvix @@ -1,7 +1,6 @@ module LhsTooManyPatterns; - inductive T { + type T := A : T; - }; f : T → T; f A x := A; diff --git a/tests/negative/Internal/MultiWrongType.juvix b/tests/negative/Internal/MultiWrongType.juvix index c15f0a1f0f..125089ff50 100644 --- a/tests/negative/Internal/MultiWrongType.juvix +++ b/tests/negative/Internal/MultiWrongType.juvix @@ -1,11 +1,9 @@ module MultiWrongType; - inductive A { + type A := a : A; - }; - inductive B { + type B := b : B; - }; f : A; f := b; diff --git a/tests/negative/Internal/PatternConstructor.juvix b/tests/negative/Internal/PatternConstructor.juvix index 4b5bd2a8d5..f3e32e2de0 100644 --- a/tests/negative/Internal/PatternConstructor.juvix +++ b/tests/negative/Internal/PatternConstructor.juvix @@ -1,11 +1,9 @@ module PatternConstructor; - inductive A { + type A := a : A; - }; -inductive B { +type B := b : B; - }; f : A → B; f b := b; diff --git a/tests/negative/Internal/Positivity/E1.juvix b/tests/negative/Internal/Positivity/E1.juvix index bbf42ee8e6..624e2cb3fd 100644 --- a/tests/negative/Internal/Positivity/E1.juvix +++ b/tests/negative/Internal/Positivity/E1.juvix @@ -1,8 +1,7 @@ module E1; axiom B : Type; -inductive X { +type X := c : (X -> B) -> X; -}; end; \ No newline at end of file diff --git a/tests/negative/Internal/Positivity/E10.juvix b/tests/negative/Internal/Positivity/E10.juvix index 981b2fcb54..d91a77bb17 100644 --- a/tests/negative/Internal/Positivity/E10.juvix +++ b/tests/negative/Internal/Positivity/E10.juvix @@ -1,14 +1,11 @@ module E10; -inductive T0 (A : Type) { +type T0 (A : Type) := t : (A -> T0 A) -> T0 A; -}; alias : Type -> Type; alias := T0; -inductive T1 { - c : (alias T1 -> T1; -}; +type T1 := c : alias T1 -> T1; end; \ No newline at end of file diff --git a/tests/negative/Internal/Positivity/E11.juvix b/tests/negative/Internal/Positivity/E11.juvix index baf2e7516c..e25223fa9c 100644 --- a/tests/negative/Internal/Positivity/E11.juvix +++ b/tests/negative/Internal/Positivity/E11.juvix @@ -1,14 +1,12 @@ module E11; -inductive T0 (A : Type) { +type T0 (A : Type) := t : (A -> T0 A) -> T0 _; -}; alias : Type -> Type -> Type; alias A B := A -> B; -inductive T1 { +type T1 := c : alias T1 T1 -> _; -}; end; \ No newline at end of file diff --git a/tests/negative/Internal/Positivity/E2.juvix b/tests/negative/Internal/Positivity/E2.juvix index d648dcaf10..942b3aa893 100644 --- a/tests/negative/Internal/Positivity/E2.juvix +++ b/tests/negative/Internal/Positivity/E2.juvix @@ -2,8 +2,7 @@ module E2; open import NegParam; -inductive D { +type D := d : T D -> D; -}; end; diff --git a/tests/negative/Internal/Positivity/E3.juvix b/tests/negative/Internal/Positivity/E3.juvix index 083a9c0c72..a98a7575b3 100644 --- a/tests/negative/Internal/Positivity/E3.juvix +++ b/tests/negative/Internal/Positivity/E3.juvix @@ -1,8 +1,7 @@ module E3; axiom B : Type; -inductive X { +type X := c : B -> (X -> B) -> X; -}; end; diff --git a/tests/negative/Internal/Positivity/E4.juvix b/tests/negative/Internal/Positivity/E4.juvix index a7284ca026..26286c96f9 100644 --- a/tests/negative/Internal/Positivity/E4.juvix +++ b/tests/negative/Internal/Positivity/E4.juvix @@ -1,12 +1,10 @@ module E4; -inductive Tree (A : Type) { - leaf : Tree A; +type Tree (A : Type) := + leaf : Tree A | node : (A -> Tree A) -> Tree A; -}; -inductive Bad { +type Bad := bad : Tree Bad -> Bad; -}; end; diff --git a/tests/negative/Internal/Positivity/E5.juvix b/tests/negative/Internal/Positivity/E5.juvix index 30445ddbf2..d9ce164d3c 100644 --- a/tests/negative/Internal/Positivity/E5.juvix +++ b/tests/negative/Internal/Positivity/E5.juvix @@ -1,16 +1,13 @@ module E5; -inductive T0 (A : Type){ +type T0 (A : Type) := c0 : (A -> T0 A) -> T0 A; -}; axiom B : Type; -inductive T1 (A : Type) { +type T1 (A : Type) := c1 : (B -> T0 A) -> T1 A; -}; -inductive T2 { +type T2 := c2 : (B -> (B -> T1 T2)) -> T2; -}; end; diff --git a/tests/negative/Internal/Positivity/E6.juvix b/tests/negative/Internal/Positivity/E6.juvix index c919d837cc..0fd23efc20 100644 --- a/tests/negative/Internal/Positivity/E6.juvix +++ b/tests/negative/Internal/Positivity/E6.juvix @@ -1,8 +1,7 @@ module E6; axiom A : Type; -inductive T (A : Type) { +type T (A : Type) := c : (A -> (A -> (T A -> A))) -> T A; -}; end; diff --git a/tests/negative/Internal/Positivity/E7.juvix b/tests/negative/Internal/Positivity/E7.juvix index 87902c48a1..48828b5f33 100644 --- a/tests/negative/Internal/Positivity/E7.juvix +++ b/tests/negative/Internal/Positivity/E7.juvix @@ -1,11 +1,9 @@ module E7; -inductive T0 (A : Type) (B : Type) { +type T0 (A : Type) (B : Type) := c0 : (B -> A) -> T0 A B; -}; -inductive T1 (A : Type) { +type T1 (A : Type) := c1 : (A -> T0 A (T1 A)) -> T1 A; -}; end; diff --git a/tests/negative/Internal/Positivity/E8.juvix b/tests/negative/Internal/Positivity/E8.juvix index dbaf2edbaf..76d4859ef9 100644 --- a/tests/negative/Internal/Positivity/E8.juvix +++ b/tests/negative/Internal/Positivity/E8.juvix @@ -1,5 +1,4 @@ module E8; -inductive B (A : Type) { +type B (A : Type) := b : (A -> B (B A -> A)) -> B A; -}; end; diff --git a/tests/negative/Internal/Positivity/E9.juvix b/tests/negative/Internal/Positivity/E9.juvix index 776583018b..60a0715c54 100644 --- a/tests/negative/Internal/Positivity/E9.juvix +++ b/tests/negative/Internal/Positivity/E9.juvix @@ -1,11 +1,9 @@ module E9; -inductive B { +type B := b : B; -}; -inductive T { +type T := c : ((B → T) -> T) -> T; -}; end; \ No newline at end of file diff --git a/tests/negative/Internal/Positivity/NegParam.juvix b/tests/negative/Internal/Positivity/NegParam.juvix index d09e21dfb7..1c3157cf2a 100644 --- a/tests/negative/Internal/Positivity/NegParam.juvix +++ b/tests/negative/Internal/Positivity/NegParam.juvix @@ -1,5 +1,4 @@ module NegParam; -inductive T (A : Type) { +type T (A : Type) := c : (A -> T A) -> T A; -}; end; diff --git a/tests/negative/Internal/Positivity/errorE5.test b/tests/negative/Internal/Positivity/errorE5.test index 9488b79461..39b0299676 100644 --- a/tests/negative/Internal/Positivity/errorE5.test +++ b/tests/negative/Internal/Positivity/errorE5.test @@ -1,6 +1,6 @@ $ juvix typecheck tests/negative/Internal/Positivity/E5.juvix --no-colors ->2 /.*\.juvix\:13:21\-23\: error\: +>2 /.*\.juvix\:11:21\-23\: error\: The type T2 is not strictly positive. It appears at a negative position in one of the arguments of the constructor c2. / ->= 1 \ No newline at end of file +>= 1 \ No newline at end of file diff --git a/tests/negative/Internal/Positivity/errorE9.test b/tests/negative/Internal/Positivity/errorE9.test index a48632bd5a..06a0ef5c87 100644 --- a/tests/negative/Internal/Positivity/errorE9.test +++ b/tests/negative/Internal/Positivity/errorE9.test @@ -1,5 +1,5 @@ $ juvix typecheck tests/negative/Internal/Positivity/E9.juvix --no-colors ->2 /.*\.juvix\:8:13\-14\: error\: +>2 /.*\.juvix\:7:13\-14\: error\: The type T is not strictly positive. It appears at a negative position in one of the arguments of the constructor c. / diff --git a/tests/negative/Internal/TooManyArguments.juvix b/tests/negative/Internal/TooManyArguments.juvix index c39ae0a403..32ef689886 100644 --- a/tests/negative/Internal/TooManyArguments.juvix +++ b/tests/negative/Internal/TooManyArguments.juvix @@ -1,7 +1,6 @@ module TooManyArguments; - inductive T (A : Type) { + type T (A : Type) := c : A → T A; - }; f : {A : Type} → A → T A; f {A} a := c {A} a a {a} ; diff --git a/tests/negative/Internal/UnsolvedMeta.juvix b/tests/negative/Internal/UnsolvedMeta.juvix index e4eadddbac..1f1d4574cf 100644 --- a/tests/negative/Internal/UnsolvedMeta.juvix +++ b/tests/negative/Internal/UnsolvedMeta.juvix @@ -1,8 +1,7 @@ module UnsolvedMeta; -inductive Proxy (A : Type) { +type Proxy (A : Type) := x : Proxy A; -}; t : Proxy _; t := x; diff --git a/tests/negative/Internal/WrongConstructorArity.juvix b/tests/negative/Internal/WrongConstructorArity.juvix index 79867e5df1..3996d8c703 100644 --- a/tests/negative/Internal/WrongConstructorArity.juvix +++ b/tests/negative/Internal/WrongConstructorArity.juvix @@ -1,7 +1,6 @@ module WrongConstructorArity; - inductive T { + type T := A : T → T; - }; f : T → T; f (A i x) := i; diff --git a/tests/negative/Internal/WrongReturnType.juvix b/tests/negative/Internal/WrongReturnType.juvix index 5baf85178f..171f5c0c09 100644 --- a/tests/negative/Internal/WrongReturnType.juvix +++ b/tests/negative/Internal/WrongReturnType.juvix @@ -1,8 +1,7 @@ module WrongReturnType; axiom B : Type; -inductive A { +type A := c : B; -}; end; diff --git a/tests/negative/Internal/WrongReturnTypeParameters.juvix b/tests/negative/Internal/WrongReturnTypeParameters.juvix index 4868c14888..a183ab5072 100644 --- a/tests/negative/Internal/WrongReturnTypeParameters.juvix +++ b/tests/negative/Internal/WrongReturnTypeParameters.juvix @@ -1,7 +1,6 @@ module WrongReturnTypeParameters; -inductive A (B : Type) { +type A (B : Type) := c : A B B; -}; end; diff --git a/tests/negative/Internal/WrongReturnTypeTooFewArguments.juvix b/tests/negative/Internal/WrongReturnTypeTooFewArguments.juvix index 8f5ee115b8..5a46cd05e7 100644 --- a/tests/negative/Internal/WrongReturnTypeTooFewArguments.juvix +++ b/tests/negative/Internal/WrongReturnTypeTooFewArguments.juvix @@ -1,7 +1,6 @@ module WrongReturnTypeTooFewArguments; -inductive A (B : Type) { +type A (B : Type) := c : A; -}; end; diff --git a/tests/negative/Internal/WrongReturnTypeTooManyArguments.juvix b/tests/negative/Internal/WrongReturnTypeTooManyArguments.juvix index e775c60ce4..cff1941216 100644 --- a/tests/negative/Internal/WrongReturnTypeTooManyArguments.juvix +++ b/tests/negative/Internal/WrongReturnTypeTooManyArguments.juvix @@ -1,7 +1,6 @@ module WrongReturnTypeTooManyArguments; -inductive A (B : Type) { +type A (B : Type) := c : A B B; -}; end; diff --git a/tests/negative/Internal/WrongType.juvix b/tests/negative/Internal/WrongType.juvix index 5bf78b712e..e61b60fac7 100644 --- a/tests/negative/Internal/WrongType.juvix +++ b/tests/negative/Internal/WrongType.juvix @@ -1,11 +1,9 @@ module WrongType; - inductive A { + type A := a : A; - }; - inductive B { + type B := b : B; - }; f : A; f := b; diff --git a/tests/negative/Termination/Data/Bool.juvix b/tests/negative/Termination/Data/Bool.juvix index 9091657035..afd0343f14 100644 --- a/tests/negative/Termination/Data/Bool.juvix +++ b/tests/negative/Termination/Data/Bool.juvix @@ -1,8 +1,7 @@ module Data.Bool; - inductive Bool { - true : Bool; + type Bool := + true : Bool | false : Bool; - }; not : Bool → Bool; not true := false; diff --git a/tests/negative/Termination/Data/Nat.juvix b/tests/negative/Termination/Data/Nat.juvix index 991df50bd5..7f888023f0 100644 --- a/tests/negative/Termination/Data/Nat.juvix +++ b/tests/negative/Termination/Data/Nat.juvix @@ -1,8 +1,7 @@ module Data.Nat; - inductive ℕ { - zero : ℕ; + type ℕ := + zero : ℕ | suc : ℕ → ℕ; - }; infixl 6 +; + : ℕ → ℕ → ℕ; diff --git a/tests/negative/Termination/Data/QuickSort.juvix b/tests/negative/Termination/Data/QuickSort.juvix index 672d66ba67..e5f3f8631e 100644 --- a/tests/negative/Termination/Data/QuickSort.juvix +++ b/tests/negative/Termination/Data/QuickSort.juvix @@ -6,10 +6,9 @@ open Data.Bool; import Data.Nat; open Data.Nat; -inductive List (A : Type) { - nil : List A; +type List (A : Type) := + nil : List A | cons : A → List A → List A; -}; filter : (A : Type) → (A → Bool) → List A → List A; filter A f nil := nil A; diff --git a/tests/negative/Termination/Data/Tree.juvix b/tests/negative/Termination/Data/Tree.juvix index b064602de2..726781dd08 100644 --- a/tests/negative/Termination/Data/Tree.juvix +++ b/tests/negative/Termination/Data/Tree.juvix @@ -1,8 +1,7 @@ module Data.Tree; -inductive Tree (A : Type) { - leaf : Tree A; +type Tree (A : Type) := + leaf : Tree A | branch : Tree A → Tree A → Tree A; -}; f : (A : Type) → Tree A → Tree A → Tree A; f A x leaf := x; diff --git a/tests/negative/Termination/Ord.juvix b/tests/negative/Termination/Ord.juvix index 1c2b87d945..122bdbdb1f 100644 --- a/tests/negative/Termination/Ord.juvix +++ b/tests/negative/Termination/Ord.juvix @@ -3,11 +3,10 @@ module Ord; import Data.Nat; open Data.Nat; -inductive Ord { - ZOrd : Ord; - SOrd : Ord -> Ord; +type Ord := + ZOrd : Ord | + SOrd : Ord -> Ord | Lim : (ℕ -> Ord) -> Ord; -}; addord : Ord -> Ord -> Ord; aux-addord : (ℕ -> Ord) -> Ord -> (ℕ -> Ord); diff --git a/tests/negative/Termination/ToEmpty.juvix b/tests/negative/Termination/ToEmpty.juvix deleted file mode 100644 index 6bafb113eb..0000000000 --- a/tests/negative/Termination/ToEmpty.juvix +++ /dev/null @@ -1,6 +0,0 @@ -module ToEmpty; - axiom A : Type; - inductive Empty {}; - f : A -> Empty; - f x := f x; -end; diff --git a/tests/negative/issue1337/Braces.juvix b/tests/negative/issue1337/Braces.juvix index 661545755c..995d1c1bad 100644 --- a/tests/negative/issue1337/Braces.juvix +++ b/tests/negative/issue1337/Braces.juvix @@ -1,9 +1,8 @@ module Braces; -inductive Nat { - O : Nat; +type Nat := + O : Nat | S : Nat -> Nat; -}; fun : Nat -> Nat; fun (S {S {x}}) := x; diff --git a/tests/negative/issue1344/M.juvix b/tests/negative/issue1344/M.juvix index f332bf534b..b715a1b89e 100644 --- a/tests/negative/issue1344/M.juvix +++ b/tests/negative/issue1344/M.juvix @@ -1,9 +1,8 @@ module M; import Other; - inductive Unit { + type Unit := t : Unit; - }; u : Other.Unit; u := t; diff --git a/tests/negative/issue1344/Other.juvix b/tests/negative/issue1344/Other.juvix index fcebd795d9..3e3642a2ce 100644 --- a/tests/negative/issue1344/Other.juvix +++ b/tests/negative/issue1344/Other.juvix @@ -1,7 +1,6 @@ module Other; - inductive Unit { + type Unit := t : Unit; - }; end; diff --git a/tests/negative/issue1344/U.juvix b/tests/negative/issue1344/U.juvix index 59fe4dbf74..cb7924470d 100644 --- a/tests/negative/issue1344/U.juvix +++ b/tests/negative/issue1344/U.juvix @@ -1,6 +1,4 @@ module U; - inductive Unit { - t : Unit; - }; + type Unit := t : Unit; end; \ No newline at end of file diff --git a/tests/positive/265/M.juvix b/tests/positive/265/M.juvix index 3cd5312cbb..2893727135 100644 --- a/tests/positive/265/M.juvix +++ b/tests/positive/265/M.juvix @@ -1,13 +1,11 @@ module M; -inductive Bool { - false : Bool; - true : Bool; -}; +type Bool := + true : Bool + | false : Bool; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; f : _ → _; f (mkPair false true) := true; diff --git a/tests/positive/272/M.juvix b/tests/positive/272/M.juvix index 910b044a8e..2bc703465d 100644 --- a/tests/positive/272/M.juvix +++ b/tests/positive/272/M.juvix @@ -1,26 +1,22 @@ module M; -inductive Bool { - false : Bool; - true : Bool; -}; +type Bool := + true : Bool + | false : Bool; -inductive T { +type T := t : T; -}; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; f : _; f false false := true; f true _ := false; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; g : _; g (mkPair (mkPair zero false) true) := mkPair false zero; diff --git a/tests/positive/BuiltinsBool.juvix b/tests/positive/BuiltinsBool.juvix index cca3ffb994..f03d12a318 100644 --- a/tests/positive/BuiltinsBool.juvix +++ b/tests/positive/BuiltinsBool.juvix @@ -1,10 +1,9 @@ module BuiltinsBool; builtin bool -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; builtin bool-if if : {A : Type} → Bool → A → A → A; diff --git a/tests/positive/BuiltinsMultiImport/Nat.juvix b/tests/positive/BuiltinsMultiImport/Nat.juvix index 1c94c8e308..881bf18791 100644 --- a/tests/positive/BuiltinsMultiImport/Nat.juvix +++ b/tests/positive/BuiltinsMultiImport/Nat.juvix @@ -1,9 +1,8 @@ module Nat; builtin nat -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; end; diff --git a/tests/positive/BuiltinsMultiOpenImport/Nat.juvix b/tests/positive/BuiltinsMultiOpenImport/Nat.juvix index 1c94c8e308..881bf18791 100644 --- a/tests/positive/BuiltinsMultiOpenImport/Nat.juvix +++ b/tests/positive/BuiltinsMultiOpenImport/Nat.juvix @@ -1,9 +1,8 @@ module Nat; builtin nat -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; end; diff --git a/tests/positive/FullExamples/MonoSimpleFungibleToken.juvix b/tests/positive/FullExamples/MonoSimpleFungibleToken.juvix index a65d3dd4d6..f1ac558911 100644 --- a/tests/positive/FullExamples/MonoSimpleFungibleToken.juvix +++ b/tests/positive/FullExamples/MonoSimpleFungibleToken.juvix @@ -8,10 +8,9 @@ foreign ghc { -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; infixr 2 ||; || : Bool → Bool → Bool; @@ -126,10 +125,9 @@ infix 4 ==String; -- Lists -------------------------------------------------------------------------------- -inductive ListString { - Nil : ListString; +type ListString := + Nil : ListString | Cons : String → ListString → ListString; -}; elem : String → ListString → Bool; elem s Nil := false; @@ -139,9 +137,8 @@ elem s (Cons x xs) := (s ==String x) || elem s xs; -- Pair -------------------------------------------------------------------------------- -inductive PairIntBool { +type PairIntBool := MakePair : Int → Bool → PairIntBool; -}; if-pairIntBool : Bool → PairIntBool → PairIntBool → PairIntBool; if-pairIntBool true x _ := x; @@ -151,10 +148,9 @@ if-pairIntBool false _ y := y; -- Optionals -------------------------------------------------------------------------------- -inductive OptionInt { - NothingInt : OptionInt; +type OptionInt := + NothingInt : OptionInt | JustInt : Int -> OptionInt; -}; if-optionInt : Bool → OptionInt → OptionInt → OptionInt; if-optionInt true x _ := x; @@ -167,10 +163,9 @@ maybe-int : Int → OptionInt → Int; maybe-int d NothingInt := d; maybe-int _ (JustInt i) := i; -inductive OptionString { - NothingString : OptionString; +type OptionString := + NothingString : OptionString | JustString : String -> OptionString; -}; if-optionString : Bool → OptionString → OptionString → OptionString; if-optionString true x _ := x; diff --git a/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix b/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix index b3dc5b9adb..9b106978cb 100644 --- a/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix +++ b/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix @@ -8,10 +8,9 @@ foreign ghc { -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; infixr 2 ||; || : Bool → Bool → Bool; @@ -146,10 +145,9 @@ infix 4 ==String; -------------------------------------------------------------------------------- infixr 5 ∷; -inductive List (A : Type) { - nil : List A; - ∷ : A → List A → List A; -}; +type List (A : Type) := + nil : List A + | ∷ : A → List A → List A; elem : {A : Type} → (A → A → Bool) → A → List A → Bool; elem _ _ nil := false; @@ -165,18 +163,16 @@ foldl f z (h ∷ hs) := foldl f (f z h) hs; infixr 4 ,; infixr 2 ×; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; -------------------------------------------------------------------------------- -- Maybe -------------------------------------------------------------------------------- -inductive Maybe (A : Type) { - nothing : Maybe A; +type Maybe (A : Type) := + nothing : Maybe A | just : A → Maybe A; -}; from-int : Int → Maybe Int; from-int i := if (i < Int_0) nothing (just i); diff --git a/tests/positive/Imports/A.juvix b/tests/positive/Imports/A.juvix index 9d33b702d6..20acdbbb94 100644 --- a/tests/positive/Imports/A.juvix +++ b/tests/positive/Imports/A.juvix @@ -2,9 +2,8 @@ module A; module M; module N; infix 3 t; - inductive T { + type T := t : T; - }; end ; infix 2 +; axiom + : Type → Type → Type; diff --git a/tests/positive/Inductive.juvix b/tests/positive/Inductive.juvix index 6cac40c8cf..47184e6157 100644 --- a/tests/positive/Inductive.juvix +++ b/tests/positive/Inductive.juvix @@ -1,6 +1,5 @@ module Inductive; - inductive T { - t : T; - }; + type T := t : T; + end ; diff --git a/tests/positive/Internal/AsPattern.juvix b/tests/positive/Internal/AsPattern.juvix index 9d6e69d9ae..12d127c140 100644 --- a/tests/positive/Internal/AsPattern.juvix +++ b/tests/positive/Internal/AsPattern.juvix @@ -5,10 +5,9 @@ infixr 9 ∘; ∘ {_} {B} {_} f g x := f (g x); builtin nat -inductive Nat { - zero : Nat; +type Nat := + zero : Nat | suc : Nat → Nat; -}; infixl 6 +; builtin nat-plus @@ -18,9 +17,8 @@ builtin nat-plus infixr 2 ×; infixr 4 ,; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; fst : {A : Type} → {B : Type} → (A × B) → A; fst p@(a, _) := a; diff --git a/tests/positive/Internal/Box.juvix b/tests/positive/Internal/Box.juvix index 235da4f552..7fd2c4fca4 100644 --- a/tests/positive/Internal/Box.juvix +++ b/tests/positive/Internal/Box.juvix @@ -1,12 +1,10 @@ module Box; - inductive Box (A : Type) { + type Box (A : Type) := box : A → Box A; - }; - inductive T { + type T := t : T; - }; b : Box _; b := box t; diff --git a/tests/positive/Internal/HoleInSignature.juvix b/tests/positive/Internal/HoleInSignature.juvix index 93992efcab..783df74c2f 100644 --- a/tests/positive/Internal/HoleInSignature.juvix +++ b/tests/positive/Internal/HoleInSignature.juvix @@ -1,12 +1,10 @@ module HoleInSignature; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; -inductive Bool { - true : Bool; +type Bool := + true : Bool | false : Bool; -}; p : Pair _ _; p := mkPair true false; diff --git a/tests/positive/Internal/Implicit.juvix b/tests/positive/Internal/Implicit.juvix index 2929de6fb4..ca3d8b543e 100644 --- a/tests/positive/Internal/Implicit.juvix +++ b/tests/positive/Internal/Implicit.juvix @@ -4,16 +4,14 @@ infixr 9 ∘; ∘ : {A : Type} → {B : Type} → {C : Type} → (B → C) → (A → B) → A → C; ∘ f g x := f (g x); -inductive Nat { - zero : Nat; +type Nat := + zero : Nat | suc : Nat → Nat; -}; infixr 2 ×; infixr 4 ,; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; uncurry : {A : Type} → {B : Type} → {C : Type} → (A → B → C) → A × B → C; uncurry f (a, b) := f a b; @@ -36,20 +34,18 @@ second f (a, b) := a, f b; both : {A : Type} → {B : Type} → (A → B) → A × A → B × B; both f (a, b) := f a, f b; -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; if : {A : Type} → Bool → A → A → A; if true a _ := a; if false _ b := b; infixr 5 ∷; -inductive List (A : Type) { - nil : List A; - ∷ : A → List A → List A; -}; +type List (A : Type) := + nil : List A + | ∷ : A → List A → List A; upToTwo : _; upToTwo := zero ∷ suc zero ∷ suc (suc zero) ∷ nil; @@ -57,9 +53,8 @@ upToTwo := zero ∷ suc zero ∷ suc (suc zero) ∷ nil; p1 : Nat → Nat → Nat × Nat; p1 a b := a, b ; -inductive Proxy (A : Type) { +type Proxy (A : Type) := proxy : Proxy A; -}; t2' : {A : Type} → Proxy A; t2' := proxy; diff --git a/tests/positive/Internal/Lambda.juvix b/tests/positive/Internal/Lambda.juvix index 182736181d..8d50097163 100644 --- a/tests/positive/Internal/Lambda.juvix +++ b/tests/positive/Internal/Lambda.juvix @@ -1,15 +1,13 @@ module Lambda; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; infixr 2 ×; infixr 4 ,; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; infixr 9 ∘; ∘ : {A : Type} → {B : Type} → {C : Type} → (B → C) → (A → B) → A → C; @@ -55,10 +53,9 @@ both : {A : Type} → {B : Type} → (A → B) → A × A → B × B; both {_} {B} := λ {f (a, b) := f a, f b}; infixr 5 ::; -inductive List (a : Type) { - nil : List a; - :: : a → List a → List a; -}; +type List (a : Type) := + nil : List a + | :: : a → List a → List a; map : {A : Type} → {B : Type} → (A → B) → List A → List B; map {_} := λ {f nil := nil; @@ -75,10 +72,9 @@ foldl : {A : Type} → {B : Type} → (B → A → B) → B → List A → B; foldl := λ {f z nil := z; f z (h :: hs) := foldl f (f z h) hs}; -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; if : {A : Type} → Bool → A → A → A; if := λ {true a _ := a; @@ -103,9 +99,8 @@ zipWith := λ {_ nil _ := nil; t : {A : Type} → {B : Type} → ({X : Type} → List X) → List A × List B; t := id {({X : Type} → List X) → _} λ { f := f {_} , f {_} }; -inductive Box (A : Type) { +type Box (A : Type) := b : A → Box A; -}; x : Box ((A : Type) → A → A); x := b λ {A a := a}; diff --git a/tests/positive/Internal/LiteralInt.juvix b/tests/positive/Internal/LiteralInt.juvix index 0ccc415c3e..5ed33219f2 100644 --- a/tests/positive/Internal/LiteralInt.juvix +++ b/tests/positive/Internal/LiteralInt.juvix @@ -1,12 +1,7 @@ module LiteralInt; open import Stdlib.Prelude; - inductive A { - a : A; - }; - - inductive B { - b : B; - }; + type A := a : A; + type B := b : B; f : Nat; f := 1; diff --git a/tests/positive/Internal/LiteralString.juvix b/tests/positive/Internal/LiteralString.juvix index 9df3e4ce5f..511fae0487 100644 --- a/tests/positive/Internal/LiteralString.juvix +++ b/tests/positive/Internal/LiteralString.juvix @@ -1,11 +1,9 @@ module LiteralString; - inductive A { + type A := a : A; - }; - inductive B { + type B := b : B; - }; f : A; f := "a"; diff --git a/tests/positive/Internal/Mutual.juvix b/tests/positive/Internal/Mutual.juvix index 1d064cb705..ecddd6ad7d 100644 --- a/tests/positive/Internal/Mutual.juvix +++ b/tests/positive/Internal/Mutual.juvix @@ -1,14 +1,12 @@ module Mutual; -inductive Bool { - false : Bool; - true : Bool; -}; +type Bool := + true : Bool + | false : Bool; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; not : _; not false := true; diff --git a/tests/positive/Internal/Positivity/E5.juvix b/tests/positive/Internal/Positivity/E5.juvix index b2e467f39f..df31170425 100644 --- a/tests/positive/Internal/Positivity/E5.juvix +++ b/tests/positive/Internal/Positivity/E5.juvix @@ -1,17 +1,14 @@ module E5; -inductive T0 (A : Type){ +type T0 (A : Type) := c0 : (A -> T0 A) -> T0 A; -}; axiom B : Type; -inductive T1 (A : Type) { +type T1 (A : Type) := c1 : (B -> T0 A) -> T1 A; -}; positive -inductive T2 { +type T2 := c2 : (B -> (B -> T1 T2)) -> T2; -}; end; diff --git a/tests/positive/Internal/Simple.juvix b/tests/positive/Internal/Simple.juvix index d6a1e1d57b..d1e5a14215 100644 --- a/tests/positive/Internal/Simple.juvix +++ b/tests/positive/Internal/Simple.juvix @@ -1,21 +1,18 @@ module Simple; - inductive T { + type T := tt : T; - }; someT : T; someT := tt; - inductive Bool { - false : Bool; + type Bool := + false : Bool | true : Bool; - }; - inductive Nat { - zero : Nat; + type Nat := + zero : Nat | suc : Nat → Nat; - }; infix 3 ==; == : Nat → Nat → Bool; @@ -29,10 +26,9 @@ module Simple; + (suc a) b := suc (a + b); infixr 5 ∷; - inductive List { - nil : List; + type List := + nil : List | ∷ : Nat → List → List; - }; foldr : (Nat → Nat → Nat) → Nat → List → Nat; foldr _ v nil := v; diff --git a/tests/positive/Judoc.juvix b/tests/positive/Judoc.juvix index 005e4fcfa7..785e0baf12 100644 --- a/tests/positive/Judoc.juvix +++ b/tests/positive/Judoc.juvix @@ -3,9 +3,7 @@ module Judoc; axiom A : Type; axiom b : Type; -inductive T { - -}; +type T := t : T; --- he ;id A; and ;A A id T A id; this is another ;id id id; example --- hahahah diff --git a/tests/positive/MiniC/AxiomNoCompile/Input.juvix b/tests/positive/MiniC/AxiomNoCompile/Input.juvix index 0b1092a17c..1d322bd135 100644 --- a/tests/positive/MiniC/AxiomNoCompile/Input.juvix +++ b/tests/positive/MiniC/AxiomNoCompile/Input.juvix @@ -2,9 +2,8 @@ module Input; open import Stdlib.Prelude; -inductive Unit { +type Unit := unit : Unit; -}; axiom ignore : Unit -> Unit; diff --git a/tests/positive/MiniC/Builtins/Input.juvix b/tests/positive/MiniC/Builtins/Input.juvix index c03c779700..c16502f1db 100644 --- a/tests/positive/MiniC/Builtins/Input.juvix +++ b/tests/positive/MiniC/Builtins/Input.juvix @@ -1,10 +1,9 @@ module Input; builtin bool -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; builtin bool-if if : {A : Type} → Bool → A → A → A; @@ -12,10 +11,9 @@ if true t _ := t; if false _ e := e; builtin nat -inductive ℕ { - zero : ℕ; +type ℕ := + zero : ℕ | suc : ℕ → ℕ; -}; boolToNat : Bool → ℕ; boolToNat false := zero; diff --git a/tests/positive/MiniC/ClosureEnv/Input.juvix b/tests/positive/MiniC/ClosureEnv/Input.juvix index a406c8b76c..bffe4cc6c9 100644 --- a/tests/positive/MiniC/ClosureEnv/Input.juvix +++ b/tests/positive/MiniC/ClosureEnv/Input.juvix @@ -36,10 +36,9 @@ compile plus { c ↦ "cplus"; }; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; nplus : Nat → Nat → Nat; nplus zero n := n; diff --git a/tests/positive/MiniC/ClosureNoEnv/Input.juvix b/tests/positive/MiniC/ClosureNoEnv/Input.juvix index 1c73792927..d5deee2eb4 100644 --- a/tests/positive/MiniC/ClosureNoEnv/Input.juvix +++ b/tests/positive/MiniC/ClosureNoEnv/Input.juvix @@ -44,10 +44,9 @@ compile plus { apply : (Int → Int → Int) → Int → Int → Int; apply f a b := f a b; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; plus-nat : Nat → Nat → Nat; plus-nat zero n := n; diff --git a/tests/positive/MiniC/HigherOrder/Input.juvix b/tests/positive/MiniC/HigherOrder/Input.juvix index 83bff1752b..6635e1f9d0 100644 --- a/tests/positive/MiniC/HigherOrder/Input.juvix +++ b/tests/positive/MiniC/HigherOrder/Input.juvix @@ -89,10 +89,9 @@ compile to-str { -- Natural Numbers -------------------------------------------------------------------------------- -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; infixl 6 +; + : Nat → Nat → Nat; @@ -119,10 +118,9 @@ three := suc two; -- Lists -------------------------------------------------------------------------------- -inductive ListNat { - null : ListNat; +type ListNat := + null : ListNat | cons : Nat → ListNat → ListNat; -}; foldl : (Nat → Nat → Nat) → Nat → ListNat → Nat; foldl _ z null := z; diff --git a/tests/positive/MiniC/Lib/Data/Bool.juvix b/tests/positive/MiniC/Lib/Data/Bool.juvix index 6e278857ba..77a5fec3bb 100644 --- a/tests/positive/MiniC/Lib/Data/Bool.juvix +++ b/tests/positive/MiniC/Lib/Data/Bool.juvix @@ -2,10 +2,9 @@ module Data.Bool; open import Data.String; -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; not : Bool → Bool; not true := false; diff --git a/tests/positive/MiniC/Lib/Data/Nat.juvix b/tests/positive/MiniC/Lib/Data/Nat.juvix index e6b1f3a19b..538f0d0310 100644 --- a/tests/positive/MiniC/Lib/Data/Nat.juvix +++ b/tests/positive/MiniC/Lib/Data/Nat.juvix @@ -3,10 +3,9 @@ module Data.Nat; open import Data.String; open import Data.Int; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; foreign c { void* natInd(int n, void* zeroCtor, juvix_function_t* sucCtor) { diff --git a/tests/positive/MiniC/Lib/Data/Pair.juvix b/tests/positive/MiniC/Lib/Data/Pair.juvix index ea6b70192e..ecb48dca1f 100644 --- a/tests/positive/MiniC/Lib/Data/Pair.juvix +++ b/tests/positive/MiniC/Lib/Data/Pair.juvix @@ -1,8 +1,7 @@ module Data.Pair; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; fst : (A : Type) → (B : Type) → Pair A B → A; fst _ _ (mkPair a b) := a; diff --git a/tests/positive/MiniC/MultiModules/Data/Bool.juvix b/tests/positive/MiniC/MultiModules/Data/Bool.juvix index 6e278857ba..77a5fec3bb 100644 --- a/tests/positive/MiniC/MultiModules/Data/Bool.juvix +++ b/tests/positive/MiniC/MultiModules/Data/Bool.juvix @@ -2,10 +2,9 @@ module Data.Bool; open import Data.String; -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; not : Bool → Bool; not true := false; diff --git a/tests/positive/MiniC/MultiModules/Data/Nat.juvix b/tests/positive/MiniC/MultiModules/Data/Nat.juvix index b660df69ff..f7135d2a97 100644 --- a/tests/positive/MiniC/MultiModules/Data/Nat.juvix +++ b/tests/positive/MiniC/MultiModules/Data/Nat.juvix @@ -3,10 +3,9 @@ module Data.Nat; open import Data.String; open import Data.Int; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; foreign c { void* natInd(int n, void* zeroCtor, juvix_function_t* sucCtor) { diff --git a/tests/positive/MiniC/MultiModules/Data/Pair.juvix b/tests/positive/MiniC/MultiModules/Data/Pair.juvix index ea6b70192e..ecb48dca1f 100644 --- a/tests/positive/MiniC/MultiModules/Data/Pair.juvix +++ b/tests/positive/MiniC/MultiModules/Data/Pair.juvix @@ -1,8 +1,7 @@ module Data.Pair; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; fst : (A : Type) → (B : Type) → Pair A B → A; fst _ _ (mkPair a b) := a; diff --git a/tests/positive/MiniC/MutuallyRecursive/Data/Bool.juvix b/tests/positive/MiniC/MutuallyRecursive/Data/Bool.juvix index 6e278857ba..77a5fec3bb 100644 --- a/tests/positive/MiniC/MutuallyRecursive/Data/Bool.juvix +++ b/tests/positive/MiniC/MutuallyRecursive/Data/Bool.juvix @@ -2,10 +2,9 @@ module Data.Bool; open import Data.String; -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; not : Bool → Bool; not true := false; diff --git a/tests/positive/MiniC/MutuallyRecursive/Data/Nat.juvix b/tests/positive/MiniC/MutuallyRecursive/Data/Nat.juvix index b660df69ff..f7135d2a97 100644 --- a/tests/positive/MiniC/MutuallyRecursive/Data/Nat.juvix +++ b/tests/positive/MiniC/MutuallyRecursive/Data/Nat.juvix @@ -3,10 +3,9 @@ module Data.Nat; open import Data.String; open import Data.Int; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; foreign c { void* natInd(int n, void* zeroCtor, juvix_function_t* sucCtor) { diff --git a/tests/positive/MiniC/MutuallyRecursive/Data/Pair.juvix b/tests/positive/MiniC/MutuallyRecursive/Data/Pair.juvix index ea6b70192e..ecb48dca1f 100644 --- a/tests/positive/MiniC/MutuallyRecursive/Data/Pair.juvix +++ b/tests/positive/MiniC/MutuallyRecursive/Data/Pair.juvix @@ -1,8 +1,7 @@ module Data.Pair; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; fst : (A : Type) → (B : Type) → Pair A B → A; fst _ _ (mkPair a b) := a; diff --git a/tests/positive/MiniC/Nat/Input.juvix b/tests/positive/MiniC/Nat/Input.juvix index a0ca312f84..1b6727b506 100644 --- a/tests/positive/MiniC/Nat/Input.juvix +++ b/tests/positive/MiniC/Nat/Input.juvix @@ -4,10 +4,9 @@ module Input; -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; -------------------------------------------------------------------------------- -- Strings @@ -108,10 +107,9 @@ compile to-str { -- Natural Numbers -------------------------------------------------------------------------------- -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; infixl 6 +; + : Nat → Nat → Nat; diff --git a/tests/positive/MiniC/NestedList/Input.juvix b/tests/positive/MiniC/NestedList/Input.juvix index 8be7b1b1d6..1880faedc2 100644 --- a/tests/positive/MiniC/NestedList/Input.juvix +++ b/tests/positive/MiniC/NestedList/Input.juvix @@ -3,14 +3,12 @@ module Input; open import Data.IO; infixr 5 ∷; -inductive List (A : Type) { - nil : List A; - ∷ : A → List A → List A; -}; +type List (A : Type) := + nil : List A + | ∷ : A → List A → List A; -inductive Foo { +type Foo := a : Foo; -}; l : List (List Foo) → List (List Foo); l ((_ ∷ nil) ∷ nil) := nil ∷ nil; diff --git a/tests/positive/MiniC/PolymorphicAxioms/Input.juvix b/tests/positive/MiniC/PolymorphicAxioms/Input.juvix index d3b43404ec..99ac159e85 100644 --- a/tests/positive/MiniC/PolymorphicAxioms/Input.juvix +++ b/tests/positive/MiniC/PolymorphicAxioms/Input.juvix @@ -1,8 +1,7 @@ module Input; -inductive Unit { +type Unit := unit : Unit; -}; axiom Action : Type; diff --git a/tests/positive/MiniC/PolymorphicTarget/Input.juvix b/tests/positive/MiniC/PolymorphicTarget/Input.juvix index 858a4eb1d6..1bc2814c1e 100644 --- a/tests/positive/MiniC/PolymorphicTarget/Input.juvix +++ b/tests/positive/MiniC/PolymorphicTarget/Input.juvix @@ -1,8 +1,7 @@ module Input; -inductive Unit { +type Unit := unit : Unit; -}; terminating loop : {A : Type} -> A; diff --git a/tests/positive/MiniC/Polymorphism/Input.juvix b/tests/positive/MiniC/Polymorphism/Input.juvix index cf151bcd5d..e988cef834 100644 --- a/tests/positive/MiniC/Polymorphism/Input.juvix +++ b/tests/positive/MiniC/Polymorphism/Input.juvix @@ -4,10 +4,9 @@ module Input; -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; -------------------------------------------------------------------------------- -- Strings @@ -65,9 +64,8 @@ bool-to-str false := "False"; infixr 2 ×; infixr 4 ,; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; fst : {A : Type} → {B : Type} → A × B → A; fst (a, b) := a; diff --git a/tests/positive/MiniC/PolymorphismHoles/Input.juvix b/tests/positive/MiniC/PolymorphismHoles/Input.juvix index 84959c5e2b..c352ad5aef 100644 --- a/tests/positive/MiniC/PolymorphismHoles/Input.juvix +++ b/tests/positive/MiniC/PolymorphismHoles/Input.juvix @@ -4,10 +4,9 @@ module Input; -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; -------------------------------------------------------------------------------- -- Strings @@ -68,9 +67,8 @@ bool-to-str false := "False"; -- Pair -------------------------------------------------------------------------------- -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; fst : {A : Type} → {B : Type} → Pair A B → A; fst (mkPair a b) := a; diff --git a/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix b/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix index 80f767aaaf..30717eb10e 100644 --- a/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix +++ b/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix @@ -30,10 +30,9 @@ foreign c { -- Booleans -------------------------------------------------------------------------------- -inductive Bool { - true : Bool; - false : Bool; -}; +type Bool := + true : Bool + | false : Bool; infixr 2 ||; || : Bool → Bool → Bool; @@ -189,10 +188,9 @@ infix 4 ==String; -------------------------------------------------------------------------------- infixr 5 ∷; -inductive List (A : Type) { - nil : List A; - ∷ : A → List A → List A; -}; +type List (A : Type) := + nil : List A + | ∷ : A → List A → List A; elem : {A : Type} → (A → A → Bool) → A → List A → Bool; elem _ _ nil := false; @@ -208,18 +206,16 @@ foldl f z (h ∷ hs) := foldl f (f z h) hs; infixr 4 ,; infixr 2 ×; -inductive × (A : Type) (B : Type) { +type × (A : Type) (B : Type) := , : A → B → A × B; -}; -------------------------------------------------------------------------------- -- Maybe -------------------------------------------------------------------------------- -inductive Maybe (A : Type) { - nothing : Maybe A; +type Maybe (A : Type) := + nothing : Maybe A | just : A → Maybe A; -}; from-int : Int → Maybe Int; from-int i := if (isNegative i) nothing (just i); diff --git a/tests/positive/MiniHaskell/HelloWorld.juvix b/tests/positive/MiniHaskell/HelloWorld.juvix index 2973f53c9a..fcf5d249e0 100644 --- a/tests/positive/MiniHaskell/HelloWorld.juvix +++ b/tests/positive/MiniHaskell/HelloWorld.juvix @@ -1,14 +1,12 @@ module HelloWorld; -inductive ℕ { - zero : ℕ; +type ℕ := + zero : ℕ | suc : ℕ → ℕ; -}; -inductive V { - zeroV : V; +type V := + zeroV : V | sucV : V; -}; infixl 6 +; diff --git a/tests/positive/Polymorphism.juvix b/tests/positive/Polymorphism.juvix index 25140eea92..9260be97f6 100644 --- a/tests/positive/Polymorphism.juvix +++ b/tests/positive/Polymorphism.juvix @@ -1,23 +1,19 @@ module Polymorphism; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; -inductive Nat { - zero : Nat; +type Nat := + zero : Nat | suc : Nat → Nat; -}; -inductive List (A : Type) { - nil : List A; +type List (A : Type) := + nil : List A | cons : A → List A → List A; -}; -inductive Bool { - false : Bool; +type Bool := + false : Bool | true : Bool; -}; id : (A : Type) → A → A; id _ a := a; diff --git a/tests/positive/PolymorphismHoles.juvix b/tests/positive/PolymorphismHoles.juvix index af118f8806..698f081266 100644 --- a/tests/positive/PolymorphismHoles.juvix +++ b/tests/positive/PolymorphismHoles.juvix @@ -1,23 +1,19 @@ module PolymorphismHoles; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : A → B → Pair A B; -}; -inductive Nat { - zero : Nat; +type Nat := + zero : Nat | suc : Nat → Nat; -}; -inductive List (A : Type) { - nil : List A; +type List (A : Type) := + nil : List A | cons : A → List A → List A; -}; -inductive Bool { - false : Bool; +type Bool := + false : Bool | true : Bool; -}; id : (A : Type) → A → A; id _ a := a; diff --git a/tests/positive/QualifiedConstructor/M.juvix b/tests/positive/QualifiedConstructor/M.juvix index e45782fffa..4a165d3250 100644 --- a/tests/positive/QualifiedConstructor/M.juvix +++ b/tests/positive/QualifiedConstructor/M.juvix @@ -8,9 +8,8 @@ module M; module N; module O; - inductive T { + type T := A : T; - }; end; end; diff --git a/tests/positive/Reachability/Data/Bool.juvix b/tests/positive/Reachability/Data/Bool.juvix index c3acdbbdeb..e39140726e 100644 --- a/tests/positive/Reachability/Data/Bool.juvix +++ b/tests/positive/Reachability/Data/Bool.juvix @@ -1,8 +1,7 @@ module Data.Bool; - inductive Bool { - true : Bool; + type Bool := + true : Bool | false : Bool; - }; not : Bool → Bool; not true := false; diff --git a/tests/positive/Reachability/Data/Maybe.juvix b/tests/positive/Reachability/Data/Maybe.juvix index 384bbc003c..b9d56ca6cf 100644 --- a/tests/positive/Reachability/Data/Maybe.juvix +++ b/tests/positive/Reachability/Data/Maybe.juvix @@ -1,8 +1,7 @@ module Data.Maybe; - inductive Maybe (a : Type) { - nothing : Maybe a; + type Maybe (a : Type) := + nothing : Maybe a | just : a → Maybe a; - } end; diff --git a/tests/positive/Reachability/Data/Nat.juvix b/tests/positive/Reachability/Data/Nat.juvix index ed72021442..5329c45739 100644 --- a/tests/positive/Reachability/Data/Nat.juvix +++ b/tests/positive/Reachability/Data/Nat.juvix @@ -1,8 +1,7 @@ module Data.Nat; - inductive ℕ { - zero : ℕ; + type ℕ := + zero : ℕ | suc : ℕ → ℕ; - }; infixl 6 +; + : ℕ → ℕ → ℕ; diff --git a/tests/positive/Reachability/Data/Ord.juvix b/tests/positive/Reachability/Data/Ord.juvix index dd85147ef8..af1348f035 100644 --- a/tests/positive/Reachability/Data/Ord.juvix +++ b/tests/positive/Reachability/Data/Ord.juvix @@ -1,7 +1,6 @@ module Data.Ord; - inductive Ordering { - LT : Ordering; - EQ : Ordering; + type Ordering := + LT : Ordering | + EQ : Ordering | GT : Ordering; - }; end; diff --git a/tests/positive/Reachability/Data/Product.juvix b/tests/positive/Reachability/Data/Product.juvix index 99ffc1d515..ee03a6d7cc 100644 --- a/tests/positive/Reachability/Data/Product.juvix +++ b/tests/positive/Reachability/Data/Product.juvix @@ -1,8 +1,7 @@ module Data.Product; infixr 2 ×; -inductive × (a : Type) (b : Type) { +type × (a : Type) (b : Type) := , : a → b → a × b; -}; end; diff --git a/tests/positive/Reachability/N.juvix b/tests/positive/Reachability/N.juvix index e7b5925b20..4f356360d0 100644 --- a/tests/positive/Reachability/N.juvix +++ b/tests/positive/Reachability/N.juvix @@ -6,8 +6,7 @@ open import Stdlib.Prelude; test : {A : Type} -> A -> A; test x := x; -inductive Unit { +type Unit := unit : Unit; -}; end; diff --git a/tests/positive/StdlibImport/A.juvix b/tests/positive/StdlibImport/A.juvix index 1f1feca541..6b90fe3bcf 100644 --- a/tests/positive/StdlibImport/A.juvix +++ b/tests/positive/StdlibImport/A.juvix @@ -1,7 +1,5 @@ module A; -inductive Foo { - bar : Foo; -}; +type Foo := bar : Foo; end; diff --git a/tests/positive/StdlibList/Data/Bool.juvix b/tests/positive/StdlibList/Data/Bool.juvix index c3acdbbdeb..e39140726e 100644 --- a/tests/positive/StdlibList/Data/Bool.juvix +++ b/tests/positive/StdlibList/Data/Bool.juvix @@ -1,8 +1,7 @@ module Data.Bool; - inductive Bool { - true : Bool; + type Bool := + true : Bool | false : Bool; - }; not : Bool → Bool; not true := false; diff --git a/tests/positive/StdlibList/Data/List.juvix b/tests/positive/StdlibList/Data/List.juvix index b9dffc93dc..93f698e8fb 100644 --- a/tests/positive/StdlibList/Data/List.juvix +++ b/tests/positive/StdlibList/Data/List.juvix @@ -4,10 +4,9 @@ import Data.Bool; open Data.Bool; -- infixr 5 ∷; waiting for implicit arguments -inductive List (a : Type) { - nil : List a; - ∷ : a → List a → List a; -}; +type List (A : Type) := + nil : List A + | ∷ : A → List A → List A; match : {A : Type} → {B : Type} → A → (A → B) → B; match x f := f x; diff --git a/tests/positive/StdlibList/Data/Maybe.juvix b/tests/positive/StdlibList/Data/Maybe.juvix index 384bbc003c..b9d56ca6cf 100644 --- a/tests/positive/StdlibList/Data/Maybe.juvix +++ b/tests/positive/StdlibList/Data/Maybe.juvix @@ -1,8 +1,7 @@ module Data.Maybe; - inductive Maybe (a : Type) { - nothing : Maybe a; + type Maybe (a : Type) := + nothing : Maybe a | just : a → Maybe a; - } end; diff --git a/tests/positive/StdlibList/Data/Nat.juvix b/tests/positive/StdlibList/Data/Nat.juvix index ed72021442..5329c45739 100644 --- a/tests/positive/StdlibList/Data/Nat.juvix +++ b/tests/positive/StdlibList/Data/Nat.juvix @@ -1,8 +1,7 @@ module Data.Nat; - inductive ℕ { - zero : ℕ; + type ℕ := + zero : ℕ | suc : ℕ → ℕ; - }; infixl 6 +; + : ℕ → ℕ → ℕ; diff --git a/tests/positive/StdlibList/Data/Ord.juvix b/tests/positive/StdlibList/Data/Ord.juvix index dd85147ef8..af1348f035 100644 --- a/tests/positive/StdlibList/Data/Ord.juvix +++ b/tests/positive/StdlibList/Data/Ord.juvix @@ -1,7 +1,6 @@ module Data.Ord; - inductive Ordering { - LT : Ordering; - EQ : Ordering; + type Ordering := + LT : Ordering | + EQ : Ordering | GT : Ordering; - }; end; diff --git a/tests/positive/StdlibList/Data/Product.juvix b/tests/positive/StdlibList/Data/Product.juvix index 9e6b8b76fe..9baa49dccc 100644 --- a/tests/positive/StdlibList/Data/Product.juvix +++ b/tests/positive/StdlibList/Data/Product.juvix @@ -2,8 +2,7 @@ module Data.Product; infixr 2 ×; -- infixr 4 ,; waiting for implicit arguments -inductive × (a : Type) (b : Type) { +type × (a : Type) (b : Type) := , : a → b → a × b; -}; end; diff --git a/tests/positive/Termination/Data/Bool.juvix b/tests/positive/Termination/Data/Bool.juvix index 914c42b1e1..9855143c73 100644 --- a/tests/positive/Termination/Data/Bool.juvix +++ b/tests/positive/Termination/Data/Bool.juvix @@ -1,8 +1,7 @@ module Data.Bool; - inductive Bool { - true : Bool; + type Bool := + true : Bool | false : Bool; - }; not : Bool → Bool; not true := false; diff --git a/tests/positive/Termination/Data/List.juvix b/tests/positive/Termination/Data/List.juvix index ba71c5125c..e91a1c4670 100644 --- a/tests/positive/Termination/Data/List.juvix +++ b/tests/positive/Termination/Data/List.juvix @@ -6,10 +6,9 @@ open Data.Bool; import Data.Nat; open Data.Nat; -inductive List (A : Type) { - nil : List A; +type List (A : Type) := + nil : List A | cons : A → List A → List A; -}; -- Do not remove implicit arguments. Useful for testing. foldr : {A : Type} → {B : Type} → (A → B → B) → B → List A → B; diff --git a/tests/positive/Termination/Data/Nat.juvix b/tests/positive/Termination/Data/Nat.juvix index 991df50bd5..7f888023f0 100644 --- a/tests/positive/Termination/Data/Nat.juvix +++ b/tests/positive/Termination/Data/Nat.juvix @@ -1,8 +1,7 @@ module Data.Nat; - inductive ℕ { - zero : ℕ; + type ℕ := + zero : ℕ | suc : ℕ → ℕ; - }; infixl 6 +; + : ℕ → ℕ → ℕ; diff --git a/tests/positive/Termination/Fib.juvix b/tests/positive/Termination/Fib.juvix index a05359b940..f0cae81a95 100644 --- a/tests/positive/Termination/Fib.juvix +++ b/tests/positive/Termination/Fib.juvix @@ -1,9 +1,8 @@ module Fib; -inductive Nat { - zero : Nat; - suc : Nat → Nat; -}; +type Nat := + zero : Nat + | suc : Nat → Nat; infixl 6 +; + : Nat → Nat → Nat; diff --git a/tests/positive/Termination/ToEmpty.juvix b/tests/positive/Termination/ToEmpty.juvix deleted file mode 100644 index 4d00971a13..0000000000 --- a/tests/positive/Termination/ToEmpty.juvix +++ /dev/null @@ -1,7 +0,0 @@ -module ToEmpty; - axiom A : Type; - inductive Empty {}; - terminating - f : A -> Empty; - f x := f x; -end; diff --git a/tests/positive/TypeAlias.juvix b/tests/positive/TypeAlias.juvix index 9312aad706..8c246fcf52 100644 --- a/tests/positive/TypeAlias.juvix +++ b/tests/positive/TypeAlias.juvix @@ -1,12 +1,10 @@ module TypeAlias; -inductive T { +type T := t : T; -}; -inductive T2 { +type T2 := t2 : T2; -}; alias : Type; alias := T; @@ -27,9 +25,8 @@ x2 := t; flip : (Type → Type → Type) → id Type → Type → (id ⊙ id) Type; flip f a b := f b a; -inductive Pair (A : Type) (B : Type) { +type Pair (A : Type) (B : Type) := mkPair : id T → id (id A) → B → Pair A B; -}; p : {A : Type} → A → Pair A A; p a := mkPair t a a; diff --git a/tests/positive/issue1333/M.juvix b/tests/positive/issue1333/M.juvix index 8b0bc5f396..6753eb8ad8 100644 --- a/tests/positive/issue1333/M.juvix +++ b/tests/positive/issue1333/M.juvix @@ -1,7 +1,6 @@ module M; -inductive T (A : Type) { +type T (A : Type) := c : T _; -}; end; diff --git a/tests/positive/issue1466/M.juvix b/tests/positive/issue1466/M.juvix index 0d4151af27..c783fd14a0 100644 --- a/tests/positive/issue1466/M.juvix +++ b/tests/positive/issue1466/M.juvix @@ -1,9 +1,8 @@ module M; -inductive ℕ { - z : ℕ; +type ℕ := + z : ℕ | s : ℕ → ℕ; -}; nat : Type; nat := ℕ; From 3d690c21ce7df96e1f9e06003dc731871a8a0c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czajka?= <62751+lukaszcz@users.noreply.github.com> Date: Tue, 3 Jan 2023 14:37:19 +0100 Subject: [PATCH 28/34] Remove unicode cons symbol (#1687) --- .../validity-predicates/PolyFungibleToken.org | 12 ++--- .../inductive-data-types.org | 6 +-- examples/milestone/Hanoi/Hanoi.juvix | 4 +- .../PascalsTriangle/PascalsTriangle.juvix | 8 ++-- .../milestone/TicTacToe/Logic/Board.juvix | 8 ++-- .../milestone/TicTacToe/Logic/Extra.juvix | 4 +- .../milestone/TicTacToe/Logic/GameState.juvix | 2 +- .../milestone/TicTacToe/Web/TicTacToe.juvix | 4 +- .../milestone/ValidityPredicates/Tests.juvix | 4 +- juvix-stdlib | 2 +- tests/Internal/positive/Lambda.juvix | 4 +- tests/Internal/positive/LitInteger.juvix | 2 +- tests/Internal/positive/QuickSort.juvix | 14 +++--- tests/Internal/positive/out/QuickSort.out | 2 +- tests/benchmark/fold/juvix/fold.juvix | 2 +- tests/benchmark/mapfold/juvix/mapfold.juvix | 4 +- tests/benchmark/mapfun/juvix/mapfun.juvix | 12 ++--- .../benchmark/mergesort/juvix/mergesort.juvix | 18 ++++---- tests/benchmark/prime/juvix/prime.juvix | 4 +- .../SimpleFungibleTokenImplicit.juvix | 12 ++--- tests/positive/Internal/Implicit.juvix | 18 ++++---- tests/positive/Internal/Simple.juvix | 6 +-- tests/positive/MiniC/NestedList/Input.juvix | 6 +-- .../SimpleFungibleTokenImplicit/Input.juvix | 12 ++--- tests/positive/StdlibList/Data/List.juvix | 46 +++++++++---------- 25 files changed, 108 insertions(+), 108 deletions(-) diff --git a/docs/org/examples/validity-predicates/PolyFungibleToken.org b/docs/org/examples/validity-predicates/PolyFungibleToken.org index 0e5f435552..4f7f4d85eb 100644 --- a/docs/org/examples/validity-predicates/PolyFungibleToken.org +++ b/docs/org/examples/validity-predicates/PolyFungibleToken.org @@ -137,18 +137,18 @@ infix 4 ==String; -- Lists -------------------------------------------------------------------------------- -infixr 5 ∷; +infixr 5 ::; type List (A : Type) := nil : List A - | ∷ : A → List A → List A; + | :: : A → List A → List A; elem : {A : Type} → (A → A → Bool) → A → List A → Bool; elem _ _ nil := false; -elem eq s (x ∷ xs) := eq s x || elem eq s xs; +elem eq s (x :: xs) := eq s x || elem eq s xs; foldl : {A : Type} → {B : Type} → (B → A → B) → B → List A → B; foldl f z nil := z; -foldl f z (h ∷ hs) := foldl f (f z h) hs; +foldl f z (h :: hs) := foldl f (f z h) hs; -------------------------------------------------------------------------------- -- Pair @@ -290,10 +290,10 @@ change2-key : String; change2-key := "change2-key"; verifiers : List String; -verifiers := owner-address ∷ nil; +verifiers := owner-address :: nil; keys-changed : List String; -keys-changed := change1-key ∷ change2-key ∷ nil; +keys-changed := change1-key :: change2-key :: nil; main : Action; main := diff --git a/docs/org/language-reference/inductive-data-types.org b/docs/org/language-reference/inductive-data-types.org index 53f8403d04..893b379cb9 100755 --- a/docs/org/language-reference/inductive-data-types.org +++ b/docs/org/language-reference/inductive-data-types.org @@ -42,14 +42,14 @@ the list, we usually called it =cons=. One possible definition for this type is the following type taken from the Juvix standard library: #+begin_example -infixr 5 ∷; +infixr 5 ::; type List (A : Type) := nil : List A - | ∷ : A -> List A -> List A; + | :: : A -> List A -> List A; elem : {A : Type} -> (A -> A -> Bool) -> A -> List A -> Bool; elem _ _ nil := false; -elem eq s (x ∷ xs) := eq s x || elem eq s xs; +elem eq s (x :: xs) := eq s x || elem eq s xs; #+end_example To see more examples of inductive types and how to use them, please check out diff --git a/examples/milestone/Hanoi/Hanoi.juvix b/examples/milestone/Hanoi/Hanoi.juvix index fd0032b638..e55e30e1d5 100644 --- a/examples/milestone/Hanoi/Hanoi.juvix +++ b/examples/milestone/Hanoi/Hanoi.juvix @@ -23,7 +23,7 @@ compile ++str { --- Concatenates a list of strings --- ---- ;concat (("a" ∷ nil) ∷ ("b" ∷ nil)); evaluates to ;"a" ∷ "b" ∷ nil; +--- ;concat (("a" :: nil) :: ("b" :: nil)); evaluates to ;"a" :: "b" :: nil; concat : List String → String; concat := foldl (++str) ""; @@ -36,7 +36,7 @@ unlines := intercalate "\n"; --- Produce a singleton List singleton : {A : Type} → A → List A; -singleton a := a ∷ nil; +singleton a := a :: nil; --- Produce a ;String; representation of a ;List Nat; showList : List Nat → String; diff --git a/examples/milestone/PascalsTriangle/PascalsTriangle.juvix b/examples/milestone/PascalsTriangle/PascalsTriangle.juvix index 7d65af56b3..131e7f9b89 100644 --- a/examples/milestone/PascalsTriangle/PascalsTriangle.juvix +++ b/examples/milestone/PascalsTriangle/PascalsTriangle.juvix @@ -12,16 +12,16 @@ open import Stdlib.Prelude; zipWith : {A : Type} → {B : Type} → {C : Type} → (A → B → C) -> List A → List B → List C; zipWith f nil _ := nil; zipWith f _ nil := nil; -zipWith f (x ∷ xs) (y ∷ ys) := f x y ∷ zipWith f xs ys; +zipWith f (x :: xs) (y :: ys) := f x y :: zipWith f xs ys; --- Return a list of repeated applications of a given function iterate : {A : Type} → Nat → (A → A) → A → List A; iterate zero _ _ := nil; -iterate (suc n) f a := a ∷ iterate n f (f a); +iterate (suc n) f a := a :: iterate n f (f a); --- Produce a singleton List singleton : {A : Type} → A → List A; -singleton a := a ∷ nil; +singleton a := a :: nil; --- Concatenation of ;String;s infixr 5 ++str; @@ -32,7 +32,7 @@ compile ++str { --- Concatenates a list of strings --- ---- ;concat (("a" ∷ nil) ∷ ("b" ∷ nil)); evaluates to ;"a" ∷ "b" ∷ nil; +--- ;concat (("a" :: nil) :: ("b" :: nil)); evaluates to ;"a" :: "b" :: nil; concat : List String → String; concat := foldl (++str) ""; diff --git a/examples/milestone/TicTacToe/Logic/Board.juvix b/examples/milestone/TicTacToe/Logic/Board.juvix index 725481bec3..5e21b89948 100644 --- a/examples/milestone/TicTacToe/Logic/Board.juvix +++ b/examples/milestone/TicTacToe/Logic/Board.juvix @@ -12,15 +12,15 @@ type Board := --- Returns the list of numbers corresponding to the empty ;Square;s possibleMoves : List Square → List Nat; possibleMoves nil := nil; -possibleMoves ((empty n) ∷ xs) := n ∷ possibleMoves xs; -possibleMoves (_ ∷ xs) := possibleMoves xs; +possibleMoves ((empty n) :: xs) := n :: possibleMoves xs; +possibleMoves (_ :: xs) := possibleMoves xs; --- ;true; if all the ;Square;s in the list are equal full : List Square → Bool; -full (a ∷ b ∷ c ∷ nil) := (==Square a b) && (==Square b c); +full (a :: b :: c :: nil) := (==Square a b) && (==Square b c); diagonals : List (List Square) → List (List Square); -diagonals ((a1 ∷ _ ∷ b1 ∷ nil) ∷ (_ ∷ c ∷ _ ∷ nil) ∷ (b2 ∷ _ ∷ a2 ∷ nil) ∷ nil) := (a1 ∷ c ∷ a2 ∷ nil) ∷ (b1 ∷ c ∷ b2 ∷ nil) ∷ nil; +diagonals ((a1 :: _ :: b1 :: nil) :: (_ :: c :: _ :: nil) :: (b2 :: _ :: a2 :: nil) :: nil) := (a1 :: c :: a2 :: nil) :: (b1 :: c :: b2 :: nil) :: nil; columns : List (List Square) → List (List Square); columns := transpose; diff --git a/examples/milestone/TicTacToe/Logic/Extra.juvix b/examples/milestone/TicTacToe/Logic/Extra.juvix index fb91faa74f..d8329cbe4a 100644 --- a/examples/milestone/TicTacToe/Logic/Extra.juvix +++ b/examples/milestone/TicTacToe/Logic/Extra.juvix @@ -13,13 +13,13 @@ compile ++str { --- Concatenates a list of strings --- ---- ;concat (("a" ∷ nil) ∷ ("b" ∷ nil)); evaluates to ;"a" ∷ "b" ∷ nil; +--- ;concat (("a" :: nil) :: ("b" :: nil)); evaluates to ;"a" :: "b" :: nil; concat : List String → String; concat := foldl (++str) ""; --- It inserts the first ;String; at the beginning, in between, and at the end of the second list surround : String → List String → List String; -surround x xs := (x ∷ intersperse x xs) ++ (x ∷ nil); +surround x xs := (x :: intersperse x xs) ++ (x :: nil); --- It inserts the first ;String; in between the ;String;s in the second list and concatenates the result intercalate : String → List String → String; diff --git a/examples/milestone/TicTacToe/Logic/GameState.juvix b/examples/milestone/TicTacToe/Logic/GameState.juvix index 21d5eb1fff..1a16490f5d 100644 --- a/examples/milestone/TicTacToe/Logic/GameState.juvix +++ b/examples/milestone/TicTacToe/Logic/GameState.juvix @@ -26,7 +26,7 @@ player (state _ p _) := p; --- initial ;GameState; beginState : GameState; beginState := state - (board (map (map empty) ((one ∷ two ∷ three ∷ nil) ∷ (four ∷ five ∷ six ∷ nil) ∷ (seven ∷ eight ∷ nine ∷ nil) ∷ nil))) + (board (map (map empty) ((one :: two :: three :: nil) :: (four :: five :: six :: nil) :: (seven :: eight :: nine :: nil) :: nil))) X noError; diff --git a/examples/milestone/TicTacToe/Web/TicTacToe.juvix b/examples/milestone/TicTacToe/Web/TicTacToe.juvix index 07d8c3290d..f8c1d7ed1d 100644 --- a/examples/milestone/TicTacToe/Web/TicTacToe.juvix +++ b/examples/milestone/TicTacToe/Web/TicTacToe.juvix @@ -52,12 +52,12 @@ mapIO f xs := sequenceIO (map f xs); -- List extensions zip : {A : Type} → {B : Type} → List A → List B → List (A × B); -zip (a ∷ as) (b ∷ bs) := (a, b) ∷ zip as bs; +zip (a :: as) (b :: bs) := (a, b) :: zip as bs; zip _ _ := nil; rangeAux : Nat → Nat → List Nat; rangeAux _ zero := nil; -rangeAux m (suc n) := m ∷ rangeAux (suc m) n; +rangeAux m (suc n) := m :: rangeAux (suc m) n; range : Nat → List Nat; range n := rangeAux zero n; diff --git a/examples/milestone/ValidityPredicates/Tests.juvix b/examples/milestone/ValidityPredicates/Tests.juvix index 8a8008b427..0fb2d478b2 100644 --- a/examples/milestone/ValidityPredicates/Tests.juvix +++ b/examples/milestone/ValidityPredicates/Tests.juvix @@ -20,10 +20,10 @@ change2-key : String; change2-key := "change2-key"; verifiers : List String; -verifiers := owner-address ∷ nil; +verifiers := owner-address :: nil; keys-changed : List String; -keys-changed := change1-key ∷ change2-key ∷ nil; +keys-changed := change1-key :: change2-key :: nil; show-result : Bool → String; show-result true := "OK"; diff --git a/juvix-stdlib b/juvix-stdlib index bdcf1ef088..2d862670db 160000 --- a/juvix-stdlib +++ b/juvix-stdlib @@ -1 +1 @@ -Subproject commit bdcf1ef0889a08de1ec334a598efbbf622607884 +Subproject commit 2d862670db8af9d357f05a8109ee2140bd3d6a37 diff --git a/tests/Internal/positive/Lambda.juvix b/tests/Internal/positive/Lambda.juvix index 9661e32c74..95d3d08e98 100644 --- a/tests/Internal/positive/Lambda.juvix +++ b/tests/Internal/positive/Lambda.juvix @@ -16,13 +16,13 @@ first' := λ {f (a, b) := f a, b}; foldr' : {A : Type} → {B : Type} → (A → B → B) → B → List A → B; foldr' := λ {_ z nil := z; - f z (h ∷ hs) := f h (foldr' f z hs)}; + f z (h :: hs) := f h (foldr' f z hs)}; main : IO; main := printNatLn (id' zero) >> printNatLn (uncurry' (+) (one, one)) >> printNatLn (fst' (zero, one)) >> printNatLn (fst (first' ((+) one) (one, zero))) - >> printNatLn (foldr' (+) zero (one ∷ two ∷ three ∷ nil)); + >> printNatLn (foldr' (+) zero (one :: two :: three :: nil)); end; diff --git a/tests/Internal/positive/LitInteger.juvix b/tests/Internal/positive/LitInteger.juvix index 78d50d039e..5b3cc87fed 100644 --- a/tests/Internal/positive/LitInteger.juvix +++ b/tests/Internal/positive/LitInteger.juvix @@ -9,6 +9,6 @@ nilNat : List Nat; nilNat := nil; cons : Nat -> List Nat -> List Nat; -cons a xs := a ∷ xs; +cons a xs := a :: xs; end; diff --git a/tests/Internal/positive/QuickSort.juvix b/tests/Internal/positive/QuickSort.juvix index ee896d3e24..c4a2c1f78b 100644 --- a/tests/Internal/positive/QuickSort.juvix +++ b/tests/Internal/positive/QuickSort.juvix @@ -5,27 +5,27 @@ open import Stdlib.Data.Nat.Ord public; open import Stdlib.Data.Ord public; qsHelper : {A : Type} → A → List A × List A → List A; -qsHelper a (l , r) := l ++ (a ∷ nil) ++ r; +qsHelper a (l , r) := l ++ (a :: nil) ++ r; terminating quickSort : {A : Type} → (A → A → Ordering) → List A → List A; quickSort _ nil := nil; -quickSort _ (x ∷ nil) := x ∷ nil; -quickSort cmp (x ∷ xs) := qsHelper x +quickSort _ (x :: nil) := x :: nil; +quickSort cmp (x :: xs) := qsHelper x (both (quickSort cmp) (partition (isGT ∘ cmp x) xs)); uniq : {A : Type} -> (A -> A -> Ordering) -> List A -> List A; uniq _ nil := nil; -uniq _ y@(x ∷ nil) := y; -uniq cmp (x ∷ x' ∷ xs) := if (isEQ (cmp x x')) (uniq cmp (x' ∷ xs)) (x ∷ (uniq cmp (x' ∷ xs))); +uniq _ y@(x :: nil) := y; +uniq cmp (x :: x' :: xs) := if (isEQ (cmp x x')) (uniq cmp (x' :: xs)) (x :: (uniq cmp (x' :: xs))); gen : Nat -> (Nat -> Nat) -> List Nat -> List Nat; gen zero _ acc := acc; -gen n@(suc n') f acc := gen n' f (f n ∷ acc); +gen n@(suc n') f acc := gen n' f (f n :: acc); gen2 : Nat -> Nat -> List (List Nat) -> List (List Nat); gen2 _ zero acc := acc; -gen2 m n@(suc n') acc := gen2 m n' ((gen m ((+) n) nil) ∷ acc); +gen2 m n@(suc n') acc := gen2 m n' ((gen m ((+) n) nil) :: acc); main : List Nat; main := uniq compare (quickSort compare (flatten (gen2 three four nil))); diff --git a/tests/Internal/positive/out/QuickSort.out b/tests/Internal/positive/out/QuickSort.out index fb345531c6..dd9cdc57fe 100644 --- a/tests/Internal/positive/out/QuickSort.out +++ b/tests/Internal/positive/out/QuickSort.out @@ -1 +1 @@ -∷ (suc (suc zero)) (∷ (suc (suc (suc zero))) (∷ (suc (suc (suc (suc zero)))) (∷ (suc (suc (suc (suc (suc zero))))) (∷ (suc (suc (suc (suc (suc (suc zero)))))) (∷ (suc (suc (suc (suc (suc (suc (suc zero))))))) nil))))) +:: (suc (suc zero)) (:: (suc (suc (suc zero))) (:: (suc (suc (suc (suc zero)))) (:: (suc (suc (suc (suc (suc zero))))) (:: (suc (suc (suc (suc (suc (suc zero)))))) (:: (suc (suc (suc (suc (suc (suc (suc zero))))))) nil))))) diff --git a/tests/benchmark/fold/juvix/fold.juvix b/tests/benchmark/fold/juvix/fold.juvix index 6a935bdd34..5eeb080bd5 100644 --- a/tests/benchmark/fold/juvix/fold.juvix +++ b/tests/benchmark/fold/juvix/fold.juvix @@ -23,7 +23,7 @@ terminating gen : Int -> List Int -> List Int; gen n acc := if (n Data.Int.Ops.== Int_0) acc - (gen (n Data.Int.Ops.- Int_1) (n ∷ acc)); + (gen (n Data.Int.Ops.- Int_1) (n :: acc)); axiom Int_100000 : Int; compile Int_100000 { diff --git a/tests/benchmark/mapfold/juvix/mapfold.juvix b/tests/benchmark/mapfold/juvix/mapfold.juvix index 36520a1db2..c4b8fab877 100644 --- a/tests/benchmark/mapfold/juvix/mapfold.juvix +++ b/tests/benchmark/mapfold/juvix/mapfold.juvix @@ -17,8 +17,8 @@ terminating gen : Int -> Int -> List Int; gen k n := if (k == n) - (k ∷ nil) - (k ∷ gen (k Data.Int.Ops.+ Int_1) n); + (k :: nil) + (k :: gen (k Data.Int.Ops.+ Int_1) n); axiom Int_10000 : Int; compile Int_10000 { diff --git a/tests/benchmark/mapfun/juvix/mapfun.juvix b/tests/benchmark/mapfun/juvix/mapfun.juvix index d09f211eae..16f036ef3d 100644 --- a/tests/benchmark/mapfun/juvix/mapfun.juvix +++ b/tests/benchmark/mapfun/juvix/mapfun.juvix @@ -8,13 +8,13 @@ open import Data.Int.Ops; mapfun : {A : Type} -> List (A -> A) -> List A -> List A; mapfun nil xs := xs; -mapfun (f ∷ fs) xs := mapfun fs (map f xs); +mapfun (f :: fs) xs := mapfun fs (map f xs); terminating genfs : Int -> List (Int -> Int); genfs n := if (n Data.Int.Ops.== Int_0) nil - (((Data.Int.Ops.-) n) ∷ genfs (n Data.Int.Ops.- Int_1)); + (((Data.Int.Ops.-) n) :: genfs (n Data.Int.Ops.- Int_1)); step : Int -> (Int -> Int) -> Int -> Int; step n f x := f (x Data.Int.Ops.+ n); @@ -23,11 +23,11 @@ terminating genffs : Int -> List ((Int -> Int) -> Int -> Int); genffs n := if (n Data.Int.Ops.== Int_0) nil - (step n ∷ genffs (n Data.Int.Ops.- Int_1)); + (step n :: genffs (n Data.Int.Ops.- Int_1)); sum_go : Int -> List Int -> Int; sum_go acc nil := acc; -sum_go acc (h ∷ t) := sum_go (acc Data.Int.Ops.+ h) t; +sum_go acc (h :: t) := sum_go (acc Data.Int.Ops.+ h) t; sum : List Int -> Int; sum := sum_go Int_0; @@ -35,8 +35,8 @@ sum := sum_go Int_0; terminating gen : Int -> Int -> List Int; gen k n := if (k Data.Int.Ops.== n) - (k ∷ nil) - (k ∷ gen (k Data.Int.Ops.+ Int_1) n); + (k :: nil) + (k :: gen (k Data.Int.Ops.+ Int_1) n); axiom Int_100 : Int; compile Int_100 { diff --git a/tests/benchmark/mergesort/juvix/mergesort.juvix b/tests/benchmark/mergesort/juvix/mergesort.juvix index d522094138..97c809e183 100644 --- a/tests/benchmark/mergesort/juvix/mergesort.juvix +++ b/tests/benchmark/mergesort/juvix/mergesort.juvix @@ -7,22 +7,22 @@ open import Data.Int.Ops; split_go : {A : Type} -> List A -> List A -> List A -> List A × List A; split_go nil ys zs := (ys, zs); -split_go (x ∷ xs') ys zs := split_go xs' zs (x ∷ ys); +split_go (x :: xs') ys zs := split_go xs' zs (x :: ys); split : {A : Type} -> List A -> List A × List A; split xs := split_go xs nil nil; revappend : {A : Type} -> List A -> List A -> List A; revappend nil ys := ys; -revappend (x ∷ xs) ys := revappend xs (x ∷ ys); +revappend (x :: xs) ys := revappend xs (x :: ys); merget : List Int -> List Int -> List Int -> List Int; merget nil ys acc := revappend acc ys; merget xs nil acc := revappend acc xs; -merget (x ∷ xs') (y ∷ ys') acc := +merget (x :: xs') (y :: ys') acc := if (x Data.Int.Ops.<= y) - (merget xs' (y ∷ ys') (x ∷ acc)) - (merget (x ∷ xs') ys' (y ∷ acc)); + (merget xs' (y :: ys') (x :: acc)) + (merget (x :: xs') ys' (y :: acc)); terminating sort' : List Int × List Int -> List Int; @@ -30,19 +30,19 @@ sort' : List Int × List Int -> List Int; terminating sort : List Int -> List Int; sort nil := nil; -sort (x ∷ nil) := x ∷ nil; +sort (x :: nil) := x :: nil; sort xs := sort' (split xs); sort' (l1, l2) := merget (sort l1) (sort l2) nil; sorted : List Int -> Bool; sorted nil := true; -sorted (_ ∷ nil) := true; -sorted (x ∷ y ∷ t) := if (x Data.Int.Ops.<= y) (sorted (y ∷ t)) false; +sorted (_ :: nil) := true; +sorted (x :: y :: t) := if (x Data.Int.Ops.<= y) (sorted (y :: t)) false; terminating gen : Int -> List Int -> List Int; -gen n acc := if (n Data.Int.Ops.== Int_0) acc (gen (n Data.Int.Ops.- Int_1) (n ∷ acc)); +gen n acc := if (n Data.Int.Ops.== Int_0) acc (gen (n Data.Int.Ops.- Int_1) (n :: acc)); axiom Int_2000000 : Int; compile Int_2000000 { diff --git a/tests/benchmark/prime/juvix/prime.juvix b/tests/benchmark/prime/juvix/prime.juvix index f95778bcb9..a69cbe585b 100644 --- a/tests/benchmark/prime/juvix/prime.juvix +++ b/tests/benchmark/prime/juvix/prime.juvix @@ -7,7 +7,7 @@ open import Data.Int.Ops; checkDivisible : Int -> List Int -> Bool; checkDivisible p nil := false; -checkDivisible p (h ∷ t) := if ((p % h) == Int_0) true (checkDivisible p t); +checkDivisible p (h :: t) := if ((p % h) == Int_0) true (checkDivisible p t); terminating go : Int -> Int -> List Int -> Int; @@ -16,7 +16,7 @@ go n p lst := (head lst) (if (checkDivisible p lst) (go n (p Data.Int.Ops.+ Int_1) lst) - (go (n - Int_1) (p Data.Int.Ops.+ Int_1) (p ∷ lst))); + (go (n - Int_1) (p Data.Int.Ops.+ Int_1) (p :: lst))); prime : Int -> Int; prime n := go n Int_2 nil; diff --git a/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix b/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix index 9b106978cb..ab1ea01b57 100644 --- a/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix +++ b/tests/positive/FullExamples/SimpleFungibleTokenImplicit.juvix @@ -144,18 +144,18 @@ infix 4 ==String; -- Lists -------------------------------------------------------------------------------- -infixr 5 ∷; +infixr 5 ::; type List (A : Type) := nil : List A - | ∷ : A → List A → List A; + | :: : A → List A → List A; elem : {A : Type} → (A → A → Bool) → A → List A → Bool; elem _ _ nil := false; -elem eq s (x ∷ xs) := eq s x || elem eq s xs; +elem eq s (x :: xs) := eq s x || elem eq s xs; foldl : {A : Type} → {B : Type} → (B → A → B) → B → List A → B; foldl f z nil := z; -foldl f z (h ∷ hs) := foldl f (f z h) hs; +foldl f z (h :: hs) := foldl f (f z h) hs; -------------------------------------------------------------------------------- -- Pair @@ -297,10 +297,10 @@ change2-key : String; change2-key := "change2-key"; verifiers : List String; -verifiers := owner-address ∷ nil; +verifiers := owner-address :: nil; keys-changed : List String; -keys-changed := change1-key ∷ change2-key ∷ nil; +keys-changed := change1-key :: change2-key :: nil; main : Action; main := diff --git a/tests/positive/Internal/Implicit.juvix b/tests/positive/Internal/Implicit.juvix index ca3d8b543e..9a5a70f7ae 100644 --- a/tests/positive/Internal/Implicit.juvix +++ b/tests/positive/Internal/Implicit.juvix @@ -42,13 +42,13 @@ if : {A : Type} → Bool → A → A → A; if true a _ := a; if false _ b := b; -infixr 5 ∷; +infixr 5 ::; type List (A : Type) := nil : List A - | ∷ : A → List A → List A; + | :: : A → List A → List A; upToTwo : _; -upToTwo := zero ∷ suc zero ∷ suc (suc zero) ∷ nil; +upToTwo := zero :: suc zero :: suc (suc zero) :: nil; p1 : Nat → Nat → Nat × Nat; p1 a b := a, b ; @@ -73,7 +73,7 @@ t4' := t3 proxy proxy ; map : {A : Type} → {B : Type} → (A → B) → List A → List B; map f nil := nil; -map f (x ∷ xs) := f x ∷ map f xs; +map f (x :: xs) := f x :: map f xs; t : {A : Type} → Proxy A; t {_} := proxy; @@ -98,20 +98,20 @@ pairEval' (f, x) := f {Nat} x; foldr : {A : Type} → {B : Type} → (A → B → B) → B → List A → B; foldr _ z nil := z; -foldr f z (h ∷ hs) := f h (foldr f z hs); +foldr f z (h :: hs) := f h (foldr f z hs); foldl : {A : Type} → {B : Type} → (B → A → B) → B → List A → B; foldl f z nil := z ; -foldl f z (h ∷ hs) := foldl f (f z h) hs; +foldl f z (h :: hs) := foldl f (f z h) hs; filter : {A : Type} → (A → Bool) → List A → List A; filter _ nil := nil; -filter f (h ∷ hs) := if (f h) - (h ∷ filter f hs) +filter f (h :: hs) := if (f h) + (h :: filter f hs) (filter f hs); partition : {A : Type} → (A → Bool) → List A → List A × List A; partition _ nil := nil, nil; -partition f (x ∷ xs) := (if (f x) first second) ((∷) x) (partition f xs); +partition f (x :: xs) := (if (f x) first second) ((::) x) (partition f xs); end; diff --git a/tests/positive/Internal/Simple.juvix b/tests/positive/Internal/Simple.juvix index d1e5a14215..fc289fa093 100644 --- a/tests/positive/Internal/Simple.juvix +++ b/tests/positive/Internal/Simple.juvix @@ -25,14 +25,14 @@ module Simple; + zero b := b; + (suc a) b := suc (a + b); - infixr 5 ∷; + infixr 5 ::; type List := nil : List | - ∷ : Nat → List → List; + :: : Nat → List → List; foldr : (Nat → Nat → Nat) → Nat → List → Nat; foldr _ v nil := v; - foldr f v (a ∷ as) := f a (foldr f v as); + foldr f v (a :: as) := f a (foldr f v as); sum : List → Nat; sum := foldr (+) zero; diff --git a/tests/positive/MiniC/NestedList/Input.juvix b/tests/positive/MiniC/NestedList/Input.juvix index 1880faedc2..9d10a66bcb 100644 --- a/tests/positive/MiniC/NestedList/Input.juvix +++ b/tests/positive/MiniC/NestedList/Input.juvix @@ -2,16 +2,16 @@ module Input; open import Data.IO; -infixr 5 ∷; +infixr 5 ::; type List (A : Type) := nil : List A - | ∷ : A → List A → List A; + | :: : A → List A → List A; type Foo := a : Foo; l : List (List Foo) → List (List Foo); -l ((_ ∷ nil) ∷ nil) := nil ∷ nil; +l ((_ :: nil) :: nil) := nil :: nil; main : Action; main := put-str-ln "no errors"; diff --git a/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix b/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix index 30717eb10e..c2fa08ab2a 100644 --- a/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix +++ b/tests/positive/MiniC/SimpleFungibleTokenImplicit/Input.juvix @@ -187,18 +187,18 @@ infix 4 ==String; -- Lists -------------------------------------------------------------------------------- -infixr 5 ∷; +infixr 5 ::; type List (A : Type) := nil : List A - | ∷ : A → List A → List A; + | :: : A → List A → List A; elem : {A : Type} → (A → A → Bool) → A → List A → Bool; elem _ _ nil := false; -elem eq s (x ∷ xs) := eq s x || elem eq s xs; +elem eq s (x :: xs) := eq s x || elem eq s xs; foldl : {A : Type} → {B : Type} → (B → A → B) → B → List A → B; foldl f z nil := z; -foldl f z (h ∷ hs) := foldl f (f z h) hs; +foldl f z (h :: hs) := foldl f (f z h) hs; -------------------------------------------------------------------------------- -- Pair @@ -346,10 +346,10 @@ change2-key : String; change2-key := "change2-key"; verifiers : List String; -verifiers := owner-address ∷ nil; +verifiers := owner-address :: nil; keys-changed : List String; -keys-changed := change1-key ∷ change2-key ∷ nil; +keys-changed := change1-key :: change2-key :: nil; main : Action; main := diff --git a/tests/positive/StdlibList/Data/List.juvix b/tests/positive/StdlibList/Data/List.juvix index 93f698e8fb..3349114346 100644 --- a/tests/positive/StdlibList/Data/List.juvix +++ b/tests/positive/StdlibList/Data/List.juvix @@ -3,30 +3,30 @@ module Data.List; import Data.Bool; open Data.Bool; --- infixr 5 ∷; waiting for implicit arguments +-- infixr 5 ::; waiting for implicit arguments type List (A : Type) := nil : List A - | ∷ : A → List A → List A; + | :: : A → List A → List A; match : {A : Type} → {B : Type} → A → (A → B) → B; match x f := f x; foldr : (a : Type) → (b : Type) → (a → b → b) → b → List a → b; foldr _ _ _ z (nil _) := z; -foldr a b f z (∷ _ h hs) := f h (foldr a b f z hs); +foldr a b f z (:: _ h hs) := f h (foldr a b f z hs); foldl : (a : Type) → (b : Type) → (b → a → b) → b → List a → b; foldl a b f z (nil _) := z ; -foldl a b f z (∷ _ h hs) := foldl a b f (f z h) hs; +foldl a b f z (:: _ h hs) := foldl a b f (f z h) hs; map : (a : Type) → (b : Type) → (a → b) → List a → List b; map _ b f (nil _) := nil b; -map a b f (∷ _ h hs) := ∷ a (f h) (map a b f hs); +map a b f (:: _ h hs) := :: a (f h) (map a b f hs); filter : (a : Type) → (a → Bool) → List a → List a; filter a f (nil _) := nil a; -filter a f (∷ _ h hs) := match (f h) λ{ - true := ∷ a h (filter a f hs); +filter a f (:: _ h hs) := match (f h) λ{ + true := :: a h (filter a f hs); false := filter a f hs; }; @@ -35,22 +35,22 @@ open Data.Nat; length : (a : Type) → List a → ℕ; length _ (nil _) := zero; -length a (∷ _ _ l) := suc (length a l); +length a (:: _ _ l) := suc (length a l); reverse : (a : Type) → List a → List a; -reverse a l := +reverse a l := let { rev : List a → List a → List a; rev (nil _) a := a; - rev (∷ _ x xs) a := rev xs (∷ a x a) + rev (:: _ x xs) a := rev xs (:: a x a) } in rev l (nil a); replicate : (a : Type) → ℕ → a → List a; replicate a zero _ := nil a; -replicate a (suc n) x := ∷ a x (replicate a n x); +replicate a (suc n) x := :: a x (replicate a n x); take : (a : Type) → ℕ → List a → List a; -take a (suc n) (∷ _ x xs) := ∷ a x (take a n xs); +take a (suc n) (:: _ x xs) := :: a x (take a n xs); take a _ _ := nil a; import Data.Ord; @@ -62,15 +62,15 @@ open Data.Product; splitAt : (a : Type) → ℕ → List a → List a; splitAt a _ (nil _) := nil a, nil a; splitAt a zero xs := , (List a) (List a) (nil a) xs; -splitAt a (suc zero) (∷ _ x xs) := , (List a) (List a) (∷ a x (nil a)) xs; -splitAt a (suc (suc m)) (∷ _ x xs) := match (splitAt a m xs) λ { - (, la _ xs' xs'') := , la la (∷ a x xs') xs''; +splitAt a (suc zero) (:: _ x xs) := , (List a) (List a) (:: a x (nil a)) xs; +splitAt a (suc (suc m)) (:: _ x xs) := match (splitAt a m xs) λ { + (, la _ xs' xs'') := , la la (:: a x xs') xs''; }; merge : (a : Type) → (a → a → Ordering) → List a → List a → List a; -merge a cmp (∷ _ x xs) (∷ _ y ys) := match (cmp x y) λ{ - LT := ∷ a x (merge a cmp xs (∷ a y ys)); - _ := ∷ a y (merge a cmp (∷ a x xs) ys); +merge a cmp (:: _ x xs) (:: _ y ys) := match (cmp x y) λ{ + LT := :: a x (merge a cmp xs (:: a y ys)); + _ := :: a y (merge a cmp (:: a x xs) ys); }; merge _ _ (nil _) ys := ys; merge _ _ xs (nil _) := xs; @@ -78,12 +78,12 @@ merge _ _ xs (nil _) := xs; -- infixr 5 ++; waiting for implicit arguments ++ : (a : Type) → List a → List a → List a; ++ a (nil _) ys := ys; -++ a (∷ _ x xs) ys := ∷ a x (++ a xs ys); +++ a (:: _ x xs) ys := :: a x (++ a xs ys); quickSort : (a : Type) → (a → a → Ordering) → List a → List a; quickSort a _ (nil _) := nil a; -quickSort a _ (∷ _ x (nil _)) := ∷ a x (nil a); -quickSort a cmp (∷ _ x ys) := +quickSort a _ (:: _ x (nil _)) := :: a x (nil a); +quickSort a cmp (:: _ x ys) := let { ltx : a → Bool; ltx y := match (cmp y x) λ{ @@ -92,10 +92,10 @@ quickSort a cmp (∷ _ x ys) := }; gex : a → Bool; gex y := not (ltx y) - } in + } in { ++ a (quickSort a (filter a ltx) ys) - (++ a (∷ a x (nil a)) (quickSort a (filter a gex) ys)) + (++ a (:: a x (nil a)) (quickSort a (filter a gex) ys)) }; end; From d92b71ecfdd18261dff9392405bf0e1728fad59a Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 3 Jan 2023 17:56:11 +0100 Subject: [PATCH 29/34] add Makefile entry for Jonathan --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index c9a73df8bd..1dd3ad5395 100644 --- a/Makefile +++ b/Makefile @@ -230,3 +230,7 @@ test-shell : install changelog-updates : @github_changelog_generator @pandoc CHANGELOG.md --from markdown --to org -o UPDATES-FOR-CHANGELOG.org + +.PHONY : bench +install: runtime submodules + @stack bench From 95eea10dabdf47849a739b3d77962a05926041e2 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 3 Jan 2023 18:24:58 +0100 Subject: [PATCH 30/34] fix makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1dd3ad5395..c2913eed3f 100644 --- a/Makefile +++ b/Makefile @@ -232,5 +232,5 @@ changelog-updates : @pandoc CHANGELOG.md --from markdown --to org -o UPDATES-FOR-CHANGELOG.org .PHONY : bench -install: runtime submodules +bench: runtime submodules @stack bench From 3baf00f2d95d94235773e4803fff6f1a8d0b5e25 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 3 Jan 2023 19:04:23 +0100 Subject: [PATCH 31/34] adjust offset and size --- gnuplot/bars.gp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index cb0f63e409..d2d8e5353c 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -35,13 +35,13 @@ unset ylabel f(x) = column(stddevCol)*100/column(meanCol) plot csvfile \ using (f('')):colorCol:xtic(2) notitle linecolor rgbcolor variable, \ - '' using 0:(f('')):(sprintf("%1.2f%",(f('')))) with labels font ",13" center offset -9,0.4 notitle + '' using ($0 - 1):(f('')):(sprintf("%1.2f%",(f('')))) with labels font ",13" center offset 0, 0.4 notitle unset multiplot -set terminal svg enhanced mouse size 600, 1100 +set terminal svg enhanced mouse size 800, 1100 set output outfile.'.svg' -set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 +set multiplot layout 2, 1 title ('suite '.name) font ",24" set key outside do for [target in targets] { replot From 724590e366f59d63a62584bc3410b5e180c03162 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Tue, 3 Jan 2023 19:31:58 +0100 Subject: [PATCH 32/34] drop pdf output --- bench/Main.hs | 9 ++++----- gnuplot/bars.gp | 18 ++++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/bench/Main.hs b/bench/Main.hs index b63fc166d3..005d7e665f 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -68,14 +68,13 @@ variantRules s v = do plotRules :: Suite -> Rules () plotRules s = do - let pdf :: Path Abs File = suitePdfFile s - csv :: Path Abs File = suiteCsvFile s + let csv :: Path Abs File = suiteCsvFile s svg :: Path Abs File = suiteSvgFile s out :: Path Abs File = suitePlotFile s - want [toFilePath pdf, toFilePath svg] - multiRecipe [pdf, svg] $ do + want [toFilePath svg] + multiRecipe [svg] $ do need [toFilePath csv, toFilePath gnuplotFile] - ensureDir (parent pdf) + ensureDir (parent svg) command_ [] "gnuplot" diff --git a/gnuplot/bars.gp b/gnuplot/bars.gp index d2d8e5353c..2c04e59e7a 100644 --- a/gnuplot/bars.gp +++ b/gnuplot/bars.gp @@ -5,9 +5,10 @@ meanCol = 'Mean' colorCol = 'Color' stddevCol = 'Stddev' targets = meanCol . ' ' . stddevCol - -set terminal pdf size 18cm, 26cm -set output outfile.'.pdf' +set terminal svg enhanced mouse size 800, 1100 +set output outfile.'.svg' +set multiplot layout 2, 1 title ('suite '.name) font ",24" +set key outside set tmargin 3 set style data histogram set datafile separator "," @@ -21,8 +22,6 @@ unset key set yrange [0 : *] set offsets graph 0,0.5 -set multiplot layout 2, 1 title ('suite '.name) font ",24" scale 1, 1 - set title meanCol font ",20" plot csvfile \ using meanCol:colorCol:xtic(2) notitle linecolor rgbcolor variable, \ @@ -38,12 +37,3 @@ plot csvfile \ '' using ($0 - 1):(f('')):(sprintf("%1.2f%",(f('')))) with labels font ",13" center offset 0, 0.4 notitle unset multiplot - -set terminal svg enhanced mouse size 800, 1100 -set output outfile.'.svg' -set multiplot layout 2, 1 title ('suite '.name) font ",24" -set key outside -do for [target in targets] { -replot -} -unset multiplot From 494bf7b948efa11e3d03f4afaa1b6e0f96861fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czajka?= <62751+lukaszcz@users.noreply.github.com> Date: Tue, 3 Jan 2023 18:52:20 +0100 Subject: [PATCH 33/34] Convert Nat literals to Core integers (#1681) Now it's possible to write `1 + 2` in the Juvix REPL and not get an error. Closes #1645. Co-authored-by: Jonathan Cubides --- src/Juvix/Compiler/Core/Data/InfoTable.hs | 2 + .../Compiler/Core/Data/InfoTableBuilder.hs | 79 +++++++++++++++++ .../Compiler/Core/Transformation/NatToInt.hs | 12 ++- .../Compiler/Core/Translation/FromInternal.hs | 74 +++++++++++++--- .../Compiler/Core/Translation/FromSource.hs | 85 +------------------ test/Internal/Eval/Positive.hs | 4 +- tests/CLI/Commands/repl.test | 6 ++ tests/Internal/positive/LitInteger.juvix | 2 +- tests/Internal/positive/out/LitInteger.out | 2 +- 9 files changed, 167 insertions(+), 99 deletions(-) diff --git a/src/Juvix/Compiler/Core/Data/InfoTable.hs b/src/Juvix/Compiler/Core/Data/InfoTable.hs index 79787ff5dc..3b89a9cac5 100644 --- a/src/Juvix/Compiler/Core/Data/InfoTable.hs +++ b/src/Juvix/Compiler/Core/Data/InfoTable.hs @@ -18,6 +18,7 @@ data InfoTable = InfoTable _infoInductives :: HashMap Symbol InductiveInfo, _infoConstructors :: HashMap Tag ConstructorInfo, _infoAxioms :: HashMap Text AxiomInfo, + _infoIntToNat :: Maybe Symbol, _infoNextSymbol :: Word, _infoNextTag :: Word } @@ -32,6 +33,7 @@ emptyInfoTable = _infoInductives = mempty, _infoConstructors = mempty, _infoAxioms = mempty, + _infoIntToNat = Nothing, _infoNextSymbol = 0, _infoNextTag = 0 } diff --git a/src/Juvix/Compiler/Core/Data/InfoTableBuilder.hs b/src/Juvix/Compiler/Core/Data/InfoTableBuilder.hs index 8293f5aa33..0cfe5830a3 100644 --- a/src/Juvix/Compiler/Core/Data/InfoTableBuilder.hs +++ b/src/Juvix/Compiler/Core/Data/InfoTableBuilder.hs @@ -85,3 +85,82 @@ runInfoTableBuilder tab = return $ HashMap.lookup txt (s ^. identMap) GetInfoTable -> get + +-------------------------------------------- +-- Builtin declarations +-------------------------------------------- + +createBuiltinConstr :: + Symbol -> + Tag -> + Text -> + Type -> + Maybe BuiltinConstructor -> + Sem r ConstructorInfo +createBuiltinConstr sym tag nameTxt ty cblt = do + return $ + ConstructorInfo + { _constructorName = nameTxt, + _constructorLocation = Nothing, + _constructorTag = tag, + _constructorType = ty, + _constructorArgsNum = length (typeArgs ty), + _constructorInductive = sym, + _constructorBuiltin = cblt + } + +declareInductiveBuiltins :: + Member InfoTableBuilder r => + Text -> + Maybe BuiltinInductive -> + [(Tag, Text, Type -> Type, Maybe BuiltinConstructor)] -> + Sem r () +declareInductiveBuiltins indName blt ctrs = do + sym <- freshSymbol + let ty = mkIdent' sym + constrs <- mapM (\(tag, name, fty, cblt) -> createBuiltinConstr sym tag name (fty ty) cblt) ctrs + registerInductive + indName + ( InductiveInfo + { _inductiveName = indName, + _inductiveLocation = Nothing, + _inductiveSymbol = sym, + _inductiveKind = mkDynamic', + _inductiveConstructors = constrs, + _inductivePositive = True, + _inductiveParams = [], + _inductiveBuiltin = blt + } + ) + mapM_ (\ci -> registerConstructor (ci ^. constructorName) ci) constrs + +declareIOBuiltins :: Member InfoTableBuilder r => Sem r () +declareIOBuiltins = + declareInductiveBuiltins + "IO" + Nothing + [ (BuiltinTag TagReturn, "return", mkPi' mkDynamic', Nothing), + (BuiltinTag TagBind, "bind", \ty -> mkPi' ty (mkPi' (mkPi' mkDynamic' ty) ty), Nothing), + (BuiltinTag TagWrite, "write", mkPi' mkDynamic', Nothing), + (BuiltinTag TagReadLn, "readLn", id, Nothing) + ] + +declareBoolBuiltins :: Member InfoTableBuilder r => Sem r () +declareBoolBuiltins = + declareInductiveBuiltins + "bool" + (Just BuiltinBool) + [ (BuiltinTag TagTrue, "true", id, Just BuiltinBoolTrue), + (BuiltinTag TagFalse, "false", id, Just BuiltinBoolFalse) + ] + +declareNatBuiltins :: Member InfoTableBuilder r => Sem r () +declareNatBuiltins = do + tagZero <- freshTag + tagSuc <- freshTag + declareInductiveBuiltins + "nat" + (Just BuiltinNat) + [ (tagZero, "zero", id, Just BuiltinNatZero), + (tagSuc, "suc", \x -> mkPi' x x, Just BuiltinNatSuc) + ] diff --git a/src/Juvix/Compiler/Core/Transformation/NatToInt.hs b/src/Juvix/Compiler/Core/Transformation/NatToInt.hs index b2d9dff51b..c43ffc1dea 100644 --- a/src/Juvix/Compiler/Core/Transformation/NatToInt.hs +++ b/src/Juvix/Compiler/Core/Transformation/NatToInt.hs @@ -17,6 +17,9 @@ convertNode tab = convert [] 0 go levels bl node = case node of NVar (Var {..}) -> End' (mkVar _varInfo (_varIndex + length (filter (\x -> x >= bl - _varIndex) levels))) + NApp (App _ (NIdt (Ident {..})) l) + | Just _identSymbol == tab ^. infoIntToNat -> + End' (convert levels bl l) NApp (App _ (NApp (App _ (NIdt (Ident {..})) l)) r) -> Recur' (levels, convertIdentApp node (\op -> mkBuiltinApp _identInfo op [l, r]) _identSymbol) NApp (App _ (NIdt (Ident {..})) l) -> @@ -90,4 +93,11 @@ convertNode tab = convert [] 0 _ -> node natToInt :: InfoTable -> InfoTable -natToInt tab = mapT (const (convertNode tab)) tab +natToInt tab = mapT (const (convertNode tab')) tab' + where + tab' = + case tab ^. infoIntToNat of + Just sym -> + tab {_identContext = HashMap.insert sym (mkLambda' (mkVar' 0)) (tab ^. identContext)} + Nothing -> + tab diff --git a/src/Juvix/Compiler/Core/Translation/FromInternal.hs b/src/Juvix/Compiler/Core/Translation/FromInternal.hs index e973b008a7..216d7fb846 100644 --- a/src/Juvix/Compiler/Core/Translation/FromInternal.hs +++ b/src/Juvix/Compiler/Core/Translation/FromInternal.hs @@ -28,21 +28,69 @@ isExplicit = (== Internal.Explicit) . (^. Internal.patternArgIsImplicit) mkIdentIndex :: Name -> Text mkIdentIndex = show . (^. Internal.nameId . Internal.unNameId) +setupIntToNat :: Symbol -> InfoTable -> InfoTable +setupIntToNat sym tab = + tab + { _infoIdentifiers = HashMap.insert sym ii (tab ^. infoIdentifiers), + _identContext = HashMap.insert sym node (tab ^. identContext), + _infoIntToNat = Just sym + } + where + ii = + IdentifierInfo + { _identifierSymbol = sym, + _identifierName = "intToNat", + _identifierLocation = Nothing, + _identifierArgsNum = 1, + _identifierArgsInfo = + [ ArgumentInfo + { _argumentName = "x", + _argumentLocation = Nothing, + _argumentType = mkTypePrim' (PrimInteger $ PrimIntegerInfo Nothing Nothing), + _argumentIsImplicit = Explicit + } + ], + _identifierType = mkDynamic', + _identifierIsExported = False, + _identifierBuiltin = Nothing + } + node = + case (tagZeroM, tagSucM, boolSymM) of + (Just tagZero, Just tagSuc, Just boolSym) -> + mkLambda' $ + mkIf' + boolSym + (mkBuiltinApp' OpEq [mkVar' 0, mkConstant' (ConstInteger 0)]) + (mkConstr (setInfoName "zero" mempty) tagZero []) + (mkConstr (setInfoName "suc" mempty) tagSuc [mkApp' (mkIdent' sym) (mkBuiltinApp' OpIntSub [mkVar' 0, mkConstant' (ConstInteger 1)])]) + _ -> + mkLambda' $ mkVar' 0 + tagZeroM = fmap ((^. constructorTag) . fst) $ uncons $ filter (\ci -> ci ^. constructorBuiltin == Just BuiltinNatZero) $ HashMap.elems (tab ^. infoConstructors) + tagSucM = fmap ((^. constructorTag) . fst) $ uncons $ filter (\ci -> ci ^. constructorBuiltin == Just BuiltinNatSuc) $ HashMap.elems (tab ^. infoConstructors) + boolSymM = fmap ((^. inductiveSymbol) . fst) $ uncons $ filter (\ind -> ind ^. inductiveBuiltin == Just BuiltinBool) $ HashMap.elems (tab ^. infoInductives) + fromInternal :: Internal.InternalTypedResult -> Sem k CoreResult fromInternal i = do - (res, _) <- runInfoTableBuilder emptyInfoTable (runReader (i ^. InternalTyped.resultIdenTypes) f) + (res, _) <- runInfoTableBuilder tab0 (runReader (i ^. InternalTyped.resultIdenTypes) f) return $ CoreResult - { _coreResultTable = res, + { _coreResultTable = setupIntToNat intToNatSym res, _coreResultInternalTypedResult = i } where + tab0 :: InfoTable + tab0 = emptyInfoTable {_infoIntToNat = Just intToNatSym, _infoNextSymbol = intToNatSym + 1} + + intToNatSym :: Symbol + intToNatSym = 0 + f :: Members '[InfoTableBuilder, Reader InternalTyped.TypesTable] r => Sem r () f = do + declareIOBuiltins let resultModules = toList (i ^. InternalTyped.resultModules) - runNameIdGen (runReader (Internal.buildTable resultModules) (mapM_ coreModule resultModules)) + runReader (Internal.buildTable resultModules) (mapM_ coreModule resultModules) where - coreModule :: Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, Reader Internal.InfoTable, NameIdGen] r => Internal.Module -> Sem r () + coreModule :: Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, Reader Internal.InfoTable] r => Internal.Module -> Sem r () coreModule m = do registerInductiveDefs m registerFunctionDefs m @@ -86,14 +134,14 @@ registerInductiveDefsBody body = mapM_ go (body ^. Internal.moduleStatements) registerFunctionDefs :: forall r. - Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, NameIdGen, Reader Internal.InfoTable] r => + Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, Reader Internal.InfoTable] r => Internal.Module -> Sem r () registerFunctionDefs m = registerFunctionDefsBody (m ^. Internal.moduleBody) registerFunctionDefsBody :: forall r. - Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, NameIdGen, Reader Internal.InfoTable] r => + Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, Reader Internal.InfoTable] r => Internal.ModuleBody -> Sem r () registerFunctionDefsBody body = mapM_ go (body ^. Internal.moduleStatements) @@ -173,7 +221,7 @@ goConstructor sym ctor = do goMutualBlock :: forall r. - Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, NameIdGen, Reader Internal.InfoTable] r => + Members '[InfoTableBuilder, Reader InternalTyped.TypesTable, Reader Internal.InfoTable] r => Internal.MutualBlock -> Sem r () goMutualBlock m = do @@ -188,7 +236,7 @@ goMutualBlock m = do goFunctionDefIden :: forall r. - Members '[InfoTableBuilder, Reader Internal.InfoTable, Reader InternalTyped.TypesTable, NameIdGen] r => + Members '[InfoTableBuilder, Reader Internal.InfoTable, Reader InternalTyped.TypesTable] r => (Internal.FunctionDef, Symbol) -> Sem r () goFunctionDefIden (f, sym) = do @@ -470,7 +518,9 @@ goExpression' :: Internal.Expression -> Sem r Node goExpression' = \case - Internal.ExpressionLiteral l -> return (goLiteral l) + Internal.ExpressionLiteral l -> do + tab <- getInfoTable + return (goLiteral (fromJust $ tab ^. infoIntToNat) l) Internal.ExpressionIden i -> case i of Internal.IdenVar n -> do k <- HashMap.lookupDefault impossible id_ <$> asks (^. indexTableVars) @@ -568,10 +618,10 @@ goApplication a = do _ -> app _ -> app -goLiteral :: LiteralLoc -> Node -goLiteral l = case l ^. withLocParam of +goLiteral :: Symbol -> LiteralLoc -> Node +goLiteral intToNat l = case l ^. withLocParam of Internal.LitString s -> mkLitConst (ConstString s) - Internal.LitInteger i -> mkLitConst (ConstInteger i) + Internal.LitInteger i -> mkApp' (mkIdent' intToNat) (mkLitConst (ConstInteger i)) where mkLitConst :: ConstantValue -> Node mkLitConst = mkConstant (Info.singleton (LocationInfo (l ^. withLocInt))) diff --git a/src/Juvix/Compiler/Core/Translation/FromSource.hs b/src/Juvix/Compiler/Core/Translation/FromSource.hs index de8b61808d..a4005dbad0 100644 --- a/src/Juvix/Compiler/Core/Translation/FromSource.hs +++ b/src/Juvix/Compiler/Core/Translation/FromSource.hs @@ -43,92 +43,13 @@ guardSymbolNotDefined sym err = do b <- lift $ checkSymbolDefined sym when b err -createBuiltinConstr :: - Symbol -> - Tag -> - Text -> - Type -> - Interval -> - Maybe BuiltinConstructor -> - Sem r ConstructorInfo -createBuiltinConstr sym tag nameTxt ty i cblt = do - return $ - ConstructorInfo - { _constructorName = nameTxt, - _constructorLocation = Just i, - _constructorTag = tag, - _constructorType = ty, - _constructorArgsNum = length (typeArgs ty), - _constructorInductive = sym, - _constructorBuiltin = cblt - } - -declareInductiveBuiltins :: - Member InfoTableBuilder r => - Text -> - Maybe BuiltinInductive -> - [(Tag, Text, Type -> Type, Maybe BuiltinConstructor)] -> - ParsecS r () -declareInductiveBuiltins indName blt ctrs = do - loc <- curLoc - let i = mkInterval loc loc - sym <- lift freshSymbol - let ty = mkIdent' sym - constrs <- lift $ mapM (\(tag, name, fty, cblt) -> createBuiltinConstr sym tag name (fty ty) i cblt) ctrs - lift $ - registerInductive - indName - ( InductiveInfo - { _inductiveName = indName, - _inductiveLocation = Just i, - _inductiveSymbol = sym, - _inductiveKind = mkDynamic', - _inductiveConstructors = constrs, - _inductivePositive = True, - _inductiveParams = [], - _inductiveBuiltin = blt - } - ) - lift $ mapM_ (\ci -> registerConstructor (ci ^. constructorName) ci) constrs - -declareIOBuiltins :: Member InfoTableBuilder r => ParsecS r () -declareIOBuiltins = - declareInductiveBuiltins - "IO" - Nothing - [ (BuiltinTag TagReturn, "return", mkPi' mkDynamic', Nothing), - (BuiltinTag TagBind, "bind", \ty -> mkPi' ty (mkPi' (mkPi' mkDynamic' ty) ty), Nothing), - (BuiltinTag TagWrite, "write", mkPi' mkDynamic', Nothing), - (BuiltinTag TagReadLn, "readLn", id, Nothing) - ] - -declareBoolBuiltins :: Member InfoTableBuilder r => ParsecS r () -declareBoolBuiltins = - declareInductiveBuiltins - "bool" - (Just BuiltinBool) - [ (BuiltinTag TagTrue, "true", id, Just BuiltinBoolTrue), - (BuiltinTag TagFalse, "false", id, Just BuiltinBoolFalse) - ] - -declareNatBuiltins :: Member InfoTableBuilder r => ParsecS r () -declareNatBuiltins = do - tagZero <- lift freshTag - tagSuc <- lift freshTag - declareInductiveBuiltins - "nat" - (Just BuiltinNat) - [ (tagZero, "zero", id, Just BuiltinNatZero), - (tagSuc, "suc", \x -> mkPi' x x, Just BuiltinNatSuc) - ] - parseToplevel :: Member InfoTableBuilder r => ParsecS r (Maybe Node) parseToplevel = do - declareIOBuiltins - declareBoolBuiltins - declareNatBuiltins + lift declareIOBuiltins + lift declareBoolBuiltins + lift declareNatBuiltins space P.endBy statement (kw kwSemicolon) r <- optional expression diff --git a/test/Internal/Eval/Positive.hs b/test/Internal/Eval/Positive.hs index f6994ad970..9a24774e79 100644 --- a/test/Internal/Eval/Positive.hs +++ b/test/Internal/Eval/Positive.hs @@ -100,12 +100,12 @@ tests = $(mkRelFile "NatMatch2.juvix") $(mkRelFile "out/NatMatch2.out"), PosTest - "Literal integer is Core integer" + "Literal Nat" $(mkRelDir ".") $(mkRelFile "LitInteger.juvix") $(mkRelFile "out/LitInteger.out"), PosTest - "Literal integer is Core string" + "Literal String" $(mkRelDir ".") $(mkRelFile "LitString.juvix") $(mkRelFile "out/LitString.out"), diff --git a/tests/CLI/Commands/repl.test b/tests/CLI/Commands/repl.test index 5ad1a36252..1527640fb3 100644 --- a/tests/CLI/Commands/repl.test +++ b/tests/CLI/Commands/repl.test @@ -90,3 +90,9 @@ $ juvix repl tests/Internal/positive/BuiltinBool.juvix $ juvix repl > /\// >= 0 + +< +1 + 2 +$ juvix repl +> /Stdlib.Prelude> suc \(suc \(suc zero\)\)/ +>= 0 \ No newline at end of file diff --git a/tests/Internal/positive/LitInteger.juvix b/tests/Internal/positive/LitInteger.juvix index 5b3cc87fed..7bcb282990 100644 --- a/tests/Internal/positive/LitInteger.juvix +++ b/tests/Internal/positive/LitInteger.juvix @@ -3,7 +3,7 @@ module LitInteger; open import Stdlib.Prelude public; main : Nat; -main := 1; +main := 1 + 2; nilNat : List Nat; nilNat := nil; diff --git a/tests/Internal/positive/out/LitInteger.out b/tests/Internal/positive/out/LitInteger.out index d00491fd7e..7574e3e74c 100644 --- a/tests/Internal/positive/out/LitInteger.out +++ b/tests/Internal/positive/out/LitInteger.out @@ -1 +1 @@ -1 +suc (suc (suc zero)) From 5798098bbdadf3375a31ec5ba0b4cd360f579228 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Thu, 5 Jan 2023 15:27:15 +0100 Subject: [PATCH 34/34] add missing suites --- bench/Main.hs | 3 ++- bench/Suites.hs | 14 ++++++-------- package.yaml | 1 + 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bench/Main.hs b/bench/Main.hs index 005d7e665f..d329095c69 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -9,6 +9,7 @@ import Development.Shake hiding (()) import Juvix.Prelude.Base import Juvix.Prelude.Path as Path hiding (doesFileExist, (-<.>)) import Juvix.Prelude.Path qualified as Path +import Statistics.Types import Suites main :: IO () @@ -119,5 +120,5 @@ config :: Suite -> Config config s = defaultConfig { csvFile = Just (toFilePath (suiteCsvFile s)), - timeLimit = 30 + confInterval = cl90 } diff --git a/bench/Suites.hs b/bench/Suites.hs index 80be3370e8..8de6695255 100644 --- a/bench/Suites.hs +++ b/bench/Suites.hs @@ -12,15 +12,13 @@ suites = "fibonacci", "maybe" ] - <> [ Suite "fold" (allVariantsExcept [C] [CoreEval]), - Suite "mapfold" (allVariantsExcept [C] [CoreEval]) + <> [ Suite suiteName (allVariantsExcept [C] [CoreEval]) + | suiteName <- ["fold", "mapfold"] + ] + <> [Suite "mapfun" (allVariantsExcept [C] [CoreEval, JuvixExe, JuvixWasm])] + <> [ Suite suiteName (allVariantsExcept [] [CoreEval, JuvixExe, JuvixWasm]) + | suiteName <- ["ackermann", "combinations", "cps", "prime"] ] - --- "mapfun" -- juvix crashes: Address boundary error --- "ackermann", -- juvix crashes --- "combinations", -- juvix crashes: call stack exhausted --- "cps", juvix: call stack exhausted --- "prime" -- juvix: Address boundary error defaultSuite :: String -> Suite defaultSuite title = diff --git a/package.yaml b/package.yaml index d9691bdaa7..f5e32a0812 100644 --- a/package.yaml +++ b/package.yaml @@ -74,6 +74,7 @@ dependencies: # benchmarks - criterion == 1.5.* +- statistics == 0.16.* - shake == 0.19.* - colour == 2.3.* - palette == 0.3.*