Skip to content

Experimental: Don't reverse parameter order for extern(D) on x86_64.#865

Closed
kinke wants to merge 3 commits intoldc-developers:masterfrom
kinke:noReverse
Closed

Experimental: Don't reverse parameter order for extern(D) on x86_64.#865
kinke wants to merge 3 commits intoldc-developers:masterfrom
kinke:noReverse

Conversation

@kinke
Copy link
Member

@kinke kinke commented Mar 15, 2015

Requires ldc-developers/druntime#19 and ldc-developers/phobos#9.
Debug unittests pass on Linux x64 with LLVM 3.5, but dmd-testsuite reveals a serious bug:

import core.stdc.stdio;
import std.algorithm;

struct Shell
{
    string str;

    const int opCmp(ref const Shell s)
    {
    return std.algorithm.cmp(this.str, s.str);
    }
}

void main()
{
    Shell[3] a;

    a[0].str = "hello";
    a[1].str = "betty";
    a[2].str = "fred";

    a.sort;

    foreach (Shell s; a)
    {
    printf("%.*s\n", s.str.length, s.str.ptr);
    }

    assert(a[0].str == "betty");
    assert(a[1].str == "fred");
    assert(a[2].str == "hello");
}

a.sort() sorts the array in reversed order.

@kinke
Copy link
Member Author

kinke commented Oct 20, 2015

I've just updated the druntime patch - I've previously missed TypeInfo_Struct.compare() which reverses the arguments when invoking _xopCmp(). The test case above now works.

@kinke kinke force-pushed the noReverse branch 2 times, most recently from d9436bc to fac881d Compare October 21, 2015 23:10
@kinke
Copy link
Member Author

kinke commented Oct 22, 2015

It finally seems to be working now (except for the 32-bit tests). The front-end hack is ugly and can't be incorporated as-is, but I guess the proper location to fix it is the upstream front-end.

@kinke kinke force-pushed the noReverse branch 2 times, most recently from fd28980 to 4c21b9b Compare October 26, 2015 13:59
@kinke
Copy link
Member Author

kinke commented Oct 26, 2015

Upstream PR: dlang/dmd#5232

kinke added 3 commits November 2, 2015 19:18
To make sure the arguments order (p, q) isn't reversed.

This is necessary as the TypeInfo_Struct's function pointers `xopEquals`
and `xopCmp` normally map to the struct's `opEquals`/`opCmp` methods,
for which lhs `p` must be passed as `this` argument before rhs `q`.

These __ wrappers are only generated if the method doesn't take its single
argument by reference.
@kinke
Copy link
Member Author

kinke commented May 17, 2022

Closing because this has finally been implemented in v1.29.

@kinke kinke closed this May 17, 2022
@kinke kinke deleted the noReverse branch May 17, 2022 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant