Files
swift-mirror/test/SILOptimizer/devirt_base_class.swift
Erik Eckstein 65e4c10113 Optimizer: remove the obsolete SpeculativeDevirtualization pass
This pass has been disabled since a very long time (because it's terrible for code size).
It does not work for OSSA. Therefore it cannot be enabled anymore (as is) once we have OSSA throughout the pipeline.
So it's time to completely remove it.
2025-10-13 10:49:17 +02:00

75 lines
1.3 KiB
Swift

// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s
public class Base1 { @inline(never) func f() -> Int { return 0 } }
public class Base2: Base1 {
}
private class A: Base2 { }
private class B : A {
@inline(never) override func f() -> Int { return 1 }
}
private class C : A {
@inline(never) override func f() -> Int { return 2 }
}
@inline(never)
private func foo(_ a: A) -> Int {
// Check that a.f() call can be devirtualized, even
// though f is defined by one of the A's superclasses.
//
// CHECK-LABEL: sil private [noinline] @{{.*}}foo
// This used to check speculative-devirtualization, which we don't have anymore.
// CHECK: class_method
return a.f()
}
// Check that invocation of addConstraint() gets completely devirtualized and inlined
//
// CHECK-LABEL: sil private [noinline] @$s17devirt_base_class2F233_{{.*}}4test
// CHECK-NOT: class_method
// CHECK-NOT: function_ref
// CHECK: return
print("foo(C()) = \(foo(C()))")
private class F1 {
init() {
}
func addConstraint() {
addToGraph()
}
func addToGraph() {
}
}
private class F2 : F1 {
init (v : Int) {
super.init()
addConstraint()
}
override func addToGraph() {
}
@inline(never)
func test() {
addConstraint()
}
}
private class F3 : F2 {
}
private var f = F2(v:1)
f.test()
print("unary constraint is: \(f)")