Issue 131106.1: Replace DW_TAG_descriptor_type (130318.1) with DW_TAG_dynamic_type

Author: Ron Brender
Champion: Ron Brender
Date submitted: 2013-11-06
Date revised:
Date closed:
Type: Enhancement
Status: Accepted
DWARF Version: 5
Section 5.15, pg 
This is a proposal to reconsider 130318.1, which was approved in 
July (pending an examples section to be supplied). In particular, 
the proposal is to replace 130318.1 in toto with a new formulation 
as described below.

Background

130318.1 is an outgrowth of the older 121112.1, which proposed a
fairly general DW_TAG_refine_type entry that could be used to
add various properties to a type, notably make it into a co-array
or add the dynamic properties represented by the DW_AT_allocated
and DW_AT_associated attributes. The committee opted for a more
specific and specialized construct for co-arrays (and similarly
assumed rank arrays), leaving the dynamic type related-attributes
to be addressed.

The dynamic type attributes DW_AT_allocated and DW_AT_associated
were added to DWARF in Version 3 to address FORTRAN needs. There
is no additional semantic functionality that needs to be expressed--
the DW_AT_data_location attribute can be used in combination with
DW_AT_allocated and/or DW_AT_associated to effectively describe a 
variety of needs in Fortran, Ada, and other languages (see Appendix 
D.2).

The case was made, however, that Fortran's syntax for adding the
dynamic properties to an existing type can lead to excessive
replication of DWARF description if these attributes must be added
to new types that are otherwise the same as earlier.

Unfortunately the matters of type description and run-time 
type representation (a potential descriptor) became more entangled 
that seems necessary or desirable. The resulting proposal and 
justification for the DW_TAG_descriptor_type reflects that.

In addition, the 1130318.1 proposal contains this sweeping statement

    "Any other attributes and/or children debugging information 
    entries on the descriptor type entry would behave identically
    as if the attribute and/or children DIEs [sic] are attached
    to the referencing type entry."
    
As formulated, this doesn't work if the referenced type has a
DW_AT_name attribute. In the example of that proposal this results
in multiple descriptor type declarations, all with the name "dt"
(like the referenced type). And it is unclear whether a descriptor
type can have a name in its own right, although apparently not.

More generally, not addressed is the effect of a DW_AT_allocated
or DW_AT_associated attribute on the descriptor type if there is
a corresponding attribute on the referenced type.

Following is a new formulation that seeks to provide the intended
functionality in a way that directly addresses the DWARF replication
motivation without mixing in descriptor concepts.

Proposal

1) In Table 2.1: Tag names add

        DW_TAG_dynamic_type
        
2) Renumber the existing 5.15, "Dynamic Type Properties" to 5.15.1
making it part of the following new 5.15:

    "5.15 Dynamic Type Entries and Properties
    *Some languages such as Fortran 90, provide types whose values
    may be dynamically allocated or associated with a variable
    under explicit program control. However, unlike the related
    pointer type in C or C++, the indirection involved in accessing
    the value of the variable is generally implicit, that is, not
    indicated as part of program source.*
    
    A dynamic type entry is used to declare a dynamic type that is 
    "just like" another non-dynamic type without needing to
    replicate the full description of that other type.

    A dynamic type is represented by a debugging information entry
    with the tag DW_TAG_dynamic_type. If a name has been given to the
    dynamic type, then the dynamic type has a DW_AT_name attribute 
    whose value is a null-terminated string containing the dynamic
    type name as it appears in the source.
    
    A dynamic type entry has a DW_AT_type attribute whose value is a
    reference to the type of the entities that are dynamically allocated.
    
    A dynamic type entry also has a DW_AT_data_location, and may also
    have DW_AT_allocated and/or DW_AT_associated attributes as 
    described following (Section 5.15.1). The type referenced by the
    DW_AT_type attribute must not have any of these attributes.
    
3) The current 5.15, "Dynamic Type Properties", is renumbered to 5.15.1.
At the beginning of 5.15.1 insert:

    *The DW_AT_data_location, DW_AT_allocated and DW_AT_associated 
    attributes described in this section can be used for any type, not
    just dynamic types.*
    
4) The current 5.15.1, "Data Location" is renumbered to 5.15.1.1, and
5.15.2, "Allocation and Association Status" is renumbered to
5.15.1.2.

5) The recently introduced 5.15.3, "Array Rank" (mis-numbered as 
5.15.4 in the October 27, 2013 draft because of an earlier header 
level error) is renumbered to 5.15.1.3. 

6) Add DW_TAG_dynamic_type to Table 7-1 (encoding TBD).

7) Add to Table A.1: List of attributes allowed on DW_TAG_descriptor_type

        DW_TAG_dynamic_type
            DECL
            DW_AT_abstract_origin
            DW_AT_allocated
            DW_AT_associated
            DW_AT_data_location
            DW_AT_description
            DW_AT_name
            DW_AT_type
            DW_AT_sibling


8) Add the following example at the end of Appendix D.2.1, "Fortran
Array Example":
    
    Consider the Fortran 90 example of dynamic properties in Figure 
    D.<1>. This can be represented in DWARF as illustrated in Figure
    D.<2>. Note that unnamed dynamic types are used to avoid replicating
    the full description of the underlying type dt that is shared by
    several variables.
    
    ----------------------------------------------------------------
      program sample
     
      type :: dt (l)
        integer, len :: l
        integer :: arr(l)
      end type

      integer :: n = 4
      contains

      subroutine s()
        type (dt(n))               :: t1
        type (dt(n)), pointer      :: t2
        type (dt(n)), allocatable  :: t3, t4
      end subroutine
     
      end sample
    -----------------------------------------------------------------
                Figure D.<1>: Fortran dynamic types: source
    
    -----------------------------------------------------------------
    11$:    DW_TAG_structure_type
            DW_AT_name("dt")
                DW_TAG_member
                    ...
                ...

    13$:    DW_TAG_dynamic_type             ! plain version
                DW_AT_data_location (dwarf expression to locate raw data)
                DW_AT_type (11$)

    14$:    DW_TAG_dynamic_type             ! 'pointer' version
                DW_AT_data_location (dwarf expression to locate raw data)
                DW_AT_associated (dwarf expression to test if associated)
                DW_AT_type (11$)

    15$:    DW_TAG_dynamic_type             ! 'allocatable' version
                DW_AT_data_location (dwarf expression to locate raw data)
                DW_AT_allocated (dwarf expression to test is allocated)
                DW_AT_type (11$)

    16$:    DW_TAG_variable
                DW_AT_name ("t1")
                DW_AT_type (13$)
                DW_AT_location (dwarf expression to locate descriptor)
    17$:    DW_TAG_variable
                DW_AT_name ("t2")
                DW_AT_type (14$)
                DW_AT_location (dwarf expression to locate descriptor)
    18$:    DW_TAG_variable
                DW_AT_name ("t3")
                DW_AT_type (15$)
                DW_AT_location (dwarf expression to locate descriptor)
    19$:    DW_TAG_variable
                DW_AT_name ("t4")
                DW_AT_type (15$)
                DW_AT_location (dwarf expression to locate descriptor)
    -----------------------------------------------------------------
         Figure D.<2>: Fortran dynamic types: DWARF description


---
Accepted: 11/20/2013.