1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 08:50:27 +00:00

Add circular dependency detection.

This detection will not stop compilation, as errors
in general do not stop compilation unless exit on error
is passed inside an import, but should notify the user something
is going on.
This commit is contained in:
Calvin Rose 2020-04-19 09:35:14 -05:00
parent 60f8dd0bfc
commit 3e60e82529

View File

@ -2102,7 +2102,7 @@
[ext loader] [ext loader]
(defn- find-prefix (defn- find-prefix
[pre] [pre]
(or (find-index |(string/has-prefix? pre ($ 0)) module/paths) 0)) (or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) module/paths) 0))
(array/insert module/paths 0 [(string ":cur:/:all:" ext) loader check-.]) (array/insert module/paths 0 [(string ":cur:/:all:" ext) loader check-.])
(def all-index (find-prefix ":all:")) (def all-index (find-prefix ":all:"))
(array/insert module/paths all-index [(string ":all:" ext) loader not-check-.]) (array/insert module/paths all-index [(string ":all:" ext) loader not-check-.])
@ -2243,12 +2243,14 @@
(unless fullpath (error mod-kind)) (unless fullpath (error mod-kind))
(if-let [check (in module/cache fullpath)] (if-let [check (in module/cache fullpath)]
check check
(if-let [check2 (module/loading fullpath)]
(error (string "circular dependency " fullpath " detected"))
(do (do
(def loader (if (keyword? mod-kind) (module/loaders mod-kind) mod-kind)) (def loader (if (keyword? mod-kind) (module/loaders mod-kind) mod-kind))
(unless loader (error (string "module type " mod-kind " unknown"))) (unless loader (error (string "module type " mod-kind " unknown")))
(def env (loader fullpath args)) (def env (loader fullpath args))
(put module/cache fullpath env) (put module/cache fullpath env)
env))) env))))
(defn import* (defn import*
"Function form of import. Same parameters, but the path "Function form of import. Same parameters, but the path