Skip to content

Commit a00c058

Browse files
committed
SIL: Don't attempt to emit keypath descriptors with unsupported reabstraction thunks
1 parent 298f2df commit a00c058

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

lib/SIL/IR/SIL.cpp

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,53 @@ bool SILModule::isTypeMetadataForLayoutAccessible(SILType type) {
296296
return ::isTypeMetadataForLayoutAccessible(*this, type);
297297
}
298298

299-
bool AbstractStorageDecl::exportsPropertyDescriptor() const {
300-
// The storage needs a descriptor if it sits at a module's ABI boundary,
301-
// meaning it has public linkage.
302-
299+
static bool isUnsupportedKeyPathValueType(Type ty) {
300+
// Visit lowered positions.
301+
if (auto tupleTy = ty->getAs<TupleType>()) {
302+
for (auto eltTy : tupleTy->getElementTypes()) {
303+
if (eltTy->is<PackExpansionType>())
304+
return true;
305+
306+
if (isUnsupportedKeyPathValueType(eltTy))
307+
return true;
308+
}
309+
310+
return false;
311+
}
312+
313+
if (auto objTy = ty->getOptionalObjectType())
314+
ty = objTy;
315+
316+
// FIXME: Remove this once isUnimplementableVariadicFunctionAbstraction()
317+
// goes away in SILGenPoly.cpp.
318+
if (auto funcTy = ty->getAs<FunctionType>()) {
319+
for (auto param : funcTy->getParams()) {
320+
auto paramTy = param.getPlainType();
321+
if (paramTy->is<PackExpansionType>())
322+
return true;
323+
324+
if (isUnsupportedKeyPathValueType(paramTy))
325+
return true;
326+
}
327+
328+
if (isUnsupportedKeyPathValueType(funcTy->getResult()))
329+
return true;
330+
}
331+
303332
// Noncopyable types aren't supported by key paths in their current form.
304333
// They would also need a new ABI that's yet to be implemented in order to
305334
// be properly supported, so let's suppress the descriptor for now if either
306335
// the container or storage type of the declaration is non-copyable.
307-
if (getValueInterfaceType()->isPureMoveOnly()) {
308-
return false;
309-
}
336+
if (ty->isPureMoveOnly())
337+
return true;
338+
339+
return false;
340+
}
341+
342+
bool AbstractStorageDecl::exportsPropertyDescriptor() const {
343+
// The storage needs a descriptor if it sits at a module's ABI boundary,
344+
// meaning it has public linkage.
345+
310346
if (!isStatic()) {
311347
if (auto contextTy = getDeclContext()->getDeclaredTypeInContext()) {
312348
if (contextTy->isPureMoveOnly()) {
@@ -362,6 +398,10 @@ bool AbstractStorageDecl::exportsPropertyDescriptor() const {
362398
llvm_unreachable("should be definition linkage?");
363399
}
364400

401+
if (isUnsupportedKeyPathValueType(getValueInterfaceType())) {
402+
return false;
403+
}
404+
365405
// Subscripts with inout arguments (FIXME)and reabstracted arguments(/FIXME)
366406
// don't have descriptors either.
367407
if (auto sub = dyn_cast<SubscriptDecl>(this)) {

0 commit comments

Comments
 (0)