ada: Implement AI22-0154 (Revised resolution of indexing aspects)

Customer code was running into an error due to a violation of the
rule for indexing aspects that any functions declared in the same
package spec that do not satisfy the legality rules for eligible
indexing functions make the aspects illegal. In this case it was
due to a derived type inheriting a function of the parent type
that had indexing aspects. Consideration of this problem led
to proposing language changes in AI22-0154, which revises the
resolution rules to take the indexing profile requirements into
account (rather than allowing resolution indexing aspect names
to consider any available function declared within the scope).
This set of changes implements the revised resolution rules,
allowing the compiler to accept the customer code.

In some cases the compiler will now issue a warning instead of
ignoring an ineligible candidate entity. Specifically this is
done when a candidate interpretation is a function that has at
least a first formal of the type associated with the aspect,
but doesn't satisfy other requirements of the particular
indexing aspect. We impose this limitation so as to avoid
issuing too many false-positive warnings.

These changes also reduce technical debt by removing code in
Sem_Util.Inherit_Nonoverridable_Aspect that was handling checking
and addition of new indexing functions for derived types via calls
to Check_Function_For_Indexing_Aspect. That handling is now covered
fully by Check_Indexing_Functions (which itself makes calls to
Check_Function_For_Indexing_Aspect).

Additionally, these changes attempt to implement rule changes
specified by AI22-0159/01 (Inheritance for aspects allowed to
denote multiple subprograms), an AI that was added to address
problems identified while finalizing AI22-0154.

gcc/ada/ChangeLog:

	* sem_ch6.adb (New_Overloaded_Entity): Add missing call to
	Check_For_Primitive_Subprogram (Is_Primitive must be set).
	* sem_ch13.ads (Check_Function_For_Indexing_Aspect): Move declaration
	to package body.
	* sem_ch13.adb (Check_Indexing_Functions): Remove early return for
	derived types. Pass appropriate values for the new Boolean parameters
	on existing calls to Check_Function_For_Indexing_Aspect. Perform a
	second interpretation loop, calling Check_Function_For_Indexing_Aspect
	and passing Indexing_Found for the Has_Eligible_Func parameter and True
	for the Error_On_Ineligible parameter, and remove the existing call
	to Error_Msg_NE that was flagging nonlocal entities (a similar error
	is now reported inside procedure Check_Function_For_Indexing_Aspect).
	Suppress call to Check_Inherited_Indexing in derived type cases.
	(Check_Nonoverridable_Aspect_Subprograms): Remove early return when
	the aspect spec does not come from source, so aspects of derived types
	will also go through this procedure. Check restrictions of AI22-0159/01
	for derived types and inheritance of aspects. Replace iteration over
	overloaded interpretations with iteration over Aspect_Subprograms (and
	only do that for indexing aspects). Condition Sloc for existing error
	check for nonprimitive operations based on whether the aspect comes
	from source, posting the error on the entity rather than the aspect
	if the aspect is not given explicitly.
	(Analyze_Aspects_At_Freeze_Point): Split off a new case alternative
	for iterator aspects, and specialize treatment for indexing aspects
	by forcing a search for new indexing functions. When none are found,
	issue an error only in the case where the type has no inherited
	indexing functions. Test that the version is at least Ada_2012 rather
	than Ada_2022 for calling Check_Nonoverridable_Aspect_Subprograms.
	(Check_Function_For_Indexing_Aspect): Move declaration from the package
	spec to the body. Add Has_Eligible_Func and Error_On_Ineligible formals
	and update spec comment.
	Return early if the candidate subprogram was already inherited (present
	in Aspect_Subprograms).
	For a scope mismatch on Subp, report error only when Has_Eligible_Func
	is False and Error_On_Ineligible is True (and never a warning).
	Add "<<" in several calls to Report_Ineligible_Indexing_Function
	(formerly Illegal_Indexing) to allow either warnings or errors.
	Return without adding subprogram to Aspect_Subprograms when
	Error_On_Ineligible is False.
	(Report_Ineligible_Indexing_Function): Name changed from
	Illegal_Indexing.
	Return early when only a warning can be issued and the ineligible
	subprogram is inherited, or if its first formal (if any) does not match
	the aspect's associated type (to reduce false-positive warnings).
	Set Error_Msg_Warn based on Error_On_Ineligible formal.
	Report a continuation message identifying the ineligible entity.
	Remove comment preceding body that has been obviated by AI22-0154.
	* sem_util.adb (Inherit_Nonoverridable_Aspect): Remove the loop over
	primitives that was checking and adding eligible primitives. That code
	was incomplete, and collection of new indexing functions for derived
	types is now handled by Check_Indexing_Functions. Also remove the
	associated "???" comment.
4 files changed