comp.lang.ada
 help / color / mirror / Atom feed
* Ada.Exceptions could be 'pragma Preelaborate' ?
@ 1998-10-30  0:00 Stephen Leake
  1998-10-30  0:00 ` Robert A Duff
  1998-10-30  0:00 ` Tucker Taft
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Leake @ 1998-10-30  0:00 UTC (permalink / raw)


Currently, Ada.Exceptions has no elaboration pragma, and thus any unit
that 'withs' Ada.Exceptions cannot have 'pragma Preelaborate'. This is
a pain; I'm building a nice library, everything is either Pure or
Preelaborate, but then I start adding nice error messages to my
exceptions, and I have to get rid of the pragmas. I started replacing
Preelaborate with Elaborate_Body, and got some circular elaboration
problems.

So, is there a reason Ada.Exceptions can't be Preelaborate? nothing in
the public spec violates a rule; do most implementations require
something that does?

-- Stephe




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ada.Exceptions could be 'pragma Preelaborate' ?
  1998-10-30  0:00 Ada.Exceptions could be 'pragma Preelaborate' ? Stephen Leake
  1998-10-30  0:00 ` Robert A Duff
@ 1998-10-30  0:00 ` Tucker Taft
  1 sibling, 0 replies; 6+ messages in thread
From: Tucker Taft @ 1998-10-30  0:00 UTC (permalink / raw)


Stephen Leake (Stephen.Leake@gsfc.nasa.gov) wrote:

: Currently, Ada.Exceptions has no elaboration pragma, and thus any unit
: that 'withs' Ada.Exceptions cannot have 'pragma Preelaborate'. This is
: a pain; I'm building a nice library, everything is either Pure or
: Preelaborate, but then I start adding nice error messages to my
: exceptions, and I have to get rid of the pragmas. I started replacing
: Preelaborate with Elaborate_Body, and got some circular elaboration
: problems.

: So, is there a reason Ada.Exceptions can't be Preelaborate? nothing in
: the public spec violates a rule; do most implementations require
: something that does?

Probably RM95 should have erred on the side of putting too many
Preelaborate pragmas in, rather than too few.  Implementations
sometimes have to "cheat" anyway, so we shouldn't have worried
about that.  I think the rationale for not putting a Preelaborate
here was that it clearly depended on the run-time system, and
most run-time systems certainly need to do some kind of run-time
initialization.  However, it is permissible to raise exceptions
in a preelaborable package, so calling Raise_Exception explicitly
should be allowed as well.

This problem could probably be "fixed" pretty quickly by the
Ada Rapporteur Group as part of their language maintenance activities.  
We have already been looking into the general issue of "categorization" 
pragmas for run-time system packages.

Package Calendar is another one which should probably get
a Preelaborate pragma.  There probably aren't many language-defined
packages that shouldn't either have a pragma Pure or
a pragma Preelaborate.  A similar issue relates to the
Remote_Types pragma, for what it is worth...

: -- Stephe

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ada.Exceptions could be 'pragma Preelaborate' ?
  1998-10-30  0:00 Ada.Exceptions could be 'pragma Preelaborate' ? Stephen Leake
@ 1998-10-30  0:00 ` Robert A Duff
  1998-10-31  0:00   ` dewar
  1998-11-04  0:00   ` Michel Gauthier
  1998-10-30  0:00 ` Tucker Taft
  1 sibling, 2 replies; 6+ messages in thread
From: Robert A Duff @ 1998-10-30  0:00 UTC (permalink / raw)


Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> Currently, Ada.Exceptions has no elaboration pragma, and thus any unit
> that 'withs' Ada.Exceptions cannot have 'pragma Preelaborate'. This is
> a pain; I'm building a nice library, everything is either Pure or
> Preelaborate, but then I start adding nice error messages to my
> exceptions, and I have to get rid of the pragmas. I started replacing
> Preelaborate with Elaborate_Body, and got some circular elaboration
> problems.

Yeah, that's a problem.  Similarly, if you want to put debugging
print-outs into a pragma-Pure package, you can't.

Here's a way to cheat, that usually works: You want to call some package
for Pure or Preelab code.  Declare another package with the same
functionality, and give it a pragma Pure.  Declare the original thing
with "pragma Export(Ada,...);" on all the procedures, and declare the
other one as "pragma Import(Ada, ...);".  This allows this package to
call the other one, without doing a "with" of it.

But be careful you don't call the Pure thing before the impure one has
been elaborated -- the run-time checks won't catch such an error!

IMHO such cheating is not "immoral", so long as it's just debugging
output we're talking about.  But you need to be careful that you don't
waste time debugging the debugging code.

> So, is there a reason Ada.Exceptions can't be Preelaborate? nothing in
> the public spec violates a rule; do most implementations require
> something that does?

Yes, I would expect implementations might want to do some
non-preelaborable stuff in Ada.Exceptions.

- Bob

