From 2a4699bad562997246ad3e7b75cc8e9e909e90a6 Mon Sep 17 00:00:00 2001 From: Roly Perera Date: Thu, 5 Oct 2023 08:24:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=A9=20[remove-unused]:=20Old=20impleme?= =?UTF-8?q?ntation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App/Fig.purs | 6 +++--- src/Module.purs | 39 +++++---------------------------------- test/Many.purs | 8 ++++---- 3 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/App/Fig.purs b/src/App/Fig.purs index c6e3a7919..dc2ff4797 100644 --- a/src/App/Fig.purs +++ b/src/App/Fig.purs @@ -29,7 +29,7 @@ import EvalBwd (evalBwd) import Expr (Expr) import Foreign.Object (lookup) import Lattice (𝔹, bot, botOf, erase, neg, topOf) -import Module (File(..), Folder(..), blah, datasetAs, defaultImports2, loadFile, open) +import Module (File(..), Folder(..), blah, datasetAs, defaultImports, loadFile, open) import Partial.Unsafe (unsafePartial) import Pretty (prettyP) import Primitive (matrixRep) as P @@ -188,7 +188,7 @@ linkResult x γ0γ e1 e2 t1 _ v1 = do loadFig :: forall m. MonadAff m => MonadError Error m => FigSpec -> m Fig loadFig spec@{ file } = do - { progCxt: ProgCxtEval { γ } } <- defaultImports2 >>= blah + { progCxt: ProgCxtEval { γ } } <- defaultImports >>= blah let γ0 = botOf <$> γ s' <- open file let s0 = botOf s' @@ -204,7 +204,7 @@ loadLinkFig spec@{ file1, file2, dataFile, x } = do dir = File "linking/" name1 × name2 = (dir <> file1) × (dir <> file2) -- views share ambient environment γ as well as dataset - { progCxt: ProgCxtEval { γ } } <- defaultImports2 >>= datasetAs (File "example/" <> dir <> dataFile) x >>= blah + { progCxt: ProgCxtEval { γ } } <- defaultImports >>= datasetAs (File "example/" <> dir <> dataFile) x >>= blah s1' × s2' <- (×) <$> open name1 <*> open name2 let γ0 = botOf <$> γ diff --git a/src/Module.purs b/src/Module.purs index b86e283eb..67eae1f66 100644 --- a/src/Module.purs +++ b/src/Module.purs @@ -21,16 +21,16 @@ import Effect.Exception (Error) import Effect.Exception (error) as E import EvalGraph (GraphConfig, eval, eval_module) import Expr (Expr, Module) -import Graph (class Graph, Vertex) +import Graph (Vertex) import Graph (empty) as G import Graph.GraphImpl (GraphImpl) -import Graph.GraphWriter (class MonadWithGraphAlloc, alloc, fresh, runWithGraphAllocT) +import Graph.GraphWriter (class MonadWithGraphAlloc, alloc, runWithGraphAllocT) import Parse (module_, program) as P import Parsing (runParser) import Primitive.Defs (primitives) import SExpr (Expr) as S import SExpr (desugarModuleFwd) -import Util (type (×), (×), concatM, mapLeft) +import Util ((×), concatM, mapLeft) import Util.Parse (SParser) import Val (Env, ProgCxt(..), ProgCxtEval(..), (<+>)) @@ -61,28 +61,14 @@ parseProgram folder file = open :: forall m. MonadAff m => MonadError Error m => File -> m (Raw S.Expr) open = parseProgram (Folder "fluid/example") -loadModule :: forall m. MonadAff m => MonadWithGraphAlloc m => File -> ProgCxtEval Vertex -> m (ProgCxtEval Vertex) -loadModule file (ProgCxtEval r@{ progCxt: ProgCxt r'@{ mods }, γ }) = do - src <- loadFile (Folder "fluid/lib") file - mod <- parse src P.module_ >>= desugarModuleFwd >>= traverse (const fresh) - γ' <- eval_module γ mod empty - pure $ ProgCxtEval r { progCxt = ProgCxt r' { mods = mod : mods }, γ = γ <+> γ' } - -defaultImports :: forall m. MonadAff m => MonadWithGraphAlloc m => m (ProgCxtEval Vertex) -defaultImports = do - γ <- traverse alloc primitives - loadModule (File "prelude") (ProgCxtEval { progCxt: ProgCxt { mods: Nil, datasets: Nil }, γ }) - >>= loadModule (File "graphics") - >>= loadModule (File "convolution") - module_ :: forall m. MonadAff m => MonadError Error m => File -> Raw ProgCxt -> m (Raw ProgCxt) module_ file (ProgCxt r@{ mods }) = do src <- loadFile (Folder "fluid/lib") file mod <- parse src P.module_ >>= desugarModuleFwd pure $ ProgCxt r { mods = mod : mods } -defaultImports2 :: forall m. MonadAff m => MonadError Error m => m (Raw ProgCxt) -defaultImports2 = +defaultImports :: forall m. MonadAff m => MonadError Error m => m (Raw ProgCxt) +defaultImports = pure (ProgCxt { mods: Nil, datasets: Nil }) >>= module_ (File "prelude") >>= module_ (File "graphics") @@ -93,21 +79,6 @@ datasetAs file x (ProgCxt r@{ datasets }) = do eα <- parseProgram (Folder "fluid") file >>= desug pure $ ProgCxt r { datasets = x ↦ eα : datasets } -openDefaultImports :: forall m g. MonadAff m => MonadError Error m => Graph g => m (GraphConfig g) -openDefaultImports = do - (g × n) × progCxt <- runWithGraphAllocT (G.empty × 0) defaultImports - pure { g, n, progCxt } - -openDatasetAs :: forall m g. MonadAff m => MonadError Error m => Graph g => File -> Var -> GraphConfig g -> m (GraphConfig g × Env Vertex) -openDatasetAs file x { g, n, progCxt: ProgCxtEval r@{ progCxt: ProgCxt r'@{ datasets }, γ } } = do - s <- parseProgram (Folder "fluid") file - (g' × n') × xv × progCxt <- - runWithGraphAllocT (g × n) do - eα <- desug s >>= alloc - v <- eval γ eα empty - pure $ D.singleton x v × ProgCxtEval (r { progCxt = ProgCxt (r' { datasets = x ↦ eα : datasets }) }) - pure ({ g: g', n: n', progCxt } × xv) - eval_progCxt :: forall m. MonadWithGraphAlloc m => ProgCxt Vertex -> m (Env Vertex) eval_progCxt (ProgCxt { mods, datasets }) = traverse alloc primitives diff --git a/test/Many.purs b/test/Many.purs index 94d46b9d3..4bfaec19d 100644 --- a/test/Many.purs +++ b/test/Many.purs @@ -6,7 +6,7 @@ import App.Fig (linkResult, loadLinkFig) import Benchmark.Util (BenchRow) import Data.Array (zip) import Effect.Aff (Aff) -import Module (File(..), Folder(..), datasetAs, defaultImports2, loadFile) +import Module (File(..), Folder(..), datasetAs, defaultImports, loadFile) import Test.Util (TestBwdSpec, TestLinkSpec, TestSpec, TestWithDatasetSpec, checkPretty, testWithSetup2) import Util (type (×)) @@ -14,7 +14,7 @@ many :: Array TestSpec -> Int -> Array (String × Aff BenchRow) many specs n = zip (specs <#> _.file) (specs <#> one) where one { file, fwd_expect } = do - progCxt <- defaultImports2 + progCxt <- defaultImports testWithSetup2 n (File file) progCxt { δv: identity, fwd_expect, bwd_expect: mempty } bwdMany :: Array TestBwdSpec -> Int -> Array (String × Aff BenchRow) @@ -22,7 +22,7 @@ bwdMany specs n = zip (specs <#> _.file) (specs <#> one) where folder = File "slicing/" one { file, file_expect, δv, fwd_expect } = do - progCxt <- defaultImports2 + progCxt <- defaultImports bwd_expect <- loadFile (Folder "fluid/example") (folder <> File file_expect) testWithSetup2 n (folder <> File file) progCxt { δv, fwd_expect, bwd_expect } @@ -30,7 +30,7 @@ withDatasetMany :: Array TestWithDatasetSpec -> Int -> Array (String × Aff Benc withDatasetMany specs n = zip (specs <#> _.file) (specs <#> one) where one { dataset, file } = do - progCxt <- defaultImports2 >>= datasetAs (File dataset) "data" + progCxt <- defaultImports >>= datasetAs (File dataset) "data" testWithSetup2 n (File file) progCxt { δv: identity, fwd_expect: mempty, bwd_expect: mempty } linkMany :: Array TestLinkSpec -> Array (String × Aff Unit)