From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!pBWEO6hi52oGFheO/GY5ag.user.gioia.aioe.org.POSTED!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Ada and "early return" - opinion/practice question Date: Tue, 16 Mar 2021 15:49:18 -0700 Organization: Aioe.org NNTP Server Message-ID: <86wnu6d89d.fsf@stephe-leake.org> References: <38356aa9-b8b0-4e0b-a490-99e7b239d0b1n@googlegroups.com> <87im5sutdt.fsf@nightsong.com> <861rcfe9w7.fsf@stephe-leake.org> NNTP-Posting-Host: pBWEO6hi52oGFheO/GY5ag.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:GROYZP5GpnMmadyTLibgfTpdBnA= Xref: reader02.eternal-september.org comp.lang.ada:61568 List-Id: Niklas Holsti writes: > Are you sure about that? As I understand it, for the full-runtime GNAT > systems, the "zero cost exception handling" means that there is no > run-time cost to placing an exception handler in a subprogram or > block, because there is no run-time code to set up such a handler when > entering the subprogram or block, nor to remove it when leaving the > subprogram or block. right > But there is cost, partly at compile/link time, when the tools set up > a static mapping from code sections (address ranges) to the exception > handlers that handle exceptions raised in those parts of the code, right. > and partly at run-time when an exception is raised. AIUI raising an > exception is not a mere goto: at run-time, the code has to use the > static mapping to locate the applicable handler, while also unwinding > the call-stack to the corresponding point, and then enter the handler > code Yes; it is more like a sequence of "return" than "goto". It is cheaper at run-time than the previous implemententation of exceptions, which used set-jmp/long-jmp. > A different zero-cost system is used when GNAT compiles for embedded > targets with run-times that do not support exception propagation. In > those cases, one can write only "local" exception handlers. For > example, the exception handlers in a subprogram can handle only > exceptions raised in that same subprogram, but not exceptions raised > in any callee subprograms. Then raising an exception is indeed the > same as a goto, because the compiler statically knows if there is a > local handler, and where it is, and no stack unwinding is needed. I did not know about this one. -- -- Stephe