+2015-03-02 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch8.adb (Available_Subtype): Optimization in
+ Find_Selected_Component: when safe, use existing subtype of
+ array component, possibly discriminant-dependent, rather than
+ creating new subtype declaration for it. In this fashion different
+ occurrences of the component have the same subtype, rather than
+ just equivalent ones. Simplifies value tracing in GNATProve.
+
2015-03-01 Arnaud Charlet <charlet@adacore.com>
PR ada/65259
Nam : Node_Id;
+ function Available_Subtype return Boolean;
+ -- A small optimization: if the prefix is constrained and the component
+ -- is an array type we may already have a usable subtype for it, so we
+ -- can use it rather than generating a new one, because the bounds
+ -- will be the values of the discriminants and not discriminant refs.
+ -- This simplifies value tracing in GNATProve.
+
function Is_Reference_In_Subunit return Boolean;
-- In a subunit, the scope depth is not a proper measure of hiding,
-- because the context of the proper body may itself hide entities in
-- because the proper body is inserted in the main unit and its context
-- is simply added to that of the parent.
+ -----------------------
+ -- Available_Subtype --
+ -----------------------
+
+ function Available_Subtype return Boolean is
+ Comp : Entity_Id;
+ begin
+ Comp := First_Entity (Etype (P));
+ while Present (Comp) loop
+ if Chars (Comp) = Chars (Selector_Name (N)) then
+ Set_Etype (N, Etype (Comp));
+ Set_Etype (Selector_Name (N), Etype (Comp));
+ return True;
+ end if;
+
+ Next_Component (Comp);
+ end loop;
+
+ return False;
+ end Available_Subtype;
+
-----------------------------
-- Is_Reference_In_Subunit --
-----------------------------
and then (not Is_Entity_Name (P)
or else Chars (Entity (P)) /= Name_uInit)
then
+ if Is_Entity_Name (P)
+ and then Ekind (Etype (P)) = E_Record_Subtype
+ and then Nkind (Parent (Etype (P))) = N_Subtype_Declaration
+ and then Is_Array_Type (Etype (Selector))
+ and then not Is_Packed (Etype (Selector))
+ and then Available_Subtype
+ then
+ return;
+
-- Do not build the subtype when referencing components of
-- dispatch table wrappers. Required to avoid generating
-- elaboration code with HI runtimes. JVM and .NET use a
-- Dispatch_Table_Wrapper and RE_No_Dispatch_Table_Wrapper.
-- Avoid raising RE_Not_Available exception in those cases.
- if VM_Target = No_VM
+ elsif VM_Target = No_VM
and then RTU_Loaded (Ada_Tags)
and then
((RTE_Available (RE_Dispatch_Table_Wrapper)