Skip to content

Commit 62a1c13

Browse files
wchilders-nvidiadaveedvdv-nvidia
authored andcommitted
Improve typeref documentation []
1 parent 9ba2df4 commit 62a1c13

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎doc/source/il.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ routine's IL scope entry (see ``find_vla_dimension`` in ``il.c``). When the
860860
bound of a VLA is unspecified (e.g., because it was declared with the ``[*]``
861861
syntax), ``is_vla`` will be TRUE but ``has_assoc_vla_dimension`` will be FALSE.
862862

863+
.. _il-typerefs:
864+
863865
Typerefs
864866
--------
865867

‎doc/source/int_overview.rst‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -858,20 +858,26 @@ also included.
858858
Typerefs
859859
--------
860860

861-
The description of a type in the intermediate language contains a type entry
862-
kind ``tk_typeref``, which is used to define typedefs, and also to add type
863-
qualifiers to a type, e.g., ``const`` in ``const int``. Such an entry is in
864-
some ways not a full-fledged type. For example, it doesn't indicate its size;
865-
one must go to the underlying type to get that. The macro ``skip_typerefs``
866-
and the function ``f_skip_typerefs`` can be used to strip off typerefs and get
867-
to the underlying type, which can then be processed in the normal way. A very
868-
common cause of bugs in code our customers add is failure to put in
869-
``skip_typerefs`` calls where necessary. (For that matter, it's a common cause
870-
of bugs in our code, though we try hard to find all those bugs before we ship
871-
the code.) The whole ``skip_typerefs`` issue is error-prone and requires
872-
discipline, but you do get used to it, and after many years of working with it
873-
we remain convinced that it's the right way to handle typedefs and type
874-
qualifiers. Just be careful.
861+
The ``a_type`` IL entry can have a ``tk_typeref`` kind; such entries
862+
represent a type that is based on another type in some way. For example, a
863+
``typedef`` is represented by a typeref entry designating the type for
864+
which it is a synonym. Similarly, cv-qualified types like ``const int`` are
865+
represented by a ``const`` typeref pointing to the entry for the ``int``
866+
type. Additional uses for typerefs include type operators like
867+
``decltype``, capturing the specific template arguments used when a
868+
class or alias template specialization is referred to, and many others.
869+
870+
In general, typerefs do not have complete information about the type they
871+
represent, such as the size and alignment. As a result, it is often
872+
necessary to access the type on which a given typeref is based, and
873+
various macros and functions are provided for that operation, such as
874+
``skip_typerefs``, ``skip_lexical_typerefs``,
875+
``skip_typerefs_not_typedefs``, etc. It is a common source of bugs to
876+
omit a call to one of these functions and operate on the typeref itself
877+
instead of its underlying type.
878+
879+
See the :ref:`il-typerefs` section in the Intermediate Language
880+
chapter for further details.
875881

876882
Source Positions
877883
----------------

0 commit comments

Comments
 (0)