chapel-lang / chapel-lang/chapel
While-const lifetime checker error
- Dominant language
- Chapel
- Stars
- 2k
- Forks
- 449
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 119
Description
The "while var/const" construct - design (1b) in #13639, implemented in #17304 - is currently unusable for traversing data structures like linked list by advancing the borrowed pointer. The following generates a compilation error:
```chpl
var curr: borrowed Node?;
while const currNN = curr {
writeln(currNN);
curr = currNN.next; // error: curr would outlive the value it is set to
}
```
a small complete reproducer
```chpl
class Node {
var next: owned Node?;
}
var curr: borrowed Node?;
curr = (new Node()).borrow(); // error comes up regardless of this line
while const currNN = curr {
writeln(currNN);
curr = currNN.next; // error: curr would outlive the value it is set to
}
```
Whereas the following variant that does not use `const` works:
```chpl
while curr {
writeln(curr!);
curr = curr!.next;
}
```
While in general this lifetime error may be appropriate, this issue requests to make it work in codes like the ones above.
Contributor guide
Research direction
Start by compiling the complete reproducer in the issue and compare it with the working variant that omits const. Trace the while-const lifetime checking involved; done means the borrowed-pointer traversal compiles and works without removing appropriate lifetime errors in other cases.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100