Skip to content

Commit 1020970

Browse files
committed
IRGen: Clean up duplication in withOpaqueTypeGenericArgs()
1 parent 1a3cbfa commit 1020970

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,10 @@ withOpaqueTypeGenericArgs(IRGenFunction &IGF,
440440
enumerateGenericSignatureRequirements(
441441
opaqueDecl->getGenericSignature().getCanonicalSignature(),
442442
[&](GenericRequirement reqt) {
443-
auto ty = reqt.getTypeParameter().subst(archetype->getSubstitutions())
444-
->getReducedType(opaqueDecl->getGenericSignature());
445-
if (reqt.isAnyWitnessTable()) {
446-
auto ref =
447-
ProtocolConformanceRef(reqt.getProtocol())
448-
.subst(reqt.getTypeParameter(), archetype->getSubstitutions());
449-
args.push_back(emitWitnessTableRef(IGF, ty, ref));
450-
} else {
451-
assert(reqt.isAnyMetadata());
452-
args.push_back(IGF.emitAbstractTypeMetadataRef(ty));
453-
}
443+
auto arg = emitGenericRequirementFromSubstitutions(
444+
IGF, reqt, archetype->getSubstitutions(),
445+
MetadataState::Abstract);
446+
args.push_back(arg);
454447
types.push_back(args.back()->getType());
455448
});
456449
auto bufTy = llvm::StructType::get(IGF.IGM.getLLVMContext(), types);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public protocol P {}
2+
3+
public func callee<T: P>(t: T) -> some P { return t }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift-dylib(%t/%target-library-name(opaque_result_type_runtime_call_other)) -enable-library-evolution %S/Inputs/opaque_result_type_runtime_call_other.swift -emit-module -emit-module-path %t/opaque_result_type_runtime_call_other.swiftmodule -module-name opaque_result_type_runtime_call_other
3+
// RUN: %target-codesign %t/%target-library-name(opaque_result_type_runtime_call_other)
4+
// RUN: %target-build-swift %s -lopaque_result_type_runtime_call_other -I %t -L %t -o %t/main %target-rpath(%t)
5+
// RUN: %target-codesign %t/main
6+
// RUN: %target-run %t/main %t/%target-library-name(opaque_result_type_runtime_call_other) | %FileCheck %s
7+
8+
import opaque_result_type_runtime_call_other
9+
10+
extension String: P {}
11+
12+
func caller<T: P>(t: T) {
13+
print(callee(t: t))
14+
}
15+
16+
// CHECK: Hello, world
17+
caller(t: "Hello, world")

0 commit comments

Comments
 (0)