Skip to content

Commit 82cf6ab

Browse files
committed
---
yaml --- r: 293851 b: refs/heads/tensorflow c: cc2a7c1 h: refs/heads/master i: 293849: 058c61c 293847: 8d7d9f8
1 parent ebf475c commit 82cf6ab

File tree

5 files changed

+142
-3
lines changed

5 files changed

+142
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: a793dfb45101a1df451ef4b8fcace8ca512a25cd
819+
refs/heads/tensorflow: cc2a7c197085d18f79f837377c2a383c9ca18f53
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/lib/AST/Type.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,8 @@ Type ReplaceOpaqueTypesWithUnderlyingTypes::operator()(
24842484
// Don't replace opaque types from resilient modules.
24852485
auto namingDecl = opaqueRoot->getDecl()->getNamingDecl();
24862486
auto module = namingDecl->getModuleContext();
2487-
if (module->isResilient() && module != modulePerformingSubstitution) {
2487+
if (module->isResilient() && module != modulePerformingSubstitution &&
2488+
!namingDecl->getAttrs().hasAttribute<InlinableAttr>()) {
24882489
return maybeOpaqueType;
24892490
}
24902491

@@ -2529,7 +2530,8 @@ ReplaceOpaqueTypesWithUnderlyingTypes::operator()(CanType maybeOpaqueType,
25292530
// Don't replace opaque types from resilient modules.
25302531
auto namingDecl = opaqueRoot->getDecl()->getNamingDecl();
25312532
auto module = namingDecl->getModuleContext();
2532-
if (module->isResilient() && module != modulePerformingSubstitution) {
2533+
if (module->isResilient() && module != modulePerformingSubstitution &&
2534+
!namingDecl->getAttrs().hasAttribute<InlinableAttr>()) {
25332535
return abstractRef;
25342536
}
25352537

branches/tensorflow/test/SILOptimizer/Inputs/specialize_opaque_type_archetypes_3.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,36 @@ extension Int64 : ExternalP2 {
1111
public func externalResilient() -> some ExternalP2 {
1212
return Int64(6)
1313
}
14+
15+
@usableFromInline
16+
@inline(never)
17+
func preventInlining() {}
18+
19+
@inlinable
20+
public func inlinableExternalResilient() -> some ExternalP2 {
21+
preventInlining()
22+
preventInlining()
23+
preventInlining()
24+
preventInlining()
25+
preventInlining()
26+
preventInlining()
27+
preventInlining()
28+
preventInlining()
29+
preventInlining()
30+
preventInlining()
31+
preventInlining()
32+
preventInlining()
33+
preventInlining()
34+
preventInlining()
35+
preventInlining()
36+
preventInlining()
37+
preventInlining()
38+
preventInlining()
39+
preventInlining()
40+
preventInlining()
41+
preventInlining()
42+
preventInlining()
43+
preventInlining()
44+
preventInlining()
45+
return Int64(6)
46+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import External2
2+
3+
@usableFromInline
4+
@inline(never)
5+
func preventInlining() {}
6+
7+
// When specializing the opaque result type for this function we should not
8+
// specialize the opaque result type of the recursive invocation.
9+
@inlinable
10+
public func inlinableExternalResilientCallsResilient() -> some ExternalP2 {
11+
preventInlining()
12+
preventInlining()
13+
preventInlining()
14+
preventInlining()
15+
preventInlining()
16+
preventInlining()
17+
preventInlining()
18+
preventInlining()
19+
preventInlining()
20+
preventInlining()
21+
preventInlining()
22+
preventInlining()
23+
preventInlining()
24+
preventInlining()
25+
preventInlining()
26+
preventInlining()
27+
preventInlining()
28+
preventInlining()
29+
preventInlining()
30+
preventInlining()
31+
preventInlining()
32+
preventInlining()
33+
preventInlining()
34+
preventInlining()
35+
return externalResilient()
36+
}
37+
38+
// In this case we should look through the recursion.
39+
@inlinable
40+
public func inlinableExternalResilientCallsInlinableExternalResilient() -> some ExternalP2 {
41+
preventInlining()
42+
preventInlining()
43+
preventInlining()
44+
preventInlining()
45+
preventInlining()
46+
preventInlining()
47+
preventInlining()
48+
preventInlining()
49+
preventInlining()
50+
preventInlining()
51+
preventInlining()
52+
preventInlining()
53+
preventInlining()
54+
preventInlining()
55+
preventInlining()
56+
preventInlining()
57+
preventInlining()
58+
preventInlining()
59+
preventInlining()
60+
preventInlining()
61+
preventInlining()
62+
preventInlining()
63+
preventInlining()
64+
preventInlining()
65+
return inlinableExternalResilient()
66+
}

branches/tensorflow/test/SILOptimizer/specialize_opaque_type_archetypes.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend %S/Inputs/specialize_opaque_type_archetypes_2.swift -module-name External -emit-module -emit-module-path %t/External.swiftmodule
33
// RUN: %target-swift-frontend %S/Inputs/specialize_opaque_type_archetypes_3.swift -enable-library-evolution -module-name External2 -emit-module -emit-module-path %t/External2.swiftmodule
4+
// RUN: %target-swift-frontend %S/Inputs/specialize_opaque_type_archetypes_4.swift -I %t -enable-library-evolution -module-name External3 -emit-module -emit-module-path %t/External3.swiftmodule
45
// RUN: %target-swift-frontend -I %t -module-name A -enforce-exclusivity=checked -Osize -emit-sil -sil-verify-all %s | %FileCheck %s
56
// RUN: %target-swift-frontend -I %t -module-name A -enforce-exclusivity=checked -enable-library-evolution -Osize -emit-sil -sil-verify-all %s | %FileCheck %s
67
import External
78
import External2
9+
import External3
810

911
public protocol P {
1012
func myValue() -> Int64
@@ -260,3 +262,39 @@ extension P3 {
260262
return Adapter(inner: self)
261263
}
262264
}
265+
266+
// We should specialize the opaque type because the resilient function is
267+
// inlineable.
268+
269+
// CHECK-LABEL: sil @$s1A21useExternalResilient2yyF : $@convention(thin) () -> ()
270+
// CHECK: [[RES:%.*]] = alloc_stack $Int64
271+
// CHECK: [[FUN:%.*]] = function_ref @$s9External226inlinableExternalResilientQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s9External226inlinableExternalResilientQryF", 0)
272+
// CHECK: [[RES2:%.*]] = unchecked_addr_cast [[RES]] : $*Int64 to $*@_opaqueReturnTypeOf("$s9External226inlinableExternalResilientQryF", 0)
273+
// CHECK: apply [[FUN]]([[RES2]])
274+
// CHECK: return
275+
public func useExternalResilient2() {
276+
let e = inlinableExternalResilient()
277+
useP(e.myValue3())
278+
}
279+
280+
// In this case we should only 'peel' one layer of opaque archetypes.
281+
// CHECK-LABEL: sil @$s1A21useExternalResilient3yyF
282+
// CHECK: [[RES:%.*]] = alloc_stack $@_opaqueReturnTypeOf("$s9External217externalResilientQryF", 0)
283+
// CHECK: [[FUN:%.*]] = function_ref @$s9External3031inlinableExternalResilientCallsD0QryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s9External3031inlinableExternalResilientCallsD0QryF", 0)
284+
// CHECK: [[RES2:%.*]] = unchecked_addr_cast [[RES]] : $*@_opaqueReturnTypeOf("$s9External217externalResilientQryF", 0){{.*}}to $*@_opaqueReturnTypeOf("$s9External3031inlinableExternalResilientCallsD0QryF", 0)
285+
// CHECK: apply [[FUN]]([[RES2]])
286+
public func useExternalResilient3() {
287+
let e = inlinableExternalResilientCallsResilient()
288+
useP(e.myValue3())
289+
}
290+
291+
// Check that we can look throught two layers of inlinable resilient functions.
292+
// CHECK-LABEL: sil @$s1A21useExternalResilient4yyF
293+
// CHECK: [[RES:%.*]] = alloc_stack $Int64
294+
// CHECK: [[FUN:%.*]] = function_ref @$s9External3040inlinableExternalResilientCallsInlinablecD0QryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s9External3040inlinableExternalResilientCallsInlinablecD0QryF", 0)
295+
// CHECK: [[RES2:%.*]] = unchecked_addr_cast [[RES]] : $*Int64 to $*@_opaqueReturnTypeOf("$s9External3040inlinableExternalResilientCallsInlinablecD0QryF", 0)
296+
// CHECK: apply [[FUN]]([[RES2]])
297+
public func useExternalResilient4() {
298+
let e = inlinableExternalResilientCallsInlinableExternalResilient()
299+
useP(e.myValue3())
300+
}

0 commit comments

Comments
 (0)