On Jan 10, 12:58 am, Georg Bauhaus <rm-
host.bauh...@maps.futureapps.de> wrote:
> Wouldn't the following lookup function handle the situation?
>
> function Lookup (Table : Dictionaries.Map;
> Object : T'Class) return Boolean is
> begin
> return Table.Contains (Object'Unchecked_Access);
> end Lookup;
> Object denotes an object, then, so no nulls. Therefore, passing
> the result of 'Unchecked_Access to function "Contains" should
> be safe in the sense that Contains always gets a meaningful
> access value to be used as a key.
Yes, but this also brings an idea for some typing convention, which I
happen to use.
The idea is to somehow express the expectation that the operation has
with regard to the lifetime of the object and with regard to the
aliasing that can be involved. In the case of Info, where no access
value is used, the operation expects nothing, which means that it
should not leak the reference to the object (store it, etc.). That is,
after the operation completes, the object can be destroyed with no
consequences, as no alias was created.
In the case of Info_3 (or any other operation that accepts access
values), the operation can assume that the object lives longer and can
therefore leak (store, etc.) the reference and make new alias - it is
up to the user to figure out the complete lifetime management.
Of course, this convention is not checked statically (other than with
the usual rules for access types, which can be bypassed with
Unchecked_XXX anyway), but is a good hint for the user with regard to
object lifetime expectations.
For this reason I would explicitly use access values in the profile if
the operation stores the access value in a dictionary.
The user should know that there is some aliasing going on there.
> The effect is that there still wouldn't be any parameters of an
> anonymous access-to-object type at the level of T's definition.
Why this should be a goal?
I prefer if the profile describes what is going on. If sh*t is going
on, then it is better to show it in the profile than to hide it and
surprise the user later.