blob: 92ff0a79ea968494aebf4ab438495b6db11196e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
;; Copyright (c) Eduardo Julian. All rights reserved.
;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
;; If a copy of the MPL was not distributed with this file,
;; You can obtain one at http://mozilla.org/MPL/2.0/.
(ns lux.compiler.parallel
(:require (clojure [string :as string]
[set :as set]
[template :refer [do-template]])
clojure.core.async
clojure.core.match
clojure.core.match.array
(lux [base :as & :refer [|let |do return* return fail fail* |case]])))
;; [Utils]
(def ^:private !state! (atom {}))
(def ^:private get-compiler
(fn [compiler]
(return* compiler compiler)))
(defn ^:private set-compiler [compiler*]
(fn [_]
(return* compiler* compiler*)))
(defn ^:private merge-modules
"(-> Compiler Compiler)"
[new old]
(->> old
(&/set$ &/$source (&/get$ &/$source new))
(&/set$ &/$modules (&/get$ &/$modules new))
(&/set$ &/$seed (&/get$ &/$seed new))
(&/set$ &/$host (&/get$ &/$host new))))
;; [Exports]
(defn setup!
"Must always call this function before using parallel compilation to make sure that the state that is being tracked is in proper shape."
[]
(reset! !state! {}))
(defn parallel-compilation [compile-module*]
(fn [module-name]
(|do [:let [_ (prn 'parallel-compilation module-name)]
pre get-compiler
output (compile-module* module-name)
post get-compiler
post* (set-compiler (merge-modules post pre))
;; TODO: Some type-vars in the typing environment stay in
;; the environment forever, making type-checking slower.
;; The merging process for modules more-or-less "fixes" the
;; problem by resetting the typing enviroment, but ideally
;; those type-vars shouldn't survive in the first place.
;; MUST FIX
;; :let [_ (prn 'parallel-compilation module-name
;; 'PRE (->> pre (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length)
;; 'POST (->> post (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length)
;; 'POST* (->> post* (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))]
]
(return output)
)))
|