Skip to content

Commit da5ce12

Browse files
authored
Merge pull request #77599 from slavapestov/fix-rdar139745699
IRGen: Adjust hacks for keypaths to protocol extension members
2 parents 4719661 + 0a23afc commit da5ce12

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,10 @@ std::string ASTMangler::mangleKeyPathGetterThunkHelper(
343343
// FIXME: This seems wrong. We used to just mangle opened archetypes as
344344
// their interface type. Let's make that explicit now.
345345
sub = sub.transformRec([](Type t) -> std::optional<Type> {
346-
if (auto *openedExistential = t->getAs<OpenedArchetypeType>())
347-
return openedExistential->getInterfaceType();
346+
if (auto *openedExistential = t->getAs<OpenedArchetypeType>()) {
347+
auto &ctx = openedExistential->getASTContext();
348+
return GenericTypeParamType::getType(0, 0, ctx);
349+
}
348350
return std::nullopt;
349351
});
350352

@@ -377,8 +379,10 @@ std::string ASTMangler::mangleKeyPathSetterThunkHelper(
377379
// FIXME: This seems wrong. We used to just mangle opened archetypes as
378380
// their interface type. Let's make that explicit now.
379381
sub = sub.transformRec([](Type t) -> std::optional<Type> {
380-
if (auto *openedExistential = t->getAs<OpenedArchetypeType>())
381-
return openedExistential->getInterfaceType();
382+
if (auto *openedExistential = t->getAs<OpenedArchetypeType>()) {
383+
auto &ctx = openedExistential->getASTContext();
384+
return GenericTypeParamType::getType(0, 0, ctx);
385+
}
382386
return std::nullopt;
383387
});
384388

lib/IRGen/GenHeap.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,10 @@ class FixedBoxTypeInfoBase : public BoxTypeInfo {
15731573
astType =
15741574
astType
15751575
.transformRec([](Type t) -> std::optional<Type> {
1576-
if (auto *openedExistential = t->getAs<OpenedArchetypeType>())
1577-
return openedExistential->getInterfaceType();
1576+
if (auto *openedExistential = t->getAs<OpenedArchetypeType>()) {
1577+
auto &ctx = openedExistential->getASTContext();
1578+
return GenericTypeParamType::getType(0, 0, ctx);
1579+
}
15781580
return std::nullopt;
15791581
})
15801582
->getCanonicalType();

lib/IRGen/GenKeyPath.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,10 @@ emitKeyPathComponent(IRGenModule &IGM,
784784
substType = substType
785785
.transformRec([](Type t) -> std::optional<Type> {
786786
if (auto *openedExistential =
787-
t->getAs<OpenedArchetypeType>())
788-
return openedExistential->getInterfaceType();
787+
t->getAs<OpenedArchetypeType>()) {
788+
auto &ctx = openedExistential->getASTContext();
789+
return GenericTypeParamType::getType(0, 0, ctx);
790+
}
789791
return std::nullopt;
790792
})
791793
->getCanonicalType();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public protocol P<A> {
2+
associatedtype A
3+
}
4+
5+
extension P {
6+
public var value: Bool { true }
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/keypath_protocol_extension_other.swift -emit-module-path %t/keypath_protocol_extension_other.swiftmodule
3+
// RUN: %target-swift-frontend -emit-ir %s -I %t
4+
5+
import keypath_protocol_extension_other
6+
7+
public func foo(array: [any P<String>]) {
8+
_ = array.filter(\.value)
9+
}

0 commit comments

Comments
 (0)