!standard 6.5(5.11/5) 15-06-03 AI12-0161-1/01 !class Amendment 20-01-29 !status Hold 20-01-29 !status work item 20-01-29 !status received 19-08-21 !priority Very_Low !difficulty Easy !subject Returnable attribute !summary [Editor's note: This AI was "born" on hold as it came too late to be included in Ada 202x.] Add the Returnable attribute. !problem It is valuable to be able to determine whether some given runtime check would fail without actually performing the check and having to raise and handle the exception. For instance, we can pretest whether an access value is null before we dereference it. However, it's not possible to make all of the checks associated with a function return; in particular, the accessibility of the call is not determinable inside of the function. !proposal Func'Returnable where Func is any enclosing function. The attribute denotes a Boolean-valued function that takes one in-mode parameter whose subtype is the result subtype of the given function (if the result subtype of the given function is anonymous, then the parameter subtype of the denoted function is similarly defined). The Boolean result is True if the argument passes all the function-return-value runtime checks described in section 6.5 and false otherwise. !wording ** TBD. It probably should go at the end of the Static Semantics section in 6.5 (after paragraph 5.11), as that is where attributes are typically defined. This one might make more sense at the end of the Dynamic Semantics section since it is tied so closely to that Dynamic Semantics (that would be after paragraph 23) !discussion It's possible to use a membership to make the tag checks, but there's no Ada 2012 way to determine the result of the accessibility checks. !ASIS [Not sure. It seems like some new capabilities might be needed, but I didn't check - Editor.] !ACATS test ACATS B- and C-Tests are needed to check that the new attribute is supported. !appendix From: Steve Baird Sent: Tuesday, September 17, 2019 7:10 PM In a discussion I was having with Randy a while back, I made the following observation about a proposal that had been posted on ada-comment: > I should mention that in general I have sympathy for somebody who > wants to know whether some given runtime check would fail without > actually performing the check and having to raise and handle the exception. > > It's nicer to be able to say > > procedure Foo (X : Some_Subtype) is ... end; > begin > if Y in Some_Subtype then > Foo (X => Y); > end if; > > as opposed to > > procedure Foo (X : Some_Subtype) is ... end; > begin > Foo (X => Y); > exception > when Constraint_Error => null; > end; > > ... > > But suppose you are inside a function with an anonymous access result > type and you want to know whether returning some value meets the > accessibility requirement associated with the master of the call. > > I don't think the approach of having an accessibility-level-valued > attribute ... is the right one, but there is an unsolved problem there > that might be worth addressing someday. and a little bit of further back and forth led to sketch of a new attribute Func'Returnable where Func is any enclosing function. The attribute denotes a Boolean-valued function that takes one in-mode parameter whose subtype is the result subtype of the given function (if the result subtype of the given function is anonymous, then the parameter subtype of the denoted function is similarly defined). The Boolean result is True if the argument passes all the function-return-value runtime checks described in section 6.5 and false otherwise. I suspect that this is just a solution looking for a problem and that no action is needed here, but I mention it in case others feel that something along these lines would be useful. If it is decided to proceed with this idea in some form then I expect that this would be a post-Ada202x addition. ****************************************************************