Skip to content

Commit 1f69673

Browse files
authored
Merge pull request #85450 from kavon/keypath-metadata-fix
IRGen/ABI: fix count of requirements in getAddrOfGenericEnvironment
2 parents 354b461 + 38af19b commit 1f69673

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/IRGen/GenProto.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4669,9 +4669,13 @@ llvm::Constant *IRGenModule::getAddrOfGenericEnvironment(
46694669
}
46704670
genericParamCounts.push_back(genericParamCount);
46714671

4672+
SmallVector<Requirement, 2> reqs;
4673+
SmallVector<InverseRequirement, 2> inverses;
4674+
signature->getRequirementsWithInverses(reqs, inverses);
4675+
46724676
auto flags = GenericEnvironmentFlags()
46734677
.withNumGenericParameterLevels(genericParamCounts.size())
4674-
.withNumGenericRequirements(signature.getRequirements().size());
4678+
.withNumGenericRequirements(reqs.size());
46754679

46764680
ConstantStructBuilder fields = builder.beginStruct();
46774681
fields.setPacked(true);
@@ -4698,7 +4702,7 @@ llvm::Constant *IRGenModule::getAddrOfGenericEnvironment(
46984702
fields.addAlignmentPadding(Alignment(4));
46994703

47004704
// Generic requirements
4701-
irgen::addGenericRequirements(*this, fields, signature);
4705+
irgen::addGenericRequirements(*this, fields, signature, reqs, inverses);
47024706
return fields.finishAndCreateFuture();
47034707
});
47044708
}

test/IRGen/keypaths_inverses.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-frontend -module-name keypaths -emit-ir %s | %FileCheck %s
2+
3+
// The purpose of this test is to validate that a keypath formed via a protocol
4+
// that has an inverse requirement on Self produces the same generic environment
5+
// metadata as one without the inverse. So Mashable and Dashable should have the
6+
// same metadata fundamentally.
7+
8+
// CHECK-LABEL: @"generic environment 8keypaths8MashableRzl" = linkonce_odr hidden constant
9+
// CHECK-SAME: i32 4097, i16 1, i8 -128, [1 x i8] zeroinitializer, i32 128
10+
11+
// CHECK-LABEL: @"generic environment 8keypaths8DashableRzl" = linkonce_odr hidden constant
12+
// CHECK-SAME: i32 4097, i16 1, i8 -128, [1 x i8] zeroinitializer, i32 128
13+
14+
15+
protocol Mashable: ~Copyable {
16+
var masher: String { get set }
17+
}
18+
19+
protocol Dashable {
20+
var dasher: String { get set }
21+
}
22+
23+
func formKeypath1<T: Mashable>(_ t: T) -> WritableKeyPath<T, String> {
24+
return \T.masher
25+
}
26+
27+
func formKeypath2<T: Dashable>(_ t: T) -> WritableKeyPath<T, String> {
28+
return \T.dasher
29+
}

0 commit comments

Comments
 (0)