Skip to content

Commit e5f5ffb

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.
1 parent e3d0e48 commit e5f5ffb

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

test/IDE/complete_enum_elements.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ enum FooEnum {
8686
// FOO_ENUM_NO_DOT: Begin completions
8787
// FOO_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Foo1[#FooEnum#]{{; name=.+$}}
8888
// FOO_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Foo2[#FooEnum#]{{; name=.+$}}
89+
// FOO_ENUM_NO_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: ._hash({#self: FooEnum#})[#(into: _UnsafeHasher) -> _UnsafeHasher#]; name=_hash(FooEnum)
8990
// FOO_ENUM_NO_DOT-NEXT: End completions
9091

9192
// FOO_ENUM_DOT: Begin completions
9293
// FOO_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Foo1[#FooEnum#]{{; name=.+$}}
9394
// FOO_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Foo2[#FooEnum#]{{; name=.+$}}
95+
// FOO_ENUM_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: _hash({#self: FooEnum#})[#(into: _UnsafeHasher) -> _UnsafeHasher#]; name=_hash(FooEnum)
9496
// FOO_ENUM_DOT-NEXT: End completions
9597

9698
// FOO_ENUM_DOT_ELEMENTS: Begin completions, 2 items
@@ -231,17 +233,19 @@ enum QuxEnum : Int {
231233
// QUX_ENUM_TYPE_CONTEXT-DAG: Decl[EnumElement]/ExprSpecific: .Qux2[#QuxEnum#]{{; name=.+$}}
232234
// QUX_ENUM_TYPE_CONTEXT: End completions
233235

234-
// QUX_ENUM_NO_DOT: Begin completions, 4 items
236+
// QUX_ENUM_NO_DOT: Begin completions, 5 items
235237
// QUX_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Qux1[#QuxEnum#]{{; name=.+$}}
236238
// QUX_ENUM_NO_DOT-NEXT: Decl[EnumElement]/CurrNominal: .Qux2[#QuxEnum#]{{; name=.+$}}
237239
// QUX_ENUM_NO_DOT-NEXT: Decl[TypeAlias]/CurrNominal: .RawValue[#Int#]{{; name=.+$}}
240+
// QUX_ENUM_NO_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: ._hash({#self: QuxEnum#})[#(into: _UnsafeHasher) -> _UnsafeHasher#]; name=_hash(QuxEnum)
238241
// QUX_ENUM_NO_DOT-NEXT: Decl[Constructor]/CurrNominal: ({#rawValue: Int#})[#QuxEnum?#]{{; name=.+$}}
239242
// QUX_ENUM_NO_DOT-NEXT: End completions
240243

241-
// QUX_ENUM_DOT: Begin completions, 4 items
244+
// QUX_ENUM_DOT: Begin completions, 5 items
242245
// QUX_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Qux1[#QuxEnum#]{{; name=.+$}}
243246
// QUX_ENUM_DOT-NEXT: Decl[EnumElement]/CurrNominal: Qux2[#QuxEnum#]{{; name=.+$}}
244247
// QUX_ENUM_DOT-NEXT: Decl[TypeAlias]/CurrNominal: RawValue[#Int#]{{; name=.+$}}
248+
// QUX_ENUM_DOT-NEXT: Decl[InstanceMethod]/CurrNominal: _hash({#self: QuxEnum#})[#(into: _UnsafeHasher) -> _UnsafeHasher#]; name=_hash(QuxEnum)
245249
// QUX_ENUM_DOT-NEXT: Decl[Constructor]/CurrNominal: init({#rawValue: Int#})[#QuxEnum?#]{{; name=.+$}}
246250
// QUX_ENUM_DOT-NEXT: End completions
247251

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: _UnsafeHasher) -> _UnsafeHasher{{$}}
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: _UnsafeHasher) -> _UnsafeHasher{{$}}
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: _UnsafeHasher) -> _UnsafeHasher{{$}}
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: _UnsafeHasher) -> _UnsafeHasher{{$}}
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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import def_enum
77

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

1111
enum E {
1212
case E0
@@ -22,11 +22,19 @@ enum E {
2222
// CHECK: %2 = icmp eq i8 %0, %1
2323
// CHECK: ret i1 %2
2424

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

2727
// CHECK-NORMAL-LABEL:define hidden swiftcc i{{.*}} @"$S12enum_derived1EO9hashValueSivg"(i8)
2828
// CHECK-TESTABLE-LABEL:define{{( protected)?}} swiftcc i{{.*}} @"$S12enum_derived1EO9hashValueSivg"(i8)
29-
// CHECK: [[R:%.*]] = zext i8 %0 to i{{.*}}
29+
// CHECK: ret i{{.*}}
30+
31+
// Check if the _hash(into:) method can be compiled to a simple zext instruction
32+
// followed by a call to _UnsafeHasher(appending:).
33+
34+
// CHECK-NORMAL-LABEL:define hidden swiftcc i{{.*}} @"$S12enum_derived1EO5_hash4intos13_UnsafeHasherVAG_tF"
35+
// CHECK-TESTABLE-LABEL:define{{( protected)?}} swiftcc i{{.*}} @"$S12enum_derived1EO5_hash4intos13_UnsafeHasherVAG_tF"
36+
// CHECK: [[V:%.*]] = zext i8 %1 to i{{.*}}
37+
// CHECK: [[R:%.*]] = tail call swiftcc i{{.*}} @"$Ss13_UnsafeHasherV9appending4bitsABSu_tF"(i{{.*}} [[V]],
3038
// CHECK: ret i{{.*}} [[R]]
3139

3240
// Derived conformances from extensions

test/SILGen/objc_bridging_any.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,4 +757,5 @@ func bridgeOptionalFunctionToAnyObject(fn: (() -> ())?) -> AnyObject {
757757
// CHECK-LABEL: sil_witness_table shared [serialized] GenericOption: Hashable module objc_generics {
758758
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics
759759
// CHECK-NEXT: method #Hashable.hashValue!getter.1: {{.*}} : @$SSo13GenericOptionas8HashableSCsACP9hashValueSivgTW
760+
// CHECK-NEXT: method #Hashable._hash!1: {{.*}} : @$SSo13GenericOptionas8HashableSCsACP5_hash4intos13_UnsafeHasherVAH_tFTW
760761
// CHECK-NEXT: }

0 commit comments

Comments
 (0)