Issue 14948 - [Reg 2.068.0] AA key requirement was broken w/o notice and w/ horrible error message
Summary: [Reg 2.068.0] AA key requirement was broken w/o notice and w/ horrible error ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2015-08-22 09:31 UTC by Martin Nowak
Modified: 2015-09-07 13:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2015-08-22 09:31:53 UTC
/usr/include/dmd/druntime/import/object.d(1962): Error: AA key type HTTP supports const equality but doesn't support const hashing
/usr/include/dmd/druntime/import/object.d(1968): Error: AA key type HTTP supports const equality but doesn't support const hashing

First of all this should have been a warning or deprecation, not directly an error.
Then it definetely should have been mentioned in the changelog.
And finally the error message doesn't give me a clue which one out of 1000 LOCs program (https://github.com/braddr/downloads.dlang.org/tree/master/src) caused the error.
Comment 1 Kenji Hara 2015-08-25 04:23:03 UTC
The reproduce case I can guess (HTTP is a struct in std.net.curl):

void main()
{
    import std.net.curl;
    int[HTTP] aa;
}

The error message "AA key type X supports const equality but doesn't support const hashing" has introduced from 2.066.

http://dlang.org/changelog/2.066.0.html#aa-key-requirement

If a struct has elaborate equality but doesn't have corresponding hash calculation, the error will be reported to avoid silent AA behavior breaking.

When we change the requirement for AA key from ordering to equality, we decided to change everything at once. Therefore no deprecation pass had been introduced there.

In 2.068, issue 14806 has been fixed. HTTP struct is defined as follows:

struct HTTP {
    ...
    private RefCounted!Impl p;
}

By that bug fix, it's silently changed to a struct which has elaborate field-wise equality without corresponding toHash method.

In short, it's a problem in the definition of HTTP struct. It had had to be detected and fixed before the 2.066 release, but unfortunately it wasn't.
Comment 2 Kenji Hara 2015-08-25 04:23:24 UTC
Changed to Phobos issue.
Comment 3 Steven Schveighoffer 2015-08-25 11:26:57 UTC
I think there are 2 separate issues here:

1. HTTP struct is not correct
2. Error message is horrible, we need to know where the AA was instantiated to be able to fix this.

Can we have an issue for each?
Comment 4 Kenji Hara 2015-08-31 11:02:49 UTC
(In reply to Steven Schveighoffer from comment #3)
> 2. Error message is horrible, we need to know where the AA was instantiated
> to be able to fix this.

With my reduced test case, the error message prints line 4, it's where the AA type int[HTTP] is declared.
Comment 5 Kenji Hara 2015-08-31 11:06:24 UTC
OK, I noticed this is a compiler issue.

Usually D compiler automatically generates toHash member function by using TypeInfo.getHash function. But in particular case it had not worked.


Reduced test case:

struct RefCounted(T)
{
    struct Impl
    {
        T data;
    }
    Impl* impl;

    @property ref T payload() { return impl.data; }

    alias payload this;
}

struct HTTP
{
    struct Impl
    {
    }

    RefCounted!Impl p;
}

void main()
{
    int[HTTP] aa;
}

The root problem is very similar to issue 14806.
Comment 7 github-bugzilla 2015-09-02 09:34:02 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5c1d3c5b63394b7d3758f86a53eace6ffb3d3165
fix Issue 14948 - AA key requirement was broken w/o notice and w/ horrible error message

https://github.com/D-Programming-Language/dmd/commit/880f45dafe5b45951f5b30d188130b32250d6e31
Merge pull request #5001 from 9rnsr/fix14948

[REG2.068] Issue 14948 - AA key requirement was broken w/o notice and w/ horrible error message
Comment 8 github-bugzilla 2015-09-07 13:36:57 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5c1d3c5b63394b7d3758f86a53eace6ffb3d3165
fix Issue 14948 - AA key requirement was broken w/o notice and w/ horrible error message

https://github.com/D-Programming-Language/dmd/commit/880f45dafe5b45951f5b30d188130b32250d6e31
Merge pull request #5001 from 9rnsr/fix14948