Skip to content

Commit

Permalink
Add more timing log sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
CuppoJava committed Oct 16, 2022
1 parent a322a74 commit 5977f71
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 153 deletions.
49 changes: 43 additions & 6 deletions compiler/dependencies.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public defn analyze-dependencies (settings:BuildSettings,
for e in errors(dep-result) do :
println(o, Indented(e))

match(output:String) : spit(output, LineWrapped(text))
else : println(LineWrapped(text))
match(output:String) : spit(output, text)
else : println(text)

;Output to graphviz
match(graphviz:String) :
Expand Down Expand Up @@ -77,33 +77,70 @@ public defn analyze-dependencies (settings:BuildSettings,
driver()

;============================================================
;======================= Datastructures =====================
;============== Dependencies for Each Package ===============
;============================================================

defstruct Dependencies :
package-dependencies: Tuple<KeyValue<Symbol,List<Symbol>>>
component-dependencies: Tuple<KeyValue<List<Symbol>,List<Symbol>>>
with:
constructor => #Dependencies

defn Dependencies (
package-dependencies: Tuple<KeyValue<Symbol,List<Symbol>>>
component-dependencies: Tuple<KeyValue<List<Symbol>,List<Symbol>>>) :

defn sort-values<?K> (xs:Seqable<KeyValue<?K,List<Symbol>>>) :
for e in xs seq : key(e) => to-list(lazy-qsort(value(e)))

defn sort-keys<?V> (xs:Seqable<KeyValue<List<Symbol>, ?V>>) :
for e in xs seq : to-list(lazy-qsort(key(e))) => value(e)

val sorted-package-dependencies =
package-dependencies $> sort-values
$> qsort{key, _}

val sorted-component-dependencies =
component-dependencies $> sort-values
$> sort-keys
$> qsort{head{key(_)}, _}

#Dependencies(sorted-package-dependencies,
sorted-component-dependencies)


defmethod print (o:OutputStream, d:Dependencies) :
defn empty-paren? (xs:Tuple) : " ()" when empty?(xs) else ""

defn line-wrapped-list (xs:List<Symbol>) :
if empty?(xs) :
"()"
else :
val wrapped = LineWrapped("%@" % [xs])
"(\n%_)" % [Indented(wrapped)]

print(o, "Package Dependencies:%_" % [empty-paren?(package-dependencies(d))])
val import-list = for entry in package-dependencies(d) seq :
"\n%~ imports %~" % [key(entry), value(entry)]
"\n%~ imports %_" % [key(entry), line-wrapped-list(value(entry))]
print(o, Indented("%*" % [import-list]))

lnprint(o, "Package Group Dependencies:%_" % [empty-paren?(component-dependencies(d))])
val component-list = for entry in component-dependencies(d) seq :
"\n%~ imports %~" % [key(entry), value(entry)]
"\n%~ imports %_" % [key(entry), line-wrapped-list(value(entry))]
print(o, Indented("%*" % [component-list]))

;============================================================
;================ Location of Source Files ==================
;============================================================

defstruct SourceFiles :
entries: Tuple<KeyValue<Symbol,String>>
with:
constructor => #SourceFiles

defn SourceFiles (entries:Seqable<KeyValue<Symbol,String>>) :
#SourceFiles(to-tuple(entries))
val sorted-entries = qsort(key, entries)
#SourceFiles(sorted-entries)

defmethod print (o:OutputStream, sf:SourceFiles) :
defn empty-paren? (xs:Tuple) : " ()" when empty?(xs) else ""
Expand Down
76 changes: 42 additions & 34 deletions compiler/el-to-vm.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,54 @@ defpackage stz/el-to-vm :
import stz/algorithms
import stz/ehier
import core/stack-trace
import stz/timing-log-api

;============================================================
;====================== Timers ==============================
;============================================================

val EL-TO-VM = TimerLabel("EL-IR to VM-IR")

;============================================================
;======================== Driver ============================
;============================================================

public defn compile (epackage:EPackage) -> VMPackage :
val io = packageio(epackage)
val iotable = IOTable(io)
val ehier = EHier(epackage)
val progbuffer = ProgBuffer()
val global-table = GlobalTable(io, epackage)
val init-compiler = Compiler(global-table, iotable, ehier, progbuffer)
take-ids(cat(used-ids(io), used-ids(epackage)))
val dtable = within time-ms!("Analyze Dependencies") :
analyze-dependencies(epackage, global-table)

compile-debug-info(progbuffer, io)
val init = within time-ms!("Compile to VM") :
for e in exps(epackage) do :
match(e) :
(e:EDefn) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EDefClosure) : compile(e, dtable, global-table, iotable, ehier, progbuffer)
(e:EDefGlobal) : compile(e, global-table, progbuffer)
(e:EDefStruct) : compile(e, global-table, iotable, progbuffer)
(e:EInit) : compile(init-compiler, e)
(e:EExtern) : compile(e, progbuffer)
(e:EDefType) : compile(e, progbuffer)
(e:EDefObject) : compile(e, dtable, global-table, iotable, progbuffer)
(e:EDefTypeObject) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EDefmulti) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EDefmethod) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EExternFn) : compile(e, global-table, iotable, ehier, progbuffer)
val init = compile-init(init-compiler, iotable, progbuffer)
init

