Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the correct behavior of fileReader.matches? #26411

Open
jabraham17 opened this issue Dec 14, 2024 · 1 comment
Open

What is the correct behavior of fileReader.matches? #26411

jabraham17 opened this issue Dec 14, 2024 · 1 comment

Comments

@jabraham17
Copy link
Member

While using Chapels IO+Regex features, I found some weird behavior with fileReader.matches.

Both of the following two programs result in infinite loops

use IO, Regex;

proc main() {
  var r = openReader("foo.txt");
  var re = new regex("X\\d+");
  for m in r.matches(re) {
    writeln("Got a match: ", m);
  }
  writeln("end");
use IO, Regex;

proc main() {
  var r = openReader("foo.txt");
  var re = new regex("X\\d+");
  var matches = r.matches(re);
  writeln(matches);
}

Is this the correct behavior? To make these be non-infinite, something must be done inside the loop that progresses the fileReader (e.g. extractMatch or advance). The second program has implicit parallelism, and will always be an infinite loop.

My reading of the documentation left me uncertain if this was the intended behavior.

Based on offline conversation, @mppf says he recalls that this infinite loop was the original intended behavior. However, it was generally agreed that the docs say thats not the intended behavior. We agreed that according to the docs, the correct behavior is that matches yields all the possible matches, after yield one match, the file reader is advanced to the end of the match where it looks for the next match.

Either way, this seems like a bug we should fix. Either the docs are wrong, or the code is wrong.

@mppf
Copy link
Member

mppf commented Dec 16, 2024

IMO we should update the implementation to match the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants