diff --git a/include/swift/IRGen/GenericRequirement.h b/include/swift/IRGen/GenericRequirement.h index 3722cb2252ede..5d8714fe661be 100644 --- a/include/swift/IRGen/GenericRequirement.h +++ b/include/swift/IRGen/GenericRequirement.h @@ -109,6 +109,11 @@ class GenericRequirement { bool isAnyWitnessTable() const { return kind == Kind::WitnessTable || kind == Kind::WitnessTablePack; } + + bool isAnyPack() const { + return kind == Kind::MetadataPack || kind == Kind::WitnessTablePack; + } + bool isValue() const { return kind == Kind::Value; } diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index 029edac50bd8a..c7dbff8117e80 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -2993,8 +2993,9 @@ void irgen::emitLazyMetadataAccessor(IRGenModule &IGM, if (IGM.getOptions().optimizeForSize()) accessor->addFnAttr(llvm::Attribute::NoInline); - bool isReadNone = (genericArgs.Types.size() <= - NumDirectGenericTypeMetadataAccessFunctionArgs); + bool isReadNone = + !genericArgs.hasPacks && (genericArgs.Types.size() <= + NumDirectGenericTypeMetadataAccessFunctionArgs); emitCacheAccessFunction( IGM, accessor, /*cache*/ nullptr, /*cache type*/ nullptr, diff --git a/lib/IRGen/GenericArguments.h b/lib/IRGen/GenericArguments.h index 18a635da8b4be..87d18049e60cc 100644 --- a/lib/IRGen/GenericArguments.h +++ b/lib/IRGen/GenericArguments.h @@ -50,8 +50,9 @@ struct GenericArguments { /// The values to use to initialize the arguments structure. SmallVector Values; SmallVector Types; + bool hasPacks = false; - void collectTypes(IRGenModule &IGM, NominalTypeDecl *nominal) { + void collectTypes(IRGenModule &IGM, NominalTypeDecl *nominal) { GenericTypeRequirements requirements(IGM, nominal); collectTypes(IGM, requirements); } @@ -59,6 +60,7 @@ struct GenericArguments { void collectTypes(IRGenModule &IGM, const GenericTypeRequirements &requirements) { for (auto &requirement : requirements.getRequirements()) { + hasPacks = hasPacks || requirement.isAnyPack(); Types.push_back(requirement.getType(IGM)); } } diff --git a/validation-test/IRGen/rdar161606892.swift b/validation-test/IRGen/rdar161606892.swift new file mode 100644 index 0000000000000..01e01c685f068 --- /dev/null +++ b/validation-test/IRGen/rdar161606892.swift @@ -0,0 +1,8 @@ +// RUN: %target-swift-frontend %s -target %target-swift-5.9-abi-triple -emit-irgen | %IRGenFileCheck %s + +// CHECK: Attrs: noinline nounwind{{$}} +// CHECK-NEXT: define {{.*}}@"$s13rdar1616068921PVMa" + +public struct P { + public var teas: (repeat each T) +}