TL;DR -- I'd like to propose the following changes:
- The C Rune compiler should infer the ! operator before dot operators (e.g. foo.bar is legal even if foo is nullable)
- Add 'mandatory' relations to the bootstrap compiler.
- Add something like "uninitialized(Foo)" to the bootstrap compiler
Having to put ! operators after nullable types to convert them to what is obviously non-null is a pain. In bootstrap/parse/pegparser.rn, I see 10% of the lines use the ! conversion operator, but for only these reasons:
- The ! operator is in code already protected by an explicit check for non-null
- A variable is initialized after being assigned null, when we really just needed to declare an uninitialized variable.
- Without tagged unions, we have to initialize some of what would be union values to nullable types.
In pegparser.rn, by inferring ! before a dot operator on a nullable type, 74 of the 115 lines with ! operators go away. Almost all of them are protected by an if !null() statement or equivalent.
In the relation transformers, we add variables holding references to both parent and child classes. Since we don't know what the initial values will be, we use null values in each case. Most of the time I use ! on one of these variables, it is a parent reference in a relation that should be declare "mandatory". "Mandatory" means cascade-delete, but also that the parent should be set to uninitialized(Parent) rather than null(Parent).
With explicit uninitialized values, and during lifetime analysis we can check that uninitialized values are never read.
The other place I see ! operators is for example when accessing the keyword object on a token object, after checking that the token's type is TokenType.Keyword. Tagged unions should eliminate this.