Skip to content

Commit 435d134

Browse files
committed
AST: making export: true in @_specialized attribute a no-operation
The client code doesn't actually call into these specialized functions even though they have public linkage. This could lead to TBD verification failure shown in rdar://44777994. This patch also warns users' codebase when `export: true` is specified.
1 parent 66ea6e6 commit 435d134

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,9 @@ ERROR(attr_specialize_unknown_parameter_name,none,
15681568
ERROR(attr_specialize_expected_bool_value,none,
15691569
"expected a boolean true or false value in '_specialize' attribute", ())
15701570

1571+
WARNING(attr_specialize_export_true_no_op,none,
1572+
"'exported: true' has no effect in '_specialize' attribute", ())
1573+
15711574
ERROR(attr_specialize_missing_parameter_label_or_where_clause,none,
15721575
"expected a parameter label or a where clause in '_specialize' attribute", ())
15731576

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ bool Parser::parseSpecializeAttributeArguments(
626626
ParamLabel);
627627
}
628628
if (ParamLabel == "exported") {
629+
auto trueLoc = Tok.getLoc();
629630
bool isTrue = consumeIf(tok::kw_true);
631+
if (isTrue) {
632+
diagnose(trueLoc, diag::attr_specialize_export_true_no_op);
633+
}
630634
bool isFalse = consumeIf(tok::kw_false);
631635
if (!isTrue && !isFalse) {
632636
diagnose(Tok.getLoc(), diag::attr_specialize_expected_bool_value);

lib/SILOptimizer/IPO/EagerSpecializer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,6 @@ void EagerSpecializerTransform::run() {
768768
auto *NewFunc = eagerSpecialize(FuncBuilder, &F, *SA, ReInfoVec.back());
769769

770770
SpecializedFuncs.push_back(NewFunc);
771-
772-
if (SA->isExported()) {
773-
NewFunc->setLinkage(SILLinkage::Public);
774-
continue;
775-
}
776771
}
777772

778773
// TODO: Optimize the dispatch code to minimize the amount

test/SILOptimizer/eager_specialize.sil

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all -eager-specializer %s | %FileCheck %s
2-
// RUN: %target-sil-opt -enable-sil-verify-all -eager-specializer -sil-deadfuncelim %s | %FileCheck --check-prefix=CHECK-DEADFUNCELIM %s
32
// RUN: %target-sil-opt -enable-sil-verify-all -eager-specializer %s -o %t.sil && %target-swift-frontend -module-name=eager_specialize -emit-ir %t.sil | %FileCheck --check-prefix=CHECK-IRGEN --check-prefix=CHECK-IRGEN-%target-cpu %s
43
// RUN: %target-sil-opt -enable-sil-verify-all -eager-specializer -sil-inline-generics=true -inline %s | %FileCheck --check-prefix=CHECK-EAGER-SPECIALIZE-AND-GENERICS-INLINE %s
54

@@ -578,10 +577,6 @@ bb0(%0 : $*T):
578577
return %3 : $()
579578
} // end sil function '$s16eager_specialize21exportSpecializationsyyxlF'
580579

581-
// Check that a public specialization for Int64 was produced.
582-
// specialized exportSpecializations<A> (A) -> ()
583-
// CHECK-DEADFUNCELIM-LABEL: sil @$s16eager_specialize21exportSpecializationsyyxlFs5Int64V_Tg5 : $@convention(thin) (Int64) -> ()
584-
585580
////////////////////////////////////////////////////////////////////
586581
// Check the ability to produce explicit partial specializations.
587582
////////////////////////////////////////////////////////////////////

test/TBD/specialize_verify.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// REQUIRES: VENDOR=apple
2+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -O -module-name test -validate-tbd-against-ir=missing %s
3+
4+
@_specialize(exported: true, where T: _Trivial)
5+
public func foo<T>(_ x : T) -> T {
6+
return x
7+
}

test/attr/attr_specialize.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public func funcWithTwoGenericParameters<X, Y>(x: X, y: Y) {
128128
}
129129

130130
@_specialize(where X == Int, Y == Int)
131-
@_specialize(exported: true, where X == Int, Y == Int)
131+
@_specialize(exported: true, where X == Int, Y == Int) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
132132
@_specialize(exported: false, where X == Int, Y == Int)
133133
@_specialize(exported: false where X == Int, Y == Int) // expected-error{{missing ',' in '_specialize' attribute}}
134134
@_specialize(exported: yes, where X == Int, Y == Int) // expected-error{{expected a boolean true or false value in '_specialize' attribute}}
@@ -143,9 +143,9 @@ public func funcWithTwoGenericParameters<X, Y>(x: X, y: Y) {
143143
@_specialize(kind: partial, where X == Int, Y == Int)
144144
@_specialize(kind: , where X == Int, Y == Int)
145145

146-
@_specialize(exported: true, kind: partial, where X == Int, Y == Int)
147-
@_specialize(exported: true, exported: true, where X == Int, Y == Int) // expected-error{{parameter 'exported' was already defined in '_specialize' attribute}}
148-
@_specialize(kind: partial, exported: true, where X == Int, Y == Int)
146+
@_specialize(exported: true, kind: partial, where X == Int, Y == Int) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
147+
@_specialize(exported: true, exported: true, where X == Int, Y == Int) // expected-error{{parameter 'exported' was already defined in '_specialize' attribute}} expected-warning2{{'exported: true' has no effect in '_specialize' attribute}}
148+
@_specialize(kind: partial, exported: true, where X == Int, Y == Int) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
149149
@_specialize(kind: partial, kind: partial, where X == Int, Y == Int) // expected-error{{parameter 'kind' was already defined in '_specialize' attribute}}
150150

151151
@_specialize(where X == Int, Y == Int, exported: true, kind: partial) // expected-error{{use of undeclared type 'exported'}} expected-error{{use of undeclared type 'kind'}} expected-error{{use of undeclared type 'partial'}} expected-error{{expected type}}
@@ -200,22 +200,22 @@ public func simpleGeneric<T>(t: T) -> T {
200200
}
201201

202202

203-
@_specialize(exported: true, where S: _Trivial(64))
203+
@_specialize(exported: true, where S: _Trivial(64)) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
204204
// Check that any bitsize size is OK, not only powers of 8.
205205
@_specialize(where S: _Trivial(60))
206-
@_specialize(exported: true, where S: _RefCountedObject)
206+
@_specialize(exported: true, where S: _RefCountedObject) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
207207
@inline(never)
208208
public func copyValue<S>(_ t: S, s: inout S) -> Int64 where S: P{
209209
return 1
210210
}
211211

212-
@_specialize(exported: true, where S: _Trivial)
213-
@_specialize(exported: true, where S: _Trivial(64))
214-
@_specialize(exported: true, where S: _Trivial(32))
215-
@_specialize(exported: true, where S: _RefCountedObject)
216-
@_specialize(exported: true, where S: _NativeRefCountedObject)
217-
@_specialize(exported: true, where S: _Class)
218-
@_specialize(exported: true, where S: _NativeClass)
212+
@_specialize(exported: true, where S: _Trivial) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
213+
@_specialize(exported: true, where S: _Trivial(64)) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
214+
@_specialize(exported: true, where S: _Trivial(32)) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
215+
@_specialize(exported: true, where S: _RefCountedObject) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
216+
@_specialize(exported: true, where S: _NativeRefCountedObject) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
217+
@_specialize(exported: true, where S: _Class) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
218+
@_specialize(exported: true, where S: _NativeClass) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
219219
@inline(never)
220220
public func copyValueAndReturn<S>(_ t: S, s: inout S) -> S where S: P{
221221
return s
@@ -234,7 +234,7 @@ struct OuterStruct<S> {
234234
}
235235

236236
// Check _TrivialAtMostN constraints.
237-
@_specialize(exported: true, where S: _TrivialAtMost(64))
237+
@_specialize(exported: true, where S: _TrivialAtMost(64)) // expected-warning{{'exported: true' has no effect in '_specialize' attribute}}
238238
@inline(never)
239239
public func copy2<S>(_ t: S, s: inout S) -> S where S: P{
240240
return s

0 commit comments

Comments
 (0)