val vmp = to-vmpackage(progbuffer, io, init)
;dump(vmp, "logs", "pre-analyze")
val vmp* = within time-ms!("VM Analyze") : analyze(vmp)
;dump(vmp*, "logs", false)
vmp*
within log-time(EL-TO-VM, suffix(name(epackage))) :
val io = packageio(epackage)
val iotable = IOTable(io)
val ehier = EHier(epackage)
val progbuffer = ProgBuffer()
val global-table = GlobalTable(io, epackage)
val init-compiler = Compiler(global-table, iotable, ehier, progbuffer)
take-ids(cat(used-ids(io), used-ids(epackage)))
val dtable = within time-ms!("Analyze Dependencies") :
analyze-dependencies(epackage, global-table)

compile-debug-info(progbuffer, io)
val init = within time-ms!("Compile to VM") :
for e in exps(epackage) do :
match(e) :
(e:EDefn) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EDefClosure) : compile(e, dtable, global-table, iotable, ehier, progbuffer)
(e:EDefGlobal) : compile(e, global-table, progbuffer)
(e:EDefStruct) : compile(e, global-table, iotable, progbuffer)
(e:EInit) : compile(init-compiler, e)
(e:EExtern) : compile(e, progbuffer)
(e:EDefType) : compile(e, progbuffer)
(e:EDefObject) : compile(e, dtable, global-table, iotable, progbuffer)
(e:EDefTypeObject) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EDefmulti) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EDefmethod) : compile(e, global-table, iotable, ehier, progbuffer)
(e:EExternFn) : compile(e, global-table, iotable, ehier, progbuffer)
val init = compile-init(init-compiler, iotable, progbuffer)
init

val vmp = to-vmpackage(progbuffer, io, init)
;dump(vmp, "logs", "pre-analyze")
val vmp* = within time-ms!("VM Analyze") : analyze(vmp)
;dump(vmp*, "logs", false)
vmp*

;============================================================
;====================== Unique IDs ==========================
Expand Down
27 changes: 21 additions & 6 deletions compiler/input.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,35 @@ defpackage stz/input :
import stz/il-ir
import stz/dl-ir
import stz/visibility
import stz/timing-log-api

;============================================================
;======================= Timers =============================
;============================================================

val IL-IR = TimerLabel("IL-IR")
val READ-TO-IL = TimerLabel(IL-IR, suffix("Read to IL"))
val CHECK-IL = TimerLabel(IL-IR, suffix("Check IL"))

;============================================================
;======================== Driver ============================
;============================================================

public defn to-ipackages (form, default-imports:Tuple<IImport>) -> Tuple<IPackage> :
val e = read-iexp(form)
check(e)
split-packages(e, default-imports)
within log-time(IL-IR) :
val e = within log-time(READ-TO-IL) :
read-iexp(form)
within log-time(CHECK-IL) :
check(e)
split-packages(e, default-imports)

public defn to-il (form) -> IExp :
val e = read-iexp(form)
check(e)
e
within log-time(IL-IR) :
val e = within log-time(READ-TO-IL) :
read-iexp(form)
within log-time(CHECK-IL) :
check(e)
e

;============================================================
;========== Exported Types from IPackage ====================
Expand Down
44 changes: 23 additions & 21 deletions compiler/main.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ defn repl-command () :
Flag("terminal-style", OneFlag, OptionalFlag,
"The terminal style (simple/edit) to use for the REPL. If not provided, defaults to 'edit' if available \
on the current platform.")
common-stanza-flag("timing-log")
Flag("-", AllRemainingFlag, OptionalFlag,
"If provided, the remaining arguments after this flag will be set as the command line arguments for the REPL session.")]

Expand All @@ -568,33 +569,34 @@ defn repl-command () :
;Main code. Will potentially be wrapped in a finally clause
;if -confirm-before-exit is provided.
defn main () :
;Read configuration file
read-config-file()
within run-with-timing-log(cmd-args) :
;Read configuration file
read-config-file()

;Add pkg directories to pkg-dirs
for dir in get?(cmd-args, "pkg", []) do :
STANZA-PKG-DIRS = cons(dir, STANZA-PKG-DIRS)
;Add pkg directories to pkg-dirs
for dir in get?(cmd-args, "pkg", []) do :
STANZA-PKG-DIRS = cons(dir, STANZA-PKG-DIRS)

;Add flags
for flag in get?(cmd-args, "flags", []) do :
add-flag(to-symbol(flag))
;Add flags
for flag in get?(cmd-args, "flags", []) do :
add-flag(to-symbol(flag))

;Add platform flag
add-flag(platform-flag(OUTPUT-PLATFORM))
;Add platform flag
add-flag(platform-flag(OUTPUT-PLATFORM))

