Skip to content

Commit 73fc4b2

Browse files
authored
Merge pull request #12976 from eeckstein/remove-semantic
Remove @_semantics("optimize.sil.never")
2 parents 7ec8512 + 76f2815 commit 73fc4b2

22 files changed

+65
-74
lines changed

docs/HighLevelSILOptimizations.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,6 @@ The optimize attribute adds function-specific directives to the optimizer.
352352

353353
The optimize attribute supports the following tags:
354354

355-
sil.never
356-
357-
The sil optimizer should not optimize this function.
358-
359-
Example:
360-
@_semantics("optimize.sil.never")
361-
func miscompile() { ... }
362-
363355
sil.specialize.generic.never
364356

365357
The sil optimizer should never create generic specializations of this function.

lib/SIL/SILFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ OptimizationMode SILFunction::getEffectiveOptimizationMode() const {
178178
}
179179

180180
bool SILFunction::shouldOptimize() const {
181-
return !hasSemanticsAttr("optimize.sil.never") &&
182-
getEffectiveOptimizationMode() != OptimizationMode::NoOptimization;
181+
return getEffectiveOptimizationMode() != OptimizationMode::NoOptimization;
183182
}
184183

185184
Type SILFunction::mapTypeIntoContext(Type type) const {

stdlib/public/SwiftOnoneSupport/SwiftOnoneSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ struct _Prespecialize {
171171
}
172172
}
173173

