From 58c299b90fbb3a20cf4e624fd20e4bb7f5846672 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 20 Aug 2018 18:58:17 -0400 Subject: - Added timing functionality to measure performance. - Measuring performance of different parts of the compilation process. --- stdlib/source/lux/compiler/default.lux | 67 ++++++++++++---------- stdlib/source/lux/compiler/default/phase.lux | 19 ++++++ .../compiler/default/phase/extension/statement.lux | 63 ++++++++++---------- stdlib/source/lux/time/duration.lux | 4 ++ 4 files changed, 93 insertions(+), 60 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux/compiler/default.lux b/stdlib/source/lux/compiler/default.lux index 5b4a1a153..16c1a2b0e 100644 --- a/stdlib/source/lux/compiler/default.lux +++ b/stdlib/source/lux/compiler/default.lux @@ -29,20 +29,13 @@ [".A" expression]] ["." translation (#+ Host Bundle)] ["." statement - [".S" total]]]] + [".S" total]] + ["." extension]]] ## (luxc [cache] ## [cache/description] ## [cache/io]) ) -(def: (forgive-eof operation) - (All [s o] - (-> (phase.Operation s o) (phase.Operation s Any))) - (function (_ compiler) - (ex.catch syntax.end-of-file - (|>> [compiler]) - (operation compiler)))) - (def: #export prelude Text "lux") (def: (read current-module aliases) @@ -65,17 +58,17 @@ ## ## (format module-name "/" cache.descriptor-name) ## ## (encoding.to-utf8 (%code (cache/description.write file-name module)))))) -(type: #export (Platform fs anchor expression statement) +(type: #export (Platform ! anchor expression statement) {#host (Host expression statement) #phase (translation.Phase anchor expression statement) #runtime (translation.Operation anchor expression statement Any) - #file-system (file.System fs)}) + #file-system (file.System !)}) (type: #export Source {#name Text #code Text}) -(with-expansions [ (as-is (Platform fs anchor expression statement)) +(with-expansions [ (as-is (Platform ! anchor expression statement)) (as-is (statement.Operation anchor expression statement Any)) (as-is (statement.State+ anchor expression statement)) (as-is (Bundle anchor expression statement))] @@ -98,18 +91,30 @@ (def: (loop-module-compilation module-name) (All [anchor expression statement] (-> Text )) - (forgive-eof - (loop [_ []] - (do phase.Monad - [code (statement.lift-analysis - (do @ - [code (..read module-name syntax.no-aliases) - #let [[cursor _] code] - _ (analysis.set-cursor cursor)] - (wrap code))) - _ (totalS.phase code) - _ init.refresh] - (forgive-eof (recur [])))))) + (let [iteration (: (All [anchor expression statement] + ) + (<| (phase.timed (name-of ..loop-module-compilation) "ITERATION") + (do phase.Monad + [code (statement.lift-analysis + (do @ + [code (<| (phase.timed (name-of ..loop-module-compilation) "syntax") + (..read module-name syntax.no-aliases)) + #let [[cursor _] code] + _ (analysis.set-cursor cursor)] + (wrap code))) + _ (<| (phase.timed (name-of ..loop-module-compilation) "PHASE") + (totalS.phase code))] + init.refresh)))] + (function (_ state) + (loop [state state] + (case (iteration state) + (#error.Success [state' output]) + (recur state') + + (#error.Error error) + (if (ex.match? syntax.end-of-file error) + (#error.Success [state []]) + (#error.Error error))))))) (def: (perform-module-compilation module-name source) (All [anchor expression statement] @@ -120,8 +125,8 @@ (end-module-compilation module-name))) (def: #export (compile-module platform configuration compiler) - (All [fs anchor expression statement] - (-> Configuration (fs ))) + (All [! anchor expression statement] + (-> Configuration (! ))) (do (:: (get@ #file-system platform) &monad) [source (context.read (get@ #file-system platform) (get@ #cli.sources configuration) @@ -132,15 +137,15 @@ (<| (:: @ map product.left) (:: (get@ #file-system platform) lift) (phase.run' compiler) - (:share [fs anchor expression statement] + (:share [! anchor expression statement] { platform} { (perform-module-compilation (get@ #cli.module configuration) source)})))) (def: #export (initialize platform configuration translation-bundle) - (All [fs anchor expression statement] - (-> Configuration (fs ))) + (All [! anchor expression statement] + (-> Configuration (! ))) (|> platform (get@ #runtime) statement.lift-translation @@ -177,8 +182,8 @@ ) (def: #export (compile platform configuration translation-bundle) - (All [fs anchor expression statement] - (-> Configuration (fs Any))) + (All [! anchor expression statement] + (-> Configuration (! Any))) (do (:: (get@ #file-system platform) &monad) [compiler (initialize platform configuration translation-bundle) _ (compile-module platform (set@ #cli.module ..prelude configuration) compiler) diff --git a/stdlib/source/lux/compiler/default/phase.lux b/stdlib/source/lux/compiler/default/phase.lux index 25ceea746..a81d5dfa7 100644 --- a/stdlib/source/lux/compiler/default/phase.lux +++ b/stdlib/source/lux/compiler/default/phase.lux @@ -9,6 +9,10 @@ ["." error (#+ Error) ("error/." Functor)] ["." text format]] + [time + ["." instant] + ["." duration]] + ["." io] [macro ["s" syntax (#+ syntax:)]]]) @@ -94,3 +98,18 @@ [[pre/state' temp] (pre input pre/state) [post/state' output] (post temp post/state)] (wrap [[pre/state' post/state'] output])))) + +(def: #export (timed definition description operation) + (All [s a] + (-> Name Text (Operation s a) (Operation s a))) + (do Monad + [_ (wrap []) + #let [pre (io.run instant.now)] + output operation + #let [_ (log! (|> instant.now + io.run + instant.relative + (duration.difference (instant.relative pre)) + %duration + (format (%name definition) " [" description "]: ")))]] + (wrap output))) diff --git a/stdlib/source/lux/compiler/default/phase/extension/statement.lux b/stdlib/source/lux/compiler/default/phase/extension/statement.lux index 6d2fbaa4e..051d264c2 100644 --- a/stdlib/source/lux/compiler/default/phase/extension/statement.lux +++ b/stdlib/source/lux/compiler/default/phase/extension/statement.lux @@ -51,35 +51,40 @@ (All [anchor expression statement] (-> Name (Maybe Type) Code (Operation anchor expression statement [Type expression Text Any]))) - (do ///.Monad - [state (//.lift ///.get-state) - #let [analyse (get@ [#statement.analysis #statement.phase] state) - synthesize (get@ [#statement.synthesis #statement.phase] state) - translate (get@ [#statement.translation #statement.phase] state)] - [_ code//type codeA] (statement.lift-analysis - (analysis.with-scope - (type.with-fresh-env - (case ?type - (#.Some type) - (type.with-type type - (do @ - [codeA (analyse codeC)] - (wrap [type codeA]))) - - #.None - (do @ - [[code//type codeA] (type.with-inference (analyse codeC)) - code//type (type.with-env - (check.clean code//type))] - (wrap [code//type codeA])))))) - codeS (statement.lift-synthesis - (synthesize codeA))] - (statement.lift-translation - (translation.with-buffer - (do @ - [codeT (translate codeS) - codeN+V (translation.define! name codeT)] - (wrap [code//type codeT codeN+V])))))) + (<| (///.timed name "DEFINE") + (do ///.Monad + [state (//.lift ///.get-state) + #let [analyse (get@ [#statement.analysis #statement.phase] state) + synthesize (get@ [#statement.synthesis #statement.phase] state) + translate (get@ [#statement.translation #statement.phase] state)] + [_ code//type codeA] (<| (///.timed name "analysis") + (statement.lift-analysis + (analysis.with-scope + (type.with-fresh-env + (case ?type + (#.Some type) + (type.with-type type + (do @ + [codeA (analyse codeC)] + (wrap [type codeA]))) + + #.None + (do @ + [[code//type codeA] (type.with-inference (analyse codeC)) + code//type (type.with-env + (check.clean code//type))] + (wrap [code//type codeA]))))))) + codeS (<| (///.timed name "synthesis") + (statement.lift-synthesis + (synthesize codeA)))] + (statement.lift-translation + (translation.with-buffer + (do @ + [codeT (<| (///.timed name "translation") + (translate codeS)) + codeN+V (<| (///.timed name "evaluation") + (translation.define! name codeT))] + (wrap [code//type codeT codeN+V]))))))) (def: lux::def Handler diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index d14ce451e..91f262fe4 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -47,6 +47,10 @@ (def: #export inverse (scale-up -1)) + (def: #export (difference from to) + (-> Duration Duration Duration) + (|> from inverse (merge to))) + (def: #export (query param subject) (-> Duration Duration Int) (i// (:representation param) (:representation subject))) -- cgit v1.2.3