-
Notifications
You must be signed in to change notification settings - Fork 797
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
Eliminate tuple allocations when sequential expressions are involved #11296
Conversation
What shape would a test for this take and where would it go? |
Ping, I really need this for a follow-up PR :). |
I think IL/CodeGen tests will be sufficient enough. @TIHan @KevinRansom what do you think? |
So I've added a test on 3 simple functions that makes sure there are no tuples and the order of operations is preserved. Let me know if more complex tests are required (an example would be nice), otherwise this is ready for review. |
Some infrastructure issue with macOS build, gonna restart. |
But net472 and net5 also apparently generate different IL for the |
@cartermp, sorry for the ping. Just want to make sure this has not been forgotten, even if the PR has been ready for barely more than a week. If you're all simply busy, that's cool. |
Apologies for the wait, I'll take a look at this. |
|> shouldSucceed | ||
|> verifyIL [ | ||
|
||
// public static int x() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: commented code should be removed
Or explain why the commented code is there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is there to show the C# representation of the IL below. Thought it would be helpful. Should I still remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks very straight-forward and very cool.
I would add a few more tests, specifically tests that actually require a tuple to be used.
example:
[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>]
let y () = 3
type Test =
[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>]
static member test(x: int32 * int32) = x
let z () =
let a, b =
"".ToString ()
System.DateTime.Now
"3".ToString ()
Test.test(2, y ())
System.DateTime.Now
a + b
[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>]
let y () = 3
type Test =
[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>]
static member test(x: int32 * int32) = x
let z () =
let (a, b) as t =
"".ToString ()
System.DateTime.Now
"3".ToString ()
2, y ()
System.DateTime.Now
let _ = Test.test(t)
a + b
Ok, I've added those two as well as this one, which demonstrates there is no intermediate tuple let v () =
let a, b =
"".ToString () |> ignore
System.DateTime.Now |> ignore
"3".ToString () |> ignore
2L, f ()
System.DateTime.Now |> ignore
a, b The optimization does not kick in in your first example. Since Please let me know if you want to keep the commented out C# code (see comment above), thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing all the feedback!
My pleasure. |
becomes
instead of