[Chapel Merge] Improve instantiation point error to print multipl

Branch: refs/heads/master
Revision: 2d03046
Author: mppf
Log Message:

Merge pull request #16175 from mppf/improve-instantiation-point-error

Improve instantiation point error to print multiple instantiations

We would like to print out more information for errors inside of generic
functions. We already print out details of the instantiation but a call
stack can be useful in such cases as well. Additionally, the
--print-callstack-on-error mechanism was previously available but not
on by default and did not work for errors that occur after the
functionResolution pass itself.

This PR addresses these problems by expanding upon the code that was
printing out instantiation details for functions to print call stacks.
This code does not use the call stack structure from function resolution
(rather it reconstructs the call stack by looking for call sites). This
allows it to function during or after functionResolution proper (as long
as which functions are called is established). This code is on by default
and does not need to be enabled with --print-callstack-on-error.

This PR keeps the flag--print-callstack-on-error and now it causes it
to also print traces for concrete functions and to include internal
functions. The --no-print-callstack-on-error will disable the stack
trace.

The PR also adds formatting (bold and underline) to error messages using
VT100 escape codes. This is by normally only enabled if a color terminal
is detected. Detecting a color terminal amounts to checking that stderr
is a tty and the TERM environment variable is a value expected to work.
The flag --use-color-terminal / --no-use-color-terminal is available
to override the detection. Note that when a test is run within
start_test, output is not a tty, and so .good files will not see this
formatting unless --use-color-terminal is provided.

For example, for this erroneous program in bb.chpl:

proc h(arg) {
  arg = 11;
}

proc g(arg) {
  h(arg);
}

proc f(arg) {
  g(arg);
}

f("hi");

the error now prints

bb.chpl:1: In function 'h':
bb.chpl:2: error: Cannot assign to string from int(64)
  bb.chpl:6: called as h(arg: string) from function 'g'
  bb.chpl:10: called as g(arg: string) from function 'f'
  bb.chpl:13: called as f(arg: string)

and on a terminal with formatting support it looks similar
but with bold error: and underlining generic instantiations.

where previously to this PR it would print

bb.chpl:1: In function 'h':
bb.chpl:2: error: Cannot assign to string from int(64)
bb.chpl:6: Function 'h' instantiated as: h(arg: string)

and previously to this PR with --print-callstack-on-error it would print

bb.chpl:1: In function 'h':
bb.chpl:2: error: Cannot assign to string from int(64)
while processing the following Chapel call chain:
  bb.chpl:2: h(arg)
  bb.chpl:6: g(arg)
  bb.chpl:10: f(arg)
  bb.chpl:13: top-level module statements for bb
bb.chpl:6: Function 'h' instantiated as: h(arg: string)

Reviewed by @e-kayrakli incorporating suggestions from @lydia-duncan and
@bradcray - thanks!

  • [x] full local futures testing

