www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Uncalled functions in hello world

reply Stefan Koch <uplink.coder googlemail.com> writes:
The current phobos hello world
import std.stdio;
void main() { "Hello World".writeln; }
generates a list of 36 functions which are generated and emitted 
but not called, and therefore presumably only used at compile time

Those are:

std.typecons.__lambda252|/usr/include/dmd/phobos/std/typecons.d(7277)
std.stdio.File.ByChunkImpl.~this|/usr/include/dmd/phobos/std/stdio.d(2615)
std.stdio.File.ByChunkImpl.__fieldPostblit|/usr/include/dmd/phobos/std/stdio.d(2615)
std.typecons.Ternary.make|/usr/include/dmd/phobos/std/typecons.d(9034)
std.stdio.File.LockingTextWriter.~this|/usr/include/dmd/phobos/std/stdio.d(2861)
std.traits.DynamicArrayTypeOf(T)|/usr/include/dmd/phobos/std/traits.d(5791)
std.range.primitives.empty!(const(char)[]).empty|/usr/include/dmd/phobos/std/range/primitives.d(2184)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(173)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(174)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(175)
object.__equals!(immutable(char), 
immutable(char)).__equals.__lambda3|/usr/include/dmd/druntime/import/object.d(398)
object.__equals!(immutable(char), 
immutable(char)).__equals.at!(immutable(char)).at|/usr/include/dmd/druntime/import/object.d(358)
object.__equals!(immutable(char), 
immutable(char)).__equals|/usr/include/dmd/druntime/import/object.d(352)
std.functional.safeOp!"<".safeOp!(ulong, 
immutable(ubyte)).safeOp|/usr/include/dmd/phobos/std/functional.d(446)
std.algorithm.comparison.min!(ulong, 
immutable(ubyte)).min|/usr/include/dmd/phobos/std/algorithm/comparison.d(1641)
std.range.primitives.popFront!char.popFront|/usr/include/dmd/phobos/std/range/primitives.d(2254)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(176)
std.utf.decodeImpl!(true, cast(Flag)false, 
const(char)[]).decodeImpl.exception!(const(char)[]).exception|/usr/include/dmd/phobos/std/utf.d(1491)
std.utf.decodeImpl!(true, cast(Flag)false, 
const(char)[]).decodeImpl.invalidUTF|/usr/include/dmd/phobos/std/utf.d(1505)
std.utf.decodeImpl!(true, cast(Flag)false, 
const(char)[]).decodeImpl.outOfBounds|/usr/include/dmd/phobos/std/utf.d(1522)
std.utf.decodeImpl!(true, cast(Flag)false, 
const(char)[]).decodeImpl|/usr/include/dmd/phobos/std/utf.d(1447)
std.utf.decode!(cast(Flag)false, 
const(char)[]).decode|/usr/include/dmd/phobos/std/utf.d(1127)
std.range.primitives.front!char.front|/usr/include/dmd/phobos/std/range/primitives.d(2454)
std.range.primitives.empty!string.empty|/usr/include/dmd/phobos/std/range/primitives.d(2184)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(173)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(174)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(175)
std.range.primitives.isInputRange(R)|/usr/include/dmd/phobos/std/range/primitives.d(176)
std.range.primitives.isInfinite(R)|/usr/include/dmd/phobos/std/range/primitives.d(1621)
std.exception.enforce!(ErrnoException).enforce!int.enforce.__lambda1|/usr/include/dmd/phobos/std/exception.d(434)
object.idup!(const(char)).idup.__lambda2|/usr/include/dmd/druntime/import/object.d(4578)
object._getPostblit!(immutable(char))._getPostblit.__dgliteral1|/usr/include/dmd/druntime/import/object.d(4652)
std.stdio.File.LockingTextWriter.put!string.put.__dgliteral2|/usr/include/dmd/phobos/std/stdio.d(2899)
std.range.primitives.front!char.front|/usr/include/dmd/phobos/std/range/primitives.d(2454)
object.__equals!(immutable(char), 
immutable(char)).__equals|/usr/include/dmd/druntime/import/object.d(352)

