Skip to content

Commit 0c3be92

Browse files
authored
Merge pull request #83652 from a7medev/feat/generalize-erase-archetypes
[IDE] Erase archetypes without declaration generic signature
2 parents eae7864 + 491b3a0 commit 0c3be92

12 files changed

+52
-47
lines changed

lib/IDE/CodeCompletionStringBuilder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ using namespace swift;
2626
using namespace swift::ide;
2727

2828
Type ide::eraseArchetypes(Type type, GenericSignature genericSig) {
29-
if (!genericSig)
30-
return type;
31-
3229
if (auto *genericFuncType = type->getAs<GenericFunctionType>()) {
3330
assert(genericFuncType->getGenericSignature()->isEqual(genericSig) &&
3431
"if not, just use the GFT's signature instead below");
@@ -64,7 +61,7 @@ Type ide::eraseArchetypes(Type type, GenericSignature genericSig) {
6461
return upperBound;
6562
}
6663

67-
if (t->isTypeParameter()) {
64+
if (t->isTypeParameter() && genericSig) {
6865
auto upperBound =
6966
genericSig->getUpperBound(t,
7067
/*forExistentialSelf=*/false,

test/IDE/complete_after_sself.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ extension MyProto {
7373
Self.#^SSELF_DOT_IN_STATICMETHOD_MyProto^#
7474
}
7575
// CHECK-MyProto: Begin completions, 5 items
76-
// CHECK-MyProto-DAG: Keyword[self]/CurrNominal: self[#Self.Type#];
77-
// CHECK-MyProto-DAG: Keyword/CurrNominal: Type[#Self.Type#];
76+
// CHECK-MyProto-DAG: Keyword[self]/CurrNominal: self[#MyProto.Type#];
77+
// CHECK-MyProto-DAG: Keyword/CurrNominal: Type[#MyProto.Type#];
7878
// CHECK-MyProto-DAG: Decl[Constructor]/CurrNominal: init()[#MyProto#];
7979
// CHECK-MyProto-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod({#(self): MyProto#})[#() -> Void#];
8080
// CHECK-MyProto-DAG: Decl[StaticMethod]/CurrNominal: staticMethod()[#Void#];

test/IDE/complete_keypath_member_lookup.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,17 @@ func testGenericUnderconstrained1<G: P>(r: G) {
125125
r.#^testGenericUnderconstrained1^#
126126
}
127127
// testGenericUnderconstrained1-NOT: CurrNominal
128-
// testGenericUnderconstrained1: Keyword[self]/CurrNominal: self[#{{any P|G}}#];
128+
// testGenericUnderconstrained1: Keyword[self]/CurrNominal: self[#P#];
129129
// testGenericUnderconstrained1-NOT: CurrNominal
130130

131131
func testExistential1(r: P) {
132-
r.#^testExistential1?check=testGenericUnderconstrained1^#
132+
r.#^testExistential1^#
133133
}
134134

135+
// testExistential1-NOT: CurrNominal
136+
// testExistential1: Keyword[self]/CurrNominal: self[#any P#];
137+
// testExistential1-NOT: CurrNominal
138+
135139
@dynamicMemberLookup
136140
protocol E {
137141
subscript<U>(dynamicMember member: KeyPath<Point, U>) -> U

test/IDE/complete_members_optional.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ func optionalMembers2<T : HasOptionalMembers1>(_ a: T) {
4040
// OPTIONAL_MEMBERS_2-DAG: Decl[InstanceMethod]/CurrNominal: optionalInstanceFunc?({#(self): HasOptionalMembers1#})[#() -> Int#]{{; name=.+$}}
4141
// OPTIONAL_MEMBERS_2-DAG: Decl[StaticMethod]/CurrNominal: optionalClassFunc?()[#Int#]{{; name=.+$}}
4242
// OPTIONAL_MEMBERS_2-DAG: Decl[StaticVar]/CurrNominal: optionalClassProperty[#Int?#]{{; name=.+$}}
43-
// OPTIONAL_MEMBERS_2-DAG: Keyword[self]/CurrNominal: self[#T.Type#]; name=self
44-
// OPTIONAL_MEMBERS_2-DAG: Keyword/CurrNominal: Type[#T.Type#]; name=Type
43+
// OPTIONAL_MEMBERS_2-DAG: Keyword[self]/CurrNominal: self[#HasOptionalMembers1.Type#]; name=self
44+
// OPTIONAL_MEMBERS_2-DAG: Keyword/CurrNominal: Type[#HasOptionalMembers1.Type#]; name=Type

test/IDE/complete_operators.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func testPostfix9<G: P where G.T == Int>(x: G) {
7272
func testPostfix10<G: P where G.T : Fooable>(x: G) {
7373
x.foo()#^POSTFIX_10^#
7474
}
75-
// POSTFIX_10: Decl[PostfixOperatorFunction]/CurrModule: ***[#G.T#]
75+
// POSTFIX_10: Decl[PostfixOperatorFunction]/CurrModule: ***[#Fooable#]
7676

7777
func testPostfixSpace(x: inout S) {
7878
x #^S_POSTFIX_SPACE^#
@@ -172,7 +172,7 @@ func ****<T: Fooable>(x: T, y: T) -> T { return x }
172172
func testInfix9<T: P where T.T: Fooable>(x: T) {
173173
x.foo()#^INFIX_9?check=FOOABLE_INFIX^#
174174
}
175-
// FOOABLE_INFIX: Decl[InfixOperatorFunction]/CurrModule: **** {#T.T#}[#T.T#]
175+
// FOOABLE_INFIX: Decl[InfixOperatorFunction]/CurrModule: **** {#T.T#}[#Fooable#]
176176

177177
func testInfix10<T: P where T.T: Fooable>(x: T) {
178178
(x.foo() **** x.foo())#^INFIX_10?check=FOOABLE_INFIX^#
@@ -210,8 +210,8 @@ func testInfix15<T: P where T.T == S2>() {
210210
// INFIX_15: Begin completions, 6 items
211211
// INFIX_15-DAG: Decl[AssociatedType]/CurrNominal: .T; name=T
212212
// INFIX_15-DAG: Decl[InstanceMethod]/CurrNominal: .foo({#(self): P#})[#() -> S2#]; name=foo(:)
213-
// INFIX_15-DAG: Keyword[self]/CurrNominal: .self[#T.Type#]; name=self
214-
// INFIX_15-DAG: Keyword/CurrNominal: .Type[#T.Type#]; name=Type
213+
// INFIX_15-DAG: Keyword[self]/CurrNominal: .self[#P.Type#]; name=self
214+
// INFIX_15-DAG: Keyword/CurrNominal: .Type[#P.Type#]; name=Type
215215
// INFIX_15-DAG: Decl[InfixOperatorFunction]/OtherModule[Swift]/IsSystem: != {#(any (~Copyable & ~Escapable).Type)?#}[#Bool#];
216216
// INFIX_15-DAG: Decl[InfixOperatorFunction]/OtherModule[Swift]/IsSystem: == {#(any (~Copyable & ~Escapable).Type)?#}[#Bool#];
217217

@@ -221,7 +221,7 @@ func testInfix16<T: P where T.T == S2>() {
221221

222222
// INFIX_16: Begin completions, 2 items
223223
// INFIX_16-DAG: Decl[InstanceMethod]/CurrNominal/Flair[ArgLabels]: ({#(self): P#})[#() -> S2#]; name=(:)
224-
// INFIX_16-DAG: Keyword[self]/CurrNominal: .self[#(T) -> () -> S2#]; name=self
224+
// INFIX_16-DAG: Keyword[self]/CurrNominal: .self[#(P) -> () -> S2#]; name=self
225225

226226
func testInfix17(x: Void) {
227227
x#^INFIX_17?check=VOID_OPERATORS^#

test/IDE/complete_protocol_static_member.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func test<T: FontStyle>(x: T) {
2121
}
2222

2323
// EXTENSION_NOT_APPLIED: Begin completions, 1 item
24-
// EXTENSION_NOT_APPLIED-DAG: Keyword[self]/CurrNominal: self[#T#];
24+
// EXTENSION_NOT_APPLIED-DAG: Keyword[self]/CurrNominal: self[#FontStyle#];
2525
// EXTENSION_NOT_APPLIED-NOT: variableDeclaredInConstraintExtension
2626

2727
struct WrapperStruct<T: FontStyle> {

test/IDE/complete_subscript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func testSubscriptCallSig<T>(val: MyStruct1<T>) {
110110
val[#^LABELED_SUBSCRIPT^#
111111
// LABELED_SUBSCRIPT: Begin completions, 2 items
112112
// LABELED_SUBSCRIPT-DAG: Decl[Subscript]/CurrNominal/Flair[ArgLabels]: ['[']{#idx1: Int#}, {#idx2: Comparable#}[']'][#Int!#];
113-
// LABELED_SUBSCRIPT-DAG: Pattern/CurrNominal/Flair[ArgLabels]: ['[']{#keyPath: KeyPath<MyStruct1<T>, Value>#}[']'][#Value#];
113+
// LABELED_SUBSCRIPT-DAG: Pattern/CurrNominal/Flair[ArgLabels]: ['[']{#keyPath: KeyPath<MyStruct1<Comparable>, Value>#}[']'][#Value#];
114114
}
115115

116116
func testSubcscriptTuple(val: (x: Int, String)) {

test/IDE/complete_type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func testTypeIdentifierGeneric1<
622622

623623
// TYPE_IDENTIFIER_GENERIC_1: Begin completions, 2 items
624624
// TYPE_IDENTIFIER_GENERIC_1-DAG: Decl[AssociatedType]/CurrNominal: FooTypeAlias1{{; name=.+$}}
625-
// TYPE_IDENTIFIER_GENERIC_1-DAG: Keyword/None: Type[#GenericFoo.Type#]
625+
// TYPE_IDENTIFIER_GENERIC_1-DAG: Keyword/None: Type[#FooProtocol.Type#]
626626

627627
func testTypeIdentifierGeneric2<
628628
GenericFoo : FooProtocol & BarProtocol
@@ -631,7 +631,7 @@ func testTypeIdentifierGeneric2<
631631
// TYPE_IDENTIFIER_GENERIC_2: Begin completions, 3 items
632632
// TYPE_IDENTIFIER_GENERIC_2-DAG: Decl[AssociatedType]/CurrNominal: BarTypeAlias1{{; name=.+$}}
633633
// TYPE_IDENTIFIER_GENERIC_2-DAG: Decl[AssociatedType]/CurrNominal: FooTypeAlias1{{; name=.+$}}
634-
// TYPE_IDENTIFIER_GENERIC_2-DAG: Keyword/None: Type[#GenericFoo.Type#]
634+
// TYPE_IDENTIFIER_GENERIC_2-DAG: Keyword/None: Type[#(BarProtocol & FooProtocol).Type#]
635635

636636
func testTypeIdentifierGeneric3<
637637
GenericFoo>(a: GenericFoo.#^TYPE_IDENTIFIER_GENERIC_3^#

test/IDE/complete_type_subscript.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extension G6 {
101101
subscript(b x: Int) -> T.#^GEN_EXT_RETURN_6^# { return 0 }
102102
}
103103
// GEN_PARAM_6-DAG: Decl[AssociatedType]/CurrNominal: Assoc;
104-
// GEN_PARAM_6-DAG: Keyword/None: Type[#T.Type#];
104+
// GEN_PARAM_6-DAG: Keyword/None: Type[#It.Type#];
105105

106106
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_PARAM_1 | %FileCheck %s -check-prefix=GENPROTO_1
107107
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_RETURN_1 | %FileCheck %s -check-prefix=GENPROTO_1
@@ -117,4 +117,4 @@ extension GP1 {
117117
subscript(b x: Int) -> I.#^GENPROTO_EXT_RETURN_1^# { return 1 }
118118
}
119119
// GENPROTO_1-DAG: Decl[AssociatedType]/CurrNominal: Assoc;
120-
// GENPROTO_1-DAG: Keyword/None: Type[#Self.I.Type#];
120+
// GENPROTO_1-DAG: Keyword/None: Type[#It.Type#];

test/IDE/complete_value_expr.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ class TestResolveFuncParam2 {
775775

776776
func testResolveFuncParam3<Foo : FooProtocol>(_ foo: Foo) {
777777
foo.#^RESOLVE_FUNC_PARAM_3^#
778-
// RESOLVE_FUNC_PARAM_3-DAG: Keyword[self]/CurrNominal: self[#Foo#]; name=self
778+
// RESOLVE_FUNC_PARAM_3-DAG: Keyword[self]/CurrNominal: self[#FooProtocol#]; name=self
779779
// RESOLVE_FUNC_PARAM_3-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar1[#Int#]{{; name=.+$}}
780780
// RESOLVE_FUNC_PARAM_3-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar2[#Int#]{{; name=.+$}}
781781
// RESOLVE_FUNC_PARAM_3-DAG: Decl[InstanceMethod]/CurrNominal: fooInstanceFunc0()[#Double#]{{; name=.+$}}
@@ -784,7 +784,7 @@ func testResolveFuncParam3<Foo : FooProtocol>(_ foo: Foo) {
784784

785785
func testResolveFuncParam4<FooBar : FooProtocol & BarProtocol>(_ fooBar: FooBar) {
786786
fooBar.#^RESOLVE_FUNC_PARAM_4^#
787-
// RESOLVE_FUNC_PARAM_4-DAG: Keyword[self]/CurrNominal: self[#FooBar#]; name=self
787+
// RESOLVE_FUNC_PARAM_4-DAG: Keyword[self]/CurrNominal: self[#BarProtocol & FooProtocol#]; name=self
788788
// RESOLVE_FUNC_PARAM_4-DAG: Decl[InstanceVar]/CurrNominal: barInstanceVar[#Int#]{{; name=.+$}}
789789
// RESOLVE_FUNC_PARAM_4-DAG: Decl[InstanceMethod]/CurrNominal: barInstanceFunc0()[#Double#]{{; name=.+$}}
790790
// RESOLVE_FUNC_PARAM_4-DAG: Decl[InstanceMethod]/CurrNominal: barInstanceFunc1({#(a): Int#})[#Double#]{{; name=.+$}}
@@ -796,7 +796,7 @@ func testResolveFuncParam4<FooBar : FooProtocol & BarProtocol>(_ fooBar: FooBar)
796796

797797
func testResolveFuncParam5<FooExBarEx : FooExProtocol & BarExProtocol>(_ a: FooExBarEx) {
798798
a.#^RESOLVE_FUNC_PARAM_5^#
799-
// RESOLVE_FUNC_PARAM_5-DAG: Keyword[self]/CurrNominal: self[#FooExBarEx#]; name=self
799+
// RESOLVE_FUNC_PARAM_5-DAG: Keyword[self]/CurrNominal: self[#BarExProtocol & FooExProtocol#]; name=self
800800
// RESOLVE_FUNC_PARAM_5-DAG: Decl[InstanceMethod]/CurrNominal: barExInstanceFunc0()[#Double#]{{; name=.+$}}
801801
// RESOLVE_FUNC_PARAM_5-DAG: Decl[InstanceVar]/Super: barInstanceVar[#Int#]{{; name=.+$}}
802802
// RESOLVE_FUNC_PARAM_5-DAG: Decl[InstanceMethod]/Super: barInstanceFunc0()[#Double#]{{; name=.+$}}
@@ -810,7 +810,7 @@ func testResolveFuncParam5<FooExBarEx : FooExProtocol & BarExProtocol>(_ a: FooE
810810

811811
func testResolveFuncParam6<Foo : FooProtocol where Foo : FooClass>(_ foo: Foo) {
812812
foo.#^RESOLVE_FUNC_PARAM_6^#
813-
// RESOLVE_FUNC_PARAM_6-DAG: Keyword[self]/CurrNominal: self[#Foo#]; name=self
813+
// RESOLVE_FUNC_PARAM_6-DAG: Keyword[self]/CurrNominal: self[#FooClass & FooProtocol#]; name=self
814814
// RESOLVE_FUNC_PARAM_6-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar1[#Int#]{{; name=.+$}}
815815
// RESOLVE_FUNC_PARAM_6-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar2[#Int#]{{; name=.+$}}
816816
// RESOLVE_FUNC_PARAM_6-DAG: Decl[InstanceMethod]/CurrNominal: fooInstanceFunc0()[#Double#]{{; name=.+$}}
@@ -829,7 +829,7 @@ class TestResolveConstructorParam1 {
829829
class TestResolveConstructorParam2 {
830830
init<Foo : FooProtocol>(foo: Foo) {
831831
foo.#^RESOLVE_CONSTRUCTOR_PARAM_2^#
832-
// RESOLVE_CONSTRUCTOR_PARAM_2-DAG: Keyword[self]/CurrNominal: self[#Foo#]; name=self
832+
// RESOLVE_CONSTRUCTOR_PARAM_2-DAG: Keyword[self]/CurrNominal: self[#FooProtocol#]; name=self
833833
// RESOLVE_CONSTRUCTOR_PARAM_2-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar1[#Int#]{{; name=.+$}}
834834
// RESOLVE_CONSTRUCTOR_PARAM_2-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar2[#Int#]{{; name=.+$}}
835835
// RESOLVE_CONSTRUCTOR_PARAM_2-DAG: Decl[InstanceMethod]/CurrNominal: fooInstanceFunc0()[#Double#]{{; name=.+$}}
@@ -840,7 +840,7 @@ class TestResolveConstructorParam2 {
840840
class TestResolveConstructorParam3<Foo : FooProtocol> {
841841
init(foo: Foo) {
842842
foo.#^RESOLVE_CONSTRUCTOR_PARAM_3^#
843-
// RESOLVE_CONSTRUCTOR_PARAM_3-DAG: Keyword[self]/CurrNominal: self[#Foo#]; name=self
843+
// RESOLVE_CONSTRUCTOR_PARAM_3-DAG: Keyword[self]/CurrNominal: self[#FooProtocol#]; name=self
844844
// RESOLVE_CONSTRUCTOR_PARAM_3-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar1[#Int#]{{; name=.+$}}
845845
// RESOLVE_CONSTRUCTOR_PARAM_3-DAG: Decl[InstanceVar]/CurrNominal: fooInstanceVar2[#Int#]{{; name=.+$}}
846846
// RESOLVE_CONSTRUCTOR_PARAM_3-DAG: Decl[InstanceMethod]/CurrNominal: fooInstanceFunc0()[#Double#]{{; name=.+$}}
@@ -953,7 +953,7 @@ func testResolveGenericParams2<Foo : FooProtocol>(_ foo: Foo) {
953953
// RESOLVE_GENERIC_PARAMS_2-DAG: Decl[InstanceMethod]/CurrNominal: .fooVoidInstanceFunc1({#(a): FooProtocol#})[#Void#]{{; name=.+$}}
954954
// RESOLVE_GENERIC_PARAMS_2-DAG: Decl[InstanceMethod]/CurrNominal: .fooTInstanceFunc1({#(a): FooProtocol#})[#FooProtocol#]{{; name=.+$}}
955955
// RESOLVE_GENERIC_PARAMS_2-DAG: Decl[InstanceMethod]/CurrNominal: .fooUInstanceFunc1({#(a): U#})[#U#]{{; name=.+$}}
956-
// RESOLVE_GENERIC_PARAMS_2-DAG: Keyword[self]/CurrNominal: .self[#FooGenericStruct<Foo>#]; name=self
956+
// RESOLVE_GENERIC_PARAMS_2-DAG: Keyword[self]/CurrNominal: .self[#FooGenericStruct<FooProtocol>#]; name=self
957957

958958
FooGenericStruct<Foo>#^RESOLVE_GENERIC_PARAMS_2_STATIC^#
959959
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ()[#FooGenericStruct<FooProtocol>#]; name=()
@@ -966,8 +966,8 @@ func testResolveGenericParams2<Foo : FooProtocol>(_ foo: Foo) {
966966
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Decl[StaticMethod]/CurrNominal: .fooVoidStaticFunc1({#(a): FooProtocol#})[#Void#]{{; name=.+$}}
967967
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Decl[StaticMethod]/CurrNominal: .fooTStaticFunc1({#(a): FooProtocol#})[#FooProtocol#]{{; name=.+$}}
968968
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Decl[StaticMethod]/CurrNominal: .fooUInstanceFunc1({#(a): U#})[#U#]{{; name=.+$}}
969-
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Keyword[self]/CurrNominal: .self[#FooGenericStruct<Foo>.Type#]; name=self
970-
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Keyword/CurrNominal: .Type[#FooGenericStruct<Foo>.Type#]; name=Type
969+
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Keyword[self]/CurrNominal: .self[#FooGenericStruct<FooProtocol>.Type#]; name=self
970+
// RESOLVE_GENERIC_PARAMS_2_STATIC-DAG: Keyword/CurrNominal: .Type[#FooGenericStruct<FooProtocol>.Type#]; name=Type
971971

972972
}
973973

@@ -1571,7 +1571,7 @@ func testDeDuped3<T : dedupP where T.T == Int>(_ x: T) {
15711571
// PROTOCOL_EXT_DEDUP_3-DAG: Decl[InstanceMethod]/CurrNominal: .foo()[#Int#]; name=foo()
15721572
// PROTOCOL_EXT_DEDUP_3-DAG: Decl[InstanceVar]/CurrNominal: .bar[#Int#]; name=bar
15731573
// PROTOCOL_EXT_DEDUP_3-DAG: Decl[Subscript]/CurrNominal: [{#(x): Int#}][#Int#]; name=[:]
1574-
// PROTOCOL_EXT_DEDUP_3-DAG: Keyword[self]/CurrNominal: .self[#T#]; name=self
1574+
// PROTOCOL_EXT_DEDUP_3-DAG: Keyword[self]/CurrNominal: .self[#dedupP#]; name=self
15751575
}
15761576
15771577
//===--- Check calls that may throw

0 commit comments

Comments
 (0)