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 Date: 3 Dec 92 05:19:26 GMT From: inmet!spock!stt@uunet.uu.net (Tucker Taft) Subject: Any limited type users out there? Message-ID: <1992Dec3.051926.26875@inmet.camb.inmet.com> List-Id: 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