Direct recursion detection possible?
Cecil Ward
cecil at cecilward.com
Thu May 25 15:46:21 UTC 2023
On Thursday, 25 May 2023 at 13:46:32 UTC, Cecil Ward wrote:
> On Thursday, 25 May 2023 at 10:35:45 UTC, Quirin Schroll wrote:
>> On Wednesday, 24 May 2023 at 23:04:53 UTC, Cecil Ward wrote:
>>> [...]
>>
>> I had this almost happen in my C++ code. It never ran because
>> I got a compile error. The compiler is MSVC.
>>
>> [...]
>
> My apologies, when I wrote ‘straightforward’ I should meant to
> say, ‘without body, with no content’. You mentioned without
> side-effects, which is more general and very useful.
We would have to add something in your quick sketch to mention
exceptions. So if the basic block is not null, a type of check
that I would settle for as a first step, in addition to your
conditions all calls would have to be nothrow if there is an
exception handler.
I don’t know what the D call is to terminate the current process,
or even begin the shutdown sequence for the system if we are
building an embedded system with (other) no o/s. But I should
think that a routine having an attribute of ‘terminate the
process’, when the reason isn’t because we mean ‘panic’,
core_dump, ud_n, etc because of a bug, but because we simply want
to terminate the process because we’re all done, with success or
failure, means that it is not pure.
In GCC there is a noreturn attribute iirc - is that correct? but
I think that there ought to be subtypes of that - to say whether
it’s debug code or not, whether it’s a straight ‘end if process’
rather than a panic / bug / core_dump etc. (Does GCC or LDC
generate a ud2 when you wish to panic? Presumably without
cleanup?)
Merely having an exception handler present above or around your
non-trivial infinite loop might be a sign that you have something
equivalent to a break inside the loop. But I don’t think we
should consider this, as there may actually be no exception
throwing at all, and that could be a bug - that the way out has
been omitted.
Anyway, it would be easier to do the "L1: jmp L1" thing first as
then there are no worries, and we would get some benefit much
sooner.
More information about the Digitalmars-d
mailing list