fix covariant behavior with 'return scope'#6429
Conversation
107211c to
a7f4281
Compare
src/mtype.d
Outdated
| static uint combine(uint from, uint to) pure nothrow @nogc @safe | ||
| { | ||
| return (from << 2) | to; | ||
| } |
There was a problem hiding this comment.
You could move the translation into the combine instead of introducing another enum.
combine(STCreturn | STCscope, 0)
The cases are CTFE'ed anyhow.
| return (from << 2) | to; | ||
| } | ||
|
|
||
| /* result is true if the 'from' can be used as a 'to' |
There was a problem hiding this comment.
The useful we can add scope, but not subtract it, we can subtract return but not add it comments got lost.
|
What is this fixing ? There's neither description nor a test case. |
That's why I marked it as "needs work". I'm working on finding a way to resolve an ambiguity I discovered, and needed to know what the existing test suite thought of my changes. |
28753f1 to
6916abc
Compare
|
@MartinNowak what's going on with the cycle detection in druntime? |
|
Blocking dlang/druntime#1733 |
|
With this, druntime now compiles without changes with |
| * returnByRef = true if the function returns by ref | ||
| * stc = storage class of parameter | ||
| */ | ||
| static uint buildSR(bool returnByRef, StorageClass stc) pure nothrow @nogc @safe |
There was a problem hiding this comment.
It seems the coverage data is messed up - the enums further on are not executable code.
| covariant[SR.Ref ][SR.ReturnRef] = true; | ||
| covariant[SR.ReturnRef_Scope][SR.ReturnRef] = true; | ||
| covariant[SR.Ref_ReturnScope][SR.Ref ] = true; | ||
| covariant[SR.Ref_ReturnScope][SR.ReturnRef] = true; |
There was a problem hiding this comment.
You're introducing a constructor cycles here.
./dmd/src/dmd -c -o- main --DRT-oncycle=print 20:19:50
Cyclic dependency between module ddmd.traits and ddmd.mtype
ddmd.traits* ->
ddmd.mtype* ->
ddmd.expression ->
ddmd.traits*
There was a problem hiding this comment.
You should be able to run this in CTFE instead of in a constructor.
There was a problem hiding this comment.
Thanks. I thought the error came from running one of the test programs, not the compiler itself. But there's nothing platform specific there - why is the error happening only one some platforms?
| covariant[SR.Ref ][SR.ReturnRef] = true; | ||
| covariant[SR.ReturnRef_Scope][SR.ReturnRef] = true; | ||
| covariant[SR.Ref_ReturnScope][SR.Ref ] = true; | ||
| covariant[SR.Ref_ReturnScope][SR.ReturnRef] = true; |
There was a problem hiding this comment.
You should be able to run this in CTFE instead of in a constructor.
Good idea. Done. |
6916abc to
d1ead46
Compare
|
Always confuses me that |
|
I never remember which is which, either. |
|
As it's an ordering relation (e.g. subtype) the same comparison operator can be used for both, just that covariant checks |
This is a significantly better way to check for covariance of function parameters that have combinations of
ref,returnandscope. It's reduced to an enumeration of 8 cases inenum SRwhich then gets fed into a matrixcovariant[][]to produce a yay or nay on covariance.It makes it feasible to reason about this without the various bits of it scattered all through the code.