Skip to content

Commit 6b05461

Browse files
authored
Merge pull request #5823 from jckarter/sil-verifier-lowered-optionals
SIL: Update verifier's `isLoweringOf` check for lowered Optionals.
2 parents 7b46aa4 + de8bbfb commit 6b05461

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,26 +1578,22 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
15781578
// Is a SIL type a potential lowering of a formal type?
15791579
static bool isLoweringOf(SILType loweredType,
15801580
CanType formalType) {
1581+
1582+
15811583
// Dynamic self has the same lowering as its contained type.
15821584
if (auto dynamicSelf = dyn_cast<DynamicSelfType>(formalType))
15831585
formalType = CanType(dynamicSelf->getSelfType());
15841586

1585-
// Optional of dynamic self has the same lowering as its contained type.
1586-
OptionalTypeKind loweredOptionalKind;
1587-
OptionalTypeKind formalOptionalKind;
1588-
1589-
CanType loweredObjectType = loweredType.getSwiftRValueType()
1590-
.getAnyOptionalObjectType(loweredOptionalKind);
1587+
// Optional lowers its contained type. The difference between Optional
1588+
// and IUO is lowered away.
1589+
SILType loweredObjectType = loweredType
1590+
.getAnyOptionalObjectType();
15911591
CanType formalObjectType = formalType
1592-
.getAnyOptionalObjectType(formalOptionalKind);
1592+
.getAnyOptionalObjectType();
15931593

1594-
if (loweredOptionalKind != OTK_None) {
1595-
if (auto dynamicSelf = dyn_cast<DynamicSelfType>(formalObjectType)) {
1596-
formalObjectType = dynamicSelf->getSelfType()->getCanonicalType();
1597-
}
1598-
return loweredOptionalKind == formalOptionalKind &&
1599-
isLoweringOf(SILType::getPrimitiveAddressType(loweredObjectType),
1600-
formalObjectType);
1594+
if (loweredObjectType) {
1595+
return formalObjectType &&
1596+
isLoweringOf(loweredObjectType, formalObjectType);
16011597
}
16021598

16031599
// Metatypes preserve their instance type through lowering.

test/SILGen/dynamic_lookup.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,16 @@ func downcast(_ obj: AnyObject) -> X {
270270
func consume(_ fruit: Fruit) {
271271
_ = fruit.juice
272272
}
273+
274+
// rdar://problem/29249513 -- looking up an IUO member through AnyObject
275+
// produces a Foo!? type. The SIL verifier did not correctly consider Optional
276+
// to be the lowering of IUO (which is now eliminated by SIL lowering).
277+
278+
@objc protocol IUORequirement {
279+
var iuoProperty: AnyObject! { get }
280+
}
281+
282+
func getIUOPropertyDynamically(x: AnyObject) -> Any {
283+
return x.iuoProperty
284+
}
285+

0 commit comments

Comments
 (0)