Skip to content

Commit 03b3f58

Browse files
committed
[test] Fix tests that look at Hashable requirements
_hash(into:) needs to be included in expectations; tests looking at synthesized Hashable implementation bodies need to be updated for resilient hashing. # Conflicts: # test/IDE/complete_enum_elements.swift
1 parent 80bee12 commit 03b3f58

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

test/IDE/complete_enum_elements.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
// RUN: %FileCheck %s -check-prefix=QUX_ENUM_NO_DOT < %t.enum.txt
5151

5252
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ENUM_QUAL_DOT_1 > %t.enum.txt
53-
// RUN: %FileCheck %s -check-prefix=FOO_ENUM_DOT < %t.enum.txt
53+
// RUN: %FileCheck %s -check-prefix=FOO_ENUM_DOT_INVALID < %t.enum.txt
5454

5555
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ENUM_QUAL_DOT_2 > %t.enum.txt
5656
// RUN: %FileCheck %s -check-prefix=BAR_ENUM_DOT < %t.enum.txt
@@ -88,17 +88,27 @@ enum FooEnum: CaseIterable {
8888
// FOO_ENUM_NO_DOT: Begin completions
8989
// FOO_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Foo1[#FooEnum#]{{; name=.+$}}
9090
// FOO_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Foo2[#FooEnum#]{{; name=.+$}}
91+
// FOO_ENUM_NO_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: ._hash({#self: FooEnum#})[#(into: inout _Hasher) -> Void#]; name=_hash(FooEnum)
9192
// FOO_ENUM_NO_DOT-NEXT: Decl[TypeAlias]/CurrNominal: .AllCases[#[FooEnum]#]{{; name=.+$}}
9293
// FOO_ENUM_NO_DOT-NEXT: Decl[StaticVar]/CurrNominal: .allCases[#[FooEnum]#]{{; name=.+$}}
9394
// FOO_ENUM_NO_DOT-NEXT: End completions
9495

9596
// FOO_ENUM_DOT: Begin completions
9697
// FOO_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Foo1[#FooEnum#]{{; name=.+$}}
9798
// FOO_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Foo2[#FooEnum#]{{; name=.+$}}
99+
// FOO_ENUM_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: _hash({#self: FooEnum#})[#(into: inout _Hasher) -> Void#]; name=_hash(FooEnum)
98100
// FOO_ENUM_DOT-NEXT: Decl[TypeAlias]/CurrNominal: AllCases[#[FooEnum]#]{{; name=.+$}}
99101
// FOO_ENUM_DOT-NEXT: Decl[StaticVar]/CurrNominal: allCases[#[FooEnum]#]{{; name=.+$}}
100102
// FOO_ENUM_DOT-NEXT: End completions
101103

104+
// FOO_ENUM_DOT_INVALID: Begin completions
105+
// FOO_ENUM_DOT_INVALID-NEXT: Decl[EnumElement]/CurrNominal: Foo1[#FooEnum#]{{; name=.+$}}
106+
// FOO_ENUM_DOT_INVALID-NEXT: Decl[EnumElement]/CurrNominal: Foo2[#FooEnum#]{{; name=.+$}}
107+
// FOO_ENUM_DOT_INVALID-NEXT: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: _hash({#self: FooEnum#})[#(into: inout _Hasher) -> Void#]; name=_hash(FooEnum)
108+
// FOO_ENUM_DOT_INVALID-NEXT: Decl[TypeAlias]/CurrNominal: AllCases[#[FooEnum]#]{{; name=.+$}}
109+
// FOO_ENUM_DOT_INVALID-NEXT: Decl[StaticVar]/CurrNominal: allCases[#[FooEnum]#]{{; name=.+$}}
110+
// FOO_ENUM_DOT_INVALID-NEXT: End completions
111+
102112
// FOO_ENUM_DOT_ELEMENTS: Begin completions, 2 items
103113
// FOO_ENUM_DOT_ELEMENTS-NEXT: Decl[EnumElement]/ExprSpecific: Foo1[#FooEnum#]{{; name=.+$}}
104114
// FOO_ENUM_DOT_ELEMENTS-NEXT: Decl[EnumElement]/ExprSpecific: Foo2[#FooEnum#]{{; name=.+$}}
@@ -237,17 +247,19 @@ enum QuxEnum : Int {
237247
// QUX_ENUM_TYPE_CONTEXT-DAG: Decl[EnumElement]/ExprSpecific: .Qux2[#QuxEnum#]{{; name=.+$}}
238248
// QUX_ENUM_TYPE_CONTEXT: End completions
239249

240-
// QUX_ENUM_NO_DOT: Begin completions, 4 items
250+
// QUX_ENUM_NO_DOT: Begin completions, 5 items
241251
// QUX_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Qux1[#QuxEnum#]{{; name=.+$}}
242252
// QUX_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Qux2[#QuxEnum#]{{; name=.+$}}
243253
// QUX_ENUM_NO_DOT-NEXT: Decl[TypeAlias]/CurrNominal: .RawValue[#Int#]{{; name=.+$}}
254+
// QUX_ENUM_NO_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: ._hash({#self: QuxEnum#})[#(into: inout _Hasher) -> Void#]; name=_hash(QuxEnum)
244255
// QUX_ENUM_NO_DOT-NEXT: Decl[Constructor]/CurrNominal: ({#rawValue: Int#})[#QuxEnum?#]{{; name=.+$}}
245256
// QUX_ENUM_NO_DOT-NEXT: End completions
246257

247-
// QUX_ENUM_DOT: Begin completions, 4 items
258+
// QUX_ENUM_DOT: Begin completions, 5 items
248259
// QUX_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Qux1[#QuxEnum#]{{; name=.+$}}
249260
// QUX_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Qux2[#QuxEnum#]{{; name=.+$}}
250261
// QUX_ENUM_DOT-NEXT: Decl[TypeAlias]/CurrNominal: RawValue[#Int#]{{; name=.+$}}
262+
// QUX_ENUM_DOT-NEXT: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: _hash({#self: QuxEnum#})[#(into: inout _Hasher) -> Void#]; name=_hash(QuxEnum)
251263
// QUX_ENUM_DOT-NEXT: Decl[Constructor]/CurrNominal: init({#rawValue: Int#})[#QuxEnum?#]{{; name=.+$}}
252264
// QUX_ENUM_DOT-NEXT: End completions
253265

test/IDE/print_ast_tc_decls.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ struct d0200_EscapedIdentifiers {
587587
// PASS_COMMON-NEXT: {{^}} case `case`{{$}}
588588
// PASS_COMMON-NEXT: {{^}} {{.*}}static func __derived_enum_equals(_ a: d0200_EscapedIdentifiers.`enum`, _ b: d0200_EscapedIdentifiers.`enum`) -> Bool
589589
// PASS_COMMON-NEXT: {{^}} var hashValue: Int { get }{{$}}
590+
// PASS_COMMON-NEXT: {{^}} func _hash(into hasher: inout _Hasher)
590591
// PASS_COMMON-NEXT: {{^}} }{{$}}
591592

592593
class `class` {}
@@ -1015,6 +1016,7 @@ enum d2000_EnumDecl1 {
10151016
// PASS_COMMON-NEXT: {{^}} case ED1_Second{{$}}
10161017
// PASS_COMMON-NEXT: {{^}} {{.*}}static func __derived_enum_equals(_ a: d2000_EnumDecl1, _ b: d2000_EnumDecl1) -> Bool
10171018
// PASS_COMMON-NEXT: {{^}} var hashValue: Int { get }{{$}}
1019+
// PASS_COMMON-NEXT: {{^}} func _hash(into hasher: inout _Hasher)
10181020
// PASS_COMMON-NEXT: {{^}}}{{$}}
10191021

10201022
enum d2100_EnumDecl2 {
@@ -1072,6 +1074,7 @@ enum d2300_EnumDeclWithValues1 : Int {
10721074
// PASS_COMMON-NEXT: {{^}} case EDV2_Second{{$}}
10731075
// PASS_COMMON-NEXT: {{^}} typealias RawValue = Int
10741076
// PASS_COMMON-NEXT: {{^}} var hashValue: Int { get }{{$}}
1077+
// PASS_COMMON-NEXT: {{^}} func _hash(into hasher: inout _Hasher)
10751078
// PASS_COMMON-NEXT: {{^}} init?(rawValue: Int){{$}}
10761079
// PASS_COMMON-NEXT: {{^}} var rawValue: Int { get }{{$}}
10771080
// PASS_COMMON-NEXT: {{^}}}{{$}}
@@ -1085,6 +1088,7 @@ enum d2400_EnumDeclWithValues2 : Double {
10851088
// PASS_COMMON-NEXT: {{^}} case EDV3_Second{{$}}
10861089
// PASS_COMMON-NEXT: {{^}} typealias RawValue = Double
10871090
// PASS_COMMON-NEXT: {{^}} var hashValue: Int { get }{{$}}
1091+
// PASS_COMMON-NEXT: {{^}} func _hash(into hasher: inout _Hasher)
10881092
// PASS_COMMON-NEXT: {{^}} init?(rawValue: Double){{$}}
10891093
// PASS_COMMON-NEXT: {{^}} var rawValue: Double { get }{{$}}
10901094
// PASS_COMMON-NEXT: {{^}}}{{$}}

test/IRGen/enum_derived.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
import def_enum
1111

12-
// Check if the hashValue and == for an enum (without payload) are generated and
13-
// check if that functions are compiled in an optimal way.
12+
// Check if hashValue, _hash(into:) and == for an enum (without payload) are
13+
// generated and check that functions are compiled in an optimal way.
1414

1515
enum E {
1616
case E0
@@ -26,12 +26,20 @@ enum E {
2626
// CHECK: %2 = icmp eq i8 %0, %1
2727
// CHECK: ret i1 %2
2828

29-
// Check if the hashValue getter can be compiled to a simple zext instruction.
29+
// Check for the presence of the hashValue getter.
3030

3131
// CHECK-NORMAL-LABEL:define hidden swiftcc i{{.*}} @"$S12enum_derived1EO9hashValueSivg"(i8)
3232
// CHECK-TESTABLE-LABEL:define{{( protected)?}} swiftcc i{{.*}} @"$S12enum_derived1EO9hashValueSivg"(i8)
33-
// CHECK: [[R:%.*]] = zext i8 %0 to i{{.*}}
34-
// CHECK: ret i{{.*}} [[R]]
33+
// CHECK: ret i{{.*}}
34+
35+
// Check if the _hash(into:) method can be compiled to a simple zext instruction
36+
// followed by a call to _Hasher.append(bits:).
37+
38+
// CHECK-NORMAL-LABEL:define hidden swiftcc void @"$S12enum_derived1EO5_hash4intoys7_HasherVz_tF"
39+
// CHECK-TESTABLE-LABEL:define{{( protected)?}} swiftcc void @"$S12enum_derived1EO5_hash4intoys7_HasherVz_tF"
40+
// CHECK: [[V:%.*]] = zext i8 %1 to i{{.*}}
41+
// CHECK: tail call swiftcc i{{.*}} @"$Ss7_HasherV6append4bitsySu_tF"(i{{.*}} [[V]],
42+
// CHECK: ret void
3543

3644
// Derived conformances from extensions
3745
// The actual enums are in Inputs/def_enum.swift

test/api-digester/Outputs/cake.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,27 @@
567567
}
568568
]
569569
},
570+
{
571+
"kind": "Function",
572+
"name": "_hash",
573+
"printedName": "_hash(into:)",
574+
"declKind": "Func",
575+
"usr": "s:4cake6NumberO5_hash4intoys7_HasherVz_tF",
576+
"location": "",
577+
"moduleName": "cake",
578+
"children": [
579+
{
580+
"kind": "TypeNominal",
581+
"name": "Void",
582+
"printedName": "()"
583+
},
584+
{
585+
"kind": "TypeNominal",
586+
"name": "InOut",
587+
"printedName": "inout _Hasher"
588+
}
589+
]
590+
},
570591
{
571592
"kind": "Constructor",
572593
"name": "init",

0 commit comments

Comments
 (0)