Skip to content

Commit 3e7a7fe

Browse files
committed
Swift: Mangle ArchetypeTypes with different constraints in different extensions.
1 parent 3061530 commit 3e7a7fe

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

swift/extractor/mangler/SwiftMangler.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,15 @@ SwiftMangledName SwiftMangler::visitTypeAliasType(const swift::TypeAliasType* ty
307307
}
308308

309309
SwiftMangledName SwiftMangler::visitArchetypeType(const swift::ArchetypeType* type) {
310-
return initMangled(type) << fetch(type->getInterfaceType());
310+
auto ret = initMangled(type) << fetch(type->getInterfaceType());
311+
for (const auto* protocol : type->getConformsTo()) {
312+
// Including the protocols in the mangled name allows us to distinguish the "same" type in
313+
// different extensions, where it might have different constraints. Mangling the context (i.e.
314+
// which ExtensionDecl or ValueDecl it's mentioned in) might be more robust, but there doesn't
315+
// seem to be a clean way to get it.
316+
ret << ':' << fetch(protocol);
317+
}
318+
return ret;
311319
}
312320

313321
SwiftMangledName SwiftMangler::visitOpaqueTypeArchetypeType(

swift/ql/test/extractor-tests/generated/type/PrimaryArchetypeType/PrimaryArchetypeType.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| Base | getName: | Base | getCanonicalType: | Base | getInterfaceType: | Base | hasSuperclass: | no | getNumberOfProtocols: | 1 |
2+
| Base | getName: | Base | getCanonicalType: | Base | getInterfaceType: | Base | hasSuperclass: | no | getNumberOfProtocols: | 1 |
13
| Param | getName: | Param | getCanonicalType: | Param | getInterfaceType: | Param | hasSuperclass: | no | getNumberOfProtocols: | 0 |
24
| ParamWithProtocols | getName: | ParamWithProtocols | getCanonicalType: | ParamWithProtocols | getInterfaceType: | ParamWithProtocols | hasSuperclass: | no | getNumberOfProtocols: | 2 |
35
| ParamWithSuperclass | getName: | ParamWithSuperclass | getCanonicalType: | ParamWithSuperclass | getInterfaceType: | ParamWithSuperclass | hasSuperclass: | yes | getNumberOfProtocols: | 0 |

swift/ql/test/extractor-tests/generated/type/PrimaryArchetypeType/PrimaryArchetypeType_getProtocol.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| Base | 0 | primary_archetypes.swift:3:1:3:13 | P |
2+
| Base | 0 | primary_archetypes.swift:4:1:4:14 | P2 |
13
| ParamWithProtocols | 0 | file://:0:0:0:0 | Equatable |
24
| ParamWithProtocols | 1 | primary_archetypes.swift:3:1:3:13 | P |
35
| ParamWithSuperclassAndProtocols | 0 | file://:0:0:0:0 | Equatable |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
class S {}
22

33
protocol P {}
4+
protocol P2 {}
45

56
func foo<Param,
67
ParamWithSuperclass: S,
78
ParamWithProtocols: P & Equatable,
89
ParamWithSuperclassAndProtocols: S & Equatable & P>(
910
_: Param, _: ParamWithSuperclass, _: ParamWithProtocols, _: ParamWithSuperclassAndProtocols) {}
11+
12+
class Generic<Base> {}
13+
extension Generic where Base : P {
14+
func f(_: Base) {}
15+
}
16+
17+
extension Generic where Base : P2 {
18+
func f(_: Base) {}
19+
}

0 commit comments

Comments
 (0)