Skip to content
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

[SR-12829] Switching over a tuple unnecessarily materializes the tuple #55275

Open
belkadan opened this issue May 18, 2020 · 0 comments
Open
Labels
compiler The Swift compiler in itself improvement

Comments

@belkadan
Copy link
Contributor

Previous ID SR-12829
Radar None
Original Reporter @belkadan
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: a79f917a0c3cfcae0dcddba3f764690b

Issue Description:

Comparing the output of the following two functions, the version that switches over a tuple forms the tuple in memory even though it's never used in aggregate. The compiler should be able to optimize the tuple away completely, since it is only formed, switched upon, and deconstructed.

public func tuple<T: Equatable>(a: T?, b: T?) -> Bool {
    switch (a, b) {
    case (nil, nil): return true
    case (.some(let x), .some(let y)): return x == y
    default: break
    }
    return false
}

public func nested<T: Equatable>(a: T?, b: T?) -> Bool {
    switch a {
    case nil:
        switch b {
        case nil: return true
        default: break
        }
    case .some(let x):
        switch b {
        case .some(let y): return x == y
        default: break
        }
    }
    return false
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

1 participant