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.
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
(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. :-(
@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