Swift: Mangle ArchetypeTypes with different superclasses in different extensions.

This commit is contained in:
Alexandre Boulgakov
2023-08-02 15:18:52 +01:00
parent 3e7a7fe54e
commit 0dafe2d757
5 changed files with 18 additions and 5 deletions

View File

@@ -308,6 +308,9 @@ SwiftMangledName SwiftMangler::visitTypeAliasType(const swift::TypeAliasType* ty
SwiftMangledName SwiftMangler::visitArchetypeType(const swift::ArchetypeType* type) {
auto ret = initMangled(type) << fetch(type->getInterfaceType());
if (const auto super = type->getSuperclass()) {
ret << ':' << fetch(super);
}
for (const auto* protocol : type->getConformsTo()) {
// Including the protocols in the mangled name allows us to distinguish the "same" type in
// different extensions, where it might have different constraints. Mangling the context (i.e.

View File

@@ -1,5 +1,7 @@
| Base | getName: | Base | getCanonicalType: | Base | getInterfaceType: | Base | hasSuperclass: | no | getNumberOfProtocols: | 1 |
| Base | getName: | Base | getCanonicalType: | Base | getInterfaceType: | Base | hasSuperclass: | no | getNumberOfProtocols: | 1 |
| Base | getName: | Base | getCanonicalType: | Base | getInterfaceType: | Base | hasSuperclass: | yes | getNumberOfProtocols: | 0 |
| Base | getName: | Base | getCanonicalType: | Base | getInterfaceType: | Base | hasSuperclass: | yes | getNumberOfProtocols: | 0 |
| Param | getName: | Param | getCanonicalType: | Param | getInterfaceType: | Param | hasSuperclass: | no | getNumberOfProtocols: | 0 |
| ParamWithProtocols | getName: | ParamWithProtocols | getCanonicalType: | ParamWithProtocols | getInterfaceType: | ParamWithProtocols | hasSuperclass: | no | getNumberOfProtocols: | 2 |
| ParamWithSuperclass | getName: | ParamWithSuperclass | getCanonicalType: | ParamWithSuperclass | getInterfaceType: | ParamWithSuperclass | hasSuperclass: | yes | getNumberOfProtocols: | 0 |

View File

@@ -1,6 +1,6 @@
| Base | 0 | primary_archetypes.swift:3:1:3:13 | P |
| Base | 0 | primary_archetypes.swift:4:1:4:14 | P2 |
| Base | 0 | primary_archetypes.swift:4:1:4:13 | P |
| Base | 0 | primary_archetypes.swift:5:1:5:14 | P2 |
| ParamWithProtocols | 0 | file://:0:0:0:0 | Equatable |
| ParamWithProtocols | 1 | primary_archetypes.swift:3:1:3:13 | P |
| ParamWithProtocols | 1 | primary_archetypes.swift:4:1:4:13 | P |
| ParamWithSuperclassAndProtocols | 0 | file://:0:0:0:0 | Equatable |
| ParamWithSuperclassAndProtocols | 1 | primary_archetypes.swift:3:1:3:13 | P |
| ParamWithSuperclassAndProtocols | 1 | primary_archetypes.swift:4:1:4:13 | P |

View File

@@ -1,2 +1,4 @@
| Base | S |
| Base | S2 |
| ParamWithSuperclass | S |
| ParamWithSuperclassAndProtocols | S |

View File

@@ -1,4 +1,5 @@
class S {}
class S2 {}
protocol P {}
protocol P2 {}
@@ -13,7 +14,12 @@ class Generic<Base> {}
extension Generic where Base : P {
func f(_: Base) {}
}
extension Generic where Base : P2 {
func f(_: Base) {}
}
extension Generic where Base : S {
func f(_: Base) {}
}
extension Generic where Base : S2 {
func f(_: Base) {}
}