Skip to content

Commit e1126b3

Browse files
committed
Prespecialization: reduce the strength of an assertion.
If we find a specialization within the current module, it's okay if it has a body. This can come up if we compile something with optimizations and then compile the resulting SIL (or SIB) without optimizations.
1 parent af874ab commit e1126b3

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

lib/SILOptimizer/IPO/UsePrespecialized.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,14 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
135135
<< PrevF << "\n");
136136
if (!PrevF)
137137
continue;
138+
assert(PrevF->isExternalDeclaration() &&
139+
"Prespecialized function should be an external declaration");
138140
NewF = PrevF;
139141
}
140142

141143
if (!NewF)
142144
continue;
143145

144-
assert(NewF->isExternalDeclaration() &&
145-
"Prespecialized function should be an external declaration");
146-
147146
// An existing specialization was found.
148147
DEBUG(llvm::dbgs() << "Found a specialization of " << ReferencedF->getName()
149148
<< " : " << NewF->getName() << "\n");
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -module-name main | FileCheck %s
2+
3+
sil_stage canonical
4+
5+
struct Box<T> {
6+
@inline(never)
7+
static func foo() {}
8+
}
9+
10+
// Reference a function in a way that will be specialized.
11+
sil @test : $@convention(thin) () -> () {
12+
bb0:
13+
// function_ref static Box.foo() -> ()
14+
%0 = function_ref @_TZFV4main3Box3foofT_T_ : $@convention(thin) <τ_0_0> (@thin Box<τ_0_0>.Type) -> () // user: %2
15+
%1 = metatype $@thin Box<()>.Type // user: %2
16+
%2 = apply %0<()>(%1) : $@convention(thin) <τ_0_0> (@thin Box<τ_0_0>.Type) -> ()
17+
%3 = tuple () // user: %4
18+
return %3 : $() // id: %4
19+
}
20+
21+
// This is the unspecialized form.
22+
sil hidden @_TZFV4main3Box3foofT_T_ : $@convention(thin) <T> (@thin Box<T>.Type) -> () {
23+
bb0(%0 : $@thin Box<T>.Type):
24+
%1 = tuple ()
25+
return %1 : $()
26+
}
27+
28+
// generic specialization <()> of static main.Box.foo () -> ()
29+
// This specialization is one that would be matched by the prespecialization
30+
// pass.
31+
sil shared @_TTSg5T____TZFV4main3Box3foofT_T_ : $@convention(thin) (@thin Box<()>.Type) -> () {
32+
bb0(%0 : $@thin Box<()>.Type):
33+
%1 = tuple ()
34+
return %1 : $()
35+
}
36+
37+
// CHECK-DAG: define linkonce_odr hidden void @_TTSg5T____TZFV4main3Box3foofT_T_() {{.*}}{
38+
// CHECK-DAG: call void @_TTSg5T____TZFV4main3Box3foofT_T_()

0 commit comments

Comments
 (0)