From 609cc6c16e75c13d87183c38245136fa038b0496 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 8 Sep 2021 02:03:18 -0400 Subject: No more module annotations. --- .../book/the_lux_programming_language/chapter_6.md | 4 +-- lux-bootstrapper/src/lux/analyser.clj | 4 +-- lux-bootstrapper/src/lux/analyser/lux.clj | 4 +-- lux-bootstrapper/src/lux/analyser/module.clj | 22 ------------ lux-bootstrapper/src/lux/compiler/cache.clj | 23 ++++-------- lux-bootstrapper/src/lux/compiler/core.clj | 7 ---- stdlib/source/library/lux.lux | 41 ++++++++-------------- .../library/lux/tool/compiler/language/lux.lux | 4 --- .../language/lux/phase/analysis/module.lux | 24 ------------- stdlib/source/poly/lux/data/format/json.lux | 1 - stdlib/source/test/lux/macro.lux | 2 -- stdlib/source/test/lux/meta.lux | 9 ----- 12 files changed, 25 insertions(+), 120 deletions(-) diff --git a/documentation/book/the_lux_programming_language/chapter_6.md b/documentation/book/the_lux_programming_language/chapter_6.md index a68d791e4..a57ff4913 100644 --- a/documentation/book/the_lux_programming_language/chapter_6.md +++ b/documentation/book/the_lux_programming_language/chapter_6.md @@ -284,11 +284,11 @@ The type-system would work just fine without it, but users of the language proba `#Named` is what gives the name _"List"_ to the `List` type, so you can actually read about it everywhere without getting bogged down in implementation details. -You see, Lux's type system is structural in nature, rather than nominal (the dominating style in programming languages). +You see, Lux's type system is structural in nature, rather than nominal (the usual style in programming languages). That means all that matters is how a type is built; not what you call it. -That implies 2 types with different names, but the exact same value, would actually type-check in your code. +That implies 2 types with different names, but the exact same internal structure, would actually type-check in your code. That may sound odd (if you come from Java or other languages with nominal types), but it's actually very convenient and enables you to do some pretty nifty tricks. diff --git a/lux-bootstrapper/src/lux/analyser.clj b/lux-bootstrapper/src/lux/analyser.clj index 27323be2b..297ad5482 100644 --- a/lux-bootstrapper/src/lux/analyser.clj +++ b/lux-bootstrapper/src/lux/analyser.clj @@ -160,9 +160,9 @@ (&&lux/analyse-program analyse optimize compile-program ?program))) "lux def module" - (|let [(&/$Item ?meta (&/$Item ?imports (&/$End))) parameters] + (|let [(&/$Item ?imports (&/$End)) parameters] (&/with-location location - (&&lux/analyse-module analyse optimize eval! compile-module ?meta ?imports))) + (&&lux/analyse-module analyse optimize eval! compile-module ?imports))) "lux in-module" (|let [(&/$Item [_ (&/$Text ?module)] (&/$Item ?expr (&/$End))) parameters] diff --git a/lux-bootstrapper/src/lux/analyser/lux.clj b/lux-bootstrapper/src/lux/analyser/lux.clj index f4d76912f..77d54fab2 100644 --- a/lux-bootstrapper/src/lux/analyser/lux.clj +++ b/lux-bootstrapper/src/lux/analyser/lux.clj @@ -666,11 +666,9 @@ (return (doto (promise) (deliver (&/$Right _compiler)))))))) -(defn analyse-module [analyse optimize eval! compile-module ?annotations ?imports] +(defn analyse-module [analyse optimize eval! compile-module ?imports] (|do [_ &/ensure-directive - ==anns (eval analyse optimize eval! &type/Code ?annotations) module-name &/get-module-name - _ (&&module/set-anns ==anns module-name) _imports (&&module/fetch-imports ?imports) current-module &/get-module-name =asyncs (&/map% (fn [_import] diff --git a/lux-bootstrapper/src/lux/analyser/module.clj b/lux-bootstrapper/src/lux/analyser/module.clj index 8c6f06d88..1904e55b7 100644 --- a/lux-bootstrapper/src/lux/analyser/module.clj +++ b/lux-bootstrapper/src/lux/analyser/module.clj @@ -22,7 +22,6 @@ "module-aliases" "defs" "imports" - "module-annotations" "module-state"]) (defn ^:private new-module [hash] @@ -34,8 +33,6 @@ (&/|table) ;; "lux;imports" &/$End - ;; module-annotations - &/$None ;; "module-state" $Active] )) @@ -212,25 +209,6 @@ (&/get$ $imports) (&/|any? (partial = imported-module-name)))) -(defn get-anns [module-name] - (fn [state] - (if-let [module (->> state - (&/get$ &/$modules) - (&/|get module-name))] - (return* state (&/get$ $module-annotations module)) - ((&/fail-with-loc (str "[Analyser Error] Module does not exist: " module-name)) - state)))) - -(defn set-anns [anns module-name] - (fn [state] - (return* (->> state - (&/update$ &/$modules - (fn [ms] - (&/|update module-name - #(&/set$ $module-annotations (&/$Some anns) %) - ms)))) - nil))) - (def empty_annotations (let [dummy_location (&/T ["" 0 0])] (&/T [dummy_location diff --git a/lux-bootstrapper/src/lux/compiler/cache.clj b/lux-bootstrapper/src/lux/compiler/cache.clj index d2b232f74..6d1e5602d 100644 --- a/lux-bootstrapper/src/lux/compiler/cache.clj +++ b/lux-bootstrapper/src/lux/compiler/cache.clj @@ -112,22 +112,16 @@ (|do [_ (delete module)] (return false))) -(defn ^:private install-module [load-def-value module module-hash imports ?module-anns def-entries] +(defn ^:private install-module [load-def-value module module-hash imports def-entries] (|do [_ (&a-module/create-module module module-hash) _ (&a-module/flag-cached-module module) - _ (|case ?module-anns - (&/$Some module-anns) - (&a-module/set-anns module-anns module) - - (&/$None _) - (return nil)) _ (&a-module/set-imports imports) _ (&/map% (partial process-def-entry load-def-value module) def-entries)] (return nil))) (defn ^:private process-module [pre-load! source-dirs cache-table module-name module-hash - _imports-section _module-anns-section _defs-section + _imports-section _defs-section load-def-value install-all-defs-in-module uninstall-all-defs-in-module] (|do [^String descriptor (&&core/read-module-descriptor! module-name) :let [imports (let [imports (vec (.split ^String _imports-section &&core/entry-separator)) @@ -144,17 +138,12 @@ imports)] (if (&/|every? (fn [_module] (contains? cache-table* _module)) imports) - (let [[?module-anns _] (if (= "..." _module-anns-section) - [&/$None nil] - (let [[module-anns _] (&&&ann/deserialize _module-anns-section)] - [(&/$Some module-anns) _])) - def-entries (let [def-entries (vec (.split ^String _defs-section &&core/entry-separator))] + (let [def-entries (let [def-entries (vec (.split ^String _defs-section &&core/entry-separator))] (if (= [""] def-entries) &/$End (&/->list def-entries)))] (|do [_ (install-all-defs-in-module module-name) - _ (install-module load-def-value module-name module-hash - imports ?module-anns def-entries) + _ (install-module load-def-value module-name module-hash imports def-entries) =module (&/find-module module-name)] (return (&/T [true (assoc cache-table* module-name =module)])))) (return (&/T [false cache-table*]))))) @@ -191,14 +180,14 @@ :else (|do [^String descriptor (&&core/read-module-descriptor! module-name) - :let [[_compiler _hash _imports-section _module-anns-section _defs-section] (.split descriptor &&core/section-separator) + :let [[_compiler _hash _imports-section _defs-section] (.split descriptor &&core/section-separator) drop-cache! (|do [_ (uninstall-cache module-name) _ (uninstall-all-defs-in-module module-name)] (return cache-table))]] (if (and (= module-hash (Long/parseUnsignedLong ^String _hash)) (= &/version _compiler)) (|do [[success? cache-table*] (process-module pre-load! source-dirs cache-table module-name module-hash - _imports-section _module-anns-section _defs-section + _imports-section _defs-section load-def-value install-all-defs-in-module uninstall-all-defs-in-module) _ (if success? (return nil) diff --git a/lux-bootstrapper/src/lux/compiler/core.clj b/lux-bootstrapper/src/lux/compiler/core.clj index b2d366d5d..3dbd93140 100644 --- a/lux-bootstrapper/src/lux/compiler/core.clj +++ b/lux-bootstrapper/src/lux/compiler/core.clj @@ -44,7 +44,6 @@ (defn generate-module-descriptor [file-hash] (|do [module-name &/get-module-name - ?module-anns (&a-module/get-anns module-name) defs &a-module/defs imports &a-module/imports :let [def-entries (&/fold (fn [def-entries _def] @@ -117,12 +116,6 @@ module-descriptor (->> (&/|list &/version (Long/toUnsignedString file-hash) import-entries - (|case ?module-anns - (&/$Some module-anns) - (&&&ann/serialize module-anns) - - (&/$None _) - "...") def-entries) (&/|interpose section-separator) (&/fold str ""))]] diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index c1696ff86..823132f6c 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -549,7 +549,6 @@ ... #module_aliases (List [Text Text]) ... #definitions (List [Text Global]) ... #imports (List Text) -... #module_annotations (Maybe Code) ... #module_state Module_State])) ("lux def type tagged" Module (#Named ["library/lux" "Module"] @@ -565,14 +564,11 @@ (#Product ... "lux.imports" (#Apply Text List) - (#Product - ... "lux.module_annotations" - (#Apply Code Maybe) - ... module_state - Module_State) + ... module_state + Module_State ))))) (record$ #End) - ["module_hash" "module_aliases" "definitions" "imports" "module_annotations" "module_state"] + ["module_hash" "module_aliases" "definitions" "imports" "module_state"] .public) ... (type: .public Type_Context @@ -1673,7 +1669,7 @@ #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions #scope_type_vars scope_type_vars #eval _eval] state] - ({(#Some [#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_annotations _ #module_state _]) + ({(#Some [#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_state _]) ({(#Some constant) ({(#Alias real_name) (#Right [state real_name]) @@ -2210,7 +2206,7 @@ ($' Maybe Macro)) (do maybe_monad [$module (plist\value module modules) - gdef (let' [[#module_hash _ #module_aliases _ #definitions bindings #imports _ #module_annotations _ #module_state _] ("lux type check" Module $module)] + gdef (let' [[#module_hash _ #module_aliases _ #definitions bindings #imports _ #module_state _] ("lux type check" Module $module)] (plist\value name bindings))] ({(#Alias [r_module r_name]) (macro'' modules current_module r_module r_name) @@ -3261,7 +3257,7 @@ (-> Name (Meta [Nat (List Name) Bit Type])) (do meta_monad [=module (..module module) - .let [[#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_annotations _ #module_state _] =module]] + .let [[#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_state _] =module]] (case (plist\value (text\composite "#" name) definitions) (#Some (#Slot [exported type group index])) (in_meta [index @@ -3289,7 +3285,7 @@ (#Named [module name] unnamed) (do meta_monad [=module (..module module) - .let [[#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_annotations _ #module_state _] =module]] + .let [[#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_state _] =module]] (case (plist\value name definitions) (#Some (#Type [exported? (#Named _ _type) (#Right slots)])) (case (interface_methods _type) @@ -4002,7 +3998,7 @@ (#Slot _) (list)))) - (let [[#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_annotations _ #module_state _] =module] + (let [[#module_hash _ #module_aliases _ #definitions definitions #imports _ #module_state _] =module] definitions))] (#Right state (list\conjoint to_alias))) @@ -4084,7 +4080,7 @@ #None #None - (#Some [#definitions definitions #module_hash _ #module_aliases _ #imports _ #module_annotations _ #module_state _]) + (#Some [#definitions definitions #module_hash _ #module_aliases _ #imports _ #module_state _]) (case (plist\value v_name definitions) #None #None @@ -4117,7 +4113,7 @@ #None (#Left (text\composite "Unknown definition: " (name\encoded name))) - (#Some [#definitions definitions #module_hash _ #module_aliases _ #imports _ #module_annotations _ #module_state _]) + (#Some [#definitions definitions #module_hash _ #module_aliases _ #imports _ #module_state _]) (case (plist\value v_name definitions) #None (#Left (text\composite "Unknown definition: " (name\encoded name))) @@ -4401,7 +4397,7 @@ (-> Text Text (Meta Bit)) (do meta_monad [module (module module_name) - .let [[#module_hash _ #module_aliases _ #definitions _ #imports imports #module_annotations _ #module_state _] module]] + .let [[#module_hash _ #module_aliases _ #definitions _ #imports imports #module_state _] module]] (in (is_member? imports import_name)))) (def: (referrals module_name options) @@ -4508,16 +4504,9 @@ (~+ localizations) (~+ openings))))) -(macro: .public (module: tokens) +(macro: .public (module: _imports) (do meta_monad - [.let [[_meta _imports] (: [(List [Code Code]) (List Code)] - (case tokens - (^ (list& [_ (#Record _meta)] _imports)) - [_meta _imports] - - _ - [(list) tokens]))] - current_module current_module_name + [current_module current_module_name imports (imports_parser #0 current_module #End _imports) .let [=imports (|> imports (list\each (: (-> Importation Code) @@ -4528,9 +4517,7 @@ (function (_ [module_name m_alias =refer]) (refer_code module_name m_alias =refer))) imports) - =module (` ("lux def module" [(~ location_code) - (#.Record (~ (definition_annotations _meta)))] - (~ =imports)))]] + =module (` ("lux def module" (~ =imports)))]] (in (#Item =module =refers)))) (macro: .public (\ tokens) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux.lux index 16493d1dc..37ccff163 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux.lux @@ -51,8 +51,6 @@ (_.list (_.and _.text global)) ... #imports (_.list _.text) - ... #module_annotations - (_.maybe _.code) ... #module_state _.any))) @@ -87,8 +85,6 @@ (.list (<>.and .text global)) ... #imports (.list .text) - ... #module_annotations - (.maybe .code) ... #module_state (\ <>.monad in #.Cached)))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux index 62bf284c3..845d07f17 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux @@ -65,38 +65,14 @@ #.Compiled "Compiled" #.Cached "Cached")])) -(exception: .public (cannot_set_module_annotations_more_than_once {module Text} {old Code} {new Code}) - (exception.report - ["Module" module] - ["Old annotations" (%.code old)] - ["New annotations" (%.code new)])) - (def: .public (empty hash) (-> Nat Module) [#.module_hash hash #.module_aliases (list) #.definitions (list) #.imports (list) - #.module_annotations #.None #.module_state #.Active]) -(def: .public (set_annotations annotations) - (-> Code (Operation Any)) - (///extension.lifted - (do ///.monad - [self_name meta.current_module_name - self meta.current_module] - (case (value@ #.module_annotations self) - #.None - (function (_ state) - (#try.Success [(revised@ #.modules - (plist.has self_name (with@ #.module_annotations (#.Some annotations) self)) - state) - []])) - - (#.Some old) - (/.except' cannot_set_module_annotations_more_than_once [self_name old annotations]))))) - (def: .public (import module) (-> Text (Operation Any)) (///extension.lifted diff --git a/stdlib/source/poly/lux/data/format/json.lux b/stdlib/source/poly/lux/data/format/json.lux index 75f042b58..e5b9baca5 100644 --- a/stdlib/source/poly/lux/data/format/json.lux +++ b/stdlib/source/poly/lux/data/format/json.lux @@ -1,5 +1,4 @@ (.module: - {#.doc "Codecs for values in the JSON format."} [library [lux "*" ["[0]" debug] diff --git a/stdlib/source/test/lux/macro.lux b/stdlib/source/test/lux/macro.lux index f465b34a6..745eeb005 100644 --- a/stdlib/source/test/lux/macro.lux +++ b/stdlib/source/test/lux/macro.lux @@ -79,7 +79,6 @@ (!global /.log_expansion!) (!global /.log_full_expansion!))) #.imports (list) - #.module_annotations #.None #.module_state #.Active]] [current_module [#.module_hash 0 @@ -89,7 +88,6 @@ (!global ..pow/4) (!global ..repeated))) #.imports (list) - #.module_annotations #.None #.module_state #.Active]]) #.scopes (list) #.type_context [#.ex_counter 0 diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index eaa0ff4d6..cea70ce68 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -183,13 +183,11 @@ #.module_aliases (list) #.definitions (list) #.imports (list) - #.module_annotations #.None #.module_state #.Active] expected_module [#.module_hash 0 #.module_aliases (list) #.definitions (list) #.imports (list imported_module_name) - #.module_annotations #.None #.module_state #.Active] expected_modules (list [expected_current_module expected_module] @@ -380,14 +378,12 @@ #.module_aliases (list) #.definitions current_globals #.imports (list) - #.module_annotations #.None #.module_state #.Active]] [expected_macro_module [#.module_hash 0 #.module_aliases (list) #.definitions macro_globals #.imports (list) - #.module_annotations #.None #.module_state #.Active]]) #.scopes (list) #.type_context [#.ex_counter 0 @@ -498,14 +494,12 @@ #.module_aliases (list) #.definitions current_globals #.imports (list) - #.module_annotations #.None #.module_state #.Active]] [expected_macro_module [#.module_hash 0 #.module_aliases (list) #.definitions macro_globals #.imports (list) - #.module_annotations #.None #.module_state #.Active]]) #.scopes (list) #.type_context [#.ex_counter 0 @@ -672,7 +666,6 @@ #.module_aliases (list) #.definitions (list) #.imports (list tag_module) - #.module_annotations #.None #.module_state #.Active]] [tag_module [#.module_hash 0 @@ -689,7 +682,6 @@ (list\each (function (_ [index short]) [(format "#" short) (#.Slot [true type_1 (#.Item tags_1) index])]))))) #.imports (list) - #.module_annotations #.None #.module_state #.Active]]) #.scopes (list) #.type_context [#.ex_counter 0 @@ -799,7 +791,6 @@ #.module_aliases (list) #.definitions globals #.imports (list) - #.module_annotations #.None #.module_state #.Active]]) #.scopes scopes #.type_context [#.ex_counter 0 -- cgit v1.2.3