[Chapel Merge] Adjust parenless procs and overrides

Branch: refs/heads/main
Revision: ec90c85
Author: mppf
Link: Adjust parenless procs and overrides by mppf · Pull Request #19505 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #19505 from mppf/fix-19474

Adjust parenless procs and overrides

Resolves #19474

This PR makes the following language changes according to the discussion
in #19474:

  • disallow fields with same name between parent class / child class
    (where previously, a child class field would shadow a parent class
    field of the same name). These now result in a compilation error.
  • allow parenless procs to 'override' a parenless proc or a field, but
    require the override keyword when doing so. (See
    param proc in child class vs param field in parent · Issue #19474 · chapel-lang/chapel · GitHub
    for an example of what could happen if the override keyword is not
    required here).
  • extends the convenience feature for param/type fields (that they can
    be accessed regardless of class management or nilability) to also
    apply to param/type returning parenless procs in order to allow for
    parenless procs to replace fields. (See also #13617 and #14549).

To support the above, the PR includes these changes:

  • adds AggregateType::checkSameNameFields to issue an error when a
    field with the same name is used in both a parent and child class.
    This is called from AggregateType::addClassToHierarchy during scope
    resolution.
  • In scope resolution, adjusts adjustTypeMethodsOnClasses to also make
    the reciever generic for parenless type and param-returning methods.
    Note that the compiler-generated field accessors can't rely on this
    routine modifying them because they are added at a later point in
    compilation.
  • in virtualDispatch.cpp, getReceiverClassType, canonicalize
    generic-management/unmanaged/borrowed but don't consider owned/shared
    types as class types for this purpose (since a method on owned
    itself not subject to virtual dispatch).
  • with the above fix in getReceiverClassType now we can simplify
    getOverrideCandidate to always call it where before it had a
    workaround which also enables the unmanaged example from #19474 to
    work correctly.
  • adds tests of parenless proc overriding parenless proc and parenless
    proc overriding a field
  • adjusts many dsi implementations to use override on a number of
    parenless procs
  • change dsiAlignedhigh / dsiAlignedlow to the regular camel case. I
    think that the uses of this spelling were in error.
  • removes proc rank param from AbsBaseArr in favor of including it in
    individual types that need it. That is because something like
    DefaultRectangularArr will want to have a field called rank and we
    can't currently have a field replacing/overriding a parenless proc.
  • removes duplicate _msg field from ArgumentParser's ArgumentError
  • Removed proc parSafe from BaseDom because DefaultAssociative
    replaces it with a field which would result in a compilation error
    with the additional checking that this PR adds.

In addition, the PR includes these changes that are less fundamental to
achieving the language change:

  • changes FnSymbol::getReceiverType to return Type* rather than
    AggregateType* since we can have methods on non-aggregate types such
    as int
  • rename resolveOverride to resolveOverrideAndAdjustMaps
  • adjust virtualDispatchUpdate to only update the function and maps for
    virtualizable methods.

Reviewed by @vasslitvinov - thanks!

  • full local futures testing

  • full gasnet testing

    Modified Files:
    A test/classes/diten/instantiatedClassname-nilable.chpl
    A test/classes/diten/instantiatedClassname-nilable.good
    A test/classes/ferguson/issue-19474-duplicate-fields.chpl
    A test/classes/ferguson/issue-19474-duplicate-fields.good
    A test/classes/ferguson/issue-19474-duplicate-fields2.chpl
    A test/classes/ferguson/issue-19474-duplicate-fields2.good
    A test/classes/ferguson/issue-19474-duplicate-fields3.chpl
    A test/classes/ferguson/issue-19474-duplicate-fields3.good
    A test/classes/ferguson/issue-19474-override-field-error.chpl
    A test/classes/ferguson/issue-19474-override-field-error.good
    A test/classes/ferguson/issue-19474-override-field-ok.chpl
    A test/classes/ferguson/issue-19474-override-field-ok.good
    A test/classes/ferguson/issue-19474-override-parenless-error.chpl
    A test/classes/ferguson/issue-19474-override-parenless-error.good
    A test/classes/ferguson/issue-19474-override-parenless-ok.chpl
    A test/classes/ferguson/issue-19474-override-parenless-ok.good
    A test/classes/ferguson/issue-19474-unmanaged-override-field-error.chpl
    A test/classes/ferguson/issue-19474-unmanaged-override-field-error.good
    A test/classes/ferguson/issue-19474-unmanaged-override-field.chpl
    A test/classes/ferguson/issue-19474-unmanaged-override-field.good
    M compiler/AST/AggregateType.cpp
    M compiler/AST/FnSymbol.cpp
    M compiler/include/AggregateType.h
    M compiler/include/FnSymbol.h
    M compiler/passes/buildDefaultFunctions.cpp
    M compiler/passes/scopeResolve.cpp
    M compiler/resolution/preFold.cpp
    M compiler/resolution/virtualDispatch.cpp
    M modules/dists/BlockCycDist.chpl
    M modules/dists/BlockDist.chpl
    M modules/dists/CyclicDist.chpl
    M modules/dists/DimensionalDist2D.chpl
    M modules/dists/HashedDist.chpl
    M modules/dists/PrivateDist.chpl
    M modules/dists/ReplicatedDist.chpl
    M modules/dists/SparseBlockDist.chpl
    M modules/dists/StencilDist.chpl
    M modules/internal/ArrayViewRankChange.chpl
    M modules/internal/ArrayViewReindex.chpl
    M modules/internal/ChapelDistribution.chpl
    M modules/internal/DefaultAssociative.chpl
    M modules/internal/DefaultRectangular.chpl
    M modules/internal/DefaultSparse.chpl
    M modules/layouts/LayoutCS.chpl
    M modules/packages/ArgumentParser.chpl
    M test/classes/deitz/class/shadowing.good
    M test/classes/diten/derived_field_chosen.good
    M test/classes/diten/instantiatedClassname.chpl
    M test/classes/diten/nearestMutualParentClass.chpl
    M test/classes/diten/returnMultipleTypes.chpl
    M test/classes/diten/shadow_with_different_type.good
    M test/classes/diten/test_shadowing.good
    M test/classes/errors/sharedImplicitCoercionError.chpl
    M test/classes/ferguson/const-override-bug.chpl
    M test/classes/ferguson/generic-inherit5.chpl
    M test/classes/ferguson/generic-inherit5a.chpl
    M test/classes/hilde/inheritance/fields.good
    M test/classes/initializers/compilerGenerated/shadow_with_different_type.good
    M test/classes/initializers/inheritance/overloaded.good
    M test/classes/override/override-no-parens.good
    M test/classes/override/type-methods/methodRetType.chpl
    M test/classes/override/type-methods/methodRetTypeNoKeyword.chpl
    M test/classes/override/type-methods/typeMethod.chpl
    M test/classes/override/type-methods/typeMethodNoKeyword.chpl
    M test/classes/override/type-methods/typeMethodRetParam.chpl
    M test/classes/override/type-methods/typeMethodRetType.chpl
    M test/functions/ferguson/ref-pair/across-scopes.chpl
    M test/studies/uts/uts_deq.chpl
    M test/studies/uts/uts_rec.chpl
    M test/types/chplhashtable/GenericAggregateHash.chpl
    M test/users/thom/class-override.good

    Compare: Comparing ae6c5e0a5efd...ec90c854b4c6 · chapel-lang/chapel · GitHub