Skip to content

Commit 54f07d3

Browse files
committed
Refine e1ed305 to use existing AST queries.
Joe asked me at the time if such a thing existed, and I had forgotten about this one. This should be effectively NFC because any other type should be filtered out by Sema.
1 parent 477933b commit 54f07d3

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,25 +2296,14 @@ RValue RValueEmitter::visitRebindSelfInConstructorExpr(
22962296
static bool isNullableTypeInC(SILModule &M, Type ty) {
22972297
ty = ty->getLValueOrInOutObjectType()->getReferenceStorageReferent();
22982298

2299+
// Functions, class instances, and @objc existentials are all nullable.
22992300
if (ty->hasReferenceSemantics())
23002301
return true;
2301-
2302-
auto &C = ty->getASTContext();
2303-
auto nom = ty->getAnyNominal();
2304-
if (!nom)
2305-
return false;
23062302

2307-
if (nom == C.getUnsafePointerDecl()
2308-
|| nom == C.getUnsafeMutablePointerDecl()
2309-
|| nom == C.getAutoreleasingUnsafeMutablePointerDecl()
2310-
|| nom == C.getOpaquePointerDecl())
2311-
return true;
2312-
2313-
auto selectorTy = M.Types.getSelectorType();
2314-
if (selectorTy && ty->isEqual(selectorTy))
2315-
return true;
2316-
2317-
return false;
2303+
// Other types like UnsafePointer can also be nullable.
2304+
ty = OptionalType::get(ty);
2305+
return ty->isTriviallyRepresentableIn(ForeignLanguage::C,
2306+
M.getAssociatedContext());
23182307
}
23192308

23202309
/// Determine whether the given declaration returns a non-optional object that

0 commit comments

Comments
 (0)