From b7e884bbf0cbf7cc3064959d9a11132f6cd03008 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Tue, 24 Oct 2023 09:27:27 -0700 Subject: [PATCH] Fix a round trip debug type failure with typealias When checking equality of types with existential types removed, recursively remove existential types inside an existential type. Fixes: #66554 Cherrypick https://github.com/apple/swift/commit/fda6f9b62febaba0620469a901de4168df47e27e --- lib/IRGen/IRGenDebugInfo.cpp | 7 ++++--- test/IRGen/round-trip-debug-types-typealias.swift | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/IRGen/round-trip-debug-types-typealias.swift diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 1b01a83d9991d..32829b1e6d7e7 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -98,10 +98,11 @@ class EqualUpToClangTypes }; static bool equalWithoutExistentialTypes(Type t1, Type t2) { - auto withoutExistentialTypes = [](Type type) -> Type { + static Type (*withoutExistentialTypes)(Type) = [](Type type) -> Type { return type.transform([](Type type) -> Type { - if (auto existential = type->getAs()) - return existential->getConstraintType(); + if (auto existential = type->getAs()) { + return withoutExistentialTypes(existential->getConstraintType()); + } return type; }); }; diff --git a/test/IRGen/round-trip-debug-types-typealias.swift b/test/IRGen/round-trip-debug-types-typealias.swift new file mode 100644 index 0000000000000..722124ae9bfcf --- /dev/null +++ b/test/IRGen/round-trip-debug-types-typealias.swift @@ -0,0 +1,10 @@ +// RUN: %target-build-swift -g %s + +// https://github.com/apple/swift/issues/66554 +// IRGenDebugInfo type reconstruction crash because existential types +// inside typealias are not taken into account when comparing type +// equality + +protocol Protocol { associatedtype T } +typealias AnyProtocol = any Protocol +let crash: AnyProtocol