╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ mutable_value.zig ────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
509 return switch (mv) { 510 .opt_payload => |pl| return .{ .payload = pl.child.* }, 511 .interned => |ip_index| switch (zcu.intern_pool.indexToKey(ip_index)) { 512 .undef => return .undef, 513 .opt => |opt| if (opt.val == .none) .null else .{ .payload = .{ .interned = opt.val } }, 514 else => unreachable, 515 }, 516 else => unreachable, 517 }; 518 } 519 520 pub fn unpackErrorUnion(mv: MutableValue, zcu: *Zcu) union(enum) { 521 undef, 522 err: InternPool.NullTerminatedString, 523 payload: MutableValue, 524 } { 525 return switch (mv) { 526 .eu_payload => |pl| return .{ .payload = pl.child.* }, 527 .interned => |ip_index| switch (zcu.intern_pool.indexToKey(ip_index)) { 528 .undef => return .undef, 529 .error_union => |eu| switch (eu.val) { 530 .err_name => |name| .{ .err = name }, 531 .payload => |pl| .{ .payload = .{ .interned = pl } }, 532 }, 533 else => unreachable, 534 }, 535 else => unreachable, 536 }; 537 } 538 539 /// Fast equality checking which may return false negatives. 540 /// Used for deciding when to switch aggregate representations without fully 541 /// interning many values. 542 fn eqlTrivial(a: MutableValue, b: MutableValue) bool { 543 const Tag = @typeInfo(MutableValue).@"union".tag_type.?; 544 if (@as(Tag, a) != @as(Tag, b)) return false; 545 return switch (a) { 546 .interned => |a_ip| a_ip == b.interned, 547 .eu_payload => |a_pl| a_pl.ty == b.eu_payload.ty and a_pl.child.eqlTrivial(b.eu_payload.child.*), 548 .opt_payload => |a_pl| a_pl.ty == b.opt_payload.ty and a_pl.child.eqlTrivial(b.opt_payload.child.*), 549 .repeated => |a_rep| a_rep.ty == b.repeated.ty and a_rep.child.eqlTrivial(b.repeated.child.*), 550 .bytes => |a_bytes| a_bytes.ty == b.bytes.ty and std.mem.eql(u8, a_bytes.data, b.bytes.data), 551 .aggregate => |a_agg| { 552 const b_agg = b.aggregate; 553 if (a_agg.ty != b_agg.ty) return false; 554 if (a_agg.elems.len != b_agg.elems.len) return false; 555 for (a_agg.elems, b_agg.elems) |a_elem, b_elem| { 556 if (!a_elem.eqlTrivial(b_elem)) return false; 557 } 558 return true; 559 }, 560 .slice => |a_slice| a_slice.ty == b.slice.ty and 561 a_slice.ptr.interned == b.slice.ptr.interned and 562 a_slice.len.interned == b.slice.len.interned, 563 .un => |a_un| a_un.ty == b.un.ty and a_un.tag == b.un.tag and a_un.payload.eqlTrivial(b.un.payload.*), 564 }; 565 } 566 }; 567