[Issue 6528] Private module functions optimizations

2022-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6528

Iain Buclaw  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||ibuc...@gdcproject.org
 Resolution|--- |WONTFIX

--- Comment #5 from Iain Buclaw  ---
This is best handled at link or LTO time, as because of templates (called from
outside the module compilation), we have no idea whether a private function
really is used or not.

--


[Issue 6528] Private module functions optimizations

2017-03-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6528

Johannes Pfau  changed:

   What|Removed |Added

 CC||johannesp...@gmail.com

--- Comment #4 from Johannes Pfau  ---
Reposting from the newsgroup:


// a.d
private void fooPrivate() {}

/*template*/ void fooPublic(string func = "fooPrivate")()
{
mixin(func ~ "();");
}


When compiling a.d we haven't analyzed the fooPublic template and the
example shows why we can't know at all which private functions could
be called from a template. As the template is instantiated into another
object file (e.g. module b.d) we can't know in a.d that fooPrivate is
actually required.

So does that mean removing private functions in D is completely
impossible as we can't know if a function is unused? People sometimes
refer to the linker as a solution but if a.d is in a shared library
this won't work either.

This seems to be a problem especially for CTFE only functions, as it
means for example that any such function in phobos (e.g. used for
string creation for mixins) bloats the phobos library.

It's interesting to think about template instances here as
well: If a template instance is completely inlined in a module, do we
have to keep the function in the object file? AFAICS no, as the
template should be re-instantiated if used in a different module, but I
don't know the template <=> object file rules in detail. Right now this
means we could get lots of template instances in the phobos shared
library for template instances only used in CTFE:


import std.conv;
private string fooPrivate(int a)
{
return `int b = ` ~ to!string(a) ~";";
}
mixin(fooPrivate(42));

https://godbolt.org/g/VW8yLr


Any idea to measure the impact of this on the binary shared libphobos
file? We probably can get some estimate by counting all template
instances that are only referenced by private functions which are
themselves never referenced...

I think the same problem was mentioned in the DLL-support context as this
implies we also have to export private functions from modules for templates to
work. Was there some kind of solution / discussion? I think I remember
something about marking `private` functions as `export private` instead?

--


[Issue 6528] Private module functions optimizations

2013-01-16 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6528


yebblies  changed:

   What|Removed |Added

 CC||yebbl...@gmail.com


--- Comment #3 from yebblies  2013-01-17 13:36:39 EST ---
The first case here is already done by the linker.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6528] Private module functions optimizations

2012-01-05 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6528


Trass3r  changed:

   What|Removed |Added

   Keywords||diagnostic, performance
 CC||mrmoc...@gmx.de


--- Comment #2 from Trass3r  2012-01-05 14:33:18 PST ---
Also there should be a warning if you define a private function and not use it
(including CTFE). Just like in C.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6528] Private module functions optimizations

2011-08-20 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6528



--- Comment #1 from bearophile_h...@eml.cc 2011-08-20 01:14:33 PDT ---
Another optimization example:

private void foo(int[] a) {}
void main() {
int[100] array;
foo(array);
}


Converted to:

private void foo(ref int[100] a) {}
void main() {
int[100] array;
foo(array);
}

--

The optimization is possible if foo has more than one call from the module, if
the body of foo is short:

private void foo(int[] a) {
// this is a short function
}
void main() {
int[100] array1;
foo(array1);
int[200] array2;
foo(array2);
}


Converted to:

private void foo(size_t N)(ref int[N] a) {
// this is a short function
}
void main() {
int[100] array1;
foo(array1);
int[200] array2;
foo(array2);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---