Skip to content

Commit 2cddb38

Browse files
committed
---
yaml --- r: 345502 b: refs/heads/master c: 5ef7fe3 h: refs/heads/master
1 parent d037569 commit 2cddb38

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: b4e9bc6cec9b69b7a17bab24f5c46adfd8603695
2+
refs/heads/master: 5ef7fe31d84575d61c32a22a63188bddf6967edc
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/SIL/SILCloner.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
174174
return asImpl().remapASTType(ty);
175175
}
176176

177+
void remapOpenedType(CanArchetypeType archetypeTy) {
178+
auto existentialTy = archetypeTy->getOpenedExistentialType()->getCanonicalType();
179+
auto replacementTy = ArchetypeType::getOpened(getOpASTType(existentialTy));
180+
registerOpenedExistentialRemapping(archetypeTy, replacementTy);
181+
}
182+
177183
ProtocolConformanceRef getOpConformance(Type ty,
178184
ProtocolConformanceRef conformance) {
179185
// If we have open existentials to substitute, do so now.
@@ -1644,10 +1650,7 @@ template<typename ImplClass>
16441650
void
16451651
SILCloner<ImplClass>::visitOpenExistentialAddrInst(OpenExistentialAddrInst *Inst) {
16461652
// Create a new archetype for this opened existential type.
1647-
auto archetypeTy = Inst->getType().castTo<ArchetypeType>();
1648-
registerOpenedExistentialRemapping(
1649-
archetypeTy,
1650-
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
1653+
remapOpenedType(Inst->getType().castTo<ArchetypeType>());
16511654

16521655
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16531656
doPostProcess(Inst,
@@ -1661,10 +1664,7 @@ template <typename ImplClass>
16611664
void SILCloner<ImplClass>::visitOpenExistentialValueInst(
16621665
OpenExistentialValueInst *Inst) {
16631666
// Create a new archetype for this opened existential type.
1664-
auto archetypeTy = Inst->getType().castTo<ArchetypeType>();
1665-
registerOpenedExistentialRemapping(
1666-
archetypeTy,
1667-
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
1667+
remapOpenedType(Inst->getType().castTo<ArchetypeType>());
16681668

16691669
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16701670
doPostProcess(Inst, getBuilder().createOpenExistentialValue(
@@ -1684,10 +1684,7 @@ visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *Inst) {
16841684
exType = exMetatype.getInstanceType();
16851685
openedType = cast<MetatypeType>(openedType).getInstanceType();
16861686
}
1687-
auto archetypeTy = cast<ArchetypeType>(openedType);
1688-
registerOpenedExistentialRemapping(
1689-
archetypeTy,
1690-
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
1687+
remapOpenedType(cast<ArchetypeType>(openedType));
16911688

16921689
if (!Inst->getOperand()->getType().canUseExistentialRepresentation(
16931690
Inst->getModule(), ExistentialRepresentation::Class)) {
@@ -1711,10 +1708,7 @@ void
17111708
SILCloner<ImplClass>::
17121709
visitOpenExistentialRefInst(OpenExistentialRefInst *Inst) {
17131710
// Create a new archetype for this opened existential type.
1714-
auto archetypeTy = Inst->getType().castTo<ArchetypeType>();
1715-
registerOpenedExistentialRemapping(
1716-
archetypeTy,
1717-
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
1711+
remapOpenedType(Inst->getType().castTo<ArchetypeType>());
17181712

17191713
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
17201714
doPostProcess(Inst,
@@ -1728,10 +1722,7 @@ void
17281722
SILCloner<ImplClass>::
17291723
visitOpenExistentialBoxInst(OpenExistentialBoxInst *Inst) {
17301724
// Create a new archetype for this opened existential type.
1731-
auto archetypeTy = Inst->getType().castTo<ArchetypeType>();
1732-
registerOpenedExistentialRemapping(
1733-
archetypeTy,
1734-
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
1725+
remapOpenedType(Inst->getType().castTo<ArchetypeType>());
17351726

17361727
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
17371728
doPostProcess(Inst,
@@ -1745,10 +1736,7 @@ void
17451736
SILCloner<ImplClass>::
17461737
visitOpenExistentialBoxValueInst(OpenExistentialBoxValueInst *Inst) {
17471738
// Create a new archetype for this opened existential type.
1748-
auto archetypeTy = Inst->getType().castTo<ArchetypeType>();
1749-
registerOpenedExistentialRemapping(
1750-
archetypeTy,
1751-
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
1739+
remapOpenedType(Inst->getType().castTo<ArchetypeType>());
17521740

17531741
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
17541742
doPostProcess(Inst,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend -emit-sil -primary-file %s | %FileCheck %s
2+
3+
class C<T> {}
4+
protocol P {
5+
func f()
6+
}
7+
8+
// CHECK-LABEL: sil hidden [transparent] @$s27inline_subclass_existential3fooyyAA1P_AA1CCyxGXclF : $@convention(thin) <T> (@guaranteed C<T> & P) -> () {
9+
// CHECK: open_existential_ref %0 : $C<T> & P to $@opened("{{.*}}") C<T> & P
10+
// CHECK: return
11+
@_transparent
12+
func foo<T>(_ x: C<T> & P) {
13+
x.f()
14+
}
15+
16+
// CHECK-LABEL: sil hidden @$s27inline_subclass_existential3baryyAA1P_AA1CCySiGXcF : $@convention(thin) (@guaranteed C<Int> & P) -> () {
17+
// CHECK: open_existential_ref %0 : $C<Int> & P to $@opened("{{.*}}") C<Int> & P
18+
// CHECK: return
19+
func bar(_ x: C<Int> & P) {
20+
foo(x)
21+
}

0 commit comments

Comments
 (0)