[Chapel Merge] IFC: late checking of generic implements statement

Branch: refs/heads/master
Revision: 36e3330
Author: vasslitvinov
Log Message:

Merge pull request #17618 from vasslitvinov/ifc-generics

IFC: late checking of generic implements statements

The first commit here implements a part of #17612. Specifically,
it discontinues early checking of generic implements statements.

So far only traditional-generic implements statements have been allowed.
They will now be checked late, that is, upon being instantiated.
Once we introduce implements statements over interface generics,
as proposed in #17612, those will be checked early.

Early checking of generic implements statements was introduced in #17239.
The implementation introduced a stand-in type and a stand-in param.
Given a generic implements statement, the implementation instantiated
the generic type(s) using the stand-in type and/or param, then checked
the resulting implements statement as if it were concrete.

// For example, given this source code:
interface IFC {...}
record R { type T; param P; }

R implements IFC;

// the implementation was checking:
R(T = dtGenericStandin, P = gGenericParam) implements IFC;

While this is an elegant idea, in practice such "stand-in" generic
instantiations could be checked only in simplest cases. Any attempts
to get closer to real code, such as the RandomStream interface,
either did not pass checking or caused compiler crash. We could
keep extending the set of cases that are handled by the compiler
successfully, however I consider this not suitable for real codes.

Affected tests:

M test/constrained-generics/basic/generic/error-generic-implements-1.chpl
M test/constrained-generics/basic/generic/error-generic-implements-6.chpl
A test/constrained-generics/basic/generic/wrapping-cg-types.chpl

WHILE THERE - the second commit

  • Allow a required function with a default or const-ref return intent
    to be implemented by a function with a const-ref or ref return return.
    This way a default-intent function can be implemented with a field accessor.

  • Impose lexical order of traversal of InterfaceSymbol::associatedTypes.

Affected tests:

M test/constrained-generics/basic/set2/error-return-intent.good
D test/constrained-generics/basic/set2/error-return-intent.prediff
M test/constrained-generics/basic/set2/error-return-type.good
D test/constrained-generics/basic/set2/error-return-type.prediff

r: @mppf

Modified Files:
A test/constrained-generics/basic/generic/wrapping-cg-types.chpl

A test/constrained-generics/basic/generic/wrapping-cg-types.good
R test/constrained-generics/basic/set2/error-return-intent.prediff
R test/constrained-generics/basic/set2/error-return-type.prediff
M compiler/AST/type.cpp
M compiler/include/resolution.h
M compiler/include/symbol.h
M compiler/include/type.h
M compiler/resolution/cleanups.cpp
M compiler/resolution/functionResolution.cpp
M compiler/resolution/interfaceResolution.cpp
M test/constrained-generics/basic/generic/error-generic-implements-1.chpl
M test/constrained-generics/basic/generic/error-generic-implements-6.chpl
M test/constrained-generics/basic/set2/error-return-intent.good
M test/constrained-generics/basic/set2/error-return-type.good

Compare: https://github.com/chapel-lang/chapel/compare/134897f32c6c...36e3330626d7