;Setup command line arguments.
val new-cmd-args = to-tuple $ cat(["repl"], get?(cmd-args, "-", []))
set-command-line-arguments(new-cmd-args)
;Setup command line arguments.
val new-cmd-args = to-tuple $ cat(["repl"], get?(cmd-args, "-", []))
set-command-line-arguments(new-cmd-args)

;Get the desired terminal style.
val terminal-style =
if flag?(cmd-args, "terminal-style") :
parse-terminal-style(cmd-args["terminal-style"]) as TerminalStyle
else :
default-terminal-style()
;Get the desired terminal style.
val terminal-style =
if flag?(cmd-args, "terminal-style") :
parse-terminal-style(cmd-args["terminal-style"]) as TerminalStyle
else :
default-terminal-style()

;Launch REPL
repl(args(cmd-args), terminal-style)
;Launch REPL
repl(args(cmd-args), terminal-style)

;Confirm exit
if flag?(cmd-args, "confirm-before-exit") :
Expand Down
2 changes: 1 addition & 1 deletion compiler/params.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public defn compiler-flags () :
to-tuple(COMPILE-FLAGS)

;========= Stanza Configuration ========
public val STANZA-VERSION = [0 17 28]
public val STANZA-VERSION = [0 17 29]
public var STANZA-INSTALL-DIR:String = ""
public var OUTPUT-PLATFORM:Symbol = `platform
public var STANZA-PKG-DIRS:List<String> = List()
Expand Down
24 changes: 16 additions & 8 deletions compiler/renamer.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ defpackage stz/renamer :
import stz/utils
import stz/dl-ir
import stz/visibility
import stz/timing-log-api

;============================================================
;===================== Timers ===============================
;============================================================

val IL-RENAMER = TimerLabel("IL Rename")

;============================================================
;===================== Rename ===============================
Expand All @@ -24,14 +31,15 @@ public defn rename-il (ipackages:Tuple<IPackage>) -> RenameResult :
;Rename all packages
ipackages* = to-tuple $
for ipackage in ipackages* seq? :
val eng = Engine(name(ipackage))
val exps* = map(rename-exp{_, eng}, exps(ipackage))
if empty?(/errors(eng)) :
val ipackage* = sub-namemap(sub-exps(ipackage, exps*), namemap(eng))
One(ipackage*)
else :
add-all(errors, /errors(eng))
None()
within log-time(IL-RENAMER, suffix(name(ipackage))) :
val eng = Engine(name(ipackage))
val exps* = map(rename-exp{_, eng}, exps(ipackage))
if empty?(/errors(eng)) :
val ipackage* = sub-namemap(sub-exps(ipackage, exps*), namemap(eng))
One(ipackage*)
else :
add-all(errors, /errors(eng))
None()

;Return result
val error = RenameErrors(to-tuple(errors)) when not empty?(errors)
Expand Down
40 changes: 21 additions & 19 deletions compiler/repl.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ val REPL-EXP-EVALUATION = TimerLabel("Repl Exp Evaluation")
val REPL-COMPILE-LOWERED = TimerLabel("Repl Compile Lowered", REPL-LOWERING-AND-COMPILATION)
val REPL-LOAD-INTO-VM = TimerLabel("Repl Load Into Vm", REPL-EXP-EVALUATION)
val REPL-INIT-PACKAGES = TimerLabel("Repl Init Packages", REPL-EXP-EVALUATION)
val REPL-RELOAD = TimerLabel("Repl Reload")

;============================================================
;===================== REPL Language ========================
Expand Down Expand Up @@ -355,25 +356,26 @@ public defn REPL () :

;Reload
defn reload-files () :
within intercept-errors() :
val inputs = changed-files(file-env)
val vmpackages = compile-to-vmpackages(inputs, {[]}, false)
load(vm, vmpackages, false)

;Clear all globals
clear-globals(vm)

;Clear all REPL definitions
val r = unload(denv, repl-packages(repl-env), [])
fatal("Could not unload repl definitions.") when r is LoadErrors
unload(vm, repl-packages(repl-env))
clear(repl-env)

;Rerun package initializers
init-packages(ordered-pkg-names) where :
val pkg-names = to-tuple $ seq(package,packageios(denv))
val dependency-graph = package-dependency-graph(denv)
val ordered-pkg-names = initialization-order(dependency-graph, pkg-names)
within log-time(REPL-RELOAD) :
within intercept-errors() :
val inputs = changed-files(file-env)
val vmpackages = compile-to-vmpackages(inputs, {[]}, false)
load(vm, vmpackages, false)

;Clear all globals
clear-globals(vm)

;Clear all REPL definitions
val r = unload(denv, repl-packages(repl-env), [])
fatal("Could not unload repl definitions.") when r is LoadErrors
unload(vm, repl-packages(repl-env))
clear(repl-env)

;Rerun package initializers
init-packages(ordered-pkg-names) where :
val pkg-names = to-tuple $ seq(package,packageios(denv))
val dependency-graph = package-dependency-graph(denv)
val ordered-pkg-names = initialization-order(dependency-graph, pkg-names)

;Load from repl
defn load-repl (form) :
Expand Down
Loading

0 comments on commit 5977f71

Please sign in to comment.