Files
swift-mirror/test/SILOptimizer/devirtualize_protocol_composition.swift
Josh Soref 730b16c569 Spelling siloptimizer
* access
* accessed
* accesses
* accessor
* acquiring
* across
* activated
* additive
* address
* addresses'
* aggregated
* analysis
* and
* appropriately
* archetype
* argument
* associated
* availability
* barriers
* because
* been
* beginning
* belongs
* beneficial
* blocks
* borrow
* builtin
* cannot
* canonical
* canonicalize
* clazz
* cleanup
* coalesceable
* coalesced
* comparisons
* completely
* component
* computed
* concrete
* conjunction
* conservatively
* constituent
* construct
* consuming
* containing
* covered
* creates
* critical
* dataflow
* declaration
* defined
* defining
* definition
* deinitialization
* deliberately
* dependencies
* dependent
* deserialized
* destroy
* deterministic
* deterministically
* devirtualizes
* diagnostic
* diagnostics
* differentiation
* disable
* discipline
* dominate
* dominates
* don't
* element
* eliminate
* eliminating
* elimination
* embedded
* encounter
* epilogue
* epsilon
* escape
* escaping
* essential
* evaluating
* evaluation
* evaluator
* executing
* existential
* existentials
* explicit
* expression
* extended
* extension
* extract
* for
* from
* function
* generic
* guarantee
* guaranteed
* happened
* heuristic
* however
* identifiable
* immediately
* implementation
* improper
* include
* infinite
* initialize
* initialized
* initializer
* inside
* instruction
* interference
* interferes
* interleaved
* internal
* intersection
* intractable
* intrinsic
* invalidates
* irreducible
* irrelevant
* language
* lifetime
* literal
* looks
* materialize
* meaning
* mergeable
* might
* mimics
* modification
* modifies
* multiple
* mutating
* necessarily
* necessary
* needsmultiplecopies
* nonetheless
* nothing
* occurred
* occurs
* optimization
* optimizing
* original
* outside
* overflow
* overlapping
* overridden
* owned
* ownership
* parallel
* parameter
* paths
* patterns
* pipeline
* plottable
* possible
* potentially
* practically
* preamble
* precede
* preceding
* predecessor
* preferable
* preparation
* probably
* projection
* properties
* property
* protocol
* reabstraction
* reachable
* recognized
* recursive
* recursively
* redundant
* reentrancy
* referenced
* registry
* reinitialization
* reload
* represent
* requires
* response
* responsible
* retrieving
* returned
* returning
* returns
* rewriting
* rewritten
* sample
* scenarios
* scope
* should
* sideeffects
* similar
* simplify
* simplifycfg
* somewhat
* spaghetti
* specialization
* specializations
* specialized
* specially
* statistically
* substitute
* substitution
* succeeds
* successful
* successfully
* successor
* superfluous
* surprisingly
* suspension
* swift
* targeted
* that
* that our
* the
* therefore
* this
* those
* threshold
* through
* transform
* transformation
* truncated
* ultimate
* unchecked
* uninitialized
* unlikely
* unmanaged
* unoptimized key
* updataflow
* usefulness
* utilities
* villain
* whenever
* writes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-10-03 18:31:33 -04:00

141 lines
2.7 KiB
Swift

// 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
// REQUIRES: objc_interop
// This is an end-to-end test to ensure that the optimizer devirtualizes
// calls to a protocol composition type.
public class ClassA<T> { }
protocol ProtocolA {
func foo() -> Int
}
protocol ProtocolB {
func bar() -> Int
}
public class ClassB: ClassA<String> {
func foo() -> Int {
return 10
}
}
extension ClassB: ProtocolA { }
public class ClassC<T>: ClassA<T> {
func foo() -> Int {
return 10
}
}
extension ClassC: ProtocolA { }
public class ClassD { }
public class ClassE : ClassD {
func foo() -> Int {
return 10
}
}
extension ClassE: ProtocolA { }
public class ClassF {
func foo() -> Int {
return 10
}
func bar() -> Int {
return 10
}
}
extension ClassF: ProtocolA, ProtocolB { }
public class ClassG <T> {
func foo() -> Int {
return 10
}
func bar() -> Int {
return 10
}
}
extension ClassG: ProtocolA, ProtocolB { }
public class ClassH {
typealias type = ClassD
}
func shouldOptimize1<T>(_ x: ClassA<T> & ProtocolA) -> Int {
return x.foo()
}
func shouldOptimize2(_ x: ClassD & ProtocolA) -> Int {
return x.foo()
}
func shouldOptimize3(_ x: ProtocolA & ProtocolB) -> Int {
return x.foo() + x.bar()
}
func shouldOptimize4(_ x: ProtocolA & ProtocolB) -> Int {
return x.foo() + x.bar()
}
func shouldOptimize5(_ x: ClassH.type & ProtocolA) -> Int {
return x.foo()
}
//CHECK: entryPoint1
//CHECK-NOT: init_existential_ref
//CHECK-NOT: open_existential_ref
//CHECK-NOT: witness_method
//CHECK: return
public func entryPoint1(c: ClassB) -> Int {
return shouldOptimize1(c)
}
// TODO: create SR -- this causes a crash on master too
//public func entryPoint2<T>(c: ClassC<T>) -> Int {
// return shouldOptimize1(c)
//}
//CHECK: entryPoint3
//CHECK-NOT: init_existential_ref
//CHECK-NOT: open_existential_ref
//CHECK-NOT: witness_method
//CHECK: return
public func entryPoint3(c: ClassE) -> Int {
return shouldOptimize2(c)
}
//CHECK: entryPoint4
//CHECK-NOT: init_existential_ref
//CHECK-NOT: open_existential_ref
//CHECK-NOT: witness_method
//CHECK: return
public func entryPoint4(c: ClassF) -> Int {
return shouldOptimize3(c)
}
//CHECK: entryPoint5
//CHECK-NOT: init_existential_ref
//CHECK-NOT: open_existential_ref
//CHECK-NOT: witness_method
//CHECK: return
public func entryPoint5<T>(c: ClassG<T>) -> Int {
return shouldOptimize4(c)
}
//CHECK: entryPoint6
//CHECK-NOT: init_existential_ref
//CHECK-NOT: open_existential_ref
//CHECK-NOT: witness_method
//CHECK: return
public func entryPoint6(c: ClassE) -> Int {
return shouldOptimize5(c)
}