chapel-lang / chapel

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

$CHPL_HOME/modules/internal/ChapelBase.chpl:912: internal error: RES-FUN-ION-4764 chpl version 1.28.0 #21262

Closed nathanielknight closed 1 year ago

nathanielknight commented 1 year ago

Summary of Problem

Compilation of the following program (which was written while attempting to solve an Advent of Code challenge) failed with this error message:

$CHPL_HOME/modules/internal/ChapelBase.chpl:912: internal error: RES-FUN-ION-4764 chpl version 1.28.0
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.

Steps to Reproduce

Source Code:

use IO, FileSystem, FormattedIO, List;

config const inf = "input.txt";

type Point = (int, int);

record Beacon {
    const location: Point, beacon: Point;

    proc init(location: Point, beacon: Point) {
        this.location = location;
        this.beacon = beacon;
    }

    proc beaconDistance(): int {
        return abs(this.location[0] - this.beacon[0]) + abs(this.location[1] - this.location[0]);
    }
}

iter loadInput() {
    var a, b, c, d: int;
    const f = open(inf, iomode.r).reader();
    while f.readf("Sensor at x=%i, y=%i: closest beacon is at x=%i, y=%i\n", a, b, c, d) {
        yield new Beacon((a, b), (c, d));
    }
}

proc blockedCells(ycoord: int, beacons: [?]Beacon): int {
    return 0;
}

proc main() {
    const beacons: list(Beacon) = loadInput();
    writeln(beacons);
}

Compile command:

chpl solve.chpl

Configuration Information

$ chpl --version
chpl version 1.28.0
  built with LLVM version 14.0.6
Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)

$ clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

# I don't seem to have printchplenv on my system
mppf commented 1 year ago

Hi @nathanielknight - thanks for posting this issue report.

I've been able to reproduce the issue with main. Looking at the compilation output with --devel, I can see that the compiler is having a problem in trying to default-initialize Beacon.

But, it's not obvious to me why Beacon should need to be default-initialized at all for this code. And if it does, and the proc init() is missing, you should get a better error. So there is more to fix here.

Anyway, here is a version of your reproducer with the workaround:

use IO, FileSystem, FormattedIO, List;

config const inf = "input.txt";

type Point = (int, int);

record Beacon {
    const location: Point, beacon: Point;

    proc init() { } // Added Workaround Here

    proc init(location: Point, beacon: Point) {
        this.location = location;
        this.beacon = beacon;
    }

    proc beaconDistance(): int {
        return abs(this.location[0] - this.beacon[0]) + abs(this.location[1] - this.location[0]);
    }
}

iter loadInput() {
    var a, b, c, d: int;
    const f = open(inf, iomode.r).reader();
    while f.readf("Sensor at x=%i, y=%i: closest beacon is at x=%i, y=%i\n", a, b, c, d) {
        yield new Beacon((a, b), (c, d));
    }
}

proc blockedCells(ycoord: int, beacons: [?]Beacon): int {
    return 0;
}

proc main() {
    const beacons: list(Beacon) = loadInput();
    writeln(beacons);
}
mppf commented 1 year ago

Inside the compiler, it looks like what is happening here is:

Ideally, we could discard this candidate earlier. But, in any case, I think the main problem here is in the module code.

https://github.com/chapel-lang/chapel/blob/e9ddcb71c4774faaa14bf01aa48cde8648524f76/modules/internal/DefaultRectangular.chpl#L686-L698

The comment here is wrong. And there's no one to git blame but myself!

nathanielknight commented 1 year ago

I confess, a lot of that went over my head 😅, but thanks for the swift response, and the workaround :+1:.

bradcray commented 1 year ago

@nathanielknight : Thanks for reporting the bug. If it helps, I interpret Michael's diagnosis as being more directed at the compiler team than you. :)