comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Ada and "early return" - opinion/practice question
Date: Tue, 16 Mar 2021 15:49:18 -0700	[thread overview]
Message-ID: <86wnu6d89d.fsf@stephe-leake.org> (raw)
In-Reply-To: ibbhmrFrnmoU1@mid.individual.net

Niklas Holsti <niklas.holsti@tidorum.invalid> 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

  reply	other threads:[~2021-03-16 22:49 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 16:46 Ada and "early return" - opinion/practice question John McCabe
2021-03-15 17:02 ` Dmitry A. Kazakov
2021-03-15 17:29   ` John McCabe
2021-03-16  7:08   ` Randy Brukardt
2021-03-15 17:31 ` Stephen Leake
2021-03-15 17:43   ` John McCabe
2021-03-15 18:15     ` Shark8
2021-03-15 20:39       ` Simon Wright
2021-03-15 20:56         ` Chris Townley
2021-03-16  7:19           ` Stéphane Rivière
2021-03-16 10:31             ` Jeffrey R. Carter
2021-03-16  8:28           ` John McCabe
2021-03-16 20:34         ` Simon Wright
2021-03-17  8:05           ` John McCabe
2021-03-17 11:43             ` Simon Wright
2021-03-18  8:08               ` John McCabe
2021-03-18 16:27                 ` Stephen Leake
2021-03-20 13:41                   ` John McCabe
2021-03-15 19:05     ` Paul Rubin
2021-03-16  8:38       ` John McCabe
2021-03-16  9:03     ` Stephen Leake
2021-03-16  9:21       ` John McCabe
2021-03-16  8:24   ` John McCabe
2021-03-16  9:13     ` Stephen Leake
2021-03-16 11:51       ` John McCabe
2021-03-16  9:46     ` Dmitry A. Kazakov
2021-03-16 10:46     ` Jeffrey R. Carter
2021-03-17  8:18       ` John McCabe
2021-03-17 10:06         ` AdaMagica
2021-03-15 18:12 ` Shark8
2021-03-15 18:20   ` John McCabe
2021-03-15 19:08   ` Paul Rubin
2021-03-15 19:37     ` Shark8
2021-03-16  7:17     ` Randy Brukardt
2021-03-16  9:26       ` Paul Rubin
2021-03-16  9:53       ` Dmitry A. Kazakov
2021-03-16  9:16     ` Stephen Leake
2021-03-16 11:04       ` Niklas Holsti
2021-03-16 22:49         ` Stephen Leake [this message]
2021-03-15 18:37 ` Jeffrey R. Carter
2021-03-15 18:54   ` John McCabe
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox