Jump to page: 1 2
Thread overview
[Issue 9655] Two functions with identical implementations are allowed to have the same address
Oct 06, 2014
yebblies
Oct 31, 2014
yebblies
Oct 31, 2014
Ketmar Dark
Oct 31, 2014
yebblies
Dec 17, 2022
Iain Buclaw
September 19, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--- Comment #2 from hsteoh@quickfur.ath.cx ---
ping

I fully support this proposal. If two functions compile to identical code, there is no reason to expect them to have different addresses. As already mentioned, this is an important part of reducing template bloat.

So, the question is, where on the website should this be documented?

--
October 06, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com

--- Comment #3 from yebblies <yebblies@gmail.com> ---
(In reply to hsteoh from comment #2)

> So, the question is, where on the website should this be documented?

A note in http://dlang.org/function.html should be fine.

--
October 30, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from hsteoh@quickfur.ath.cx ---
https://github.com/D-Programming-Language/dlang.org/pull/684

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

--- Comment #5 from github-bugzilla@puremagic.com ---
Commit pushed to master at https://github.com/D-Programming-Language/dlang.org

https://github.com/D-Programming-Language/dlang.org/commit/e5d39c811d080ad8aae8903e96711f7f7715ca99 Merge pull request #684 from quickfur/issue9655

Issue 9655: Functions with identical bodies are allowed to be merged by compiler.

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

--- Comment #6 from bearophile_hugs@eml.cc ---
(In reply to github-bugzilla from comment #5)
> Commit pushed to master at https://github.com/D-Programming-Language/dlang.org
> 
> https://github.com/D-Programming-Language/dlang.org/commit/
> e5d39c811d080ad8aae8903e96711f7f7715ca99
> Merge pull request #684 from quickfur/issue9655
> 
> Issue 9655: Functions with identical bodies are allowed to be merged by compiler.

This is not enough. What do you have to do if you want to be certain to have distinct D functions pointers even if the function body may or may not be the same? (There is C code out there that relies on this guaranteed, like some evolutionary algorithm that breeds functions). Are D functions tagged with extern(C) exempt from this optimization?

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

--- Comment #7 from yebblies <yebblies@gmail.com> ---
(In reply to bearophile_hugs from comment #6)
> 
> This is not enough. What do you have to do if you want to be certain to have distinct D functions pointers even if the function body may or may not be the same? (There is C code out there that relies on this guaranteed, like some evolutionary algorithm that breeds functions). Are D functions tagged with extern(C) exempt from this optimization?

No, you shouldn't rely on this ever.

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--- Comment #8 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
(In reply to bearophile_hugs from comment #6)
> This is not enough. What do you have to do if you want to be certain to have distinct D functions pointers even if the function body may or may not be the same? (There is C code out there that relies on this guaranteed, like some evolutionary algorithm that breeds functions). Are D functions tagged with extern(C) exempt from this optimization?
that code is foobared. please, don't use it.

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

--- Comment #9 from bearophile_hugs@eml.cc ---
(In reply to yebblies from comment #7)

> No, you shouldn't rely on this ever.

Why? I think the C standard requires those functions to have different addresses. So I think that C code is correct. (And indeed as far as I know GCC replaces equal function implementations with a jump, to keep addressed distinct).

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

--- Comment #10 from yebblies <yebblies@gmail.com> ---
(In reply to bearophile_hugs from comment #9)
> (In reply to yebblies from comment #7)
> 
> > No, you shouldn't rely on this ever.
> 
> Why?

Because in D it's specified that the functions may not have distinct addresses.

> I think the C standard requires those functions to have different addresses. So I think that C code is correct. (And indeed as far as I know GCC replaces equal function implementations with a jump, to keep addressed distinct).

In a language without templates, code folding is much less useful.

--
October 31, 2014
https://issues.dlang.org/show_bug.cgi?id=9655

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #11 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to bearophile_hugs from comment #9)
> Why? I think the C standard requires those functions to have different addresses.

I don't think this is true.
(In reply to bearophile_hugs from comment #9)
> (In reply to yebblies from comment #7)
> 
> > No, you shouldn't rely on this ever.
> 
> Why? I think the C standard requires those functions to have different addresses. So I think that C code is correct. (And indeed as far as I know GCC replaces equal function implementations with a jump, to keep addressed distinct).

>From the C standard:

Two pointers compare equal if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at its beginning) or function, both are pointers to one past the last element of the same array object, or one is a pointer to one past the end of one array object and the other is a pointer to the start of a different array object that happens to immediately follow the first array object in the address space.

So it appears, from the "if and only if", that bearophile is right.

But D does not have to follow C rules. Even if we define an extern(C) function in D, it does not mean we have to follow those rules.

I would say the issues that might occur because of this change are astronomically small. Consider that a piece of code that depends on distinct functions having distinct addresses may still work just fine even with ICF.

However, it should be noted on the spec that we deviate from those requirements. It currently does not address this point from what I could find.

--
« First   ‹ Prev
1 2