P.S. Pragma Preelaborate is one of the features of Ada 95 I'm least
happy with -- don't get me started...  ;-)
-- 
Change robert to bob to get my real email address.  Sorry.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ada.Exceptions could be 'pragma Preelaborate' ?
  1998-10-30  0:00 ` Robert A Duff
@ 1998-10-31  0:00   ` dewar
  1998-11-04  0:00   ` Michel Gauthier
  1 sibling, 0 replies; 6+ messages in thread
From: dewar @ 1998-10-31  0:00 UTC (permalink / raw)


In article <wccn26dvfgi.fsf@world.std.com>,
  Robert A Duff <bobduff@world.std.com> wrote:
> Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:
>
> > Currently, Ada.Exceptions has no elaboration pragma, and thus any unit
> > that 'withs' Ada.Exceptions cannot have 'pragma Preelaborate'. This is
> > a pain; I'm building a nice library, everything is either Pure or
> > Preelaborate, but then I start adding nice error messages to my
> > exceptions, and I have to get rid of the pragmas. I started replacing
> > Preelaborate with Elaborate_Body, and got some circular elaboration
> > problems.
>
> Yeah, that's a problem.  Similarly, if you want to put debugging
> print-outs into a pragma-Pure package, you can't.


A little note for GNAT users:

The I/O package GNAT.IO is preelaborable. This is a convenient subset of
Text_IO features, perfectly adequate for debugging use.

Robert Dewar
Ada Core Technologies

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ada.Exceptions could be 'pragma Preelaborate' ?
  1998-10-30  0:00 ` Robert A Duff
  1998-10-31  0:00   ` dewar
@ 1998-11-04  0:00   ` Michel Gauthier
  1998-11-04  0:00     ` dewar
  1 sibling, 1 reply; 6+ messages in thread
From: Michel Gauthier @ 1998-11-04  0:00 UTC (permalink / raw)



>>  Stephen Leake <Stephen.Leake@gsfc.nasa.gov> wrote :
>>  
>>  > Currently, Ada.Exceptions has no elaboration pragma, and thus any unit
>>  > that 'withs' Ada.Exceptions cannot have 'pragma Preelaborate'. This is
>>  > a pain; I'm building a nice library, everything is either Pure or
>>  > Preelaborate, but then I start adding nice error messages to my
>>  > exceptions, and I have to get rid of the pragmas. I started replacing
>>  > Preelaborate with Elaborate_Body, and got some circular elaboration
>>  > problems.
>>  [...]
>>  > So, is there a reason Ada.Exceptions can't be Preelaborate? nothing in
>>  > the public spec violates a rule; do most implementations require
>>  > something that does?

to which in article <wccn26dvfgi.fsf@world.std.com>, Robert A Duff
<bobduff@world.std.com>replied :

>>  Yes, I would expect implementations might want to do some
>>  non-preelaborable stuff in Ada.Exceptions.

Couldn't designers envisage a Pure or Preelaborate Ada.Exceptions declaring
at least Exception_Id and Raise_Exception, and a non-Preelaborate child ?

It is really harmful to depend on a non-Preelaborate unit when the only 
need is to attach a message to a raise. It is more important than simply
'nice to have'.

In some cases, I worked around the problem with a basic package containing 
raises with messages, with two bodies Pure (messages are ignored) versus
Raise_Exception. Pragmas have to be set or reset by editor macros.

----------          ----------          ----------          ---------- 
Michel Gauthier / Laboratoire d'informatique
123 avenue Albert Thomas / F-87060 Limoges
telephone + 33 5 55 43 69 73
fax +33 5 55 43 69 77
----------          ----------          ----------          ----------
Hein, quoi, quelle annee dix-neuf cent nonante dix ?
What exactly about year nineteen ninety ten ?
----------          ----------          ----------          ----------




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ada.Exceptions could be 'pragma Preelaborate' ?
  1998-11-04  0:00   ` Michel Gauthier
@ 1998-11-04  0:00     ` dewar
  0 siblings, 0 replies; 6+ messages in thread
From: dewar @ 1998-11-04  0:00 UTC (permalink / raw)


In article <gauthier-0411981349510001@cemrad.unilim.fr>,
  gauthier@alphainfo.unilim.fr (Michel Gauthier) wrote:

 Couldn't designers envisage a Pure or Preelaborate Ada.Exceptions declaring
> at least Exception_Id and Raise_Exception, and a non-Preelaborate child ?
>
> It is really harmful to depend on a non-Preelaborate unit when the only
> need is to attach a message to a raise. It is more important than simply
> 'nice to have'.
>
> In some cases, I worked around the problem with a basic package containing
> raises with messages, with two bodies Pure (messages are ignored) versus
> Raise_Exception. Pragmas have to be set or reset by editor macros.


Note that at least some of the time, people use pragma Preelaborate to avoid
the presence of elaboration code.

Unfortunately, this pragma has not much too do with this avoidance. There can
be code with pragma Preelaborate that has elaboration code, and code that
is inconsistent with pragma Preelaborate that has no elaboration code.

We have found it helpful to introduce in GNAT a new implementation dependent
restriction, pragma Restriction (No_Elaboration_Code) that requires that a
given unit (it is a configuration pragma that can apply to selected units)
may not generate any elaboration code. Note that, unlike pragma Preelaborate,
this restriction pragma does not necessarily apply to with'ed units etc.

Robert Dewar
Ada Core Technologies

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-11-04  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-30  0:00 Ada.Exceptions could be 'pragma Preelaborate' ? Stephen Leake
1998-10-30  0:00 ` Robert A Duff
1998-10-31  0:00   ` dewar
1998-11-04  0:00   ` Michel Gauthier
1998-11-04  0:00     ` dewar
1998-10-30  0:00 ` Tucker Taft

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