Skip to content

Commit

Permalink
🧩 [remove-unused]: Old implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolyp committed Oct 5, 2023
1 parent 57ee0b4 commit 2a4699b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/App/Fig.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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 <$> γ
Expand Down
39 changes: 5 additions & 34 deletions src/Module.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..), (<+>))

Expand Down Expand Up @@ -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")
Expand All @@ -93,21 +79,6 @@ datasetAs file x (ProgCxt r@{ datasets }) = do
<- 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
<- 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
Expand Down
8 changes: 4 additions & 4 deletions test/Many.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ 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 (×))

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)
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 }

withDatasetMany :: Array TestWithDatasetSpec -> Int -> Array (String × Aff BenchRow)
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)
Expand Down

0 comments on commit 2a4699b

Please sign in to comment.