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
compile druntime with -preview=dip1021 #16390
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#16390" |
Failing due to:
I'll look into that. |
88803a1
to
a52a7a8
Compare
I'm baffled by:
I don't know where the multiple mutable ref is coming from. @jmdavis can you have a look at this, please? |
Does dip1021 affect signatures? |
@ibuclaw no it does not affect signatures. It only adds additional checks. |
a52a7a8
to
e87bd28
Compare
e87bd28
to
bcbd5ab
Compare
@jmdavis I took a break and came back later, and figured it out. On to the next problem! |
Next problem:
I'll look at that tomorrow. |
57c8e09
to
dfe3e91
Compare
Next problem(s):
|
12a49aa
to
ae71243
Compare
A problem showing up repeatedly is __cmp() should have const parameters, not mutable ones. |
ae71243
to
5bc0b6b
Compare
It's templated so that it can work with both |
Another mysterious failure with no message:
|
@jmdavis the parameters must be const, not just templated to take either. Dip1021 looks to see if two mutable arguments are passed to __cmp(), and fails it if it does, because __cmp() accepts mutable arguments and configures itself to have mutable parameters. |
But In general, requiring any particular attribute causes problems even if a particular attribute makes sense in most cases. I don't know what needs to happen here with what you're trying to do with DIP 1021, but it's going to be a problem if |
__cmp can cast away const in its call to opCmp. (Even if not using the borrow checker, the rule of only one mutable reference to the same object is good style.) |
Okay, but then what if And sure, it may be good in general to not be passing multiple mutable references to the same object to a function, but that's going to be inevitable at least some of the time when you start dealing with stuff like generic code or with references to the same object where you don't know that they're reference to the same object. And it's expected that stuff like the comparison operators work when the same object is on both sides of the comparison. |
Yes. And it's the only way forward. opCmp was put in long before const appeared. Having comparison mutate state is just as broken if a cast is not required to match the function prototype. |
We cannot be requiring It's quite reasonable for a function like And in the general case, IMHO, if So, if this DIP is going to require that |
There is a difference between state and memory representation of said state. For example, consider data structures with amortized runtime guarantees. They necessarily have to restructure the internal representation even for queries, even though the logically represented data does not change. |
Should the usual comparison function mutate state? No. Should we disallow functions that for some reason need to? I don't think so. Should the answer to those rare cases that need it be "it's ok, go break the type system"? I don't think so. |
@atilaneves the problem is that Object.opCmp takes mutable parameters, and a const class object cannot be passed to it. The same problem exists for Object.toString(), Object.toHash(), and Object.opEquals(). @andralex and I have talked about this for years, and have been unable to come up with a solution that doesn't disrupt everything. But I finally found one! With an edition, have the compiler internally rewrite those declarations (and their overrides) to be const, but don't change the name mangling. A hack, but it ought to work. |
The core problem is that we cannot require that these functions work as The partial solution that's currently in-place is that the free function Regardless, we cannot be requiring |
@jmdavis thank you for your reasoned analysis. It is off topic for the PR, so I request reposting your comment in the n.g. I already opened a thread for it. Thanks! |
I have a few errors on druntime side, I found here at Weka by trying out |
https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md
This adds some important checks:
Given the following:
The compiler gives:
when the
-preview=dip1021
switch is used. C++ is moving in this direction (Nick Treveaven).