Skip to content

Commit

Permalink
Fix: Better hybrid file-system management for caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Nov 21, 2024
1 parent 51dfe6d commit 17060df
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
[Phase translation.Phase]
[Handler translation.Handler]
[Bundle translation.Bundle]
[Extender translation.Extender]]
)
[Extender translation.Extender]])

(every .public (Expression i)
(-> Phase Archive i
Expand All @@ -102,9 +101,10 @@
(translation.Host (Bytecode Any) Definition))

(the .public (class_name [module id])
(-> unit.ID Text)
(-> unit.ID
Text)
(text "lux"
"." (%.natural (++ (.universe#)))
"." (%.natural (n.% 10 (++ (.universe#))))
"." (%.natural module)
"." (%.natural id)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
["%" \\injection]]]
[macro
["[0]" expansion]
["[0]" template]]]]
["[0]" template]]
[math
[number
[/64
["n" natural]]]]]]
[////
["[0]" phase (.use "[1]#[0]" monad)]
["[0]" translation]
Expand All @@ -21,7 +25,7 @@

(the .public (artifact [module artifact])
(-> unit.ID Text)
(text "u" (%.natural (.universe#))
(text "u" (%.natural (n.% 10 (++ (.universe#))))
"m" (%.natural module)
"a" (%.natural artifact)))

Expand Down
14 changes: 13 additions & 1 deletion stdlib/source/library/lux/compiler/meta/cache.lux
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
[error
["[0]" try (.only Try)]]
[world
["[0]" file]]]])
["[0]" file]]
[function
[predicate (.only Predicate)]]
[data
["[0]" text]]]])

(the .public path
file.Path
"cache")

(the .public (path? fs it)
(for_any (_ !)
(-> (file.System !)
(Predicate file.Path)))
(let [prefix (text ..path (by fs delimiter))]
(or (text.starts_with? prefix it)
(text.= path it))))

(the .public (enabled? fs)
(for_any (_ !)
(-> (file.System !)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/library/lux/compiler/meta/io/archive.lux
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@

(the pseudo_module
Text
"(Lux Caching System)")
"(Caching System)")

(the cache_of
(-> (List Custom)
Expand Down
53 changes: 22 additions & 31 deletions stdlib/source/library/lux/compiler/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,16 @@
(by host delimiter))
(,, (template.with [<name>]
[(the (<name> path)
(monad.let future.monad
[?/0 (by cache <name> path)
?/1 (by host <name> path)]
(pure (or ?/0 ?/1))))]
(if (cache.path? cache path)
(by cache <name> path)
(by host <name> path)))]

[[file?]
[directory?]]))
(the (read path)
(if (cache.path? cache path)
(by cache read path)
(by host read path)))
(,, (template.with [<name>]
[(the <name>
(by cache <name>))]
Expand All @@ -167,21 +170,9 @@
[file_size]
[last_modified]
[can_execute?]
[delete]]))
(the (read path)
(monad.let future.monad
[it (by cache read path)]
(when it
{try.#Failure _}
(by host read path)

_
(pure it))))
(,, (template.with [<name>]
[(the <name>
(by cache <name>))]

[[modify]
[delete]

[modify]
[write]
[append]
[move]]))
Expand Down Expand Up @@ -276,14 +267,14 @@
tar)]
(pure [])))))

(the (cache! original_fs context platform)
(the (cache! host_fs context platform)
(for_any (_ <parameters>)
(-> (file.System Future) Context (Platform <parameters>)
(Future (Try Any))))
(monad.let (try.with future.monad)
[cache (cache_tar context (its platform.#file_system platform))]
(by original_fs write
(cache_path original_fs context)
(by host_fs write
(cache_path host_fs context)
(by tar.binary as cache))))

(the (with_cache it)
Expand All @@ -294,15 +285,15 @@
[cache_fs
(revised platform.#file_system (hybrid_fs cache_fs) it)]))

(the (enable_output! original_fs context)
(the (enable_output! host_fs context)
(-> (file.System Future) Context
(Future (Try Any)))
(let [target_root (its context.#target context)]
(monad.let [! future.monad]
[? (by original_fs directory? target_root)]
[? (by host_fs directory? target_root)]
(if ?
(pure {try.#Success []})
(file.make_directories ! original_fs target_root)))))
(file.make_directories ! host_fs target_root)))))

(the .public (compiler lux_compiler file_context
expander host_analysis platform translation_bundle host_declaration_bundle program global extender
Expand All @@ -328,10 +319,10 @@
(<| (or_crash! "Compilation failed:")
..timed
(monad.let [! (try.with !)]
[.let [original_fs (its platform.#file_system platform)
[.let [host_fs (its platform.#file_system platform)
[cache_fs platform] (with_cache platform)]
_ (enable_output! original_fs file_context)
_ (load_cache! original_fs cache_fs file_context)
_ (enable_output! host_fs file_context)
_ (load_cache! host_fs cache_fs file_context)
import (import.import (its platform.#file_system platform) (its cli.#libraries compilation))
.let [all_extensions [(analysisE.bundle host_analysis)
synthesisE.bundle
Expand Down Expand Up @@ -375,12 +366,12 @@
{try.#Success [archive state]}
(monad.let !
[_ (cache/archive.cache! (its platform.#file_system platform) (its cli.#configuration compilation) archive)
_ (cache! original_fs file_context platform)
_ (cache! host_fs file_context platform)
host_dependencies (..load_host_dependencies (its platform.#file_system platform)
(its cli.#host_dependencies compilation))

_ (..package! file_context
original_fs
host_fs
host_dependencies
packager,package
archive
Expand All @@ -389,7 +380,7 @@

{try.#Failure error}
(monad.let !
[_ (cache! original_fs file_context platform)]
[_ (cache! host_fs file_context platform)]
(future#pure {try.#Failure error})))))

{cli.#Export export}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/transduction.lux
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
... https://clojure.org/news/2012/05/08/reducers
... https://clojure.org/news/2012/05/15/anatomy-of-reducer
(every .public (Reduction summary detail)
(-> detail summary
summary))
(-> detail
(Change summary)))

(the .public functor
(for_any (_ summary)
Expand Down
7 changes: 6 additions & 1 deletion stdlib/source/test/lux/compiler/meta/archive.lux
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@
(list [module/0' @module/0' entry'])
(and (same? module/0 module/0')
(same? @module/0 @module/0')
(same? entry entry'))
(when entry'
{.#Some entry'}
(same? entry entry')

else
false))

_
false))))
Expand Down

0 comments on commit 17060df

Please sign in to comment.