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
Getting rid of "out" params in order to use ValueTuple / Nullability #12729
Comments
out
params in order to use ValueTuple / Nullability
And your suggestion would be a huge breaking change. |
No, they are not. The out reference itself may be in a register but the actual value has to be in memory, you can't have a reference to a register.
That depends on the struct and the calling convention. A
No, it's the other way around.
I don't see what's good about your suggestion. The language was specifically improved to make What you're suggesting requires an option type and language support for that. Without that, it's just a different and IMO worse way to do what you can already do today. In any case, API suggestions belong in the corefx repository. Language suggestions belong in the csharplang repository. |
Oh, I simplified too much, so it got really inprecise and incorrect (which I didn't notice while writing). Thanks precising and correcting that!
I definitely beliefe you, but out of interest: |
There definitely are issues with the way the JIT handle struct returns. It's enough to look at the simple case of 33C0 xor eax, eax
8944242C mov dword ptr [rsp+2CH], eax
C744242C2A000000 mov dword ptr [rsp+2CH], 42
C644242801 mov byte ptr [rsp+28H], 1
488B442428 mov rax, qword ptr [rsp+28H] But issues like this are solvable.
Yes, it needs to go to memory and not only for the duration of the call - once passed via int sum = 0;
for (int i = 0; i < 100; i++)
sum += i;
return sum; generates G_M55886_IG03:
03C2 add eax, edx
FFC2 inc edx
83FA64 cmp edx, 100
7CF7 jl SHORT G_M55886_IG03 now [MethodImpl(MethodImplOptions.NoInlining)]
static void log(ref int value) { }
int sum = 0;
log(ref sum);
for (int i = 0; i < 100; i++)
sum += i;
return sum; generates G_M55886_IG03:
8BD0 mov edx, eax
03542420 add edx, dword ptr [rsp+20H]
89542420 mov dword ptr [rsp+20H], edx
FFC0 inc eax
83F864 cmp eax, 100
7CEF jl SHORT G_M55886_IG03 This issue is more difficult to solve:
In contrast, structs that are not returned in register are returned via an hidden That said, this should not give anyone the impression that struct returns are necessarily better. In fact I'd argue that they're worse in a certain way - consistency. The way a struct is returned depends on the struct and the calling convention. At least with |
@mikedn thank you! 👍 |
https://github.com/dotnet/coreclr/blob/9773db1e7b1acb3ec75c9cc0e36bd62dcbacd6d5/src/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs#L9-L81
Why cannot we repalce all those
out
params with for example ValueTuples or Nullability?Current approach:
My suggestion:
A:
B:
A:
B:
I think it'd:
Made old code being more maintainable by updating old code to "modern standards"
We'd be able to get rid of side effects functions
How it'd affect performance?
The text was updated successfully, but these errors were encountered: