You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// This function issues a compile error with a helpful message if there
120
-
/// is a problem with the provided context type. A context must have the following
121
-
/// member functions:
122
-
/// - hash(self, PseudoKey) Hash
123
-
/// - eql(self, PseudoKey, Key) bool
124
-
///
125
-
/// If you are passing a context to a *Adapted function, PseudoKey is the type
126
-
/// of the key parameter. Otherwise, when creating a HashMap or HashMapUnmanaged
127
-
/// type, PseudoKey = Key = K.
128
-
pubfnverifyContext(
129
-
comptimeRawContext: type,
130
-
comptimePseudoKey: type,
131
-
comptimeKey: type,
132
-
comptimeHash: type,
133
-
comptimeis_array: bool,
134
-
) void {
135
-
comptime {
136
-
varallow_const_ptr=false;
137
-
varallow_mutable_ptr=false;
138
-
// Context is the actual namespace type. RawContext may be a pointer to Context.
139
-
varContext=RawContext;
140
-
// Make sure the context is a namespace type which may have member functions
141
-
switch (@typeInfo(Context)) {
142
-
.@"struct", .@"union", .@"enum"=> {},
143
-
// Special-case .@"opaque" for a better error message
144
-
.@"opaque"=>@compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context) ++" because it is opaque. Use a pointer instead."),
145
-
.pointer=>|ptr| {
146
-
if (ptr.size!=.One) {
147
-
@compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context) ++" because it is not a single pointer.");
148
-
}
149
-
Context=ptr.child;
150
-
allow_const_ptr=true;
151
-
allow_mutable_ptr=!ptr.is_const;
152
-
switch (@typeInfo(Context)) {
153
-
.@"struct", .@"union", .@"enum", .@"opaque"=> {},
154
-
else=>@compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context)),
155
-
}
156
-
},
157
-
else=>@compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context)),
158
-
}
159
-
160
-
// Keep track of multiple errors so we can report them all.
161
-
varerrors: []constu8="";
162
-
163
-
// Put common errors here, they will only be evaluated
// We use cold instead of unlikely to force a jump to this case,
1195
959
// no matter the weight of the opposing side.
@@ -1199,12 +963,8 @@ pub fn HashMapUnmanaged(
1199
963
1200
964
// If you get a compile error on this line, it means that your generic hash
1201
965
// function is invalid for these parameters.
1202
-
consthash=ctx.hash(key);
1203
-
// verifyContext can't verify the return type of generic hash functions,
1204
-
// so we need to double-check it here.
1205
-
if (@TypeOf(hash) !=Hash) {
1206
-
@compileError("Context "++@typeName(@TypeOf(ctx)) ++" has a generic hash function that returns the wrong type! "++@typeName(Hash) ++" was expected, but found "++@typeName(@TypeOf(hash)));
1207
-
}
966
+
consthash: Hash=ctx.hash(key);
967
+
1208
968
constmask=self.capacity() -1;
1209
969
constfingerprint=Metadata.takeFingerprint(hash);
1210
970
// Don't loop indefinitely when there are no empty slots.
@@ -1215,15 +975,8 @@ pub fn HashMapUnmanaged(
1215
975
while (!metadata[0].isFree() andlimit!=0) {
1216
976
if (metadata[0].isUsed() andmetadata[0].fingerprint==fingerprint) {
1217
977
consttest_key=&self.keys()[idx];
1218
-
// If you get a compile error on this line, it means that your generic eql
1219
-
// function is invalid for these parameters.
1220
-
consteql=ctx.eql(key, test_key.*);
1221
-
// verifyContext can't verify the return type of generic eql functions,
1222
-
// so we need to double-check it here.
1223
-
if (@TypeOf(eql) !=bool) {
1224
-
@compileError("Context "++@typeName(@TypeOf(ctx)) ++" has a generic eql function that returns the wrong type! bool was expected, but found "++@typeName(@TypeOf(eql)));
// If you get a compile error on this line, it means that your generic hash
1384
1136
// function is invalid for these parameters.
1385
-
consthash=ctx.hash(key);
1386
-
// verifyContext can't verify the return type of generic hash functions,
1387
-
// so we need to double-check it here.
1388
-
if (@TypeOf(hash) !=Hash) {
1389
-
@compileError("Context "++@typeName(@TypeOf(ctx)) ++" has a generic hash function that returns the wrong type! "++@typeName(Hash) ++" was expected, but found "++@typeName(@TypeOf(hash)));
1390
-
}
1137
+
consthash: Hash=ctx.hash(key);
1138
+
1391
1139
constmask=self.capacity() -1;
1392
1140
constfingerprint=Metadata.takeFingerprint(hash);
1393
1141
varlimit=self.capacity();
@@ -1400,13 +1148,8 @@ pub fn HashMapUnmanaged(
1400
1148
consttest_key=&self.keys()[idx];
1401
1149
// If you get a compile error on this line, it means that your generic eql
1402
1150
// function is invalid for these parameters.
1403
-
consteql=ctx.eql(key, test_key.*);
1404
-
// verifyContext can't verify the return type of generic eql functions,
1405
-
// so we need to double-check it here.
1406
-
if (@TypeOf(eql) !=bool) {
1407
-
@compileError("Context "++@typeName(@TypeOf(ctx)) ++" has a generic eql function that returns the wrong type! bool was expected, but found "++@typeName(@TypeOf(eql)));
0 commit comments