Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
zoecarver committed Nov 3, 2019
1 parent bfb3dd7 commit 287bbd4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/SILOptimizer/devirtualize_protocol_composition.swift
@@ -0,0 +1,31 @@
// RUN: %target-swift-frontend -parse-as-library -O -wmo -emit-sil %s | %FileCheck %s
// RUN: %target-swift-frontend -parse-as-library -Osize -wmo -emit-sil %s | %FileCheck %s

// This is an end-to-end test to ensure that the optimizer devertualizes
// calls to a protocol composition type.

public class ClassA<T> { }

protocol ProtocolA {
func foo() -> Int
}

func shouldOptimizeWitness<T>(_ x: ClassA<T> & ProtocolA) -> Int {
return x.foo()
}

public class ClassB: ClassA<String> {
func foo() -> Int {
return 10
}
}
extension ClassB: ProtocolA { }

//CHECK: witnessEntryPoint
//CHECK-NOT: init_existential_ref
//CHECK-NOT: open_existential_ref
//CHECK-NOT: witness_method
//CHECK: return
public func witnessEntryPoint(c: ClassB) -> Int {
return shouldOptimizeWitness(c)
}

0 comments on commit 287bbd4

Please sign in to comment.