Skip to content

[AST Mangler] Don't mangle marker protocols in retroactive conformances. #59103

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
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
10 changes: 10 additions & 0 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,10 @@ static bool isRetroactiveConformance(const RootProtocolConformance *root) {
return false; // self-conformances are never retroactive. nor are builtin.
}

// Don't consider marker protocols at all.
if (conformance->getProtocol()->isMarkerProtocol())
return false;

return conformance->isRetroactive();
}

Expand Down Expand Up @@ -1682,6 +1686,12 @@ void ASTMangler::appendRetroactiveConformances(SubstitutionMap subMap,

unsigned numProtocolRequirements = 0;
for (auto conformance : subMap.getConformances()) {
if (conformance.isInvalid())
continue;

if (conformance.getRequirement()->isMarkerProtocol())
continue;

SWIFT_DEFER {
++numProtocolRequirements;
};
Expand Down
5 changes: 5 additions & 0 deletions test/IRGen/marker_protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ public func markerInDictionary() -> Any {
// CHECK: swiftcc void @"$s15marker_protocol7genericyyxAA1PRzlF"(%swift.opaque* noalias nocapture %0, %swift.type* %T)
public func generic<T: P>(_: T) { }

public struct GenericType<T: Hashable & P> { }

// CHECK-LABEL: @"$s15marker_protocol11testGeneric1i5arrayySi_SaySiGtF"(
public func testGeneric(i: Int, array: [Int]) {
generic(i)
generic(array)
// CHECK: __swift_instantiateConcreteTypeFromMangledName{{.*}}$s15marker_protocol11GenericTypeVySaySiGGmMD
print(GenericType<[Int]>.self)
}

// Forming an existential involving a marker protocol would crash the compiler
Expand Down