ref: 2219ea535f4a0fd0afd9000ba5c6918c6b276210 Carth/src/Selections.hs -rw-r--r-- 1.7 KiB
Codegen: Do more at Val & ptr level everywhere. getelemementptr etc.

The website said to "avoid loads and stores of large aggregate type"
to improve performance. This seems like solid advice, so this commit
changes a bunch of different stuff in the codegen to keep structs in
pointers for as long as possible and use getelementptr instead of
extractvalue/insertvalue. Particularly in the pattern matching stuff,
change the selection stuff to operate on Val instead of operand, using
new convenience functions like genIndexStruct which does extractvalue
if the Val is a local, and getelementptr if it's a stack var.

Performance improvement is not obviously noticable for my small
programs, but it seems less code is generated overall. .dbg.ll of
Fizzbuzz decreased from like 1700 to 1500 lines or something. That's
at least a 10% improvement.

Make some strict Map:s lazy, and some lazy State:s strict

No great reason. Just seemed more reasonable. No obvious performance impact.
Add skeleton module Optimize between Monomorphize & Compile
Change formatting: 90 cols, IndentPolicyFree, etc. Add brittany.yaml

Most people have pretty wide and high res screens at this point. I
can't fit two windows with 100 line length next to eachother with my
font size, but 90 works and most people have smaller font size than me
I think.

Also, change brittanys indentation policy to Free. This almost always
looks better. I just had to disable formatting of imports -- I don't
want to align those, but IndentationPolicyFree insists.

Finally, actually add a project-local brittany config file, so that
anyone (or me in the future / on another computer) can use the same
formatting rules.
Improve module names. Ast -> Parsed, AnnotAst -> Inferred, and more
Allow Box in pattern to dereference
Scale datatype tag size by n of variants. 1 variant => no tag

Types with only 1 variant have no tag. Types with <=2^n variants have
n-bit tag.
Integrate Match with rest of compiler

Until now, the Match module was just kind of for "testing". It wasn't
actually used in the rest of the compiler. This commit replaces my
earlier, quite bad implementation of pattern matching to decision
trees with Sestofts one.

One major change made along the way was to how sub-matchees are
accessed in the code-generator and interpreter. Previously, the
decision tree was assumed to be structured such that we could simply
extract sub-matchees and put them on a stack. As far as I understand
it, that way is incompatible with Sestofts trees, as they can "skip"
steps that are known to be irrefutable in context. As such, I have
chosen to augment the `Access` type with some additional information,
such that the value of a sub-matchee can simply be generated from the
Access-path as needed, with memoization in the Selections module. See