CVS difference for ais/ai-00348.txt

Differences between 1.3 and version 1.4
Log of other versions for file ais/ai-00348.txt

--- ais/ai-00348.txt	2003/09/11 21:59:43	1.3
+++ ais/ai-00348.txt	2003/09/19 01:42:28	1.4
@@ -1,11 +1,12 @@
-!standard  6.07(00)                                     03-09-02  AI95-00348/01
+!standard  6.07(00)                                     03-09-05  AI95-00348/04
 !standard  3.01(09)
 !standard  7.06(06)
 !standard  7.06(08)
 !standard  7.06(09)
 !standard 12.06(03)
-!standard 12.06(08)
+!standard 12.06(04)
 !standard 12.06(10)
+!standard 12.06(16)
 !class amendment 03-09-02
 !status work item 03-09-02
 !status received 03-09-02
@@ -84,24 +85,23 @@
 Add to 12.6(3)
     subprogram_default ::= ... | null
-Add after 12.6(8)
+Add after 12.6(4)
     A subprogram_default of null shall not be specified for a formal function.
-  Add after 12.6(10)
+Add after 12.6(10)
     If a generic unit has a subprogram_default specified by the reserved word
     null, and the corresponding actual parameter is omitted, then it is
     equivalent to an explicit actual parameter that is a null procedure having
     the profile given in the formal_subprogram_declaration.
-  Add after 12.6(16)
+Add after 12.6(16)
     If a generic unit has a subprogram_default specified by the reserved word
-    null, and the corresponding actual parameter is omitted, then the calling
-    convention of the actual parameter is Intrinsic (see 6.3.1).
+    null, then in an instance where the corresponding actual parameter is
+    omitted, the formal subprogram has convention Intrinsic (see 6.3.1).
 Like an instantiation, a null procedure is not allowed as a completion.
@@ -188,6 +188,9 @@
 Eq must be False.
+The convention of a formal procedure whose default is null and actual is
+omitted is Intrinsic. This follows from 6.3.1(7). Thus we don't have to worry
+about access issues for such formal subprograms.
@@ -203,6 +206,156 @@
+From: Thomas Wolf
+Sent: Monday, June 30, 2003  5:36 AM
+AI-251 proposes new null procedures ("procedure ... is null")
+for the new interfaces.
+Wouldn't it make sense to allow "is null" as a subprogram default
+for generic formal procedures, too? Semantics as the box default
+("is <>") but if no actual parameter is given and no match exists,
+defaults to a null procedure.
+   type Item (<>) is private;
+   with procedure Clean_Up (X : in out Item) is null;
+package Some_Containers is
+   type Container is limited private;
+   ...
+   procedure Clear (C : in out Container);
+   -- Removes all items currently in 'C'. Calls 'Clean_Up' for any item
+   -- just before it is removed from 'C'.
+   type Item_Ptr is access Item;
+   type Container is limited
+     record
+        The_Item : Item_Ptr;
+     end record;
+   --  Assume some complex dynamic container, such as an AVL tree.
+end Some_Containers;
+and an implementation like
+procedure Clear (C : in out Container)
+  procedure Free is new Unchecked_Dealloctaion (Item, Item_Pr);
+  for I in "all items in C" loop
+    Clean_Up (I.all);
+    Free (I);
+  end loop;
+end Clear;
+Now, instantiating this with a type where we don't care about clean-up
+is easy:
+  package Int_Containers is new Some_Containers (Integer);
+Instantiating with a controlled type also is simple, for we don't need
+a clean-up routine, "built-in" finalization is supposed to do that job:
+  type XYZ is new Ada.Finalization.Controlled with ...
+  package XYZ_Containers is new Some_Containers (XYZ);
+So far, package Some_Containers could've been written without the
+'Clean_Up' formal procedure.
+But now suppose we want to instantiate Some_Containers with an access
+  type Int_Ptr is access Integer;
+  package Int_Ptr_Containers is new Some_Containers (Int_Ptr);
+Now, if the values added to such a container had been allocated
+dynamically, we'd like to have them automatically deallocated
+when the container is cleared. Hence, we could do instead
+  procedure Free is new Unchecked_Deallocation (Integer, Int_Ptr);
+  package Int_Ptr_Containers is new Some_Containers (Int_Ptr, Free);
+Without a "is null" generic formal procedure, one would either have to
+provide explicit null implementations of Clean_Up for Int_Containers
+and XYZ_Containers, or write the 'Some_Containers' generic package
+without the 'Clean_Up' formal parameter in the first place and insist
+that the Int_Ptr_Container be written using a wrapping of the Int_Ptr
+in a controlled type, so that its Finalize operation be called when
+the container is cleared.
+Both variants cause additional, basically useless work for users of
+Some_Containers, and the instantiations are needlessly complicated.
+Since AI-251 proposes "null procedures" anyway, it seems a small step
+to allow them not only as primitive operations of abstract interfaces,
+but also in other contexts where they might make sense.
+Note: to get a similar effect as the "is null", one would currently
+have to use two nested generics, which still complicates the
+instantiation further:
+   type Item  (<>) is private;
+package Some_Container_Wrapper is
+   procedure Null_Clean_Up (X : in out Item);
+   -- Has a null body
+   generic
+      with Clean_Up (X : in out Item) is Null_Clean_Up;
+   package Some_Containers is
+      ...
+   end Some_Containers;
+end Some_Container_Wrapper;
+and an instantiation like
+   package Wrapper is new Some_Container_Wrapper (A_Type);
+   package A_Type_Containers is new Wrapper.Some_Containers;
+or something like
+   type Item (<>) is private;
+   with procedure Clean_Up (X : in out Item) is null;
+package Some_Containers is
+   ...
+end Some_Containers;
+   type Item (<>) is private;
+procedure Null_Clean_Up (X : in out Item);
+and an instantiation like
+   procedure No_Clean_up is new Null_Clean_Up (A_Type);
+   package A_Type_Containers is
+      new Some_Containers (A_Type, No_Clean_up);
+Both variants are substantially more complex than the one with the
+"is null" formal procedure.
+A minor disadvantage of "is null" for generic formal procedures is
+that this would not make sense for generic formal functions.
+From: Tucker Taft
+Sent: Monday, June 30, 2003  7:46 AM
+The ARG discussed this at our recent meeting and we also concluded
+this was a useful and natural generalization of the proposal.
+It was noted that it is fairly common when defining a generic
+with a formal subprogram to explicitly define a "Do_Nothing"
+procedure as a default.  "is null" would provide a natural and
+more uniform way to accomplish the same thing.
 From: Stephen W Baird
 Sent: Tuesday, September 2, 2003  4:01 PM
@@ -456,6 +609,8 @@
 > not possible to refer directly to the actual parameter.)
 Ok by me.
+[These changes were made in version /04 - ED.]

Questions? Ask the ACAA Technical Agent