174-
// Mark with optimize.sil.never to make sure its not get
174+
// Mark with optimize(none) to make sure its not get
175175
// rid of by dead function elimination.
176-
@_semantics("optimize.sil.never")
176+
@_optimize(none)
177177
internal func _swift_forcePrespecializations() {
178178
_Prespecialize._specializeArrays()
179179
_Prespecialize._specializeRanges()

test/IRGen/fixlifetime.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct Agg {
4444
var f : F
4545
}
4646

47-
sil [_semantics "optimize.sil.never"] @test
47+
sil [Onone] @test
4848
: $@convention(thin) (C, P, @callee_owned () -> (), Agg) -> () {
4949
bb0(%0 : $C, %1 : $P, %2 : $@callee_owned () -> (), %3 : $Agg):
5050
fix_lifetime %0 : $C

test/IRGen/lazy_metadata.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ public func needPrivateConformance(_ x: Any) -> Bool {
8080
}
8181

8282
@inline(never)
83-
@_semantics("optimize.sil.never")
83+
@_optimize(none)
8484
func consume1<T>(_ t: T) {
8585
}
8686

8787
@inline(never)
88-
@_semantics("optimize.sil.never")
88+
@_optimize(none)
8989
func consume2<T: Proto>(_ t: T) {
9090
t.abc()
9191
}
9292
@inline(never)
93-
@_semantics("optimize.sil.never")
93+
@_optimize(none)
9494
func consume3(_ p: Proto) {
9595
p.abc()
9696
}
9797
@inline(never)
98-
@_semantics("optimize.sil.never")
98+
@_optimize(none)
9999
func consume4(_ t: StructD) {
100100
t.abc()
101101
}

test/Interpreter/protocol_resilience.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func callBaseRequirement(t: ResilientBaseProtocol) -> Int {
5555
return t.requirement()
5656
}
5757

58-
@_semantics("optimize.sil.never")
58+
@_optimize(none)
5959
func castToDerivedProtocol<T>(t: T) -> Int {
6060
return callBaseRequirement(t: t as! ResilientDerivedProtocol)
6161
}

test/SILOptimizer/closure_specialize_fragile.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import Builtin
88
import Swift
99
import SwiftShims
1010

11-
@_semantics("optimize.sil.never") public func action()
11+
@_optimize(none) public func action()
1212

1313
@inline(__always) public func fragileCaller()
1414

1515
public func resilientCallee(fn: () -> ())
1616

1717
// action()
18-
sil [_semantics "optimize.sil.never"] @_T026closure_specialize_fragile6actionyyF : $@convention(thin) () -> () {
18+
sil [Onone] @_T026closure_specialize_fragile6actionyyF : $@convention(thin) () -> () {
1919
bb0:
2020
%0 = tuple ()
2121
return %0 : $()

test/SILOptimizer/dead_function_elimination.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Derived : Base {
5959
}
6060

6161
@inline(never)
62-
@_semantics("optimize.sil.never") // avoid devirtualization
62+
@_optimize(none) // avoid devirtualization
6363
override func calledWithSuper() {
6464
super.calledWithSuper()
6565
}
@@ -84,21 +84,21 @@ class Other : Derived {
8484
}
8585

8686
@inline(never)
87-
@_semantics("optimize.sil.never") // avoid devirtualization
87+
@_optimize(none) // avoid devirtualization
8888
func testClasses(_ b: Base) {
8989
b.aliveMethod()
9090
}
9191

9292
@inline(never)
93-
@_semantics("optimize.sil.never") // avoid devirtualization
93+
@_optimize(none) // avoid devirtualization
9494
func testWithDerived(_ d: Derived) {
9595
d.baseNotCalled()
9696
d.notInDerived()
9797
d.calledWithSuper()
9898
}
9999

100100
@inline(never)
101-
@_semantics("optimize.sil.never") // avoid devirtualization
101+
@_optimize(none) // avoid devirtualization
102102
func testWithOther(_ o: Other) {
103103
o.notInOther()
104104
}
@@ -143,18 +143,18 @@ struct Adopt : Prot {
143143
}
144144

145145
@inline(never)
146-
@_semantics("optimize.sil.never") // avoid devirtualization
146+
@_optimize(none) // avoid devirtualization
147147
func testProtocols(_ p: Prot) {
148148
p.aliveWitness()
149149
}
150150

151151
@inline(never)
152-
@_semantics("optimize.sil.never") // avoid devirtualization
152+
@_optimize(none) // avoid devirtualization
153153
func testDefaultWitnessMethods(_ p: Prot) {
154154
p.aliveDefaultWitness()
155155
}
156156

157-
@_semantics("optimize.sil.never") // avoid devirtualization
157+
@_optimize(none) // avoid devirtualization
158158
public func callTest() {
159159
testClasses(Base())
160160
testClasses(Derived())
@@ -163,7 +163,7 @@ public func callTest() {
163163
testProtocols(Adopt())
164164
}
165165

166-
@_semantics("optimize.sil.never") // make sure not eliminated
166+
@_optimize(none) // make sure not eliminated
167167
internal func donotEliminate() {
168168
return
169169
}

test/SILOptimizer/devirt_nested_class.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
fileprivate class Outer<T> {
44
class Inner<U> : Base<T, U> {
5-
@_semantics("optimize.sil.never")
5+
@_optimize(none)
66
override func method<V>(v: V) {}
77
}
88
}
99

1010
fileprivate class Base<T, U> {
11-
@_semantics("optimize.sil.never")
11+
@_optimize(none)
1212
func method<V>(v: V) {}
1313
}
1414

test/SILOptimizer/devirt_protocol_method_invocations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protocol RRR : QQQ {
1313
struct S : RRR {}
1414

1515
extension QQQ {
16-
@_semantics("optimize.sil.never")
16+
@_optimize(none)
1717
func f() {}
1818
}
1919

test/SILOptimizer/eager_specialize.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum ArithmeticError : Error {
4949
@_specialize(where T == Int)
5050
public func divideNum<T : SignedInteger & _ExpressibleByBuiltinIntegerLiteral>(num: T, den: T) throws -> T
5151

52-
@inline(never) @_semantics("optimize.sil.never") func foo<T>(t: T) -> Int64
52+
@inline(never) @_optimize(none) func foo<T>(t: T) -> Int64
5353

5454
// CHECK: @_specialize(exported: false, kind: full, where T == Int64)
5555
// CHECK: @_specialize(exported: false, kind: full, where T == Float)
@@ -240,7 +240,7 @@ bb2:
240240
// --- test: multiple void and non-void return values
241241

242242
// foo<A> (A) -> Int64
243-
sil hidden [noinline] [_semantics "optimize.sil.never"] @_T016eager_specialize3foos5Int64VxlF : $@convention(thin) <T> (@in T) -> Int64 {
243+
sil hidden [noinline] [Onone] @_T016eager_specialize3foos5Int64VxlF : $@convention(thin) <T> (@in T) -> Int64 {
244244
// %0 // users: %1, %4
245245
bb0(%0 : $*T):
246246
%2 = integer_literal $Builtin.Int64, 3

test/SILOptimizer/globalopt_global_propagation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal var IVITakenAddress = 1
2323

2424
// Taking the address of a global should prevent from performing the propagation of its value.
2525
@inline(never)
26-
@_semantics("optimize.sil.never")
26+
@_optimize(none)
2727
public func takeInout<T>(_ x: inout T) {
2828
}
2929

test/SILOptimizer/no_opt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public func foo1() {
1818
// CHECK: integer_literal
1919
// CHECK: integer_literal
2020
// CHECK: return
21-
@_semantics("optimize.sil.never")
21+
@_optimize(none)
2222
public func foo2() {
2323
bar(1)
2424
bar(2)

test/SILOptimizer/optimize_never.sil

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -inline -generic-specializer -inline %s > %t.sil
22
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -sil-full-demangle -enable-sil-verify-all -specdevirt %t.sil | %FileCheck %s
33

4-
// Check that the @_semantics("optimize.sil.never") annotation prevents
4+
// Check that the @_optimize(none) annotation prevents
55
// any optimizations of the annotated function:
66
// - No functions are inlined into the annotated function.
77
// - No calls are devirtualized in the body of the annotated function.
@@ -27,15 +27,15 @@ public class D : C {
2727
}
2828

2929
public class Base {
30-
@_semantics("optimize.sil.never") func foo() -> Int32
30+
@_optimize(none) func foo() -> Int32
3131
func boo() -> Int32
3232
deinit
3333
init()
3434
}
3535

3636
public class Derived1 : Base {
3737
override func foo() -> Int32
38-
@_semantics("optimize.sil.never") override func boo() -> Int32
38+
@_optimize(none) override func boo() -> Int32
3939
deinit
4040
override init()
4141
}
@@ -49,13 +49,13 @@ public class Derived2 : Base {
4949

5050
public func transform1<T>(x: T) -> Int32
5151

52-
@_semantics("optimize.sil.never") public func foo1<T>(x: T, _ c: C) -> Int32
52+
@_optimize(none) public func foo1<T>(x: T, _ c: C) -> Int32
5353

5454
public func boo1(c: C) -> Int32
5555

5656
public func transform2(x: Int32) -> Int32
5757

58-
@_semantics("optimize.sil.never") public func foo2(x: Int32, _ c: C) -> Int32
58+
@_optimize(none) public func foo2(x: Int32, _ c: C) -> Int32
5959

6060
public func boo2(c: C) -> Int32
6161

@@ -171,15 +171,15 @@ bb0(%0 : $*T):
171171

172172

173173
// Check that both calls are not inlined or devirtualized.
174-
// CHECK-LABEL: sil [_semantics "optimize.sil.never"] @_T014optimize_never4foo1s5Int32Vx_AA1CCtlF
174+
// CHECK-LABEL: sil [Onone] @_T014optimize_never4foo1s5Int32Vx_AA1CCtlF
175175
// CHECK-NOT: checked_cast_br
176176
// CHECK: function_ref @_T014optimize_never10transform1s5Int32VxlF
177177
// CHECK: apply
178178
// CHECK-NOT: checked_cast_br
179179
// CHECK: class_method {{%.*}} : $C, #C.foo!1 : (C) -> () -> Int32, $@convention(method) (@guaranteed C) -> Int32
180180
// CHECK: apply
181181
// CHECK: return
182-
sil [_semantics "optimize.sil.never"] @_T014optimize_never4foo1s5Int32Vx_AA1CCtlF : $@convention(thin) <T> (@in T, @owned C) -> Int32 {
182+
sil [Onone] @_T014optimize_never4foo1s5Int32Vx_AA1CCtlF : $@convention(thin) <T> (@in T, @owned C) -> Int32 {
183183
bb0(%0 : $*T, %1 : $C):
184184
%4 = function_ref @_T014optimize_never10transform1s5Int32VxlF : $@convention(thin) <τ_0_0> (@in τ_0_0) -> Int32
185185
%5 = alloc_stack $T
@@ -207,7 +207,7 @@ sil [transparent] [serialized] @_T0s1pois5Int32VAC_ACtFZ : $@convention(thin) (I
207207

208208
// CHECK-LABEL: sil @_T014optimize_never4boo1s5Int32VAA1CCF
209209
// CHECK-NOT: return
210-
// This call should not be inlined, because the callee is annotated with @_semantics("optimize.sil.never")
210+
// This call should not be inlined, because the callee is annotated with @_optimize(none)
211211
// CHECK: function_ref @_T014optimize_never4foo1s5Int32Vx_AA1CCtlF
212212
// CHECK: apply
213213
// CHECK: return
@@ -236,15 +236,15 @@ bb0(%0 : $Int32):
236236

237237

238238
// Check that both calls are not inlined or devirtualized.
239-
// CHECK-LABEL: sil [_semantics "optimize.sil.never"] @_T014optimize_never4foo2s5Int32VAD_AA1CCtF
239+
// CHECK-LABEL: sil [Onone] @_T014optimize_never4foo2s5Int32VAD_AA1CCtF
240240
// CHECK-NOT: checked_cast_br
241241
// CHECK: function_ref @_T014optimize_never10transform2s5Int32VADF
242242
// CHECK: apply
243243
// CHECK-NOT: checked_cast_br
244244
// CHECK: class_method {{%.*}} : $C, #C.foo!1 : (C) -> () -> Int32, $@convention(method) (@guaranteed C) -> Int32
245245
// CHECK: apply
246246
// CHECK: return
247-
sil [_semantics "optimize.sil.never"] @_T014optimize_never4foo2s5Int32VAD_AA1CCtF : $@convention(thin) (Int32, @owned C) -> Int32 {
247+
sil [Onone] @_T014optimize_never4foo2s5Int32VAD_AA1CCtF : $@convention(thin) (Int32, @owned C) -> Int32 {
248248
bb0(%0 : $Int32, %1 : $C):
249249
%4 = function_ref @_T014optimize_never10transform2s5Int32VADF : $@convention(thin) (Int32) -> Int32
250250
%5 = apply %4(%0) : $@convention(thin) (Int32) -> Int32
@@ -265,7 +265,7 @@ bb0(%0 : $Int32, %1 : $C):
265265

266266
// CHECK-LABEL: sil @_T014optimize_never4boo2s5Int32VAA1CCF
267267
// CHECK-NOT: return
268-
// This call should not be inlined, because the callee is annotated with @_semantics("optimize.sil.never")
268+
// This call should not be inlined, because the callee is annotated with @_optimize(none)
269269
// CHECK: function_ref @_T014optimize_never4foo2s5Int32VAD_AA1CCtF
270270
// CHECK: apply
271271
// CHECK: return
@@ -282,7 +282,7 @@ bb0(%0 : $C):
282282

283283
// Check that no generic specialization was produced for foo1 because it is excluded from optimizations.
284284
// CHECK-NOT: generic specialization <Swift.Int> of {{.*}}.foo1
285-
// But foo3 was specialized, because it is not annotated with @_semantics("optimize.sil.never")
285+
// But foo3 was specialized, because it is not annotated with @_optimize(none)
286286
// CHECK: generic specialization <Swift.Int32> of {{.*}}.foo3
287287

288288

@@ -389,7 +389,7 @@ bb0(%0 : $C):
389389
return %6 : $Int32
390390
}
391391

392-
sil hidden [_semantics "optimize.sil.never"] @_T014optimize_never4BaseC3foos5Int32VyF : $@convention(method) (@guaranteed Base) -> Int32 {
392+
sil hidden [Onone] @_T014optimize_never4BaseC3foos5Int32VyF : $@convention(method) (@guaranteed Base) -> Int32 {
393393
bb0(%0 : $Base):
394394
%2 = integer_literal $Builtin.Int32, 1
395395
%3 = struct $Int32 (%2 : $Builtin.Int32)
@@ -409,7 +409,7 @@ bb0(%0 : $Derived1):
409409
return %3 : $Int32
410410
}
411411

412-
sil hidden [_semantics "optimize.sil.never"] @_T014optimize_never8Derived1C3boos5Int32VyF : $@convention(method) (@guaranteed Derived1) -> Int32 {
412+
sil hidden [Onone] @_T014optimize_never8Derived1C3boos5Int32VyF : $@convention(method) (@guaranteed Derived1) -> Int32 {
413413
bb0(%0 : $Derived1):
414414
%2 = integer_literal $Builtin.Int32, 4
415415
%3 = struct $Int32 (%2 : $Builtin.Int32)
@@ -432,7 +432,7 @@ bb0(%0 : $Derived2):
432432

433433
// Check that class_method is not speculatively devirtualized, because the
434434
// method foo in the class Base, which mentioned in the class_method
435-
// instruction is marked with @_semantics("optimize.sil.never").
435+
// instruction is marked with @_optimize(none).
436436
//
437437
// CHECK-LABEL: sil @_T014optimize_never19testDoNotDevirtBases5Int32VAA0G0C1o_tF
438438
// CHECK: bb0
@@ -449,7 +449,7 @@ bb0(%0 : $Base):
449449
}
450450

451451
// Check that Derived1.boo is not devirtualized, because this method
452-
// is marked with @_semantics("optimize.sil.never") and thus should not
452+
// is marked with @_optimize(none) and thus should not
453453
// participate in speculative devirtualization.
454454
//
455455
// CHECK-LABEL: sil @_T014optimize_never23testDoNotDevirtDerived1s5Int32VAA4BaseC1o_tF

test/SILOptimizer/specialize_dynamic_self.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
protocol P {}
44

55
extension P {
6-
@_semantics("optimize.sil.never") func method1() {}
6+
@_optimize(none) func method1() {}
77

88
@inline(__always) func method2() { method1() }
99
}

test/SILOptimizer/specialize_inherited_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -primary-file %s %S/Inputs/specialize_inherited_multifile.swift -O -emit-sil -sil-verify-all | %FileCheck %s
22

3-
@_semantics("optimize.sil.never") func takesBase<T : Base>(t: T) {}
3+
@_optimize(none) func takesBase<T : Base>(t: T) {}
44

55
@inline(never) func takesHasAssocType<T : HasAssocType>(t: T) {
66
takesBase(t: t.value)

test/SILOptimizer/specialize_same_type_constraint.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ protocol SecondParent {
1616
var secondChild: Child { get }
1717
}
1818

19-
@_semantics("optimize.sil.never")
19+
@_optimize(none)
2020
func takesFirstChild<T : FirstChild>(t: T) {}
2121

22-
@_semantics("optimize.sil.never")
22+
@_optimize(none)
2323
func takesSecondChild<T : SecondChild>(t: T) {}
2424

2525
@inline(never)

0 commit comments

Comments
 (0)