Files
swift-mirror/validation-test/compiler_crashers_2_fixed/0056-sr3326.swift
Slava Pestov 9b03f9d18c SILGen: Fix reabstraction thunk emission when generic parameters are made non-canonical
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>.
2017-01-03 21:49:44 -08:00

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
}
}
}