Skip to content

Commit 13da4c2

Browse files
authored
Merge pull request swiftlang#77034 from slavapestov/fix-rdar117815191
IRGen: Fix emission of calls to opaque return type metadata access function with packs
2 parents 1e7cc98 + 6437e32 commit 13da4c2

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,16 @@ withOpaqueTypeGenericArgs(IRGenFunction &IGF,
453453
SmallVector<llvm::Value *, 4> args;
454454
SmallVector<llvm::Type *, 4> types;
455455

456+
// We need to pass onHeapPacks=true because the runtime demangler
457+
// expects to differentiate on-heap packs from non-pack types by
458+
// checking the least significant bit of the metadata pointer.
456459
enumerateGenericSignatureRequirements(
457460
opaqueDecl->getGenericSignature().getCanonicalSignature(),
458461
[&](GenericRequirement reqt) {
459462
auto arg = emitGenericRequirementFromSubstitutions(
460463
IGF, reqt, MetadataState::Abstract,
461-
archetype->getSubstitutions());
464+
archetype->getSubstitutions(),
465+
/*onHeapPacks=*/true);
462466
args.push_back(arg);
463467
types.push_back(args.back()->getType());
464468
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public protocol P {}
2+
3+
extension Int: P {}
4+
extension String: P {}
5+
extension Bool: P {}
6+
extension Double: P {}
7+
8+
public protocol Q {}
9+
10+
public func f1<each T: P>(_ t: repeat each T) -> some Any {
11+
return (repeat each t)
12+
}
13+
14+
public struct G2<T>: Q {}
15+
public func f2<each T: P>(_ t: repeat each T) -> some Q {
16+
return G2<(repeat each T)>()
17+
}
18+
19+
public struct G3<each T>: Q {}
20+
public func f3<each T: P>(_ t: repeat each T) -> some Q {
21+
return G3<repeat each T>()
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t)
2+
//
3+
// RUN: %target-build-swift-dylib(%t/%target-library-name(variadic_generic_opaque_type_other)) %S/Inputs/variadic_generic_opaque_type_other.swift -emit-module -emit-module-path %t/variadic_generic_opaque_type_other.swiftmodule -module-name variadic_generic_opaque_type_other -Xfrontend -disable-availability-checking -enable-library-evolution
4+
// RUN: %target-codesign %t/%target-library-name(variadic_generic_opaque_type_other)
5+
//
6+
// RUN: %target-build-swift %s -I %t -o %t/main.out -L %t %target-rpath(%t) -lvariadic_generic_opaque_type_other
7+
// RUN: %target-codesign %t/main.out
8+
//
9+
// RUN: %target-run %t/main.out %t/%target-library-name(variadic_generic_opaque_type_other)
10+
11+
// REQUIRES: executable_test
12+
13+
import variadic_generic_opaque_type_other
14+
import StdlibUnittest
15+
16+
var opaque = TestSuite("VariadicGenericOpaqueTypes")
17+
18+
func getType<T>(_: T) -> Any.Type {
19+
return T.self
20+
}
21+
22+
opaque.test("Opaque1") {
23+
expectEqual((Int, String).self, getType(f1(1, "hi")))
24+
expectEqual(G2<(Bool, String)>.self, getType(f2(false, "hi")))
25+
expectEqual(G3<Bool, Double>.self, getType(f3(false, 3.0)))
26+
}
27+
28+
func g1<each T: P>(_ t: repeat each T) -> Any.Type {
29+
return getType(f1(repeat each t))
30+
}
31+
func g2<each T: P>(_ t: repeat each T) -> Any.Type {
32+
return getType(f2(repeat each t))
33+
}
34+
func g3<each T: P>(_ t: repeat each T) -> Any.Type {
35+
return getType(f3(repeat each t))
36+
}
37+
38+
opaque.test("Opaque2") {
39+
expectEqual((Int, String).self, g1(1, "hi"))
40+
expectEqual(G2<(Bool, String)>.self, g2(false, "hi"))
41+
expectEqual(G3<Bool, Double>.self, g3(false, 3.0))
42+
}
43+
44+
runAllTests()

0 commit comments

Comments
 (0)