* SMM bugs/improvements [10/14]
  - [ ] Investigate why compiling SMM with O2 (at least on the build server) breaks it.
  - [ ] Investigate how often the history should be advanced. It seems to be wasteful to always increase it
    whenever we do some GC work since that happens quite often for the nursery generation. It would be more
    useful to tick the history whenever we have a gen-1 or larger collection, or whenever we have collected
    the nursery a certain number of time, or moved a certain number of objects.
  - [ ] Perhaps we should have some exponential back-off in the history, so that the resolution in time
    is fine-grained in recent history, but rougher towards the end.
  - [ ] Perhaps we should move the pointer summaries from individual Blocks to Chunks, since we generally
    don't have better resolution than that from the VMAlloc class.
  - [ ] We probably want a fenwick tree to provide quick range queries regarding write barriers (perhaps
    other operations as well) in the VMAlloc system (Note: This is not critical at the moment, as generations
    prefer to allocate 32K blocks, which is exactly the resolution of the VMAlloc system).
  - [X] Examine why the SMM Gc has much worse performance when running the main Storm binary compared
    to the test suite.
  - [X] Attempt to collect higher generations that are almost full before attempting to collect lower
    generations. Otherwise, recently allocated objects may propagate all the way to the highest generation
    instantly.
  - [X] Properly scan the type descriptions of weak objects in the ScanState weak queue.
  - [X] Currently, we treat the header pointer of weak objects as a weak pointer. This is not correct,
    as the object would be unusable if the type was splatted.
  - [X] SMM crashes fairly consistently when running the test suite with an additional generation of 1 MB.
    (Seemingly always when scanning a weak array). Making VMAlloc::anyWrites always return 'true' seems to
    alleviate this issue, pointing towards an issue with keeping track of references between generations.
    We should investigate this further!
  - [X] Investigate where we should put 'suggestCollection' in 'allocBlock'. Currently, we're a bit aggressive.
  - [X] Tweak collection frequency. Currently, it seems gen 1 collections are always triggered because
    we try to allocate large objects from gen 0 rather than objects from gen 0 spilling into gen 1. This
    could mean that we're too aggressive with collections (we try as soon as we would otherwise need
    to allocate memory, even though we're way below our threshold).
  - [X] Utilize memory protection (write barriers) to improve performance.
  - [X] GcWatch objects seem to fail to notify their owner of moved objects in rare circumstances. Investigate
    further to see if the bug is remaining after the recent refactor. MapMoveTest could fail from time to time.
  - [X] Calling 'objectMoved' for individual objects is probably wasteful. We could batch calls to 'objectMoved'
    by updating history during compaction rather than object movement. At that time, we can simply mark all
    reclaimed memory as moved (with some exceptions related to GcType objects).

* Performance improvements [4/9]
  - [X] The main culprit of the startup time is loading all functions in the system (about 50%). Investigate why.
    It seems much of the time can be traced to filling in the VTables, out of which the main culprit is
    'fn->directRef()', which initializes references.
    Finished: reduced startup with approx. 10-20 ms on Windows.
  - [X] Each function needs to create strings to initialize the references. This is not optimized for speed
    and takes about 10 ms during startup. Should be fixed by allowing RefSource to take arbitrary objects
    as their "names" instead of strings.
  - [X] TypeChain is currently always allocating an array of size 1 before it is properly initialized. This is very
    wasteful, as it is almost always overwritten with a new array an instant later.
  - [X] Move the atomic operations in Utils/Utils.h to a separate header, and implement them inline in the
    header so that they can be properly inlined in more cases. Also reduce the harsh checking of alignment,
    it likely bloats the code quite a bit.
  - [ ] Improving StrBuf << Char likely improves reading source code. Currently it calls the "output string"
    function, which is overly complicated for that context.
  - [ ] Take a look at improving the performance of Map<>. On Linux, it actually performs worse than std::map
    during insertions at least.
  - [ ] If a copy constructor for a type is marked as 'pure', keep the 'copy' entry in the handle 'null' so that
    containers may use memcpy instead of calling the copy ctor for trivial types all the time.
  - [ ] In Basic Storm: It is likely that "result" is called multiple times from some nodes, which causes an
    exponential growth in calls towards the leaves of the AST. Caching in Expr could solve the issue,
    but the scale of the issue should be assessed first.
  - [ ] Parsing core.lang.syntax.bnf takes about 80 ms, which is a bit on the high end when compiling code...

