diff options
| author | Wooster <wooster0@proton.me> | 2024-07-16 03:18:38 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-15 18:18:38 +0000 |
| commit | 888708ec8af9b60681ef14fb0a5c265f2a30b41f (patch) | |
| tree | 95da742d1d0082ae0150ea109f57e5ce2eebddb8 /src/InternPool.zig | |
| parent | 89942ebd03b2943cbbe84b575a024e156ca5bf52 (diff) | |
| download | zig-888708ec8af9b60681ef14fb0a5c265f2a30b41f.tar.gz zig-888708ec8af9b60681ef14fb0a5c265f2a30b41f.zip | |
Sema: support pointer subtraction
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index 55ae300cce..ff748ebc62 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -1931,6 +1931,23 @@ pub const Key = union(enum) { /// the original pointer type alignment must be used. orig_ty: Index, }; + + pub fn eql(a: BaseAddr, b: BaseAddr) bool { + if (@as(Key.Ptr.BaseAddr.Tag, a) != @as(Key.Ptr.BaseAddr.Tag, b)) return false; + + return switch (a) { + .decl => |a_decl| a_decl == b.decl, + .comptime_alloc => |a_alloc| a_alloc == b.comptime_alloc, + .anon_decl => |ad| ad.val == b.anon_decl.val and + ad.orig_ty == b.anon_decl.orig_ty, + .int => true, + .eu_payload => |a_eu_payload| a_eu_payload == b.eu_payload, + .opt_payload => |a_opt_payload| a_opt_payload == b.opt_payload, + .comptime_field => |a_comptime_field| a_comptime_field == b.comptime_field, + .arr_elem => |a_elem| std.meta.eql(a_elem, b.arr_elem), + .field => |a_field| std.meta.eql(a_field, b.field), + }; + } }; }; @@ -2369,21 +2386,8 @@ pub const Key = union(enum) { const b_info = b.ptr; if (a_info.ty != b_info.ty) return false; if (a_info.byte_offset != b_info.byte_offset) return false; - - if (@as(Key.Ptr.BaseAddr.Tag, a_info.base_addr) != @as(Key.Ptr.BaseAddr.Tag, b_info.base_addr)) return false; - - return switch (a_info.base_addr) { - .decl => |a_decl| a_decl == b_info.base_addr.decl, - .comptime_alloc => |a_alloc| a_alloc == b_info.base_addr.comptime_alloc, - .anon_decl => |ad| ad.val == b_info.base_addr.anon_decl.val and - ad.orig_ty == b_info.base_addr.anon_decl.orig_ty, - .int => true, - .eu_payload => |a_eu_payload| a_eu_payload == b_info.base_addr.eu_payload, - .opt_payload => |a_opt_payload| a_opt_payload == b_info.base_addr.opt_payload, - .comptime_field => |a_comptime_field| a_comptime_field == b_info.base_addr.comptime_field, - .arr_elem => |a_elem| std.meta.eql(a_elem, b_info.base_addr.arr_elem), - .field => |a_field| std.meta.eql(a_field, b_info.base_addr.field), - }; + if (!a_info.base_addr.eql(b_info.base_addr)) return false; + return true; }, .int => |a_info| { |
