Skip to content

Commit 4ddeba1

Browse files
authored
Merge pull request #16832 from gottesmm/pr-769c02db89f9caceec9c48e9e9f081fe78655b9a
[func-sig-opts][+0->+1] Add a benchmark that requires the optimizer t…
2 parents ad82fe6 + 0629afc commit 4ddeba1

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ set(SWIFT_BENCH_MODULES
110110
single-source/ObserverForwarderStruct
111111
single-source/ObserverPartiallyAppliedMethod
112112
single-source/ObserverUnappliedMethod
113+
single-source/OpaqueConsumingUsers
113114
single-source/OpenClose
114115
single-source/PartialApplyDynamicType
115116
single-source/Phonebook
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//===--- OpaqueConsumingUsers.swift ---------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
public let OpaqueConsumingUsers = BenchmarkInfo(
16+
name: "OpaqueConsumingUsers",
17+
runFunction: run_OpaqueConsumingUsers,
18+
tags: [.regression, .abstraction, .refcount],
19+
setUpFunction: setup_OpaqueConsumingUsers)
20+
21+
// This test exercises the ability of the optimizer to propagate the +1 from a
22+
// consuming argument of a non-inlineable through multiple non-inlinable call
23+
// frames.
24+
//
25+
// We are trying to simulate a user application that calls into a resilient
26+
// setter or initialization. We want to be able to propagate the +1 from the
27+
// setter through the app as far as we can.
28+
29+
class Klass {}
30+
31+
class ConsumingUser {
32+
var _innerValue: Klass = Klass()
33+
34+
var value: Klass {
35+
@inline(never) get {
36+
return _innerValue
37+
}
38+
@inline(never) set {
39+
_innerValue = newValue
40+
}
41+
}
42+
}
43+
44+
var data: Klass? = nil
45+
var user: ConsumingUser? = nil
46+
47+
func setup_OpaqueConsumingUsers() {
48+
switch (data, user) {
49+
case (let x?, let y?):
50+
let _ = x
51+
let _ = y
52+
return
53+
case (nil, nil):
54+
data = Klass()
55+
user = ConsumingUser()
56+
default:
57+
fatalError("Data and user should both be .none or .some")
58+
}
59+
}
60+
61+
@inline(never)
62+
func callFrame1(_ data: Klass, _ user: ConsumingUser) {
63+
callFrame2(data, user)
64+
}
65+
66+
@inline(never)
67+
func callFrame2(_ data: Klass, _ user: ConsumingUser) {
68+
callFrame3(data, user)
69+
}
70+
71+
@inline(never)
72+
func callFrame3(_ data: Klass, _ user: ConsumingUser) {
73+
callFrame4(data, user)
74+
}
75+
76+
@inline(never)
77+
func callFrame4(_ data: Klass, _ user: ConsumingUser) {
78+
user.value = data
79+
}
80+
81+
@inline(never)
82+
public func run_OpaqueConsumingUsers(_ N: Int) {
83+
let d = data._unsafelyUnwrappedUnchecked
84+
let u = user._unsafelyUnwrappedUnchecked
85+
for _ in 0..<N*200000 {
86+
callFrame4(d, u)
87+
}
88+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import ObserverClosure
9797
import ObserverForwarderStruct
9898
import ObserverPartiallyAppliedMethod
9999
import ObserverUnappliedMethod
100+
import OpaqueConsumingUsers
100101
import OpenClose
101102
import PartialApplyDynamicType
102103
import Phonebook
@@ -255,6 +256,7 @@ registerBenchmark(ObserverClosure)
255256
registerBenchmark(ObserverForwarderStruct)
256257
registerBenchmark(ObserverPartiallyAppliedMethod)
257258
registerBenchmark(ObserverUnappliedMethod)
259+
registerBenchmark(OpaqueConsumingUsers)
258260
registerBenchmark(OpenClose)
259261
registerBenchmark(PartialApplyDynamicType)
260262
registerBenchmark(Phonebook)

0 commit comments

Comments
 (0)