* Loose ends so far [65/118]
  - [ ] Relative imports in Basic Storm?
  - [ ] Serialization: When a default constructor exists, use it for default initialization, even if
    no explicit default is set?
  - [ ] The Compiler thread should probably wait for all UThreads to terminate. Otherwise any UThreads
    that are sleeping will not block the system from terminating properly.
  - [ ] When type-checking e.g. where-clauses in the SQL plugin, the type system there does not
    account for things that may be nullable due to LEFT, RIGHT or OUTER JOINS. As such,
    we can not check for cases where IS NULL or IS NOT NULL always returns false/true. The information
    exists, but seems to only be used to generate output types.
  - [ ] Add a buffered input stream to match the buffered output stream. Add to stream documentation.
  - [ ] Introduce "negative matches" or "lookahead" in the BNF grammar. This would make it easier
    to write rules for matching "int" that do not match "intx" by having the "int" rule like:
    Primitive : "int" - !"[A-Za-z]"; or
    Primitive : "int" - !SIdentifier;
  - [ ] Serializing an object graph containing multiple references to the same string currently
    causes the string to be duplicated. This might not be ideal, and surprising since we break
    object identity (even if it generally does not matter for strings, as they are immutable).
  - [ ] It is possible to create a function pointer to a constructor, but they will not behave
    properly when calling the constructor of an actor, for example.
  - [ ] Font sizes in DirectX (in particular, the default font) are larger than when using Gdi.
  - [ ] We want to allocate threads in some kind of pool. since the minimum alignment for VirtualAlloc on Windows
    is 64k, we might waste quite a lot of memory when allocating small stacks.
  - [ ] Rename "StrBuf::add" to "StrBuf::push" to be consistent with "Array".
  - [ ] Cyclic dependencies between packages are not always handled nicely. One idea to solve this
    would be to have Package only load stages that correspond to the ones loaded by the package that
    is currently loading, and then hold off remaining loading until a later point, for example when
    the other package advances.
  - [ ] SSL library should report errors properly.
  - [ ] Perhaps port the Windows SSL library to use newer API:s than SChannel. That might allow us to
    handle server-side certificates better.
  - [ ] Maybe types are not visualized properly in Progvis. We need a special pointer/value for those.
  - [ ] The Value() ctor was changed to accept a Maybe-type. Because of this, auto-cast from Type to Value
    no longer works in Basic Storm. Investigate, and make a special case for Maybe perhaps.
  - [ ] Having a generator in Basic Storm generate types, makes it impossible to use those types in other files
    in the same package (depending on load order).
  - [ ] If CppAbstractHints is empty, it is still possible to instantiate it, even if the base class is abstract.
  - [ ] Implement 'clearBody' in all classes that implement 'createBody'.
  - [ ] A production like this: "SOp3 : "&", SOp3(block) n;" works for "Expr SOp3(Block block);". It should give an error!
  - [ ] It is currently possible to crash the system by attempting to call (e.g. using the pointer() function)
    a function that has not been given any Code(). This should perhaps raise an exception or something similar.
  - [ ] A new thread association for Actors would be useful. In many cases inside libraries, we want to be
    able to provide some object that is able to execute on any thread, yet have the semantics of an actor,
    since copying does not really make sense (e.g. ui.Painter, util.FileStream). Here, we would like to say:
    this object should remain on the thread it was created on, disallow passing it to other threads (perhaps
    "on same"). It should be possible to subclass such classes and associate them with a particular thread.
    This allows a caller to be "unaware" of threads, while code in the subclasses may still avoid thread
    switches since the actual thread is known there. Of course, such subclasses shall only be possible to
    create on the specified thread. This is potentially also useful for implementing the generated types
    in the syntax language. The base classes can be locked, and the derived classes could be placed
    on threads inside the syntax language.
  - [ ] When using "unless (foo)", "foo" uses a local variable in the block as well as outside of the block,
    which makes assignments to that variable to not write to the original variable even if one would expect so.
    We should at least warn about this.
  - [ ] Perhaps most containers shall provide a range-iterator as well? It is probably easier to provide
    some generic facility to convert from a pair of iterators to a range and use that.
  - [ ] The expression Int[]:foo does not parse properly. I don't know if we want it to or not, but it is
    nice when calling static functions (which is rare for these).
  - [ ] Finish the implementation of core:Variant. It is currently lacking a typesafe Storm interface (usable with "as").
  - [ ] Calling init(1, 2) {} when the superclass is Object will not raise an error as expected.
  - [ ] It should be easier to write toS functions for values. Ideally, they should look the same as for classes.
  - [ ] Update the grammar inside the "ui" package so that "window Foo extends Bar" uses a decorator.
  - [ ] Inside Type::updateHandle, we should check return types for the found functions! Otherwise, things
    may end badly if the return type differ from what we expect!
  - [ ] The documentation view in Emacs should probably show which package the type is located in as well.
    It is not easy to keep track of the current package oneself when navigating through the hyperlinks.
  - [ ] When editing a file that uses parent requirements in the language server, and there are multiple
    valid parses for some token when context is disregarding, introducing an error regarding requirements
    could make other valid places pick the wrong parse with regards to context. See the file
    test/server/context.bs for an example of this happening.
  - [ ] When a .bnf-file includes another package, productions from there are not automatically visible,
    which seems unintuitive. Even though a package (perhaps containing syntax helpers) is included, its
    productions are not visible. This could probably be solved nicely with 'package exports' or a similar
    mechanism.
  - [ ] Support documentation of templates from C++.
  - [ ] It seems like the sound library crashes during shutdown from time to time, at least on Windows.
  - [ ] In Basic Storm, writing 1.2 currently produces a float by default. Is this desirable?
  - [ ] Allow easy creation of subtypes similar to Ada, where one can something like: type Foo is (0 .. 99).
    Implement this as a library, eg. lang:bs:subtype
  - [ ] Expose all function pointers the Engine knows about to Storm using a similar API to what is used now.
    This allows other languages to use "internal" features, for example, to access global variables properly.
  - [ ] Generalize the "weak cast" functionality so that new types may "overload" them. This can for example
    be done by providing an entity type WeakCast that one can include (named "as" for example) that provides
    the desired functionality. It can then be injected using generators.
  - [ ] It is not possible to chain 'assignment' functions using the = operator.
  - [ ] Allow declaring member functions (at least in values) as a different thread than the owner. Possible
    in C++, not in Basic Storm.
  - [ ] Change the default visibility of class members in Basic Storm to private.
  - [ ] Destructors do not need their own slot in the Storm vtables anymore since we have another mechanism for that.
  - [ ] Check so that destructors are required if a value-type object within a class or actor
    contains a destructor.
  - [ ] Improve the preprocessor by generating toS() and deepCopy() if not present.
  - [ ] Finish the clone() functionality.
  - [ ] Destructors in maps and arrays are not working properly yet. Idea: add (yet another) member
    to array headers, and let the user provide a custom destructor in there if neccessary. The same
    is true for places that allocate plain GcArray:s.
  - [ ] Make sure Array<>, Map<> and Set<> clear the memory when an element is removed (and call destructors).
  - [ ] Function pointers should maybe allow casting to less specific types of parameters.
  - [ ] if (x = foo.bar) does not produce an error if 'foo.bar' is not Maybe<T>.
  - [ ] Support marking functions as 'pure' in C++.
  - [ ] Move the 'assign' declaration to being purely a decorator (ie. Foo field(Foo v) : assign)?
  - [ ] If a type has a '==' or '<' outside the type itself, the corresponding operator will not be present in
    a Handle, like '<<' at the moment.
  - [X] In the UI-library, button, checkbox, and group labels are interpreted as mnemonic strings, even
    if they are not advertised as such. They should be properly escaped.
  - [X] We can not use 'this' captured inside a lambda function since 'this' refers to the one already present
    in the lambda function.
  - [X] Interestingly: "strBuf << maybe<Str>" calls via Variant. This is since Maybe<Str> does not have
    an "<<" operator. Note: solved by reworking how toS works for value types.
  - [X] Lambda functions can not infer their proper type when being assigned to Maybe<T>.
  - [X] If a class contains a variable "center", and the layout library is imported, the class
    "center" in the library takes precedence over the class-local variable. This should probably not
    be the case.
  - [X] Str:unescape() does not handle \\. Adding this breaks the syntax language, so we need to
    revise the logic for that particular language.
  - [X] Trap division by zero errors. On Linux + AMD64, division by zero crashes the process. ARM gives zero.
  - [X] Add some helper "rules" to the recursive descent parser. For example: Capture(Nat n) that
    just captures 'n' chars/bytes (can't implement this in grammar). Then we can parse quite a bit
    of binary formats!  Perhaps also some rules for quick parsing of various integer types.
  - [X] When a non-member function declares a "this" variable, we implicitly assume that it is a true "this"
    and make assumptions about it (wrt threads) based on this assumption. This is dangerous. We need
    to detect whether the "this" pointer is a "true" this-pointer or not.
  - [X] Using "spawn" always causes class-types to be copied, even if we're spawning on the same UThread.
  - [X] The Value() ctor was changed to accept a Maybe-type. Because of this, auto-cast from Type to Value
    no longer works in Basic Storm. Investigate, and make a special case for Maybe perhaps.
  - [X] Add a 'pos' member to Named. Then we can implement a generic 'file private' and use that in Basic Storm.
    If this is done, we should remove or replace storm::bs::FileScope in Basic/Scope.h, as it is most likely not
    needed anymore.
  - [X] Nested classes declared in C++ are not private in Storm, even if they are declared as such in C++.
  - [X] This expression "VarInfo v = r.location(to);" should not compile, since we should not be able to auto cast here.
  - [X] A production like this: "SOp3 : "&", SOp3(block) n;" works for "Expr SOp3(Block block);". It should give an error!
  - [X] An exception thrown as "const Exception" will not be catched by the Code backend currently.
  - [X] Executing "Var v = to.to.createVar(to.to.root, sPtr, exitFn.ref);" on an improper thread cases
    a crash (where "to.to" is a "Listing" and "exitFn" is a "Function").
  - [X] Sometimes when reloading a large presentation quite a few times, Storm runs out of memory, failing
    to spawn new UThreads for handling UI events. The error message tells that around 30000 threads are alive
    at the point of failure, hinting at a resource leak somewhere. An utility that outputs stack traces for
    all UThreads would be very useful in finding this bug!
  - [X] The scope for lambda functions is not correct. A lambda function inside a class should be able to
    access a private member in that class. That is currently not the case.
  - [X] Support two-stage initialization. First a call to 'super' or similarly, after which 'this' is accessible
    as the parent class, then a call to 'init {}' which initializes the rest of the object. Slightly tricky
    to implement wrt the 'as' operator.
  - [X] The for loop does not work for WeakSet<>.
  - [X] It would be nice to rework the semantics of Value::isValue to also return "true" for primitive types. 
    It is easier to think of it that way in many cases.
  - [X] Finish integrating the Double class in the system. Basic Storm should be able to instantiate them from
    literals. Str and StrBuf should be able to parse and stringify them, and conversions between built-in
    types should be implemented. Finally, the implementation needs to be tested.
  - [X] We don't properly unescape \" in string literals in Basic Storm.
  - [X] The expression -1 can not be automatically casted to a float since the - operator is used rather than
    interpreting the entire thing as a numeric literal.
  - [X] Asking for a random access stream from an IStream should produce a LazyIStream if nothing better
    is available. However, this is not yet implemented!
  - [X] The Ui library crashes during shutdown under heavy rendering load.
  - [X] The core does not check the return type of overloaded functions, which leads to strange behaviours from time to time...
  - [X] We probably want to allow creating documentation for an entire package. Possibly by creating
    a file called 'doc.txt' or similar inside the appropriate folder.
  - [X] Gradients in the UI library should prehaps have a fixed origin, so that we can draw things
    in multiple passes with the same gradient without issues... It seems like all graphic API:s are
    designed this way, perhaps for a good reason.
  - [X] There seems to be a small issues with expressions like ~10 | 5
  - [X] Support marking functions as 'pure' in Storm.
  - [X] Missing bitwise operators and hexadecimal numbers.
  - [X] Add documentation for the built-in types (such as core.Int).
  - [X] Improve the preprocessor by automatically adding copy constructors and assignment operators
    where neccessary.
  - [X] Global variables should perhaps be initialized lazily. Otherwise, initialization expressions may fail
    to compile properly if they refer to functions in the same compilation unit.
  - [X] Allow creating variables from the REPL. We could use global variables inside the ReplSandbox object for this.
  - [X] Function pointers should perhaps be able to infer the parameter types from context if possible, just like lambdas.
  - [X] Allow initializers for global variables.
  - [X] Automatically mark non-virtual functions in C++ as 'final' in storm, since VTables will not work anyway.
  - [X] The scope of the type lookup for parameters in Basic Storm is wrong (with respect to visibility).
  - [X] BSFunction and BSCtor should release their syntax tree after they are compiled.
  - [X] Show 'known subclasses' inside the documentation in Emacs?
  - [X] Storm crashes when running the test suite when compiling with newer GCC (8.0 or 8.1 and newer).
  - [X] Unary negation is not implemented in Basic Storm (and possibly not in the built-in types).
  - [X] Allow nesting class declarations in Basic Storm.
  - [X] Accessing member variables do not respect the thread associated with the type like functions do.
    Therefore, it is possible to break the threading model by using raw variable accesses!
  - [X] In Basic Storm, taking a function pointer of a private function does not work.
  - [X] Make a generic toS() for Storm which uses operator << (if present) for values.
  - [X] In Basic Storm, expressions like '2 - 1.0' fail to compile since Float is not searched for
    candidates. This could be solved by moving the operators out of the number classes or improve
    overload resolution in this case.
  - [X] Implement 'private' for non-members in Basic Storm.
  - [X] When creating an Arena using code:arena(), the vtable dispatch for 'transform' is not correct. The
    base class is called directly (no lookup) even though there are implementations in the derived classes.
  - [X] Stack traces for Windows (32-bit) do not always contain names of Storm functions. Only functions
    that require exception handling are currently shown.
  - [X] Examine if the special case in the stack scanning actually works. The one time I've seen
    it, everything crashed shortly afterwards, but that could have been something else.
    Note: The crash was due to newly created UThreads being visible to the GC before they
    were completely initialized, resulting in the GC trying to scan the address 0 or being
    very confused with multiple main stacks.
  - [X] Check all synchronization primitives used on Linux. It seems that the BSThread test crashes
    sometimes when the GC decides it needs to perform garbage collection around the time when threads
    are spawned and/or when futures are used.
  - [X] We need to scan the data inside a StackTrace object using mps_rank_ambig().
  - [X] The grammar rule X : Y ("w", Y)* "w"; does not parse properly. It should either work as expected
    or report an error!
  - [X] Thread sleep needs to be improved! We should put threads in a sleep queue so that the thread
    can be properly put to sleep even if there is another uthread active on the current thread.
  - [X] Review the semantics of Buffer::filled() wrt IStream::read. Buffer::filled could be used instead
    of the explicit 'start' parameter. This allows a Buffer to be passed to 'read' multiple times
    to fill the buffer until completion.
  - [X] Handles for values do not get a proper == operator.
  - [X] Enums should be treated like raw integers (currently they are Values).
  - [X] Destructors should be auto-generated in Basic Storm if they are needed.
  - [X] It seems we fail to handle moving objects in Set and Map in rare cases. Examine why!
  - [X] Implement shrink() for Map<> as well.
  - [X] Handles and templates does not work with built-in types (like Int).

* Improvements [6/25]
  - [ ] In the language server: Add the ability to tell the parser to abort parsing after some time.
    In cases where parsing takes much time, the results are typically very bad anyway, so it might
    be a good strategy to actually just give up if parsing takes more than 100 ms or so, and try
    again later (at least when re-parsing parts of the AST, maybe not on the initial parse, or in
    other situations). Also: we probably want to ensure that we *always* schedule a full re-parse of
    nodes that contain errors, even if the regexes match, or if the surrounding node is too large.
    Otherwise, we might end up in situations where code right before- or after a comment is never
    re-parsed into code (this is common when working with large-ish presentations when adding a new
    slide after a comment block).
  - [ ] Consider utilizing the transformations better in Basic Storm. We could, for example, skip the
    XxxDecl classes, and just have lists of AST nodes that are transformed as appropriate later in the
    compilation instead.
  - [ ] Maybe we want to reverse the concatenation order of Transform to make it easier to understand.
    It is currently right to left (since we're using a column vector), but maybe it should be left to right.
  - [ ] Add a type that represents byte sizes. Use that in eg. Socket::readBuffer.
  - [ ] The call to 'getaddrinfo' in the networking subsystem blocks an entire OS thread waiting for
    the network. This is not very good, as we might have other things to do in the meantime.
  - [ ] Automatically re-flow the raw text in comments, just like Markdown would. This is good
    when the width of the users terminal or buffer is smaller than the width of the comments.
  - [ ] Allow comment that 'groups' functions together. This will form a two-level tree that could improve
    readability of the documentation.
  - [ ] Switch the order of 'src' and 'dest' in 'jmp'. They are currently reversed when compared to 'call'.
  - [ ] Use the LO pool for object formats, this should make it possible to have them garbage collected
    and readable during scanning.
  - [ ] Cache and re-use the function thunks generated by CodeGen/callThunk().
  - [ ] Decouple a variable's storage location from when it needs destruction. This could be used to make
    variables immediatly eligible for destruction even if they are moved to an outer scope.
  - [ ] Properly handle failure conditions when creating Threads and UThreads (eg. out of memory).
  - [ ] Rename 'TObject' to 'Actor' to make it easier to understand.
  - [ ] Fix destructors in Storm...
  - [ ] Clone objects using a member function generated by the STORM_CLASS macro or the preprocessor.
  - [ ] Generate toS() and deepCopy() automatically using the preprocessor unless supressed.
  - [ ] We can remove a lot of copy-constructors in Code/, and use memcpy + default generated ones!
  - [ ] Remove mov eax, eax (or similar) They are occasionally generated if we're unlucky.
  - [ ] Idea: disallow cloning of values without deepCopy() so that we can safely make iterators for actors.
  - [X] Indicate function return types and types of variables in Doc objects.
  - [X] Why is the expression '"foo" + foo()' allowed if 'foo()' returns null?
  - [X] The syntax SExpr (, SExpr)? is treated as a parameter list. Switch to {} for capture so that
    this does not happen. (requiring SExpr - (,SExpr) instead), stricter parsing.
  - [X] Implement attaching and detaching threads using ThreadGroups for os::Thread.
  - [X] Make it possible to mark entire rules with syntax colors. That would be equivalent to marking
    all usages of that token with the corresponding color.
  - [X] In Array.get(), do not create the exception in getRaw() since it takes up a lot of valuable space in
    the i-cache. Instead, call a separate function or reverse the logic.
* Bugs/improvements in Progvis [1/3]
  - [ ] Make it possible for the model checker to check for memory leaks -- just check if there
    is anything left in all leaf nodes at the end of model checking.
  - [ ] Rendering is very flickering when resizing the Progvis window. Probably due to repaints from
    the window system fail to ensure that a new frame is rendered for some reason. Most notably
    visible on Linux, but also on high-refresh displays on Windows in some situations. (At least
    partially fixed by not moving the window incorrectly in Gtk).
  - [X] The program below does not behave correctly in Progvis, the call
    to "thread_main" is skipped, and Progvis seems generally confused about
    what is happening: root/progvis_demo/test/step_error.c

* C++ front-end (in Progvis) [8/18]
  - [ ] Fix the for-loop to allow for ( ; ; ) and other variants.
  - [ ] Allow multiple variables to be declared on the same line.
  - [ ] Allow type-checked casts between pointer types? We could cache the layout to make this relatively cheap.
  - [ ] Ability to make const member functions.
  - [ ] Check if function resolution works somewhat properly with const parameters etc.
  - [ ] Ability to declare member functions outside the class.
  - [ ] static_cast, c-style-cast, etc.
  - [ ] Some kind of standard library for C++?
  - [ ] Check so that we don't overwrite pointers with something weird.
  - [ ] sizeof() for an array probably don't work correctly.
  - [X] Global arrays (e.g. int x[2])
  - [X] Threading constructs.
  - [X] Strings.
  - [X] malloc/free
  - [X] Arrays
  - [X] sizeof()
  - [X] Pointer arithmetics.
  - [X] nullptr/NULL
