authorgravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-09-30 22:57:41-05:00
committergravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-02 15:21:48-05:00
log8d42500699939028aaf78e9463326820b6d08353
tree1a34657fc64435142895ad83a9900995341a067a
parent0b8ddb4478ebf14811caf8a083ca493f9ed733b2

Implement hashing and equals for some pointer values


1 files changed, 50 insertions(+), 2 deletions(-)

src/value.zig+50-2
......@@ -1238,9 +1238,24 @@ pub const Value = extern union {
12381238 const b_field_index = b.castTag(.enum_field_index).?.data;
12391239 return a_field_index == b_field_index;
12401240 },
1241 .elem_ptr => @panic("TODO: Implement more pointer eql cases"),
1242 .field_ptr => @panic("TODO: Implement more pointer eql cases"),
1243 .eu_payload_ptr => @panic("TODO: Implement more pointer eql cases"),
1244 .opt_payload_ptr => @panic("TODO: Implement more pointer eql cases"),
12411245 else => {},
12421246 }
12431247 }
1248
1249 if (a.pointerDecl()) |a_decl| {
1250 if (b.pointerDecl()) |b_decl| {
1251 return a_decl == b_decl;
1252 } else {
1253 return false;
1254 }
1255 } else if (b.pointerDecl()) |_| {
1256 return false;
1257 }
1258
12441259 if (ty.zigTypeTag() == .Type) {
12451260 var buf_a: ToTypeBuffer = undefined;
12461261 var buf_b: ToTypeBuffer = undefined;
......@@ -1285,8 +1300,28 @@ pub const Value = extern union {
12851300 const float = val.toFloat(f128);
12861301 std.hash.autoHash(hasher, @bitCast(u128, float));
12871302 },
1288 .Pointer => {
1289 @panic("TODO implement hashing pointer values");
1303 .Pointer => switch (val.tag()) {
1304 .decl_ref_mut,
1305 .extern_fn,
1306 .decl_ref,
1307 .function,
1308 .variable,
1309 => std.hash.autoHash(hasher, val.pointerDecl().?),
1310
1311 .elem_ptr => @panic("TODO: Implement more pointer hashing cases"),
1312 .field_ptr => @panic("TODO: Implement more pointer hashing cases"),
1313 .eu_payload_ptr => @panic("TODO: Implement more pointer hashing cases"),
1314 .opt_payload_ptr => @panic("TODO: Implement more pointer hashing cases"),
1315
1316 .zero,
1317 .one,
1318 .int_u64,
1319 .int_i64,
1320 .int_big_positive,
1321 .int_big_negative,
1322 => @panic("TODO: Implement pointer hashing for int pointers"),
1323
1324 else => unreachable,
12901325 },
12911326 .Array, .Vector => {
12921327 @panic("TODO implement hashing array/vector values");
......@@ -1432,6 +1467,19 @@ pub const Value = extern union {
14321467 return sub_val;
14331468 }
14341469
1470 /// Gets the decl referenced by this pointer. If the pointer does not point
1471 /// to a decl, or if it points to some part of a decl (like field_ptr or element_ptr),
1472 /// this function returns null.
1473 pub fn pointerDecl(self: Value) ?*Module.Decl {
1474 return switch (self.tag()) {
1475 .decl_ref_mut => self.castTag(.decl_ref_mut).?.data.decl,
1476 .extern_fn, .decl_ref => self.cast(Payload.Decl).?.data,
1477 .function => self.castTag(.function).?.data.owner_decl,
1478 .variable => self.castTag(.variable).?.data.owner_decl,
1479 else => null,
1480 };
1481 }
1482
14351483 pub fn sliceLen(val: Value) u64 {
14361484 return switch (val.tag()) {
14371485 .empty_array => 0,