Chapel: compilation error when initializating linked list with domain type

Created on 29 Mar 2020  路  2Comments  路  Source: chapel-lang/chapel

Summary of Problem


I want to have a list of arrays of certain size, I want the list to be created on run-time. So I try to create the list with the type deduction.

Steps to Reproduce

Source Code:

use LinkedLists;
var a = [1,2,3,4,5];
var c : LinkedList(a.type);
c.append(a);

Error:

foo.chpl:4: note: mentions module-scope variable 'default_runtime_temp' not initialized yet

Compile command:
chpl foo.chpl

Execution command:

Associated Future Test(s):

Configuration Information

  • chpl version 1.21.0
  • clang version 6.0.0-1ubuntu2:
Compiler Bug

Most helpful comment

A few more thoughts:

That message is only a note, so the program compiles. It crashes when run:

foo.chpl:4: error: attempt to dereference nil

Compiled with developer mode, the line given is in buildArray(),

$CHPL_HOME/modules/internal/ChapelArray.chpl:1404: error: attempt to dereference nil

      var x = _value.dsiBuildArray(eltType);

default_runtime_temp is created in functionResolution.cpp, createGenericRecordVarDefaultInitCall(), with this comment,

    if (field->isParameter()) {
      appendExpr = new SymExpr(e->value);
    } else if (field->hasFlag(FLAG_TYPE_VARIABLE)) {
      if (e->value->getValType()->symbol->hasFlag(FLAG_HAS_RUNTIME_TYPE)) {
        // 2018-11-02: This technically generates code that would
        // crash at runtime because aggregate types don't contain the runtime
        // type information for their fields, so this temporary will go
        // uninitialized. At the moment we fortunately do not access such
        // fields for default-initialized records, and avoid crashing.
        VarSymbol* tmp = newTemp("default_runtime_temp");
        tmp->addFlag(FLAG_TYPE_VARIABLE);
        CallExpr* query = new CallExpr(PRIM_QUERY_TYPE_FIELD, at->symbol, new_CStringSymbol(e->key->name));
        CallExpr* move = new CallExpr(PRIM_MOVE, tmp, query);

@OmarElawady pointed out a workaround,

initializing the list with var c : LinkedList(a.type) = new LinkedList(a.type); solves the problem.

All 2 comments

A few more thoughts:

That message is only a note, so the program compiles. It crashes when run:

foo.chpl:4: error: attempt to dereference nil

Compiled with developer mode, the line given is in buildArray(),

$CHPL_HOME/modules/internal/ChapelArray.chpl:1404: error: attempt to dereference nil

      var x = _value.dsiBuildArray(eltType);

default_runtime_temp is created in functionResolution.cpp, createGenericRecordVarDefaultInitCall(), with this comment,

    if (field->isParameter()) {
      appendExpr = new SymExpr(e->value);
    } else if (field->hasFlag(FLAG_TYPE_VARIABLE)) {
      if (e->value->getValType()->symbol->hasFlag(FLAG_HAS_RUNTIME_TYPE)) {
        // 2018-11-02: This technically generates code that would
        // crash at runtime because aggregate types don't contain the runtime
        // type information for their fields, so this temporary will go
        // uninitialized. At the moment we fortunately do not access such
        // fields for default-initialized records, and avoid crashing.
        VarSymbol* tmp = newTemp("default_runtime_temp");
        tmp->addFlag(FLAG_TYPE_VARIABLE);
        CallExpr* query = new CallExpr(PRIM_QUERY_TYPE_FIELD, at->symbol, new_CStringSymbol(e->key->name));
        CallExpr* move = new CallExpr(PRIM_MOVE, tmp, query);

@OmarElawady pointed out a workaround,

initializing the list with var c : LinkedList(a.type) = new LinkedList(a.type); solves the problem.

Compiling today, the note about default_runtime_temp is gone, but the program still crashes the same way on the same dsiBuildArray() call.

Was this page helpful?
0 / 5 - 0 ratings