Modified Files:
A test/compflags/ferguson/error-message-bolding.chpl
A test/compflags/ferguson/error-message-bolding.colors.good
A test/compflags/ferguson/error-message-bolding.compopts
A test/compflags/ferguson/error-message-bolding.nocolors.good
A test/distributions/dm/s7.compopts
A test/distributions/dm/s8.compopts
A test/distributions/dm/s9.compopts
A test/functions/compilation-errors/error-stack-trace-recursive1.chpl
A test/functions/compilation-errors/error-stack-trace-recursive1.good
A test/functions/compilation-errors/error-stack-trace-recursive2.chpl
A test/functions/compilation-errors/error-stack-trace-recursive2.good
A test/functions/compilation-errors/error-stack-trace.chpl
A test/functions/compilation-errors/error-stack-trace.good
M compiler/AST/FnSymbol.cpp
M compiler/AST/astutil.cpp
M compiler/include/FnSymbol.h
M compiler/include/astutil.h
M compiler/include/driver.h
M compiler/include/misc.h
M compiler/main/driver.cpp
M compiler/optimizations/noAliasSets.cpp
M compiler/util/misc.cpp
M test/analysis/flowanalysis/rec_fun-1.good
M test/analysis/flowanalysis/rec_fun-2.good
M test/analysis/flowanalysis/rec_fun-3.good
M test/arrays/bradc/arrayOfArrayArg.bad
M test/arrays/errors/domainTypeAsDomainExpr.good
M test/arrays/ferguson/return-array-as-int.good
M test/arrays/ferguson/runtime-type-type.good
M test/arrays/formals/queryArrOfArr2.bad
M test/arrays/return/returnArbitraryBadEltType.good
M test/arrays/return/returnArbitraryCoerced.bad
M test/arrays/types-fixed-array/testTuple.bad
M test/arrays/types-resized-array/testTuple.bad
M test/arrays/userAPI/arrayOps2D-IRV.good
M test/arrays/userAPI/arrayOps2D-reverse.good
M test/arrays/userAPI/arrayOps2D-sorted.good
M test/associative/types/testBorrowed.bad
M test/associative/types/testOwned.bad
M test/associative/types/testShared.bad
M test/associative/types/testTuple.bad
M test/associative/types/testUnmanaged.bad
M test/classes/bradc/arrayInClass/arrayDomInClassRecord-illegal.good
M test/classes/bradc/compilerErrorInMethod/testClear.bad
M test/classes/deinitializers/deinitExplicitCall.good
M test/classes/deitz/method/method_call2.good
M test/classes/delete-free/lifetimes/ref-escapes.good
M test/classes/delete-free/lifetimes/save-borrow-in-collection.good
M test/classes/delete-free/lifetimes/specified-formal-order-primary-methods.good
M test/classes/delete-free/lifetimes/specified-formal-order-secondary-methods.good
M test/classes/delete-free/owned/owned-record-instantiation-types-user-init-borrows-error.good
M test/classes/delete-free/owned/owned-transfer-from-nonnil.good
M test/classes/delete-free/type-casting.errors.good
M test/classes/delete-free/undecorated-generic/duplicate-management-owned.bad
M test/classes/delete-free/undecorated-generic/duplicate-management.good
M test/classes/diten/subclassMethodCall.bad
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-borrowed-from-oknil-borrowed.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-borrowed-from-oknil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-borrowed-from-oknil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-borrowed-from-oknil-unmanaged.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-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-unmanaged-from-nonnil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-unmanaged-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-unmanaged-from-oknil-borrowed.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-nonnil-unmanaged-from-oknil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-unmanaged-from-oknil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-nonnil-unmanaged-from-oknil-unmanaged.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-arg/init-field-arg-oknil-unmanaged-from-nonnil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-unmanaged-from-nonnil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-unmanaged-from-nonnil-shared.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-unmanaged-from-oknil-borrowed.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-unmanaged-from-oknil-owned.good
M test/classes/errors/nilability-init-field-arg/init-field-arg-oknil-unmanaged-from-oknil-shared.good
M test/classes/ferguson/class-double-modifier.good
M test/classes/ferguson/forwarding/call-forwarded-omit-this.bad
M test/classes/forwarding/forwardGenericVirtual.bad
M test/classes/initializers/generics/phase1/nested-function-mods-field1.bad
M test/classes/initializers/generics/phase1/nested-function-mods-field2.bad
M test/classes/initializers/generics/phase1/nested-function-phase-2-mods-fields.bad
M test/classes/initializers/initequals/wrongType.bad
M test/classes/initializers/phase1/initFromThis.good
M test/classes/initializers/postInit/invalidSuperPostinit.good
M test/classes/nilability/error-with-bang-suggestion.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/domains/bradc/modDomQuery.good
M test/domains/compilerErrors/partialQueriedDomain-inIntent.good
M test/domains/compilerErrors/partialQueriedDomain-multiple.good
M test/domains/compilerErrors/partialQueriedDomain.good
M test/domains/marybeth/test_compare_range.good
M test/domains/sungeun/assoc/expand.1.good
M test/domains/sungeun/assoc/expand.2.good
M test/domains/sungeun/assoc/exterior.1.good
M test/domains/sungeun/assoc/exterior.2.good
M test/domains/sungeun/assoc/interior.1.good
M test/domains/sungeun/assoc/interior.2.good
M test/domains/sungeun/assoc/translate.1.good
M test/domains/sungeun/assoc/translate.2.good
M test/domains/sungeun/sparse/expand.good
M test/domains/sungeun/sparse/exterior.good
M test/domains/sungeun/sparse/interior.good
M test/domains/sungeun/sparse/translate.good
M test/errhandling/errorMessages/throwNew.good
M test/execflags/vass/print-callstack-on-error-1.good
M test/execflags/vass/print-callstack-on-error-2.good
M test/execflags/vass/print-callstack-on-warning-1.good
M test/execflags/vass/print-callstack-on-warning-2.good
M test/extern/fnPtrs/passBadFnsToCChapel-cPtrToChapel.good
M test/functions/bradc/intents/intents-int.error1.good
M test/functions/bradc/intents/intents-int.error2.good
M test/functions/bradc/intents/intents-int.error3.good
M test/functions/bradc/intents/intents-int.error4.good
M test/functions/bradc/intents/intents-strings.error1.good
M test/functions/bradc/intents/intents-strings.error2.good
M test/functions/bradc/intents/intents-strings.error3.good
M test/functions/bradc/intents/intents-strings.error4.good
M test/functions/bradc/typeFns/myTypeFnConstKeyword.good
M test/functions/bradc/typeFns/myTypeFnNoKeyword.good
M test/functions/bradc/varFns/retLitFromVarFn.good
M test/functions/bradc/varFns/retLocFromVarFn.good
M test/functions/deitz/test_rec_infer.good
M test/functions/deitz/test_where_recursion.good
M test/functions/deitz/test_where_recursion2.good
M test/functions/diten/badwhere.good
M test/functions/diten/compilerWarningDepth.good
M test/functions/diten/formalArrayWithQueriedEltSize.bad
M test/functions/diten/test_redefine_greater_or_equal.good
M test/functions/diten/tupleTypeInParamCondExpr.bad
M test/functions/ferguson/check-instantiations-with-defaults-simple.1.good
M test/functions/ferguson/check-instantiations-with-defaults-simple.2.good
M test/functions/ferguson/check-instantiations-with-defaults-simple.3.good
M test/functions/ferguson/check-instantiations-with-defaults-simple.4.good
M test/functions/ferguson/check-instantiations-with-defaults-simple.5.good
M test/functions/ferguson/check-instantiations-with-defaults-simple.6.good
M test/functions/ferguson/check-instantiations-with-defaults.1.good
M test/functions/ferguson/check-instantiations-with-defaults.2.good
M test/functions/ferguson/check-instantiations-with-defaults.3.good
M test/functions/ferguson/check-instantiations-with-defaults.4.good
M test/functions/ferguson/check-instantiations-with-defaults.5.good
M test/functions/ferguson/check-instantiations-with-defaults.6.good
M test/functions/ferguson/generic-default-nil.good
M test/functions/ferguson/generic-default-nil2.good
M test/functions/ferguson/generic-default-nil3.good
M test/functions/ferguson/query/owned-inner2.bad
M test/functions/ferguson/query/unmanaged-inner2.bad
M test/functions/ferguson/ref-pair/tuples/tuple-args2.good
M test/functions/ferguson/set-const-ref-this.good
M test/functions/ferguson/set-const-this.good
M test/functions/ferguson/spec-insn-method-no-this.bad
M test/functions/generic/err-in-insn.good
M test/functions/generic/poi/ApplicationB.methods.good
M test/functions/generic/poi/canresolve-in-sort.good
M test/functions/generic/poi/check-gc-reuse.good
M test/functions/generic/poi/forwarding-wrapper.good
M test/functions/generic/poi/hashed-dist-with-mapper.good
M test/functions/generic/poi/init-in-private-array.good
M test/functions/generic/poi/random-choice.good
M test/functions/generic/poi/shadowing-field.bad
M test/functions/generic/poi/shadowing-method.bad
M test/functions/generic/poi/sort-check-comparator.good
M test/functions/generic/poi/writethis-user-record.good
M test/functions/generic/poi/zmq-initequals.good
M test/functions/iterators/engin/paramFormalInForall.good
M test/functions/iterators/recursive/recursive-leader-errr.good
M test/functions/iterators/vass/forall-over-iteratorRecord-arg.good
M test/functions/jplevyak/intent-5-error.good
M test/functions/lydia/method-iter-resolution-bug.bad
M test/functions/this/bradc/domainSliceConfusion.good
M test/functions/this/implicit-this.bad
M test/functions/vass/resolution/param-detuple.good
M test/functions/vass/varargs-2.good
M test/functions/whereClauses/whereClauseNoFn2.good
M test/functions/whereClauses/whereClauseNonParamGeneric.good
M test/library/draft/Vector/types/testBorrowed.good
M test/library/draft/Vector/types/testOwned.good
M test/library/draft/Vector/types/testShared.good
M test/library/draft/Vector/types/testTuple.good
M test/library/draft/Vector/types/testUnmanaged.good
M test/library/standard/List/init/listInitGenericError.good
M test/library/standard/Version/compareChplVersionErrors.good
M test/parallel/forall/vass/other/fields-of-this-3-const-fields.good
M test/parallel/taskPar/taskIntents/fields-of-this-3-const-fields.good
M test/parallel/taskPar/taskIntents/fields-of-this-4-begin-cobegin.good
M test/parallel/taskPar/vass/const-in-intent-arrays-domains.good
M test/parallel/taskPar/vass/errorFieldMethodInWithClause.good
M test/param/diten/errorDepth.depth0.good
M test/param/diten/errorDepth.depth1.good
M test/param/diten/errorDepth.depth2.good
M test/param/ferguson/field-name-not-in-range.good
M test/param/ifExprCopyInitBug.bad
M test/scan/scanViews.good
M test/scan/scanViewsBlock.good
M test/sparse/types/testBorrowed.good
M test/sparse/types/testOwned.good
M test/sparse/types/testShared.good
M test/sparse/types/testTuple.bad
M test/sparse/types/testUnmanaged.good
M test/studies/beer/bradc/beer-promoted-infer.good
M test/studies/hpcc/HPL/bradc/hpl-blc-noreindex.good
M test/trivial/shannon/condReturn2.good
M test/types/bool/bradc/numBitsBytesDefault.good
M test/types/enum/paramEnumCast.good
M test/types/errors/assignTypes.good
M test/types/partial/match-param.bad
M test/types/range/open/openRanges-both.good
M test/types/range/open/openRanges-low.good
M test/types/range/userAPI/byteRangeTest.good
M test/types/range/userAPI/codepointRangeTest.good
M test/types/range/userAPI/simpleRangeTest.good
M test/types/range/vass/offset-1.good
M test/types/records/const-checking/scenario-3-assoc-dom-of-record-with-const-fld.bad
M test/types/records/generic/genericFieldDecl-used.bad
M test/types/sync/vass/generic-sync-1.good
M test/types/sync/vass/ref-sync-1.good
M test/types/tuple/errors/returnWrongSize.good
M test/types/tuple/errors/tuple-assignment-2.good
M test/types/tuple/tupleTypeAccess.bad
M test/types/typeFunctions/illegalValueReturn.good
M test/types/type_variables/bharshbarg/illegalFieldQuery.good
M test/users/jglewis/array_reindexing/desirable_syntax.bad
M test/users/kreider/bug_array_of_arrays.bad
M test/users/lucashimizu/inferRecursive.bad
M test/users/vass/div-ceil-on-more-int-types.bad
M test/users/vass/isX/isX.byBlankArgs-compWarns.na-none.good
M test/users/weili/raiseType-blc.good
M test/visibility/private/uses/pointOfInstantiation/methodOnType2.good
M test/visibility/shadow-overload.good
M util/chpl-completion.bash

Compare: https://github.com/chapel-lang/chapel/compare/b54df66be318...2d03046297c9