chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Bug]: Lifetime checker mishandling ` if/else` due to throwing proc with `in` intent

Open stress-tess opened this issue 7 months ago • 0 comments

Summary of Problem

Feel free to change the title! I couldn't think of a better description that wasn't too long. Also it's completely possible this isn't a bug and that I'm misunderstanding what the lifetime checker should be doing here

In https://github.com/Bears-R-Us/arkouda/pull/3524, I ran into this issue with the lifetime checker. In the if we pass the array into a throwing proc using an in intent, which causes the lifetime checker to think the array is out of scope in the else.

Description:

An array is declared and we immediately enter an if/else. In the if block we pass the array into a throwing proc using an in argument intent. In the else block, we loop the array. The lifetime checker complains about the array possibly being out of scope in the else seemingly due to the the logic in the if block.

Is this issue currently blocking your progress?

Nope. Instead of declaring the array before the if/else, I declare it in both blocks and it works just fine. Also in the reproducer it seems if I drop either the in argument intent or the throws, the compiler has no problem.

Steps to Reproduce

Source Code:

use Map;

proc arrSteal(in mineNow: [] int) throws {
  return "This array belongs to me";
}

proc reproducer(retIdxArr: bool) {
  const idxArray = [4,3,2,1,0];

  if retIdxArr {
    return arrSteal(idxArray);
  }
  else {
    var otherArr: [idxArray.domain] int;
    
    forall (oa,idx) in zip(otherArr, idxArray) {
      oa = idx;
    }

    return arrSteal(otherArr);
  }
}

writeln(reproducer(false)); 

Compile command:

$ chpl PlayingAround.chpl
PlayingAround.chpl:7: In function 'reproducer':
PlayingAround.chpl:16: error: Reference to scoped variable idx reachable after lifetime ends
PlayingAround.chpl:8: note: consider scope of idxArray

Configuration Information

  • Output of chpl --version:
chpl version 2.1.0
  built with LLVM version 18.1.8
  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, loongarch64, loongarch32, 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)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
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: system *
CHPL_HWLOC: bundled
CHPL_RE2: bundled *
CHPL_LLVM: system *
CHPL_AUX_FILESYS: none
  • Back-end compiler and version, e.g. gcc --version or clang --version:
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

stress-tess avatar Jul 24 '24 18:07 stress-tess