Skip to content

[Optimization] Detuple branch results #8953

Closed

Description

@NinoFloris

https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChjjgFsUAPACgEoUBeYlVlcyjFeplAZlJE27CtwCGAGgBGDRihZsFw1gEswKACJjcAFRV4EAOgByMAO6GtXAHwoAjCmwALZPKHKPGehJQAmJcoIwBAIbh4evj5edILCYigA1ChSQA==

open System

let x() =
    let y () = 3

    let (a,b) =     
        if DateTime.Now.Day > 1 then 
            y(), 2
        else 
            2, y()

    a + b

I would expect a direct tuple/detuple in a binding, like the above, to be rewritten to mutable a and b mutated directly from their branches.

In cases where detupling is successful (example of a case below) the entire function compiles down to the result of a + b.

let x() =
    let y () = 3

    let (a,b) = 
        y(), 2
    
    a + b

Related:
dotnet/coreclr#21950

Activity

  1. kerams commented on Jul 14, 2021

    @kerams
    Contributor

    This is done and can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions