mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
In a generic signature like <T, U where T.A == U>, there is only one primary archetype, 'T'. 'U' will not appear in SubstitutionMaps, and the SubstitutionMap version of Type::subst() cannot handle an interface type containing 'U'. For interface types, there are two levels of canonicalization: - The AST-level getCanonicalType() which strips away sugar - The GenericSignature-level getCanonicalTypeInContext() which replaces each interface type in an equivalence class with a representative SILFunctionTypes must be canonical with respect to a generic signature. When emitting re-abstraction thunks we could end up constructing a SILFunctionType containing 'U', because we were calling getCanonicalType() on the result of mapTypeOutOfContext(). Fix this by making sure to use getCanonicalTypeInContext() on the result of mapTypeOutOfContext(), just as we do in capture lowering. Unfortunately I worry this problem will come up again in a different form -- a more general fix would change mapTypeOutOfContext() to always return "generic signature canonical" types, and also fix SubstitutionMaps to understand same type constraints better. Fixes <https://bugs.swift.org/browse/SR-3326>.
12 lines
319 B
Swift
12 lines
319 B
Swift
// RUN: %target-swift-frontend %s -emit-ir
|
|
|
|
extension Collection where Self.Iterator.Element: Equatable {
|
|
func count<T: Equatable>(of element: T) -> Int where T == Self.Iterator.Element {
|
|
return self.reduce(0) {
|
|
sum, e in
|
|
let isSame: Int = (e == element ? 1 : 0)
|
|
return sum + isSame
|
|
}
|
|
}
|
|
}
|