]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Clean up scope depth and related code (tech debt)
authorBob Duff <duff@adacore.com>
Tue, 5 Sep 2023 18:40:22 +0000 (14:40 -0400)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 15 Sep 2023 13:01:29 +0000 (15:01 +0200)
commit553c37bedcfb04f52237ef3cdd2a19747c61cde1
tree3d93df681fb0727604b4fbec9904a6c64c939914
parent545af80aef6dcc368f3e50cbd0c2119ddbdde2e7
ada: Clean up scope depth and related code (tech debt)

The main point of this patch is to remove the special case
for Atree.F_Scope_Depth_Value in the Assert that Field_Present
in Get_Field_Value. Pulling on that thread leads to lots
of related cleanup.

gcc/ada/ChangeLog:

* atree.adb (Node_Kind_Table): Specify parameter explicitly in
GNAT.Table instantiations. Use fully qualified references instead
of relying on use clauses.
(Get_Field_Value): Remove special case for F_Scope_Depth_Value.
That is, enable the Field_Present check in that case.
(It was already enabled for all other fields.) Violations of this
check were already fixed.
(Print_Node_Statistics): Sort the output in decreasing order of
frequencies.
(Print_Field_Statistics): Likewise (sort).
* accessibility.adb (Accessibility_Level): Pass Allow_Alt_Model in
recursive calls. Apparently, an oversight.
(Innermost_Master_Scope_Depth): Need to special-case the 'Old
attribute and allocators.
* einfo-utils.ads (Scope_Depth): Use Scope_Kind_Id to get
predicate checks.
(Scope_Depth_Set): Likewise.
(Scope_Depth_Default_0): Likewise.
* einfo-utils.adb: As for spec.
* frontend.adb (Frontend): Remove unnecessary "return;".
* gen_il-types.ads (Scope_Kind): New union type.
* gen_il-gen-gen_entities.adb (Scope_Kind): New union type.
* sem.ads: Move "with Einfo.Entities;" from body to spec.
(Scope_Stack_Entry): Declare Entity to be of Scope_Kind_Id to get
predicate checks. We had previously been putting non-scopes on the
scope stack; this prevents such anomalies.
* sem.adb: Move "with Einfo.Entities;" from body to spec.
* sem_ch8.ads: Move "with Einfo.Entities;" from body to spec. Add
"with Types;".
(Push_Scope): Use Scope_Kind_Id to get predicate checks.
* sem_ch8.adb: Move "with Einfo.Entities;" from body to spec. Add
"with Types;".
(Push_Scope): Use Scope_Kind_Id to get predicate checks.
(Pop_Scope): Use Scope_Kind_Id on popped entity to get predicate
checks. This prevents anomalies where a scope pushed onto the
stack is later mutated to a nonscope before being popped.
* sem_util.ads (Find_Enclosing_Scope): Add postcondition to ensure
that the enclosing scope of a node N is not the same node N.
Clearly, N does not enclose itself.
* sem_util.adb (Find_Enclosing_Scope): There were several bugs
where Find_Enclosing_Scope(N) = N. For example, if N is an entity,
then we would typically go up to its declaration, and then back
down to the Defining_Entity of the declaration, which is N itself.
There were other cases where Find_Enclosing_Scope of an entity
disagreed with Scope. Clearly, Find_Enclosing_Scope and Scope
should agree (when both are defined). Such bugs caused latent bugs
in accessibility.adb related to 'Old, and fixing bugs here caused
such bugs to be revealed. These are fixed by calling Scope when N
is an entity.

Co-authored-by: Ronan Desplanques <desplanques@adacore.com>
13 files changed:
gcc/ada/accessibility.adb
gcc/ada/atree.adb
gcc/ada/einfo-utils.adb
gcc/ada/einfo-utils.ads
gcc/ada/frontend.adb
gcc/ada/gen_il-gen-gen_entities.adb
gcc/ada/gen_il-types.ads
gcc/ada/sem.adb
gcc/ada/sem.ads
gcc/ada/sem_ch8.adb
gcc/ada/sem_ch8.ads
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads