Chapel: Internal error when returning an array from function whose return type is not an array

Created on 6 Feb 2018  路  17Comments  路  Source: chapel-lang/chapel

During a test, I got an "it's us, not you" kinda error, like I got from my stupid girlfriend in high school. So I will just say, Chapel, you were lucky to have me! And here is my error

[Removing log file with duplicate name /Users/buddha/github/chapel/test/Logs/buddha.darwin.log
[Starting Chapel regression tests - 180206.140349]
[Warning: start_test not invoked from a subdirectory of $CHPL_HOME]
[starting directory: "/Users/buddha/github/buddha314/numsuch/test"]
[Logs directory: "/Users/buddha/github/chapel/test/Logs"]
[log_file: "/Users/buddha/github/chapel/test/Logs/buddha.darwin.log"]
[CHPL_HOME: /Users/buddha/github/chapel]
[host platform: darwin]
[target platform: darwin]
[valgrind: OFF]
[performance tests: OFF]
[compiler performance tests: OFF]
[number of trials: 1]
[performance graph generation: OFF]
[compiler: "/Users/buddha/github/chapel/bin/darwin/chpl"]
[compopts: "--cc-warnings"]
[execopts: ""]
[launchcmd: ""]
[comm: "none"]
[localeModel: "flat"]
[numlocales: "(default)"]
[max_locales: "(default)"]
[tests: "/Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test.chpl"]
[directories: ""]

### Chapel Environment ###
machine info: Darwin macbuddha.lan 16.7.0 Darwin Kernel Version 16.7.0: Mon Nov 13 21:56:25 PST 2017; root:xnu-3789.72.11~1/RELEASE_X86_64 x86_64
CHPL_HOME: /Users/buddha/github/chapel *
script location: /Users/buddha/github/chapel/util
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: clang
CHPL_TARGET_ARCH: 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: intrinsics
CHPL_GMP: gmp
CHPL_HWLOC: hwloc
CHPL_REGEXP: re2
CHPL_AUX_FILESYS: none
##########################

[Cleaning file /Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test.chpl]
[Starting /Users/buddha/github/chapel/util/test/sub_clean NamedMatrix-test.chpl Tue Feb 06 14:03:49 PST 2018]
[Starting sub_clean - Tue Feb 06 14:03:49 PST 2018]
[pwd: /Users/buddha/github/buddha314/numsuch/test]
Cleaning test: NamedMatrix-test

[Working on file NamedMatrix-test.chpl]
[Starting /Users/buddha/github/chapel/util/test/sub_test Tue Feb 06 14:03:49 PST 2018]
[Starting subtest - Tue Feb 06 14:03:49 PST 2018]
[test: /Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test.chpl]
[Executing compiler /Users/buddha/github/chapel/bin/darwin/chpl -o NamedMatrix-test --cc-warnings -M../src -M/Users/buddha/github/cdo/src -L/usr/local/Cellar/openblas/0.2.20/lib -lblas -I/usr/local/Cellar/openblas/0.2.20/include NamedMatrix-test.chpl < /dev/null]
[Elapsed compilation time for "/Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test (compopts: 1)" - 14.918 seconds]
[Error cannot locate compiler output comparison file /Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test.good]
[Compiler output was as follows:]
../src/MatrixOps.chpl:36: internal error: SCA0500 chpl version 1.17.0 pre-release (f732cb37da)
Note: This source location is a guess.

Internal errors indicate a bug in the Chapel compiler ("It's us, not you"),
and we're sorry for the hassle.  We would appreciate your reporting this bug --
please see https://chapel-lang.org/bugs.html for instructions.  In the meantime,
the filename + line number above may be useful in working around the issue.

[Elapsed time to compile and execute all versions of "/Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test" - 14.919 seconds]
[Finished subtest "/Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test" - 15.166 seconds]

[Removing /var/folders/g5/4zwyfk513hd94tjs1fm5mdq00000gn/T/chplTestTmpDir.f4HGaP directory]
[Done with tests - 180206.140404]
[Log file: /Users/buddha/github/chapel/test/Logs/buddha.darwin.log ]

[Test Summary - 180206.140404]
[Error cannot locate compiler output comparison file /Users/buddha/github/buddha314/numsuch/test/NamedMatrix-test.good]
[Summary: #Successes = 0 | #Failures = 1 | #Futures = 0 | #Warnings = 0 ]
[Summary: #Passing Suppressions = 0 | #Passing Futures = 0 ]
[END]

I'm attaching files for posterity. NO, I'm not. Github won't let me select .chpl files, so I'm pasting the relevant bits.

NamedMatrix.test.chpl

use NumSuch;

var nv: int = 8,
    D: domain(2) = {1..nv, 1..nv},
    SD: sparse subdomain(D),
    X: [SD] real;

var vn: [1..0] string;
vn.push_back("star lord");
vn.push_back("gamora");
vn.push_back("groot");
vn.push_back("drax");
vn.push_back("rocket");
vn.push_back("mantis");
vn.push_back("yondu");

SD += (1,2); X[1,2] = 1;
SD += (1,3); X[1,3] = 1;
SD += (1,4); X[1,4] = 1;
SD += (2,2); X[2,2] = 1;
SD += (2,4); X[2,4] = 1;
SD += (3,4); X[3,4] = 1;
SD += (4,5); X[4,5] = 1;
SD += (5,6); X[5,6] = 1;
SD += (6,7); X[6,7] = 1;
SD += (6,8); X[6,8] = 1;
SD += (7,8); X[7,8] = 1;

var nm = new NamedMatrix(X=X);
/* Should Error out, too few names */
try {
  nm.setRowNames(vn);
} catch {
  writeln("throwing to second!");
}

vn.push_back("nebula");
writeln(nm.setRowNames(vn));

MatrixOps.chpl (edited)

use Cdo,
    LinearAlgebra,
    LinearAlgebra.Sparse,
    Random;

class NamedMatrix {
  var D: domain(2),
      SD = CSRDomain(D),
      X: [SD] real,  // the actual data
      rowNames: [1..0] string;

   proc init(X) {
     this.D = {X.domain.dim(1), X.domain.dim(2)};
     super.init();
     this.loadX(X);
   }
}

proc NamedMatrix.loadX(X:[]) {
  for (i,j) in X.domain {
    this.SD += (i,j);
    this.X(i,j) = X(i,j);
  }
}

proc NamedMatrix.setRowNames(rn:[]): int throws {
  if rn.size != X.domain.dim(1).size then throw new Error();
  for i in 1..rn.size {
    this.rowNames.push_back(rn[i]);
  }
  return this.rowNames;
}
Compiler Bug Error Message user issue

Most helpful comment

Would you prefer "The curious case of the array returned from a function"?

All 17 comments

Looks like the problem was that I was returning a string array when I said I was gonna return an int. That's fine, but the compiler error is weird or I read it wrong.

Looks like we're failing an assert in scalarReplace. Somehow a move or assign has been created over two things with different valTypes (when I would've expected that to be checked already). Maybe this is a promotion issue? I know very little about this pass, though, so that's just a guess

I got it to compile using

proc NamedMatrix.setRowNames(rn:[]): string throws {
  if rn.size != X.domain.dim(1).size then throw new Error();
  for i in 1..rn.size {
    this.rowNames.push_back(rn[i]);
  }
  return this.rowNames;
}

Note the string in there, even though I am returning an array of strings. Is that supposed to be okay?

That doesn't seem like it should be okay to me, and does make me more inclined to blame promotion in some form.

Can you print out the return value? Does it give you a single string or the array?

This is exactly the Peter Principle in action, I agree.

Return is now

throwing to second!
star lord gamora groot drax rocket mantis yondu nebula

Do you get the appropriate error message if you comment out the error handling?

start_test gets mad if I do that

nm.setRowNames(vn);
> uncaught Error:
>   ../src/MatrixOps.chpl:42: thrown here
>   NamedMatrix-test.chpl:32: uncaught here

Is that what you wanted to see or something else?

I meant remove the throws declaration from the method and the throw new Error from within the body

I believe you mean:

//proc NamedMatrix.setRowNames(rn:[]): string throws {
proc NamedMatrix.setRowNames(rn:[]): int {
  //if rn.size != X.domain.dim(1).size then throw new Error();
  for i in 1..rn.size {
    this.rowNames.push_back(rn[i]);
  }
  return this.rowNames;
}

which gives me the error

> ../src/MatrixOps.chpl:46: internal error: SCA0500 chpl version 1.17.0 pre-release (04472a0924)
> Note: This source location is a guess.
>
> Internal errors indicate a bug in the Chapel compiler ("It's us, not you"),
> and we're sorry for the hassle.  We would appreciate your reporting this bug --
> please see https://chapel-lang.org/bugs.html for instructions.  In the meantime,
> the filename + line number above may be useful in working around the issue.
>

This has the mismatch of return type.

Yes, that's what I meant. Looks like this is independent of error handling, so I'll update the issue description

Go for it!

I like "Odd behavior" better, sounds like you are introducing a novel.

Internal error is a bit more descriptive, though :)

B O O O R R I N G

All, I am now officially BORED TO DEATH. YOU! YOU KILLED ME LYDIA!

Would you prefer "The curious case of the array returned from a function"?

It IS a curious case, isn't it? How intriguing!

Do go on...

Was this page helpful?
0 / 5 - 0 ratings