On Saturday, 3 May 2025 at 11:18:00 UTC, Nick Treleaven wrote:
Second, in assigning from arrays of differing sizes, Phobos
causes an illegal instruction, rather than the sort of
exception I'd have expected. I'm curious why they stepped
away from D's exception architecture?
It throws a RangeError rather than an Exception. One advantage
is that allows indexing an array to be used in `nothrow` code.
Also, bounds checks can be turned off, in which case nothing
would be thrown, and code attempting to catch this occurence
would never be called.
At least on 1.40.1 of the ldc2 distro for x86-64, uses the
"illegal instruction" instruction. But it does make sense that
array operations want to be outside the "nothrow" guarantee, as
that would make nothrow almost useless.
Thanks,
Andy
```
(gdb) r
Starting program: /home/vandys/dlang/tst41
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
[2, 2, 2, 2, 1, 1, 1, 1]
[2, 2, 2, 2, 1, 1, 1, 1]
Program received signal SIGILL, Illegal instruction.
0x00007ffff7f5a9e8 in
core.internal.util.array._enforceSameLength(const(char[]),
const(ulong), const(ulong)) ()
from
/home/vandys/ldc2-1.39.0-linux-x86_64/bin/../lib/libdruntime-ldc-shared.so.109
(gdb) x/i $pc
=> 0x7ffff7f5a9e8
<_D4core8internal4util5array18_enforceSameLengthFNbNfxAaxmxmZv+168>: ud2
(gdb)
```