Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 11591 (std.typecons.Tuple regression) by workarounding Issue 11557. #1707

Closed
wants to merge 1 commit into from

Conversation

denis-sh
Copy link
Contributor

return field[i] < rhs.field[i] ? -1 : 1;
// Workaround dmd @@@BUG11557@@@
static if(is(Unused == class))
return cast() field[i] < cast() rhs.field[i] ? -1 : 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semi on topic, but is this kind of cast documented? I couldn't find it any? I think it basically casts away the qualifiers? It's the same as cast(Unqual!(typeof(arg))(arg); ? Or are there more subtleties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is documented. Just search for cast() at cast documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I couldn't find it. I get it now. I was actually wondering how to make a qualified cast to "no qualification", I have my answer. Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "correct" cast should be cast(Type[i]): cast() strips all qualifiers, regardless of what the original qualifiers on the type were. Currently, Tuples don't support const fields, but they could. Furthermore, they currently do support shared fields, so that shouldn't be stripped away when calling opCmp.

@denis-sh
Copy link
Contributor Author

This fixes a nasty regression. Pull as soon as possible please.

@monarchdodra
Copy link
Collaborator

This fixes a nasty regression.

What regression? This hasn't been working for as far back as 2.060 (haven't checked any further). Could you show which you are thinking about exactly?

Pull as soon as possible please.

I'm concerned about the const casting you are doing here. If the types in the type tuple can't be ordered when const, then I don't see why it would be expected for the tuple itself to be order-able. There is really nothing that justifies that the cast is safe.

@denis-sh
Copy link
Contributor Author

What regression?

At least year ago Tuples worked as associative array keys.

I'm concerned about the const casting you are doing here.

It is needed because of druntime Issue 1824. And dmd already calls opEquals on const objects so the fact opCmp doesn't work is inconsistent, see Issue 11557.

@monarchdodra
Copy link
Collaborator

At least year ago Tuples worked as associative array keys.

Right... Array keys :/ I was testing them as values. My bad. Indeed, that is a regression.

It is needed because of druntime.

I get what you are trying to bypass, I'm pointing out it is also breaking the type system.

so the fact opCmp doesn't work is inconsistent.

Right, but inconsistency/bugs isn't an excuse to introduce more inconsistency, bugs elsewhere.


That said, this bug seems to be pretty nasty indeed, so I think it there is a net gain to doing this.

@9rnsr
Copy link
Contributor

9rnsr commented Nov 21, 2013

Today, const class types cannot become key of AAs. Therefore Tuple of const class should also be impossible to become key of AAs. It is correct behavior from type system.

We should be careful to add specific workaround in Phobos or druntime, because they are core parts of D language.
Note that, accepting essentially incorrect code today, will increase future incorrect user code. Breaking it in the future would be very very difficult.

From the long-term view, I think that keeping the current broken behavior would have certain amount benefit, that will make easy to fix language in near the future.

@denis-sh
Copy link
Contributor Author

I filed Issue 11591 for std.typecons.Tuple regression.

We should be careful to add specific workaround in Phobos or druntime, because they are core parts of D language.
Note that, accepting essentially incorrect code today, will increase future incorrect user code. Breaking it in the future would be very very difficult.

Tuple regression is for unqualified tuples, see example from Comment 1 of Issue 11591. Sorry for bad unittest, it managed to misguide even myself when filing the issue.

Today, const class types cannot become key of AAs. Therefore Tuple of const class should also be impossible to become key of AAs. It is correct behavior from type system.

Actually they can, filed Issue 11589. Also any uncomparable type can, filed Issue 11590. And finally associative arrays work with unoverriden toHash/opEquals/opCmp, Issue 10374.

From the long-term view, I think that keeping the current broken behavior would have certain amount benefit, that will make easy to fix language in near the future.

Nop. Runtime failures because of type system has no excuse. Make it compile-time at least. As for current situation with class comparison IMO we should solve inconsistency first, e.g. Issue 11588 and Issue 11592.

@denis-sh
Copy link
Contributor Author

Right, but inconsistency/bugs isn't an excuse to introduce more inconsistency, bugs elsewhere.

Is it possible to add more inconsistency in D associative arrays? It's really obscure what the hell it is doing in the language and runtime complicating supporter lives instead of just being a regular library collection.

@denis-sh
Copy link
Contributor Author

denis-sh commented Jul 9, 2014

_AA_s fixed now.

@denis-sh denis-sh closed this Jul 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants