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-12710] Static use of existentials not optimized #55155

Closed
dabrahams opened this issue Apr 30, 2020 · 3 comments
Closed

[SR-12710] Static use of existentials not optimized #55155

dabrahams opened this issue Apr 30, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-12710
Radar rdar://problem/62894035
Original Reporter @dabrahams
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Performance
Assignee None
Priority Medium

md5: 355d50717c62db9585ae76fe498472da

Issue Description:

In this example,

protocol P { associatedtype A = Int }
protocol Q : P {}

protocol B { var x: Int { get } }
struct Y<T> {}
extension Y : B where T : Q { var x: Int { 0 }}

extension P {
  var z: Int? { (Y<Self>() as? B)?.x }
}

struct X : Q {
  var testMe: Int? { z }
}

The code generated for `testMe` should compile to the equivalent of `return 0`. Instead we get:

x.X.testMe.getter : Swift.Int?:
    .cfi_startproc
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register %rbp
    pushq   %r15
    pushq   %r14
    pushq   %r13
    pushq   %rbx
    subq    $48, %rsp
    .cfi_offset %rbx, -48
    .cfi_offset %r13, -40
    .cfi_offset %r14, -32
    .cfi_offset %r15, -24
    leaq    demangling cache variable for type metadata for x.Y<x.X>(%rip), %rdi
    callq   ___swift_instantiateConcreteTypeFromMangledName
    movq    %rax, %r14
    movq    %rax, -48(%rbp)
    callq   lazy protocol witness table accessor for type x.Y<x.X> and conformance <A where A: x.Q> x.Y<A> : x.B in x
    movq    %rax, %rbx
    movq    %rax, -40(%rbp)
    leaq    -72(%rbp), %r15
    movq    %r15, %rdi
    movq    %r14, %rsi
    callq   ___swift_project_boxed_opaque_existential_1
    movq    %rax, %r13
    movq    %r14, %rdi
    movq    %rbx, %rsi
    callq   *8(%rbx)
    movq    %rax, %rbx
    movq    %r15, %rdi
    callq   ___swift_destroy_boxed_opaque_existential_1
    movq    %rbx, %rax
    xorl    %edx, %edx
    addq    $48, %rsp
    popq    %rbx
    popq    %r13
    popq    %r14
    popq    %r15
    popq    %rbp
    retq
    .cfi_endproc
@beccadax
Copy link
Contributor

beccadax commented May 5, 2020

@swift-ci create

@eeckstein
Copy link
Member

#32267

I hope that this time it's complete.

@dabrahams
Copy link
Collaborator Author

From looking at the results of our Swift for Tensorflow toolchain, it appears to be fixed! The fix didn't make it into Swift 5.3, FWIW.

See also SR-13438

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 in itself performance
Projects
None yet
Development

No branches or pull requests

3 participants