Bug 20218 – Checked format string takes infinite time for infinite ranges
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-09-16T21:44:01Z
Last change time
2019-09-17T14:33:54Z
Keywords
pull
Assigned to
No Owner
Creator
Ali Cehreli
Comments
Comment #0 by acehreli — 2019-09-16T21:44:01Z
dmd 2.088 does not stop compiling the following program seemingly because it is expanding the infinite range at compile time:
import std.string;
import std.range;
void main() {
format!"%s"(1.repeat);
}
1) SAME PROBLEM for writefln
2) SAME PROBLEM for element formatters %( and %):
format!"%(%s%)"(1.repeat);
3) SIMILAR PROBLEM: Apparently, it can take "close to infinite time" if the range is large. The following line either does not finish compilation or takes a very long time (I did not wait):
format!"%s"(1.repeat(1_000_000_000));
Ali
Comment #1 by default_357-line — 2019-09-17T12:43:32Z
That should not happen... `format` should not evaluate the range at compiletime.
Comment #2 by dlang-bot — 2019-09-17T13:09:09Z
@FeepingCreature created dlang/phobos pull request #7185 "Fix issue 20218: format: don't try to print the entire range while merely testing the format string" fixing this issue:
- Fix issue 20218: format: don't try to print the entire range while merely testing the format string
https://github.com/dlang/phobos/pull/7185
Comment #3 by dlang-bot — 2019-09-17T14:33:54Z
dlang/phobos pull request #7185 "Fix issue 20218: format: don't try to print the entire range while merely testing the format string" was merged into master:
- 70c8d50948f8b502d58dfe1b62edbce6f1dc54a7 by Mathis Beer:
Fix issue 20218: format: don't try to print the entire range while merely testing the format string
https://github.com/dlang/phobos/pull/7185