[Chapel Merge] Remove cast-by-assign in insertCasts and FLAG_INIT

Branch: refs/heads/master
Revision: 7609735
Author: mppf
Log Message:

Merge pull request #17046 from mppf/remove-cast-by-assign

Remove cast-by-assign in insertCasts and FLAG_INITIALIZED_LATER

This PR improves insertCasts so that it never emits a default-init/assign
pattern.

This is a prerequisite improvements to error checking for different types
of conversions (PR #17092).

The main part of this PR is a rewrite of insertCasts to make it more
clear and to avoid the default-init/assign pattern. insertCasts already
had code to handle array/domain initialization and the main case
remaining where it was using default-init/assign was for extern types.
But for extern types, the pattern can be expressed by calling a cast
function instead, now that we are expecting to have user-provided cast
functions.

This PR takes the following related steps:

  • Adds a withType argument to a few toString functions to allow
    opting out of printing the type
  • Adds support for showing param values in toString(VarSymbol*)
  • Removes FLAG_INITIALIZED_LATER since the compiler no longer emits
    the pattern this flag was marking - and removes several dead code
    paths that were relying on this flag
  • Adjusted several transformations in callDestructors to apply to
    PRIM_ASSIGN in addition to PRIM_MOVE. These transformations
    predated current usage of PRIM_ASSIGN and this PR adds more
    PRIM_ASSIGN calls in insertCasts
  • Fix compilation errors in range cast (IIRC these had to do with
    assigning to none)
  • Makes errors for failure to initialize one type from another more
    consistent, across owned/shared module code and compiler emitted
    errors
  • Changes c_nil in CPtr to return nil. It’s my view that c_nil
    should be deprecated but regardless it was returning a c_void_ptr
    and that resulted in relying on conversions from c_void_ptr to
    c_ptr in order for things like var x: c_ptr(int(8)) = c_nil to
    function.
  • Tightened up conversions among c_ptr types.

Note that some tests in test/distributions/dm now have duplicate warnings
(left as future work – see issue #17090).

Also note, additional init/deinit pairs in
test/statements/ferguson/var-init-records.good are related to the future
work issue #17089. For now, this PR disables copy elision when the LHS
and RHS types do not match. Before, we were copy eliding the scalar in
array-from-scalar initialization, but I doubt that fits with the general
rule for copy elision.

This PR reopens issue #15700 since that case was relying on
default-init/assign which this PR removes.

Future work:

  • Resolve design question - copy elision when LHS and RHS have different
    types #17089
  • compilerWarning implementation issues #17090
  • Initializing tuples of ranges causes lvalue errors when range coercion
    is involved #15700

Reviewed by @vasslitvinov - thanks!

  • [x] primers pass with valgrind, verify, and do not leak
  • [x] full local testing
  • [x] full gasnet testing

Modified Files:
A test/types/cptr/cross_type_assign.chpl
A test/types/cptr/cross_type_assign.good
A test/types/cptr/cross_type_init.chpl
A test/types/cptr/cross_type_init.good
A test/types/range/ferguson/cast-to-stridable.chpl
A test/types/range/ferguson/cast-to-stridable.good
A test/types/tuple/ranges/tupleOfRanges.bad
A test/types/tuple/ranges/tupleOfRanges.future
A test/users/ferguson/literals/t8.bad
M compiler/AST/symbol.cpp
M compiler/AST/type.cpp
M compiler/include/flags_list.h
M compiler/include/symbol.h
M compiler/optimizations/propagateDomainConstness.cpp
M compiler/passes/InitNormalize.cpp
M compiler/resolution/ResolutionCandidate.cpp
M compiler/resolution/addAutoDestroyCalls.cpp
M compiler/resolution/callDestructors.cpp
M compiler/resolution/functionResolution.cpp
M compiler/resolution/generics.cpp
M compiler/resolution/resolveFunction.cpp
M compiler/resolution/wrappers.cpp
M modules/dists/DSIUtil.chpl
M modules/internal/ChapelArray.chpl
M modules/internal/ChapelRange.chpl
M modules/internal/OwnedObject.chpl
M modules/internal/SharedObject.chpl
M modules/packages/OrderedSet.chpl
M modules/standard/CPtr.chpl
M modules/standard/Set.chpl
M test/arrays/bradc/scalarArrMismatch.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.block.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.blockcyclic.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.cyclic.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.default.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.replicated-comm.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.replicated-no-comm.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns-dists.stencil.good
M test/arrays/ferguson/array-initialization-patterns/array-initialization-patterns.good
M test/arrays/ferguson/return-array-as-int.good
M test/classes/bradc/syncAsClass2.good
M test/classes/bradc/syncAsClass3.bad
M test/classes/diten/error_default_field_init.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-borrowed-from-oknil-nil.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-oknil-nil.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-oknil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-oknil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-owned-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-oknil-nil.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-oknil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-oknil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-shared-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-unmanaged-from-oknil-nil.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-owned-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-owned-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-owned-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-owned-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-owned-from-oknil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-owned-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-shared-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-shared-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-shared-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-shared-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-borrowed-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-borrowed-from-oknil-nil.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-borrowed-from-oknil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-borrowed-from-oknil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-borrowed-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-oknil-nil.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-oknil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-oknil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-owned-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-oknil-nil.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-oknil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-oknil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-shared-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-nonnil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-oknil-nil.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-oknil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-oknil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-nonnil-unmanaged-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-owned-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-owned-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-owned-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-owned-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-owned-from-oknil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-owned-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-shared-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-shared-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-shared-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-shared-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-unmanaged-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-unmanaged-from-nonnil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-unmanaged-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-unmanaged-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-unmanaged-from-oknil-owned.good
M test/classes/errors/nilability-init-field-dflt/init-field-dflt-oknil-unmanaged-from-oknil-shared.good
M test/classes/errors/nilability-init-var/init-var-nonnil-borrowed-from-oknil-nil.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-nonnil-shared.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-oknil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-oknil-nil.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-oknil-owned.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-oknil-shared.good
M test/classes/errors/nilability-init-var/init-var-nonnil-owned-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-oknil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-oknil-nil.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-oknil-owned.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-oknil-shared.good
M test/classes/errors/nilability-init-var/init-var-nonnil-shared-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-nonnil-unmanaged-from-oknil-nil.good
M test/classes/errors/nilability-init-var/init-var-oknil-owned-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-oknil-owned-from-nonnil-shared.good
M test/classes/errors/nilability-init-var/init-var-oknil-owned-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-oknil-owned-from-oknil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-oknil-owned-from-oknil-shared.good
M test/classes/errors/nilability-init-var/init-var-oknil-owned-from-oknil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-oknil-shared-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-oknil-shared-from-nonnil-unmanaged.good
M test/classes/errors/nilability-init-var/init-var-oknil-shared-from-oknil-borrowed.good
M test/classes/errors/nilability-init-var/init-var-oknil-shared-from-oknil-unmanaged.good
M test/classes/errors/nilability-return-yield/return-borrowed.good
M test/classes/errors/nilability-return-yield/return-owned.good
M test/classes/errors/nilability-return-yield/return-shared.good
M test/classes/errors/nilability-return-yield/return-unmanaged.good
M test/classes/errors/nilability-return-yield/yield-borrowed.good
M test/classes/errors/nilability-return-yield/yield-owned.good
M test/classes/errors/nilability-return-yield/yield-shared.good
M test/classes/errors/nilability-return-yield/yield-unmanaged.good
M test/classes/initializers/generics/explicitAssignment.good
M test/classes/initializers/generics/phase1/param-from-new.good
M test/classes/initializers/generics/phase1/type-from-new.good
M test/classes/initializers/initequals/changing-param-field-error3.good
M test/classes/marybeth/test_dispatch1-error.good
M test/compflags/ferguson/default-type-prints-generic.good
M test/compflags/ferguson/default-type-prints.good
M test/distributions/dm/s7.comm-none.good
M test/distributions/dm/s7.good
M test/distributions/dm/s8.comm-none.good
M test/distributions/dm/s8.good
M test/distributions/dm/s9.comm-none.good
M test/distributions/dm/s9.good
M test/distributions/ferguson/init-local-from-distributed-warning.chpl
M test/distributions/ferguson/init-local-from-distributed-warning.good
M test/expressions/bradc/reduceVsMathPrec2.bad
M test/functions/default-arguments/default-argument-type-mismatches.good
M test/functions/default-arguments/test_default_promote_instantiate.good
M test/functions/ferguson/error-return-parentclass.good
M test/functions/ferguson/generic-default-nil.good
M test/functions/ferguson/generic-default-nil2.good
M test/functions/iterators/errors/incorrectYieldTypes.good
M test/functions/vass/declaredGenericReturnTuple.bad
M test/functions/vass/return-type-function-failure.good
M test/io/nspark/print-cptr.chpl
M test/modules/diten/mutualuse2.bad
M test/param/ferguson/param-real-init-bool-error.good
M test/param/ferguson/param-real-init-imag-error.good
M test/statements/ferguson/var-init-records.good
M test/studies/hpcc/RA/marybeth/ra-uint-test4.good
M test/trivial/deitz/coerce-assign/imag_coerce2.good
M test/types/bytes/param-compiler-error.good
M test/types/partial/bad-managed-init.owned.good
M test/types/partial/bad-managed-init.shared.good
M test/types/partial/invalid-set-param-again.good
M test/types/records/split-init/different-types-in-conditional.good
M test/types/records/split-init/incompatible-type2.good
M test/types/scalar/bradc/assignUintNegative.good
M test/types/string/diten/multilineStringLineNumber.good
M test/types/sync/lydia/defaultValArg.bad
M test/types/tuple/errors/returnWrongSize.good
M test/types/tuple/lydia/nonDefaultSize/tupleInt16.bad
M test/types/tuple/lydia/nonDefaultSize/tupleInt32.bad
M test/types/tuple/lydia/nonDefaultSize/tupleInt8.bad
M test/types/tuple/lydia/nonDefaultSize/tupleReal32.bad
M test/types/void/nothing-variable-use-2.good

Compare: Comparing 5cb54c9858a5...76097352e7de · chapel-lang/chapel · GitHub