comp.lang.ada
 help / color / mirror / Atom feed
* Any limited type users out there?
@ 1992-12-03  5:19 Tucker Taft
  0 siblings, 0 replies; only message in thread
From: Tucker Taft @ 1992-12-03  5:19 UTC (permalink / raw)


Have you got any code that returns a local variable of a limited
type?  If so, we want to see it!  "Why?" you ask...

The semantics for returning a local variable of a limited
type have always been a bit problematic in Ada 83.  If the
variable contains a task, current AI rulings say the resulting
execution is "erroneous" (i.e. anything can happen).  Of course
if the type is "limited private," the user of the type
isn't supposed to know or care what the type contains.
Similarly for a generic that takes a formal limited private type --
can it safely return a local variable of the type?

As we try to produce the draft reference manual for Ada 9X,
the issue of what to do about the semantics for returning
a local variable of a limited type has become a bit of a hot topic.
We would like to make it illegal at compile-time if the variable 
contains a task, rather than leave it the dreaded "erroneous," partly because
we now have other kinds of limited types for which returning local
variables doesn't make sense.  For example, local variables containing
protected objects, or local variables of a limited type that have user-defined
finalization (aka "destructor") actions, are not meaningful to
return.

So... we would like to know under what circumstances current Ada code
includes functions that return local variables (or parameters) of
a limited type.  Note that we are not worried about types which
are non-limited inside the function body, only those that are truly
limited inside the function body with the offending return statement.

Here are some examples:

     package A is
         type L is limited private;  -- might contain a task, for all
                                     -- the clients know.
         function F0 return L;  -- This function is no problem, 
                                -- since L is in fact non-limited
                                -- inside the body of F0.
         function Copy(X : L) return L;  -- Ditto for this one
     private
         type L is new Integer;
     end A;

     with A;
     package B is
         function F1 return A.L;
         function F2(X : A.L) return A.L;
     end B;
     package body B is
         function F1 return A.L is
             V1 : A.L;  -- local variable of a limited type
         begin
             if Blah then
                  return V1;       -- Trouble if A.L contains a task.
             elsif Burp then
                  return F2(V1);   -- Trouble since F2 returns its arg.
             else
                  return A.Copy(V1); -- No problem, since Copy presumably
                                     -- does the "right thing" (it can see
                                     -- the full type decl for A.L).
             end if;
         end F1;
         function F2(X : A.L) return A.L is
         begin
             return X;  -- parameter, which might be trouble if F2
                        -- itself is called in a return statement
         end F2;
     end B;

So, we are looking for code samples, appropriately disguised
if necessary to protect proprietary software, of functions that return
a local variable or a parameter of a limited type.
Examples from off-the-shelf components like EVB Grace
or the Booch components would be particularly interesting,
as would examples drawn from big production Ada systems.
(Our preliminary scan of the Booch components found no offending code.)

Our hope is that such examples (or perhaps the lack of
such examples) will help us decide whether we should take
the "low road" and just declare anything fishy "erroneous," or
try to catch more of these problems at compile-time with some
relatively simple legality rule.

Thanks in advance.

S. Tucker Taft     stt@inmet.com
Ada 9X Mapping/Revision Team
Intermetrics, Inc.
Cambridge,  MA  02138

P.S. I am (quite) aware that a function doesn't "return" a variable, but
rather the value of a variable (or some other expression).
But hopefully you know what I mean... -T

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1992-12-03  5:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-12-03  5:19 Any limited type users out there? Tucker Taft

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