Skip to content

IRGen: Consistently mangle 'associated type paths' without a generic signature #38304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
4 changes: 4 additions & 0 deletions lib/IRGen/IRGenMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ std::string IRGenMangler::mangleSymbolNameForAssociatedConformanceWitness(
Buffer << "default associated conformance";
}

// appendProtocolConformance() sets CurGenericSignature; clear it out
// before calling appendAssociatedTypePath().
CurGenericSignature = nullptr;

bool isFirstAssociatedTypeIdentifier = true;
appendAssociatedTypePath(associatedType, isFirstAssociatedTypeIdentifier);
appendProtocolName(proto);
Expand Down
9 changes: 9 additions & 0 deletions lib/IRGen/IRGenMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ class IRGenMangler : public Mangle::ASTMangler {
const ProtocolDecl *Proto) {
beginMangling();
appendProtocolConformance(Conformance);

// appendProtocolConformance() sets CurGenericSignature; clear it out
// before calling appendAssociatedTypePath().
CurGenericSignature = nullptr;

bool isFirstAssociatedTypeIdentifier = true;
appendAssociatedTypePath(AssociatedType, isFirstAssociatedTypeIdentifier);
appendAnyGenericType(Proto);
Expand All @@ -444,6 +449,10 @@ class IRGenMangler : public Mangle::ASTMangler {
}

void appendAssociatedTypePath(CanType associatedType, bool &isFirst) {
// In the mangling format, the "short associated type" optimization is
// not performed when mangling an associated type path.
assert(!CurGenericSignature && "Caller needs to explicitly clear the signature");

if (auto memberType = dyn_cast<DependentMemberType>(associatedType)) {
appendAssociatedTypePath(memberType.getBase(), isFirst);
appendAssociatedTypeName(memberType);
Expand Down
8 changes: 4 additions & 4 deletions test/IRGen/associated_type_witness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct WithUniversal : Assocked {
// Witness table for GenericWithUniversal : Assocked.
// GLOBAL-LABEL: @"$s23associated_type_witness20GenericWithUniversalVyxGAA8AssockedAAWP" = hidden global [4 x i8*] [
// GLOBAL-SAME: @"$s23associated_type_witness20GenericWithUniversalVyxGAA8AssockedAAMc"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness20GenericWithUniversalVyxGAA8AssockedAA5Assoc_AA1P"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness20GenericWithUniversalVyxGAA8AssockedAA5Assoc_AA1Q"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness20GenericWithUniversalVyxGAA8AssockedAA5AssocAaEP_AA1P"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness20GenericWithUniversalVyxGAA8AssockedAA5AssocAaEP_AA1Q"
// GLOBAL-SAME: @"symbolic{{.*}}23associated_type_witness9UniversalV"
// GLOBAL-SAME: ]
struct GenericWithUniversal<T> : Assocked {
Expand Down Expand Up @@ -88,8 +88,8 @@ struct Pair<T, U> : P, Q {}
// Generic witness table pattern for Computed : Assocked.
// GLOBAL-LABEL: @"$s23associated_type_witness8ComputedVyxq_GAA8AssockedAAWp" = internal global [4 x i8*] [
// GLOBAL-SAME: @"$s23associated_type_witness8ComputedVyxq_GAA8AssockedAAMc"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness8ComputedVyxq_GAA8AssockedAA5Assoc_AA1P"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness8ComputedVyxq_GAA8AssockedAA5Assoc_AA1Q"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness8ComputedVyxq_GAA8AssockedAA5AssocAaEP_AA1P"
// GLOBAL-SAME: @"associated conformance 23associated_type_witness8ComputedVyxq_GAA8AssockedAA5AssocAaEP_AA1Q"
// GLOBAL-SAME: @"symbolic{{.*}}23associated_type_witness4PairV{{.*}}"
// GLOBAL-SAME: ]

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/assoctypepath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protocol P {
protocol Q: P where A: Z {}
protocol R: Q where A.ZZ: Y {}

// CHECK: define {{.*}} @"$s13assoctypepath1SVyxGAA1RAA1A_2ZZAA1YPWT"
// CHECK: define {{.*}} @"$s13assoctypepath1SVyxGAA1RAA1AAA1PP_2ZZAA1ZPAA1YPWT"

struct S<T>: R where T: Z, T.ZZ: Y {
typealias A = T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Foo<T: Tubb>: P {
func foo(_ x: T) -> some Tubb { return x }
}

// CHECK-LABEL: define {{.*}} @"$s030opaque_result_type_associated_C17_conformance_path3FooVyxGAA1PAA1B_AA4ButtPWT"
// CHECK-LABEL: define {{.*}} @"$s030opaque_result_type_associated_C17_conformance_path3FooVyxGAA1PAA1AAaEP_AA4ButtPWT"
// CHECK: [[TUBB_CONFORMANCE:%.*]] = call swiftcc i8** @swift_getOpaqueTypeConformance({{.*}}, i{{.*}} 1)
// CHECK: [[BUTT_CONFORMANCE_ADDR:%.*]] = getelementptr {{.*}} [[TUBB_CONFORMANCE]], i32 1
// CHECK: [[BUTT_CONFORMANCE_LOAD:%.*]] = load {{.*}} [[BUTT_CONFORMANCE_ADDR]]
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/same_type_constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where Self : CodingType,
print(Self.ValueType.self)
}

// OSIZE: define internal swiftcc i8** @"$s21same_type_constraints12GenericKlazzCyxq_GAA1EAA4Data_AA0F4TypePWT"(%swift.type* readnone %"GenericKlazz<T, R>.Data", %swift.type* nocapture readonly %"GenericKlazz<T, R>", i8** nocapture readnone %"GenericKlazz<T, R>.E") [[ATTRS:#[0-9]+]] {
// OSIZE: define internal swiftcc i8** @"$s21same_type_constraints12GenericKlazzCyxq_GAA1EAA4DataAaEP_AA0F4TypePWT"(%swift.type* readnone %"GenericKlazz<T, R>.Data", %swift.type* nocapture readonly %"GenericKlazz<T, R>", i8** nocapture readnone %"GenericKlazz<T, R>.E") [[ATTRS:#[0-9]+]] {
// OSIZE: [[ATTRS]] = {{{.*}}noinline

// Check that same-typing two generic parameters together lowers correctly.
Expand Down
2 changes: 1 addition & 1 deletion test/Inputs/conditional_conformance_recursive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protocol P3: P2 where A: P3 { }
extension Wrapper: P3 where T: P3 { }

// associated type witness table accessor for A : P2 in Wrapper<T>: P2
// CHECK-LABEL: define internal swiftcc i8** @"$s33conditional_conformance_recursive7WrapperVyxGAA2P2A2aERzrl1A_AaEPWT"
// CHECK-LABEL: define internal swiftcc i8** @"$s33conditional_conformance_recursive7WrapperVyxGAA2P2A2aERzrl1AAA2P1P_AaEPWT"
// CHECK: [[CONDITIONAL_REQ_BUFFER:%.*]] = alloca [1 x i8**]
// CHECK: [[FIRST_REQ:%.*]] = getelementptr inbounds [1 x i8**], [1 x i8**]* [[CONDITIONAL_REQ_BUFFER]]
// CHECK: call i8** @swift_getWitnessTable