chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.78k stars 418 forks source link

Creating a list of arrays with an explicit array type causes memory issues #24305

Open jabraham17 opened 7 months ago

jabraham17 commented 7 months ago

The following code compiles, but crashes at runtime due to memory issues.

use List;
var b: list([1..3] int) = [[1,2,3],[4,5,6]];
compilerWarning(b.type:string);

This seg faults at the initialization of b. Adjusting the domain of the contained array to be zero-based does not resolve the issue. The following code does work as expected.

use List;
var b: list(?) = [[1,2,3],[4,5,6]];
compilerWarning(b.type:string);

This correctly creates a list of arrays. I would expect both of these programs to have the same result and correctly initialize the list.

This issue is captured as a future test in test/library/standard/List/initEquals/listInitEqualsArrayBug.chpl

chpl --version output

chpl version 1.34.0 pre-release (11eab99b6e)
  built with LLVM version 15.0.7
  available LLVM targets: xcore, x86-64, x86, wasm64, wasm32, ve, systemz, sparcel, sparcv9, sparc, riscv64, riscv32, ppc64le, ppc64, ppc32le, ppc32, nvptx64, nvptx, msp430, mips64el, mips64, mipsel, mips, lanai, hexagon, bpfeb, bpfel, bpf, avr, thumbeb, thumb, armeb, arm, amdgcn, r600, aarch64_32, aarch64_be, aarch64, arm64_32, arm64
Copyright 2020-2024 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)

printchplenv output

CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: llvm
CHPL_TARGET_ARCH: arm64
CHPL_TARGET_CPU: native *
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads *
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc *
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled *
CHPL_HWLOC: bundled
CHPL_RE2: bundled *
CHPL_LLVM: system *
CHPL_AUX_FILESYS: none
dlongnecke-cray commented 6 months ago

Reopening this because, while we fixed the compile-time bug that was affecting this future, the original segfault at runtime still occurs.

I've managed to convert it into an "attempt to dereference nil" error with some slight massaging of the list code, but it still breaks in ways that it shouldn't. PR forthcoming.

dlongnecke-cray commented 6 months ago

I've opened https://github.com/chapel-lang/chapel/pull/24598 which refuturizes listInitEqualsArrayBug.chpl.

Note that the following variant has been split off into a separate test since it always seems to work:

var a: list(?) = [[1,2,3],[4,5,6]];
writeln(a.type:string, " = ", a);

It is only this variant with a specified array type that seems to fail on COMM != none:

var b: list([1..3] int) = [[1,2,3],[4,5,6]];
writeln(b.type:string, " = ", b);

Note that before I massaged the List initializer code in #24598, this test failed with a segfault instead. The segfault is concerning to me, because I think the pattern I sidestepped (calling pushBack directly on the x loop index variable) should work out of the box.

At first glance, my guess is the failing example is breaking due to runtime types. I haven't debugged it further yet though.