So you can see that there is something to be won even in the most 
trivial examples if we have facilities to disable codegen for 
functions which are only used at compiletime.
Apr 08
next sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Wednesday, 8 April 2020 at 13:57:47 UTC, Stefan Koch wrote:
 The current phobos hello world
 import std.stdio;
 void main() { "Hello World".writeln; }
 generates a list of 36 functions which are generated and 
 emitted but not called, and therefore presumably only used at 
 compile time

 Those are:

 [...]

 So you can see that there is something to be won even in the 
 most trivial examples if we have facilities to disable codegen 
 for functions which are only used at compiletime.
Are you sure that this is not also caused by bad speculative template instantiation ? In case I'd use the wrong wording, I mean "some function templates that are wrongly determined to be emitted ".
Apr 08
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 8 April 2020 at 14:08:23 UTC, Basile B. wrote:
 On Wednesday, 8 April 2020 at 13:57:47 UTC, Stefan Koch wrote:
 The current phobos hello world
 import std.stdio;
 void main() { "Hello World".writeln; }
 generates a list of 36 functions which are generated and 
 emitted but not called, and therefore presumably only used at 
 compile time

 Those are:

 [...]

 So you can see that there is something to be won even in the 
 most trivial examples if we have facilities to disable codegen 
 for functions which are only used at compiletime.
Are you sure that this is not also caused by bad speculative template instantiation ? In case I'd use the wrong wording, I mean "some function templates that are wrongly determined to be emitted ".
That might very well be the cause. Most of those would however benefit from being annotated ctfe-only.
Apr 08
parent Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 8 April 2020 at 14:10:48 UTC, Stefan Koch wrote:
 On Wednesday, 8 April 2020 at 14:08:23 UTC, Basile B. wrote:
 Are you sure that this is not also caused by bad speculative 
 template instantiation ?
 In case I'd use the wrong wording, I mean "some function 
 templates that are wrongly determined to be emitted ".
That might very well be the cause. Most of those would however benefit from being annotated ctfe-only.
Having the meta information about a function template, that it is not supposed to be emitted of course will also help, when debugging the algorithm that determines template emission.
Apr 08
prev sibling next sibling parent reply Jonathan Marler <johnnymarler gmail.com> writes:
On Wednesday, 8 April 2020 at 13:57:47 UTC, Stefan Koch wrote:
 The current phobos hello world
 import std.stdio;
 void main() { "Hello World".writeln; }
 generates a list of 36 functions which are generated and 
 emitted but not called, and therefore presumably only used at 
 compile time

 [...]
This is uncalled for.
Apr 08
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Apr 08, 2020 at 03:50:41PM +0000, Jonathan Marler via Digitalmars-d
wrote:
 On Wednesday, 8 April 2020 at 13:57:47 UTC, Stefan Koch wrote:
 The current phobos hello world
 import std.stdio;
 void main() { "Hello World".writeln; }
 generates a list of 36 functions which are generated and emitted but
 not called, and therefore presumably only used at compile time
 
 [...]
This is uncalled for.
LOL! T -- Leather is waterproof. Ever see a cow with an umbrella?
Apr 08
prev sibling parent Basile B. <b2.temp gmx.com> writes:
On Wednesday, 8 April 2020 at 13:57:47 UTC, Stefan Koch wrote:
 The current phobos hello world
 import std.stdio;
 void main() { "Hello World".writeln; }
 generates a list of 36 functions which are generated and 
 emitted but not called, and therefore presumably only used at 
 compile time

 Those are:

 [...]
Now that I read those 36 calls carefully it really looks like there's among them some used when writeln!string fails and throws, e.g when decoding the argument.
Apr 08