Make -preview=in means [ref] const scope and accept rvalues#11000
Make -preview=in means [ref] const scope and accept rvalues#11000dlang-bot merged 2 commits intodlang:masterfrom
-preview=in means [ref] const scope and accept rvalues#11000Conversation
|
Thanks for your pull request, @Geod24! 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#11000" |
|
I think the optimal solution would be either |
|
@kinke : I agree. However, why limit it to |
|
I think this takes too much control away from the programmer. What if I don't want to pass by ref? Sure, I could declare |
You mean Limited to Edit: The opposite direction, passing some suited by-value args by-ref under the hood, was discussed in lengthy https://forum.dlang.org/thread/oipegxuwqmrmmzefrqcx@forum.dlang.org, and later in a mailing list with Walter. That'd work with mutable params too, but it's not trivial. |
|
Not sure if this is the best place to leave this, but Herb Sutter's preliminary proposal seems related. Basically, he says the programmer should specify intent (read only, output parameter, etc) and the compiler should choose whether things are passed by pointer or value and ensure legal usage: https://www.youtube.com/watch?v=qx22oxlQmKc&t=3454s |
|
@kinke : Good point, I didn't think about taking the address of it. And things like fiber context switch would make that visible to the user, even if
It doesn't take any control away. One is still free to apply the storage classes as one see fit. It doesn't restrict what can be done. However, it makes it easy to do the right thing by default. You have an input parameter, you put Regarding move semantic, what @kinke said. The code generated by DMD is terrible, and uncontrollable (you can't prevent a struct being moved). Over the past two years, we've seen work in that direction: The abstract of that last link directly mention copy elision as a goal for the DIP. |
-preview=in means ref const scope-preview=in means [ref] const scope and accept rvalues
00cbd58 to
4a59fea
Compare
36a8c78 to
129b874
Compare
|
Tests with my projects pass. Going to extend the usage of |
|
Wow this is a big one. We should have left a Prefix character for mangle extensions .... |
As explained in details in dlang/dmd#11000 and dlang/dmd#11474, 'in' has been for a very long time lowered to simply 'const', or 'scope const' when v2.092.0's '-preview=in' switch is used. DMD PR 11474 aims to change this, so 'in' is not (visibly) lowered, and shows up in any user-visible string. This includes header generation, error messages, and stringof. Since this code was testing stringof directly, it is affected by the change. To support testing of both aforementioned DMD PRs, the change is not tied to a version, but uses the (soon-to-be) old way as a fallback.
|
Great, a Windows-only SEGV creeping in... |
|
I told you so: #11000 (comment) due to Lines 558 to 559 in de995df |
|
Ah I missed that comment. So, any suggestion ? |
|
IMO, just leave proper ABI handling to a follow-up. |
|
Works for me, reverted to the size check |
Right, the intent be fine though. Just having a guess though. |
As explained in the changelog entry, this puts `in` more in line with its intended meaning, that of an input parameter. The compiler should be free to decide whether or not an input parameter is passed by value or by ref. Additionally, building on the rationale for rejecting DIP1016, this adds the ability to accept rvalues for `in` parameter, and deprecate the switch that was introduced for the rejected DIP.
|
All green again. |
|
Wonderful! |
'in' and 'in ref' overloads will conflict in the future if dlang/dmd#11000 is accepted. Even if not, 'in' currently means something different based on a switch, however the intention of this code is obviously the full 'const scope'. In the some places, 'scope' was omitted as it is meaningless on value types.
This is the promised follow-up on dlang#11000 and makes DMD exploit the specifics of the few supported ABIs (Win64, SysV x86_64, 32-bit x86). It also almost perfectly matches the proposed LDC implementation in ldc-developers/ldc#3578 (just a minor divergence for Win64 and dynamic arrays, but in that point the LDC and DMD Win64 ABI diverges in general).
This is the promised follow-up on dlang#11000 and makes DMD exploit the specifics of the few supported ABIs (Win64, SysV x86_64, 32-bit x86). It also almost perfectly matches the proposed LDC implementation in ldc-developers/ldc#3578 (just a minor divergence for Win64 and dynamic arrays, but in that point the LDC and DMD Win64 ABI diverges in general).
This is the promised follow-up on dlang#11000 and makes DMD exploit the specifics of the few supported ABIs (Win64, SysV x86_64, 32-bit x86). It also almost perfectly matches the proposed LDC implementation in ldc-developers/ldc#3578 (just a minor divergence for Win64 and dynamic arrays, but in that point the LDC and DMD Win64 ABI diverges in general).
This is the promised follow-up on dlang#11000 and makes DMD exploit the specifics of the few supported ABIs (Win64, SysV x86_64, 32-bit x86). It also almost perfectly matches the proposed LDC implementation in ldc-developers/ldc#3578 (just a minor divergence for Win64 and dynamic arrays, but in that point the LDC and DMD Win64 ABI diverges in general).

Needs test, I know, and won't pass the CI because druntime has scope
const scopeinheritingin.But before I dig into making this work, I'd like to start the discussion on the concept itself.
The goal is to make
inthe "go to" type for input parameter. I had this in mind for a long time, and discussed it with @JinShil on some occasions.Now that
-preview=inhas been merged ( #10769 ), I figured it would be the right time to introduce it, hoping to get his approved before the next release.CC @atilaneves @WalterBright