Bug 18472 – [Reg 2.078] betterC: cannot use format at compile time.

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2018-02-20T06:51:00Z
Last change time
2023-03-01T02:32:47Z
Keywords
betterC, pull
Assigned to
No Owner
Creator
Nicholas Wilson
See also
https://issues.dlang.org/show_bug.cgi?id=18101, https://issues.dlang.org/show_bug.cgi?id=23754

Comments

Comment #0 by iamthewilsonator — 2018-02-20T06:51:00Z
import std.format; import std.stdio; void main() { enum s = "%1$s,%2$s".format("foo","bar"); writeln(s); } fails with /dlang/dmd-nightly/linux/bin64/../../src/phobos/std/array.d(2889): Error: TypeInfo cannot be used with -betterC due to the use of Appender at line 2889 is `private struct Data` This did use to work as I have always compiled Dcompute with -betterC, however upgrading to LDC 1.8.0b1 based on v2.078.2 (from LDC master in about December), I hit #18101, and trying run.dlang.io to see how soon it would get fixed and hit this.
Comment #1 by slavo5150 — 2018-02-20T13:54:16Z
The test doesn't compile with 2.078.3. 2.078.3 does not include the TypeInfo check, so at most this is a diagnostic regression. https://run.dlang.io/is/fvj8jb /dlang/dmd/linux/bin64/../../src/phobos/std/range/primitives.d(405): Error: static assert "Cannot put a const(char)[] into a Appender!string." /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(1172): instantiated from here: put!(Appender!string, const(char)[]) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(473): instantiated from here: writeUpToNextSpec!(Appender!string) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(5831): instantiated from here: formattedWrite!(Appender!string, char, string, string) onlineapp.d(5): instantiated from here: format!(char, string, string) Do you have a test that will demonstrate a successful build prior to the TypeInfo check introduced in 2.079?
Comment #2 by code — 2018-02-20T17:16:03Z
cat > bug.d << CODE import std.format; import std.stdio; void main() { enum s = "%1$s,%2$s".format("foo","bar"); writeln(s); } CODE dmd -c -betterC bug.d ---- /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/range/primitives.d(405): Error: static assert "Cannot put a const(char)[] into a Appender!string." /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/format.d(1172): instantiated from here: put!(Appender!string, const(char)[]) /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/format.d(473): instantiated from here: writeUpToNextSpec!(Appender!string) /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/format.d(5831): instantiated from here: formattedWrite!(Appender!string, char, string, string) /home/dawg/Code/D/bug.d(5): instantiated from here: format!(char, string, string) ---- Confirmed that this stopped to work with 2.078.0, the error looks rather weird, as betterC shouldn't change types. Also indeed with 2.079.0-beta.1 the error message is now about using TypeInfo. ---- /home/dawg/dlang/dmd-2.079.0-beta.1/linux/bin64/../../src/phobos/std/array.d(2889): Error: TypeInfo cannot be used with -betterC ---- The test case compiles fine with 2.077.1.
Comment #3 by iamthewilsonator — 2018-02-21T00:04:46Z
(In reply to Martin Nowak from comment #2) > cat > bug.d << CODE > import std.format; > import std.stdio; > void main() > { > enum s = "%1$s,%2$s".format("foo","bar"); > writeln(s); > } > CODE > dmd -c -betterC bug.d > ---- > /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/range/ > primitives.d(405): Error: static assert "Cannot put a const(char)[] into a > Appender!string." > /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/format.d(1172): > instantiated from here: put!(Appender!string, const(char)[]) > /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/format.d(473): > instantiated from here: writeUpToNextSpec!(Appender!string) > /home/dawg/dlang/dmd-2.078.0/linux/bin64/../../src/phobos/std/format.d(5831): > instantiated from here: formattedWrite!(Appender!string, char, string, > string) > /home/dawg/Code/D/bug.d(5): instantiated from here: format!(char, > string, string) > ---- > > Confirmed that this stopped to work with 2.078.0, the error looks rather > weird, as betterC shouldn't change types. > Indeed that is issue 18101 which was fixed to check typeinfo, but now also fails at compile time. > Also indeed with 2.079.0-beta.1 the error message is now about using > TypeInfo. > ---- > /home/dawg/dlang/dmd-2.079.0-beta.1/linux/bin64/../../src/phobos/std/array. > d(2889): Error: TypeInfo cannot be used with -betterC > ---- > > The test case compiles fine with 2.077.1. That sounds about the right timeframe.
Comment #4 by slavo5150 — 2018-02-21T01:15:05Z
Isn't this then a duplicate of Issue 18101? In other words, if Issue 18101 were solved, there wouldn't be a need for TypeInfo, and therefore the TypeInfo error would not be triggered?
Comment #5 by r.sagitario — 2018-04-15T13:41:42Z
Here's a simpler test case: module betterc; enum b = typeid(size_t) is typeid(uint); >dmd -betterC -c betterc.d betterc.d(2): Error: TypeInfo cannot be used with -betterC
Comment #6 by slavo5150 — 2018-04-15T23:26:14Z
(In reply to Rainer Schuetze from comment #5) > Here's a simpler test case: > > module betterc; > enum b = typeid(size_t) is typeid(uint); At https://dlang.org/spec/betterc.html under the "Not Available" section: > 2. TypeInfo and ModuleInfo So, it is by design that any call to `typeid` is going to fail when compiled with `-betterC`. This specific issue is about not being able to use `format` in `-betterC`. Perhaps the reason for that is because `format` relies on runtime type information (i.e. TypeInfo). So the solution, specific to this issue, would not be allow uses of `typeid` in `-betterC`, but rather to remove the dependency of `format` on runtime type information (if that's even possible). D has excellent facilities for doing introspection at compile-time, so it may be possible to look to those facilities in concert with templates to find a solution that does not rely on runtime type information. It would likely also help to begin replacing compiler-generated calls to runtime hooks that depend on `TypeInfo` with templates. See also https://forum.dlang.org/post/[email protected]
Comment #7 by r.sagitario — 2018-04-16T05:40:42Z
I think the main issue is that the compiler does not distinguish between information needed at compile time and what's necessary inside the object file.
Comment #8 by slavo5150 — 2018-04-16T08:17:14Z
(In reply to Rainer Schuetze from comment #7) > I think the main issue is that the compiler does not distinguish between > information needed at compile time and what's necessary inside the object > file. Ok, I understand now: `enum b = typeid(size_t) is typeid(uint);` should be evaluated at compile time, and I the -betterC limitations should only apply at runtime.
Comment #9 by slavo5150 — 2018-04-16T08:50:18Z
Comment #10 by slavo5150 — 2018-04-16T10:47:49Z
PR 8173 seems to take care of the case... module betterc; enum b = typeid(size_t) is typeid(uint) ... but still fails for ... import std.format; import std.stdio; void main() { enum s = "%1$s,%2$s".format("foo","bar"); writeln(s); } ... with the same TypeInfo error. However, if I comment out the TypeInfo check altogether, the `format` test case fails with... phobos/std/range/primitives.d(405): Error: static assert: "Cannot put a const(char)[] into a Appender!string." phobos/std/format.d(1184): instantiated from here: put!(Appender!string, const(char)[]) /phobos/std/format.d(473): instantiated from here: writeUpToNextSpec!(Appender!string) phobos/std/format.d(6168): instantiated from here: formattedWrite!(Appender!string, char, string, string) main.d(5): instantiated from here: format!(char, string, string) I'm wondering if there was another change to Phobos around the same time frame was the TypeInfo change that prevents the `format` expression from evaluating at compile-time.
Comment #11 by github-bugzilla — 2018-05-02T08:24:27Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/cb2b0b848a1c6a2b208ba12257f6204c725744e4 Partial fix for Issue 18472 - permit using typeid at compile-time in betterC https://github.com/dlang/dmd/commit/a402a791694df063d8bd7a5b9d2f6651e9185cee Merge pull request #8173 from JinShil/fix_18472 Partial fix for Issue 18472 - permit using typeid at compile-time in betterC merged-on-behalf-of: Jacob Carlborg <[email protected]>
Comment #12 by slavo5150 — 2018-08-02T18:13:26Z
This appears to work now in nightly: import std.format; import std.stdio; void main() { enum s = "%1$s,%2$s".format("foo","bar"); writeln(s); } https://run.dlang.io/is/BDyoHF It may have been fixed inadvertently by https://github.com/dlang/dmd/pull/8523
Comment #13 by slavo5150 — 2018-08-02T18:15:05Z
(In reply to Mike Franklin from comment #12) > This appears to work now in nightly: > > import std.format; > import std.stdio; > void main() > { > enum s = "%1$s,%2$s".format("foo","bar"); > writeln(s); > } > > https://run.dlang.io/is/BDyoHF > > It may have been fixed inadvertently by > https://github.com/dlang/dmd/pull/8523 Gah, scratch that. Forgot to add the -betterC flag. :-(
Comment #14 by aldacron — 2019-10-17T09:43:53Z
Comment #15 by dlang-bot — 2022-12-09T01:17:37Z
@etcimon updated dlang/dmd pull request #14676 "Fix 18472: betterC cannot use format at compile time." fixing this issue: - Fix 18472: betterC cannot use format at compile time. https://github.com/dlang/dmd/pull/14676
Comment #16 by dlang-bot — 2023-02-28T04:43:47Z
@WalterBright created dlang/dmd pull request #14930 "fix Issue 18472: betterC cannot use format at compile time" fixing this issue: - fix Issue 18472: betterC cannot use format at compile time https://github.com/dlang/dmd/pull/14930
Comment #17 by dlang-bot — 2023-02-28T09:28:35Z
dlang/dmd pull request #14930 "fix Issue 18472: betterC cannot use format at compile time" was merged into master: - 116d35134cc17fc06fc4b3ad1ed9af65b44e7d39 by Walter Bright: fix Issue 18472: betterC cannot use format at compile time https://github.com/dlang/dmd/pull/14930
Comment #18 by bugzilla — 2023-03-01T02:32:47Z
Continued with https://issues.dlang.org/show_bug.cgi?id=23754 as a Phobos bug.