Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/IRGen/GenericRequirement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2996,8 +2996,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,
Expand Down
4 changes: 3 additions & 1 deletion lib/IRGen/GenericArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ struct GenericArguments {
/// The values to use to initialize the arguments structure.
SmallVector<llvm::Value *, 8> Values;
SmallVector<llvm::Type *, 8> Types;
bool hasPacks = false;

void collectTypes(IRGenModule &IGM, NominalTypeDecl *nominal) {
void collectTypes(IRGenModule &IGM, NominalTypeDecl *nominal) {
GenericTypeRequirements requirements(IGM, nominal);
collectTypes(IGM, requirements);
}

void collectTypes(IRGenModule &IGM,
const GenericTypeRequirements &requirements) {
for (auto &requirement : requirements.getRequirements()) {
hasPacks = hasPacks || requirement.isAnyPack();
Types.push_back(requirement.getType(IGM));
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/IRGen/IRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,8 @@ class IRGenFunction {

// Emit a call to the given generic type metadata access function.
MetadataResponse emitGenericTypeMetadataAccessFunctionCall(
llvm::Function *accessFunction,
ArrayRef<llvm::Value *> args,
DynamicMetadataRequest request);
llvm::Function *accessFunction, ArrayRef<llvm::Value *> args,
DynamicMetadataRequest request, bool hasPacks = false);

// Emit a reference to the canonical type metadata record for the given AST
// type. This can be used to identify the type at runtime. For types with
Expand Down
12 changes: 5 additions & 7 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ static MetadataResponse emitNominalMetadataRef(IRGenFunction &IGF,
theDecl, genericArgs.Types, NotForDefinition);

response = IGF.emitGenericTypeMetadataAccessFunctionCall(
accessor, genericArgs.Values, request);
accessor, genericArgs.Values, request, genericArgs.hasPacks);
}

IGF.setScopedLocalTypeMetadata(theType, response);
Expand Down Expand Up @@ -2467,11 +2467,9 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM, llvm::Function *accessor,
IGF.Builder.CreateRet(ret);
}

MetadataResponse
IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
llvm::Function *accessFunction,
ArrayRef<llvm::Value *> args,
DynamicMetadataRequest request) {
MetadataResponse IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
llvm::Function *accessFunction, ArrayRef<llvm::Value *> args,
DynamicMetadataRequest request, bool hasPacks) {

SmallVector<llvm::Value *, 8> callArgs;

Expand All @@ -2495,7 +2493,7 @@ IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
accessFunction, callArgs);
call->setDoesNotThrow();
call->setCallingConv(IGM.SwiftCC);
call->setMemoryEffects(allocatedArgsBuffer
call->setMemoryEffects(hasPacks || allocatedArgsBuffer
? llvm::MemoryEffects::inaccessibleOrArgMemOnly()
: llvm::MemoryEffects::none());

Expand Down
8 changes: 8 additions & 0 deletions validation-test/IRGen/rdar161606892.swift
Original file line number Diff line number Diff line change
@@ -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<each T> {
public var teas: (repeat each T)
}
40 changes: 40 additions & 0 deletions validation-test/IRGen/rdar161606892_2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-build-swift \
// RUN: -emit-module \
// RUN: -target %target-swift-5.9-abi-triple \
// RUN: %t/Library.swift \
// RUN: -parse-as-library \
// RUN: -module-name Library \
// RUN: -emit-module-path %t/Library.swiftmodule

// RUN: %target-swift-frontend \
// RUN: %t/Downstream.swift \
// RUN: -emit-irgen \
// RUN: -target %target-swift-5.9-abi-triple \
// RUN: -module-name main \
// RUN: -lLibrary \
// RUN: -I %t \
// RUN: | %FileCheck %t/Downstream.swift --check-prefixes=CHECK,CHECK-OLD

//--- Library.swift

public struct Pack<each T> {
public init() {}
}

public func sink<T>(_ t: T) {}

//--- Downstream.swift

import Library

// CHECK: doit
// CHECK: @"$s7Library4PackVMa"{{.*}} [[CALL:#[^,]+]]

// CHECK: attributes [[CALL]] = { nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) }
@_silgen_name("doit")
func doit<each T, each U>(ts: repeat each T, us: repeat each U) {
sink(Pack<repeat each T, repeat each U>())
}