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-990] Unable to eliminate force cast with known type #43602

Open
ddunbar opened this issue Mar 19, 2016 · 0 comments
Open

[SR-990] Unable to eliminate force cast with known type #43602

ddunbar opened this issue Mar 19, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself performance

Comments

@ddunbar
Copy link
Contributor

ddunbar commented Mar 19, 2016

Previous ID SR-990
Radar None
Original Reporter @ddunbar
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Performance
Assignee None
Priority Medium

md5: d4c71e79aeff2734b27fd87267021530

Issue Description:

Swift 3 is unable to optimize f1() down to the trivial function here, even though it should be statically inferable that the cast always succeeds:

private protocol P {
    static func foo() -> P
}
private extension P {
    static func foo2<T: P>() -> T {
        return foo() as! T
    }
}

private class A: P {
    func hi() {}
    
    static func foo() -> P {
        return A()
    }
}
private class B: A {
}

private func f0<T: P>(type: T.Type) -> T {
    return T.self.foo2()
}

func f1() {
    f0(A.self).hi()
}

I only tested with an older Swift 3:
Apple Swift version 3.0-dev (LLVM a7663bb722, Clang 4ca3c7fa28, Swift 1c2f40e)

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself performance
Projects
None yet
Development

No branches or pull requests

1 participant