Proposed canes to null safety.

2 views
Skip to first unread message

Bill Cox

unread,
Jun 22, 2023, 7:51:18 AM6/22/23
to Rune language discussion
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:
  1. The ! operator is in code already protected by an explicit check for non-null
  2. A variable is initialized after being assigned null, when we really just needed to declare an uninitialized variable.
  3. 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.

Aiden Hall

unread,
Jun 22, 2023, 7:56:51 AM6/22/23
to Bill Cox, Rune language discussion
This sounds like a great way to reduce boilerplate.

--
You received this message because you are subscribed to the Google Groups "Rune language discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rune-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rune-discuss/CAH9QtQGbZsV1%2Bq4k9zhHueYsEdArbtGJEJioAZVrM_4DLyZbDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages