Replies: 4 comments 7 replies
-
on Rust they implemented copy and destroy hooks as for this case, on Nimskull we can keep i'm more in favor forbid raising on hooks because allowing it can led more complexity on control flow and implicit raising cases |
Beta Was this translation helpful? Give feedback.
-
Initial thoughts on hooks raising, with a focus on managing other resources:
|
Beta Was this translation helpful? Give feedback.
-
So here are my thoughts, coming from high-level/managed languages
|
Beta Was this translation helpful? Give feedback.
-
I've thought through and gathered some of the consequences that the hooks being allowed to raise would have.
|
Beta Was this translation helpful? Give feedback.
-
Recently, the language specification was changed to disallow exceptions being raised from hook procedures (
=copy
,=sink
,=destroy
,=trace
,=deepCopy
).Before the change, what happened when a hook routine raised an exception was undefined behaviour. In many cases, actually raising from a hook procedure could result in crashes or other unexpected behaviour (e.g., #1012).
The aforementioned change made the behaviour well specified, but the significant change in behaviour was brought up to be, perhaps, too restrictive.
What are hook routines?
Hook routines are much like normal procedures/functions, with the difference that the compiler can place invocations thereof itself. They're used to "hook"/override what some compiler-decided action does at run-time.
A procedure becomes a hook routine if it uses a special name and signature.
What actions can be hooked?
=copy
). Invoked on assignment, or when copying into asink
parameter=sink
). Invoked on assignment, or when moving into asink
parameter=destroy
). Invoked when a location (which includes compiler-inserted temporaries), is destroyed, usually because it goes out of scope=trace
). Potentially invoked as part of cycle collection=deepCopy
). Invoked when callingdeepCopy
If for an action no hook is provided by user code, the compiler usually synthesizes one.
What needs to be discussed?
The questions that need to be answered, for each hook, whether them raising exceptions should be allowed, and, if so under, what circumstances.
Put in a more concrete way:
x
be allowed to raise? What happens if it does raise at run-time?x
raising? Can it be solved differently?For answering these questions, it could help to look at what exception-related rules exist in other languages with similar facilities (destructors in C++, Rust, etc.). How do libraries handle the restrictions (if any) there?
Due to both applying to assignments,
=copy
and=sink
can be treated as one hook, in the context of the discussion.Beta Was this translation helpful? Give feedback.
All reactions