Value Type Exceptions
Richard Andrew Cattermole (Rikki)
richard at cattermole.co.nz
Thu Sep 19 18:31:02 UTC 2024
Many people around these parts have read my proposal from August
2022 for value type exceptions.
Now is the time, to put them here officially.
In response to the original proposal, is the origin of my
interest on sumtypes, matching, member-of-operator. All of these
things come together to form this proposal. They are effectively
designed together, requirements filter between each to give a
clean design that will give a good user experience for when
laziness or costs are a concern.
Latest:
https://gist.github.com/rikkimax/883dddc4a61134d4c17cb18727287d92
Current:
https://gist.github.com/rikkimax/883dddc4a61134d4c17cb18727287d92/f8fa440535ac4ec089efe940e8daddeb658556dc
It has applied Walter's carry flag idea from DConf 2024, to elide
the tag value of the tagged union. Allowing for an even cheaper
throw.
So what is included?
- Default for functions remains to be throwing a ``Exception``,
specifying the empty set is equivalent to ``nothrow``.
- The introduction of the throw set ``@throw(...)``.
- The throw set may include structs, member-of-operator and
classes that inherit from ``Throwable``.
- A catch-all that is represented by sumtypes ``} catch(sumtype
varName) {``
- When using a struct, support an optional low-cost backtrack
method by only using compiler information.
- Structs support copy constructor and destructor, see my sumtype
proposal on how the variable layout works.
- Did I mention the throw set is inferred? Sadly it cannot shrink
down to the empty set due to virtual functions/function pointers,
but we could change that with an edition if it's desirable to do
so.
```d
int toCall() @throw(:FailedToDecodeUTF) {
throw :FailedToDecodeUTF;
}
int caller() /* @throw() */ {
int result;
try {
result = toCall();
} catch(:FailedToDecodeUTF) {
result = 0xDEADBEEF;
}
return result;
}
```
More information about the dip.ideas
mailing list