| author | |
| committer | |
| log | ec4c60c4812d4ed850841b85c59e24ea3f73c355 |
| tree | 0db200bb02e8ad38e4e08058b6a3396d7b086589 |
| parent | 29386f0d3021f4868ac021f05ff47455f011d674 |
16 files changed, 165 insertions(+), 180 deletions(-)
lib/std/array_hash_map.zig+54-56| ... | @@ -124,7 +124,7 @@ pub fn ArrayHashMap( | ... | @@ -124,7 +124,7 @@ pub fn ArrayHashMap( |
| 124 | /// Create an ArrayHashMap instance which will use a specified allocator. | 124 | /// Create an ArrayHashMap instance which will use a specified allocator. |
| 125 | pub fn init(allocator: *Allocator) Self { | 125 | pub fn init(allocator: *Allocator) Self { |
| 126 | if (@sizeOf(Context) != 0) | 126 | if (@sizeOf(Context) != 0) |
| 127 | @compileError("Cannot infer context "++@typeName(Context)++", call initContext instead."); | 127 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call initContext instead."); |
| 128 | return initContext(allocator, undefined); | 128 | return initContext(allocator, undefined); |
| 129 | } | 129 | } |
| 130 | pub fn initContext(allocator: *Allocator, ctx: Context) Self { | 130 | pub fn initContext(allocator: *Allocator, ctx: Context) Self { |
| ... | @@ -518,7 +518,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -518,7 +518,7 @@ pub fn ArrayHashMapUnmanaged( |
| 518 | /// the promoted map should no longer be used. | 518 | /// the promoted map should no longer be used. |
| 519 | pub fn promote(self: Self, allocator: *Allocator) Managed { | 519 | pub fn promote(self: Self, allocator: *Allocator) Managed { |
| 520 | if (@sizeOf(Context) != 0) | 520 | if (@sizeOf(Context) != 0) |
| 521 | @compileError("Cannot infer context "++@typeName(Context)++", call promoteContext instead."); | 521 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); |
| 522 | return self.promoteContext(allocator, undefined); | 522 | return self.promoteContext(allocator, undefined); |
| 523 | } | 523 | } |
| 524 | pub fn promoteContext(self: Self, allocator: *Allocator, ctx: Context) Managed { | 524 | pub fn promoteContext(self: Self, allocator: *Allocator, ctx: Context) Managed { |
| ... | @@ -618,7 +618,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -618,7 +618,7 @@ pub fn ArrayHashMapUnmanaged( |
| 618 | /// the value (but not the key). | 618 | /// the value (but not the key). |
| 619 | pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult { | 619 | pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult { |
| 620 | if (@sizeOf(Context) != 0) | 620 | if (@sizeOf(Context) != 0) |
| 621 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContext instead."); | 621 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); |
| 622 | return self.getOrPutContext(allocator, key, undefined); | 622 | return self.getOrPutContext(allocator, key, undefined); |
| 623 | } | 623 | } |
| 624 | pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult { | 624 | pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult { |
| ... | @@ -630,7 +630,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -630,7 +630,7 @@ pub fn ArrayHashMapUnmanaged( |
| 630 | } | 630 | } |
| 631 | pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { | 631 | pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { |
| 632 | if (@sizeOf(Context) != 0) | 632 | if (@sizeOf(Context) != 0) |
| 633 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContextAdapted instead."); | 633 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); |
| 634 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); | 634 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); |
| 635 | } | 635 | } |
| 636 | pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { | 636 | pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { |
| ... | @@ -658,7 +658,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -658,7 +658,7 @@ pub fn ArrayHashMapUnmanaged( |
| 658 | /// is enough capacity to store it. | 658 | /// is enough capacity to store it. |
| 659 | pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult { | 659 | pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult { |
| 660 | if (@sizeOf(Context) != 0) | 660 | if (@sizeOf(Context) != 0) |
| 661 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutAssumeCapacityContext instead."); | 661 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutAssumeCapacityContext instead."); |
| 662 | return self.getOrPutAssumeCapacityContext(key, undefined); | 662 | return self.getOrPutAssumeCapacityContext(key, undefined); |
| 663 | } | 663 | } |
| 664 | pub fn getOrPutAssumeCapacityContext(self: *Self, key: K, ctx: Context) GetOrPutResult { | 664 | pub fn getOrPutAssumeCapacityContext(self: *Self, key: K, ctx: Context) GetOrPutResult { |
| ... | @@ -716,7 +716,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -716,7 +716,7 @@ pub fn ArrayHashMapUnmanaged( |
| 716 | 716 | ||
| 717 | pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !GetOrPutResult { | 717 | pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !GetOrPutResult { |
| 718 | if (@sizeOf(Context) != 0) | 718 | if (@sizeOf(Context) != 0) |
| 719 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutValueContext instead."); | 719 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); |
| 720 | return self.getOrPutValueContext(allocator, key, value, undefined); | 720 | return self.getOrPutValueContext(allocator, key, value, undefined); |
| 721 | } | 721 | } |
| 722 | pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !GetOrPutResult { | 722 | pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !GetOrPutResult { |
| ... | @@ -735,7 +735,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -735,7 +735,7 @@ pub fn ArrayHashMapUnmanaged( |
| 735 | /// `expected_count` will not cause an allocation, and therefore cannot fail. | 735 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 736 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { | 736 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { |
| 737 | if (@sizeOf(ByIndexContext) != 0) | 737 | if (@sizeOf(ByIndexContext) != 0) |
| 738 | @compileError("Cannot infer context "++@typeName(Context)++", call ensureTotalCapacityContext instead."); | 738 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 739 | return self.ensureTotalCapacityContext(allocator, new_capacity, undefined); | 739 | return self.ensureTotalCapacityContext(allocator, new_capacity, undefined); |
| 740 | } | 740 | } |
| 741 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void { | 741 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void { |
| ... | @@ -769,7 +769,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -769,7 +769,7 @@ pub fn ArrayHashMapUnmanaged( |
| 769 | additional_capacity: usize, | 769 | additional_capacity: usize, |
| 770 | ) !void { | 770 | ) !void { |
| 771 | if (@sizeOf(ByIndexContext) != 0) | 771 | if (@sizeOf(ByIndexContext) != 0) |
| 772 | @compileError("Cannot infer context "++@typeName(Context)++", call ensureTotalCapacityContext instead."); | 772 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 773 | return self.ensureUnusedCapacityContext(allocator, additional_capacity, undefined); | 773 | return self.ensureUnusedCapacityContext(allocator, additional_capacity, undefined); |
| 774 | } | 774 | } |
| 775 | pub fn ensureUnusedCapacityContext( | 775 | pub fn ensureUnusedCapacityContext( |
| ... | @@ -794,7 +794,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -794,7 +794,7 @@ pub fn ArrayHashMapUnmanaged( |
| 794 | /// existing data, see `getOrPut`. | 794 | /// existing data, see `getOrPut`. |
| 795 | pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 795 | pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void { |
| 796 | if (@sizeOf(Context) != 0) | 796 | if (@sizeOf(Context) != 0) |
| 797 | @compileError("Cannot infer context "++@typeName(Context)++", call putContext instead."); | 797 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); |
| 798 | return self.putContext(allocator, key, value, undefined); | 798 | return self.putContext(allocator, key, value, undefined); |
| 799 | } | 799 | } |
| 800 | pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 800 | pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { |
| ... | @@ -806,7 +806,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -806,7 +806,7 @@ pub fn ArrayHashMapUnmanaged( |
| 806 | /// entry with the same key is already present | 806 | /// entry with the same key is already present |
| 807 | pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 807 | pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void { |
| 808 | if (@sizeOf(Context) != 0) | 808 | if (@sizeOf(Context) != 0) |
| 809 | @compileError("Cannot infer context "++@typeName(Context)++", call putNoClobberContext instead."); | 809 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); |
| 810 | return self.putNoClobberContext(allocator, key, value, undefined); | 810 | return self.putNoClobberContext(allocator, key, value, undefined); |
| 811 | } | 811 | } |
| 812 | pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 812 | pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { |
| ... | @@ -820,7 +820,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -820,7 +820,7 @@ pub fn ArrayHashMapUnmanaged( |
| 820 | /// existing data, see `getOrPutAssumeCapacity`. | 820 | /// existing data, see `getOrPutAssumeCapacity`. |
| 821 | pub fn putAssumeCapacity(self: *Self, key: K, value: V) void { | 821 | pub fn putAssumeCapacity(self: *Self, key: K, value: V) void { |
| 822 | if (@sizeOf(Context) != 0) | 822 | if (@sizeOf(Context) != 0) |
| 823 | @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityContext instead."); | 823 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityContext instead."); |
| 824 | return self.putAssumeCapacityContext(key, value, undefined); | 824 | return self.putAssumeCapacityContext(key, value, undefined); |
| 825 | } | 825 | } |
| 826 | pub fn putAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) void { | 826 | pub fn putAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) void { |
| ... | @@ -833,7 +833,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -833,7 +833,7 @@ pub fn ArrayHashMapUnmanaged( |
| 833 | /// To detect if a put would clobber existing data, see `getOrPutAssumeCapacity`. | 833 | /// To detect if a put would clobber existing data, see `getOrPutAssumeCapacity`. |
| 834 | pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void { | 834 | pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void { |
| 835 | if (@sizeOf(Context) != 0) | 835 | if (@sizeOf(Context) != 0) |
| 836 | @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityNoClobberContext instead."); | 836 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityNoClobberContext instead."); |
| 837 | return self.putAssumeCapacityNoClobberContext(key, value, undefined); | 837 | return self.putAssumeCapacityNoClobberContext(key, value, undefined); |
| 838 | } | 838 | } |
| 839 | pub fn putAssumeCapacityNoClobberContext(self: *Self, key: K, value: V, ctx: Context) void { | 839 | pub fn putAssumeCapacityNoClobberContext(self: *Self, key: K, value: V, ctx: Context) void { |
| ... | @@ -845,7 +845,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -845,7 +845,7 @@ pub fn ArrayHashMapUnmanaged( |
| 845 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. | 845 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. |
| 846 | pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV { | 846 | pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV { |
| 847 | if (@sizeOf(Context) != 0) | 847 | if (@sizeOf(Context) != 0) |
| 848 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutContext instead."); | 848 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); |
| 849 | return self.fetchPutContext(allocator, key, value, undefined); | 849 | return self.fetchPutContext(allocator, key, value, undefined); |
| 850 | } | 850 | } |
| 851 | pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV { | 851 | pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV { |
| ... | @@ -865,7 +865,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -865,7 +865,7 @@ pub fn ArrayHashMapUnmanaged( |
| 865 | /// If insertion happens, asserts there is enough capacity without allocating. | 865 | /// If insertion happens, asserts there is enough capacity without allocating. |
| 866 | pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV { | 866 | pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV { |
| 867 | if (@sizeOf(Context) != 0) | 867 | if (@sizeOf(Context) != 0) |
| 868 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutAssumeCapacityContext instead."); | 868 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutAssumeCapacityContext instead."); |
| 869 | return self.fetchPutAssumeCapacityContext(key, value, undefined); | 869 | return self.fetchPutAssumeCapacityContext(key, value, undefined); |
| 870 | } | 870 | } |
| 871 | pub fn fetchPutAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) ?KV { | 871 | pub fn fetchPutAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) ?KV { |
| ... | @@ -884,7 +884,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -884,7 +884,7 @@ pub fn ArrayHashMapUnmanaged( |
| 884 | /// Finds pointers to the key and value storage associated with a key. | 884 | /// Finds pointers to the key and value storage associated with a key. |
| 885 | pub fn getEntry(self: Self, key: K) ?Entry { | 885 | pub fn getEntry(self: Self, key: K) ?Entry { |
| 886 | if (@sizeOf(Context) != 0) | 886 | if (@sizeOf(Context) != 0) |
| 887 | @compileError("Cannot infer context "++@typeName(Context)++", call getEntryContext instead."); | 887 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getEntryContext instead."); |
| 888 | return self.getEntryContext(key, undefined); | 888 | return self.getEntryContext(key, undefined); |
| 889 | } | 889 | } |
| 890 | pub fn getEntryContext(self: Self, key: K, ctx: Context) ?Entry { | 890 | pub fn getEntryContext(self: Self, key: K, ctx: Context) ?Entry { |
| ... | @@ -903,7 +903,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -903,7 +903,7 @@ pub fn ArrayHashMapUnmanaged( |
| 903 | /// Finds the index in the `entries` array where a key is stored | 903 | /// Finds the index in the `entries` array where a key is stored |
| 904 | pub fn getIndex(self: Self, key: K) ?usize { | 904 | pub fn getIndex(self: Self, key: K) ?usize { |
| 905 | if (@sizeOf(Context) != 0) | 905 | if (@sizeOf(Context) != 0) |
| 906 | @compileError("Cannot infer context "++@typeName(Context)++", call getIndexContext instead."); | 906 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getIndexContext instead."); |
| 907 | return self.getIndexContext(key, undefined); | 907 | return self.getIndexContext(key, undefined); |
| 908 | } | 908 | } |
| 909 | pub fn getIndexContext(self: Self, key: K, ctx: Context) ?usize { | 909 | pub fn getIndexContext(self: Self, key: K, ctx: Context) ?usize { |
| ... | @@ -938,7 +938,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -938,7 +938,7 @@ pub fn ArrayHashMapUnmanaged( |
| 938 | /// Find the value associated with a key | 938 | /// Find the value associated with a key |
| 939 | pub fn get(self: Self, key: K) ?V { | 939 | pub fn get(self: Self, key: K) ?V { |
| 940 | if (@sizeOf(Context) != 0) | 940 | if (@sizeOf(Context) != 0) |
| 941 | @compileError("Cannot infer context "++@typeName(Context)++", call getContext instead."); | 941 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getContext instead."); |
| 942 | return self.getContext(key, undefined); | 942 | return self.getContext(key, undefined); |
| 943 | } | 943 | } |
| 944 | pub fn getContext(self: Self, key: K, ctx: Context) ?V { | 944 | pub fn getContext(self: Self, key: K, ctx: Context) ?V { |
| ... | @@ -952,7 +952,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -952,7 +952,7 @@ pub fn ArrayHashMapUnmanaged( |
| 952 | /// Find a pointer to the value associated with a key | 952 | /// Find a pointer to the value associated with a key |
| 953 | pub fn getPtr(self: Self, key: K) ?*V { | 953 | pub fn getPtr(self: Self, key: K) ?*V { |
| 954 | if (@sizeOf(Context) != 0) | 954 | if (@sizeOf(Context) != 0) |
| 955 | @compileError("Cannot infer context "++@typeName(Context)++", call getPtrContext instead."); | 955 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getPtrContext instead."); |
| 956 | return self.getPtrContext(key, undefined); | 956 | return self.getPtrContext(key, undefined); |
| 957 | } | 957 | } |
| 958 | pub fn getPtrContext(self: Self, key: K, ctx: Context) ?*V { | 958 | pub fn getPtrContext(self: Self, key: K, ctx: Context) ?*V { |
| ... | @@ -967,7 +967,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -967,7 +967,7 @@ pub fn ArrayHashMapUnmanaged( |
| 967 | /// Check whether a key is stored in the map | 967 | /// Check whether a key is stored in the map |
| 968 | pub fn contains(self: Self, key: K) bool { | 968 | pub fn contains(self: Self, key: K) bool { |
| 969 | if (@sizeOf(Context) != 0) | 969 | if (@sizeOf(Context) != 0) |
| 970 | @compileError("Cannot infer context "++@typeName(Context)++", call containsContext instead."); | 970 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call containsContext instead."); |
| 971 | return self.containsContext(key, undefined); | 971 | return self.containsContext(key, undefined); |
| 972 | } | 972 | } |
| 973 | pub fn containsContext(self: Self, key: K, ctx: Context) bool { | 973 | pub fn containsContext(self: Self, key: K, ctx: Context) bool { |
| ... | @@ -983,7 +983,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -983,7 +983,7 @@ pub fn ArrayHashMapUnmanaged( |
| 983 | /// element. | 983 | /// element. |
| 984 | pub fn fetchSwapRemove(self: *Self, key: K) ?KV { | 984 | pub fn fetchSwapRemove(self: *Self, key: K) ?KV { |
| 985 | if (@sizeOf(Context) != 0) | 985 | if (@sizeOf(Context) != 0) |
| 986 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchSwapRemoveContext instead."); | 986 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchSwapRemoveContext instead."); |
| 987 | return self.fetchSwapRemoveContext(key, undefined); | 987 | return self.fetchSwapRemoveContext(key, undefined); |
| 988 | } | 988 | } |
| 989 | pub fn fetchSwapRemoveContext(self: *Self, key: K, ctx: Context) ?KV { | 989 | pub fn fetchSwapRemoveContext(self: *Self, key: K, ctx: Context) ?KV { |
| ... | @@ -991,7 +991,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -991,7 +991,7 @@ pub fn ArrayHashMapUnmanaged( |
| 991 | } | 991 | } |
| 992 | pub fn fetchSwapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV { | 992 | pub fn fetchSwapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV { |
| 993 | if (@sizeOf(ByIndexContext) != 0) | 993 | if (@sizeOf(ByIndexContext) != 0) |
| 994 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchSwapRemoveContextAdapted instead."); | 994 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchSwapRemoveContextAdapted instead."); |
| 995 | return self.fetchSwapRemoveContextAdapted(key, ctx, undefined); | 995 | return self.fetchSwapRemoveContextAdapted(key, ctx, undefined); |
| 996 | } | 996 | } |
| 997 | pub fn fetchSwapRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) ?KV { | 997 | pub fn fetchSwapRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) ?KV { |
| ... | @@ -1004,7 +1004,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1004,7 +1004,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1004 | /// thereby maintaining the current ordering. | 1004 | /// thereby maintaining the current ordering. |
| 1005 | pub fn fetchOrderedRemove(self: *Self, key: K) ?KV { | 1005 | pub fn fetchOrderedRemove(self: *Self, key: K) ?KV { |
| 1006 | if (@sizeOf(Context) != 0) | 1006 | if (@sizeOf(Context) != 0) |
| 1007 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchOrderedRemoveContext instead."); | 1007 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchOrderedRemoveContext instead."); |
| 1008 | return self.fetchOrderedRemoveContext(key, undefined); | 1008 | return self.fetchOrderedRemoveContext(key, undefined); |
| 1009 | } | 1009 | } |
| 1010 | pub fn fetchOrderedRemoveContext(self: *Self, key: K, ctx: Context) ?KV { | 1010 | pub fn fetchOrderedRemoveContext(self: *Self, key: K, ctx: Context) ?KV { |
| ... | @@ -1012,7 +1012,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1012,7 +1012,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1012 | } | 1012 | } |
| 1013 | pub fn fetchOrderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV { | 1013 | pub fn fetchOrderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV { |
| 1014 | if (@sizeOf(ByIndexContext) != 0) | 1014 | if (@sizeOf(ByIndexContext) != 0) |
| 1015 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchOrderedRemoveContextAdapted instead."); | 1015 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchOrderedRemoveContextAdapted instead."); |
| 1016 | return self.fetchOrderedRemoveContextAdapted(key, ctx, undefined); | 1016 | return self.fetchOrderedRemoveContextAdapted(key, ctx, undefined); |
| 1017 | } | 1017 | } |
| 1018 | pub fn fetchOrderedRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) ?KV { | 1018 | pub fn fetchOrderedRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) ?KV { |
| ... | @@ -1025,7 +1025,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1025,7 +1025,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1025 | /// was removed, false otherwise. | 1025 | /// was removed, false otherwise. |
| 1026 | pub fn swapRemove(self: *Self, key: K) bool { | 1026 | pub fn swapRemove(self: *Self, key: K) bool { |
| 1027 | if (@sizeOf(Context) != 0) | 1027 | if (@sizeOf(Context) != 0) |
| 1028 | @compileError("Cannot infer context "++@typeName(Context)++", call swapRemoveContext instead."); | 1028 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call swapRemoveContext instead."); |
| 1029 | return self.swapRemoveContext(key, undefined); | 1029 | return self.swapRemoveContext(key, undefined); |
| 1030 | } | 1030 | } |
| 1031 | pub fn swapRemoveContext(self: *Self, key: K, ctx: Context) bool { | 1031 | pub fn swapRemoveContext(self: *Self, key: K, ctx: Context) bool { |
| ... | @@ -1033,7 +1033,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1033,7 +1033,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1033 | } | 1033 | } |
| 1034 | pub fn swapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool { | 1034 | pub fn swapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool { |
| 1035 | if (@sizeOf(ByIndexContext) != 0) | 1035 | if (@sizeOf(ByIndexContext) != 0) |
| 1036 | @compileError("Cannot infer context "++@typeName(Context)++", call swapRemoveContextAdapted instead."); | 1036 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call swapRemoveContextAdapted instead."); |
| 1037 | return self.swapRemoveContextAdapted(key, ctx, undefined); | 1037 | return self.swapRemoveContextAdapted(key, ctx, undefined); |
| 1038 | } | 1038 | } |
| 1039 | pub fn swapRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) bool { | 1039 | pub fn swapRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) bool { |
| ... | @@ -1046,7 +1046,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1046,7 +1046,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1046 | /// current ordering. Returns true if an entry was removed, false otherwise. | 1046 | /// current ordering. Returns true if an entry was removed, false otherwise. |
| 1047 | pub fn orderedRemove(self: *Self, key: K) bool { | 1047 | pub fn orderedRemove(self: *Self, key: K) bool { |
| 1048 | if (@sizeOf(Context) != 0) | 1048 | if (@sizeOf(Context) != 0) |
| 1049 | @compileError("Cannot infer context "++@typeName(Context)++", call orderedRemoveContext instead."); | 1049 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call orderedRemoveContext instead."); |
| 1050 | return self.orderedRemoveContext(key, undefined); | 1050 | return self.orderedRemoveContext(key, undefined); |
| 1051 | } | 1051 | } |
| 1052 | pub fn orderedRemoveContext(self: *Self, key: K, ctx: Context) bool { | 1052 | pub fn orderedRemoveContext(self: *Self, key: K, ctx: Context) bool { |
| ... | @@ -1054,7 +1054,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1054,7 +1054,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1054 | } | 1054 | } |
| 1055 | pub fn orderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool { | 1055 | pub fn orderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool { |
| 1056 | if (@sizeOf(ByIndexContext) != 0) | 1056 | if (@sizeOf(ByIndexContext) != 0) |
| 1057 | @compileError("Cannot infer context "++@typeName(Context)++", call orderedRemoveContextAdapted instead."); | 1057 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call orderedRemoveContextAdapted instead."); |
| 1058 | return self.orderedRemoveContextAdapted(key, ctx, undefined); | 1058 | return self.orderedRemoveContextAdapted(key, ctx, undefined); |
| 1059 | } | 1059 | } |
| 1060 | pub fn orderedRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) bool { | 1060 | pub fn orderedRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) bool { |
| ... | @@ -1066,7 +1066,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1066,7 +1066,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1066 | /// by swapping it with the last element. | 1066 | /// by swapping it with the last element. |
| 1067 | pub fn swapRemoveAt(self: *Self, index: usize) void { | 1067 | pub fn swapRemoveAt(self: *Self, index: usize) void { |
| 1068 | if (@sizeOf(ByIndexContext) != 0) | 1068 | if (@sizeOf(ByIndexContext) != 0) |
| 1069 | @compileError("Cannot infer context "++@typeName(Context)++", call swapRemoveAtContext instead."); | 1069 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call swapRemoveAtContext instead."); |
| 1070 | return self.swapRemoveAtContext(index, undefined); | 1070 | return self.swapRemoveAtContext(index, undefined); |
| 1071 | } | 1071 | } |
| 1072 | pub fn swapRemoveAtContext(self: *Self, index: usize, ctx: Context) void { | 1072 | pub fn swapRemoveAtContext(self: *Self, index: usize, ctx: Context) void { |
| ... | @@ -1079,7 +1079,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1079,7 +1079,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1079 | /// current ordering. | 1079 | /// current ordering. |
| 1080 | pub fn orderedRemoveAt(self: *Self, index: usize) void { | 1080 | pub fn orderedRemoveAt(self: *Self, index: usize) void { |
| 1081 | if (@sizeOf(ByIndexContext) != 0) | 1081 | if (@sizeOf(ByIndexContext) != 0) |
| 1082 | @compileError("Cannot infer context "++@typeName(Context)++", call orderedRemoveAtContext instead."); | 1082 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call orderedRemoveAtContext instead."); |
| 1083 | return self.orderedRemoveAtContext(index, undefined); | 1083 | return self.orderedRemoveAtContext(index, undefined); |
| 1084 | } | 1084 | } |
| 1085 | pub fn orderedRemoveAtContext(self: *Self, index: usize, ctx: Context) void { | 1085 | pub fn orderedRemoveAtContext(self: *Self, index: usize, ctx: Context) void { |
| ... | @@ -1090,7 +1090,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1090,7 +1090,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1090 | /// The copy uses the same context and allocator as this instance. | 1090 | /// The copy uses the same context and allocator as this instance. |
| 1091 | pub fn clone(self: Self, allocator: *Allocator) !Self { | 1091 | pub fn clone(self: Self, allocator: *Allocator) !Self { |
| 1092 | if (@sizeOf(ByIndexContext) != 0) | 1092 | if (@sizeOf(ByIndexContext) != 0) |
| 1093 | @compileError("Cannot infer context "++@typeName(Context)++", call cloneContext instead."); | 1093 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); |
| 1094 | return self.cloneContext(allocator, undefined); | 1094 | return self.cloneContext(allocator, undefined); |
| 1095 | } | 1095 | } |
| 1096 | pub fn cloneContext(self: Self, allocator: *Allocator, ctx: Context) !Self { | 1096 | pub fn cloneContext(self: Self, allocator: *Allocator, ctx: Context) !Self { |
| ... | @@ -1110,7 +1110,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1110,7 +1110,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1110 | /// can call `reIndex` to update the indexes to account for these new entries. | 1110 | /// can call `reIndex` to update the indexes to account for these new entries. |
| 1111 | pub fn reIndex(self: *Self, allocator: *Allocator) !void { | 1111 | pub fn reIndex(self: *Self, allocator: *Allocator) !void { |
| 1112 | if (@sizeOf(ByIndexContext) != 0) | 1112 | if (@sizeOf(ByIndexContext) != 0) |
| 1113 | @compileError("Cannot infer context "++@typeName(Context)++", call reIndexContext instead."); | 1113 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call reIndexContext instead."); |
| 1114 | return self.reIndexContext(allocator, undefined); | 1114 | return self.reIndexContext(allocator, undefined); |
| 1115 | } | 1115 | } |
| 1116 | pub fn reIndexContext(self: *Self, allocator: *Allocator, ctx: Context) !void { | 1116 | pub fn reIndexContext(self: *Self, allocator: *Allocator, ctx: Context) !void { |
| ... | @@ -1128,7 +1128,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1128,7 +1128,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1128 | /// index entries. Keeps capacity the same. | 1128 | /// index entries. Keeps capacity the same. |
| 1129 | pub fn shrinkRetainingCapacity(self: *Self, new_len: usize) void { | 1129 | pub fn shrinkRetainingCapacity(self: *Self, new_len: usize) void { |
| 1130 | if (@sizeOf(ByIndexContext) != 0) | 1130 | if (@sizeOf(ByIndexContext) != 0) |
| 1131 | @compileError("Cannot infer context "++@typeName(Context)++", call shrinkRetainingCapacityContext instead."); | 1131 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkRetainingCapacityContext instead."); |
| 1132 | return self.shrinkRetainingCapacityContext(new_len, undefined); | 1132 | return self.shrinkRetainingCapacityContext(new_len, undefined); |
| 1133 | } | 1133 | } |
| 1134 | pub fn shrinkRetainingCapacityContext(self: *Self, new_len: usize, ctx: Context) void { | 1134 | pub fn shrinkRetainingCapacityContext(self: *Self, new_len: usize, ctx: Context) void { |
| ... | @@ -1147,7 +1147,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1147,7 +1147,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1147 | /// index entries. Reduces allocated capacity. | 1147 | /// index entries. Reduces allocated capacity. |
| 1148 | pub fn shrinkAndFree(self: *Self, allocator: *Allocator, new_len: usize) void { | 1148 | pub fn shrinkAndFree(self: *Self, allocator: *Allocator, new_len: usize) void { |
| 1149 | if (@sizeOf(ByIndexContext) != 0) | 1149 | if (@sizeOf(ByIndexContext) != 0) |
| 1150 | @compileError("Cannot infer context "++@typeName(Context)++", call shrinkAndFreeContext instead."); | 1150 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkAndFreeContext instead."); |
| 1151 | return self.shrinkAndFreeContext(allocator, new_len, undefined); | 1151 | return self.shrinkAndFreeContext(allocator, new_len, undefined); |
| 1152 | } | 1152 | } |
| 1153 | pub fn shrinkAndFreeContext(self: *Self, allocator: *Allocator, new_len: usize, ctx: Context) void { | 1153 | pub fn shrinkAndFreeContext(self: *Self, allocator: *Allocator, new_len: usize, ctx: Context) void { |
| ... | @@ -1165,13 +1165,13 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1165,13 +1165,13 @@ pub fn ArrayHashMapUnmanaged( |
| 1165 | /// Removes the last inserted `Entry` in the hash map and returns it. | 1165 | /// Removes the last inserted `Entry` in the hash map and returns it. |
| 1166 | pub fn pop(self: *Self) KV { | 1166 | pub fn pop(self: *Self) KV { |
| 1167 | if (@sizeOf(ByIndexContext) != 0) | 1167 | if (@sizeOf(ByIndexContext) != 0) |
| 1168 | @compileError("Cannot infer context "++@typeName(Context)++", call popContext instead."); | 1168 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call popContext instead."); |
| 1169 | return self.popContext(undefined); | 1169 | return self.popContext(undefined); |
| 1170 | } | 1170 | } |
| 1171 | pub fn popContext(self: *Self, ctx: Context) KV { | 1171 | pub fn popContext(self: *Self, ctx: Context) KV { |
| 1172 | const item = self.entries.get(self.entries.len-1); | 1172 | const item = self.entries.get(self.entries.len - 1); |
| 1173 | if (self.index_header) |header| | 1173 | if (self.index_header) |header| |
| 1174 | self.removeFromIndexByIndex(self.entries.len-1, if (store_hash) {} else ctx, header); | 1174 | self.removeFromIndexByIndex(self.entries.len - 1, if (store_hash) {} else ctx, header); |
| 1175 | self.entries.len -= 1; | 1175 | self.entries.len -= 1; |
| 1176 | return .{ | 1176 | return .{ |
| 1177 | .key = item.key, | 1177 | .key = item.key, |
| ... | @@ -1276,7 +1276,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1276,7 +1276,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1276 | } | 1276 | } |
| 1277 | 1277 | ||
| 1278 | fn removeFromArrayAndUpdateIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I), comptime removal_type: RemovalType) void { | 1278 | fn removeFromArrayAndUpdateIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I), comptime removal_type: RemovalType) void { |
| 1279 | const last_index = self.entries.len-1; // overflow => remove from empty map | 1279 | const last_index = self.entries.len - 1; // overflow => remove from empty map |
| 1280 | switch (removal_type) { | 1280 | switch (removal_type) { |
| 1281 | .swap => { | 1281 | .swap => { |
| 1282 | if (last_index != entry_index) { | 1282 | if (last_index != entry_index) { |
| ... | @@ -1358,8 +1358,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1358,8 +1358,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1358 | 1358 | ||
| 1359 | fn getSlotByIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I)) usize { | 1359 | fn getSlotByIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I)) usize { |
| 1360 | const slice = self.entries.slice(); | 1360 | const slice = self.entries.slice(); |
| 1361 | const h = if (store_hash) slice.items(.hash)[entry_index] | 1361 | const h = if (store_hash) slice.items(.hash)[entry_index] else checkedHash(ctx, slice.items(.key)[entry_index]); |
| 1362 | else checkedHash(ctx, slice.items(.key)[entry_index]); | ||
| 1363 | const start_index = safeTruncate(usize, h); | 1362 | const start_index = safeTruncate(usize, h); |
| 1364 | const end_index = start_index +% indexes.len; | 1363 | const end_index = start_index +% indexes.len; |
| 1365 | 1364 | ||
| ... | @@ -1569,30 +1568,30 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1569,30 +1568,30 @@ pub fn ArrayHashMapUnmanaged( |
| 1569 | } | 1568 | } |
| 1570 | } | 1569 | } |
| 1571 | 1570 | ||
| 1572 | fn checkedHash(ctx: anytype, key: anytype) callconv(.Inline) u32 { | 1571 | inline fn checkedHash(ctx: anytype, key: anytype) u32 { |
| 1573 | comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(key), K, u32); | 1572 | comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(key), K, u32); |
| 1574 | // If you get a compile error on the next line, it means that | 1573 | // If you get a compile error on the next line, it means that |
| 1575 | const hash = ctx.hash(key); // your generic hash function doesn't accept your key | 1574 | const hash = ctx.hash(key); // your generic hash function doesn't accept your key |
| 1576 | if (@TypeOf(hash) != u32) { | 1575 | if (@TypeOf(hash) != u32) { |
| 1577 | @compileError("Context "++@typeName(@TypeOf(ctx))++" has a generic hash function that returns the wrong type!\n"++ | 1576 | @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic hash function that returns the wrong type!\n" ++ |
| 1578 | @typeName(u32)++" was expected, but found "++@typeName(@TypeOf(hash))); | 1577 | @typeName(u32) ++ " was expected, but found " ++ @typeName(@TypeOf(hash))); |
| 1579 | } | 1578 | } |
| 1580 | return hash; | 1579 | return hash; |
| 1581 | } | 1580 | } |
| 1582 | fn checkedEql(ctx: anytype, a: anytype, b: K) callconv(.Inline) bool { | 1581 | inline fn checkedEql(ctx: anytype, a: anytype, b: K) bool { |
| 1583 | comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(a), K, u32); | 1582 | comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(a), K, u32); |
| 1584 | // If you get a compile error on the next line, it means that | 1583 | // If you get a compile error on the next line, it means that |
| 1585 | const eql = ctx.eql(a, b); // your generic eql function doesn't accept (self, adapt key, K) | 1584 | const eql = ctx.eql(a, b); // your generic eql function doesn't accept (self, adapt key, K) |
| 1586 | if (@TypeOf(eql) != bool) { | 1585 | if (@TypeOf(eql) != bool) { |
| 1587 | @compileError("Context "++@typeName(@TypeOf(ctx))++" has a generic eql function that returns the wrong type!\n"++ | 1586 | @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic eql function that returns the wrong type!\n" ++ |
| 1588 | @typeName(bool)++" was expected, but found "++@typeName(@TypeOf(eql))); | 1587 | @typeName(bool) ++ " was expected, but found " ++ @typeName(@TypeOf(eql))); |
| 1589 | } | 1588 | } |
| 1590 | return eql; | 1589 | return eql; |
| 1591 | } | 1590 | } |
| 1592 | 1591 | ||
| 1593 | fn dumpState(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8) void { | 1592 | fn dumpState(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8) void { |
| 1594 | if (@sizeOf(ByIndexContext) != 0) | 1593 | if (@sizeOf(ByIndexContext) != 0) |
| 1595 | @compileError("Cannot infer context "++@typeName(Context)++", call dumpStateContext instead."); | 1594 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call dumpStateContext instead."); |
| 1596 | self.dumpStateContext(keyFmt, valueFmt, undefined); | 1595 | self.dumpStateContext(keyFmt, valueFmt, undefined); |
| 1597 | } | 1596 | } |
| 1598 | fn dumpStateContext(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8, ctx: Context) void { | 1597 | fn dumpStateContext(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8, ctx: Context) void { |
| ... | @@ -1600,21 +1599,20 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1600,21 +1599,20 @@ pub fn ArrayHashMapUnmanaged( |
| 1600 | p("{s}:\n", .{@typeName(Self)}); | 1599 | p("{s}:\n", .{@typeName(Self)}); |
| 1601 | const slice = self.entries.slice(); | 1600 | const slice = self.entries.slice(); |
| 1602 | const hash_status = if (store_hash) "stored" else "computed"; | 1601 | const hash_status = if (store_hash) "stored" else "computed"; |
| 1603 | p(" len={} capacity={} hashes {s}\n", .{slice.len, slice.capacity, hash_status}); | 1602 | p(" len={} capacity={} hashes {s}\n", .{ slice.len, slice.capacity, hash_status }); |
| 1604 | var i: usize = 0; | 1603 | var i: usize = 0; |
| 1605 | const mask: u32 = if (self.index_header) |header| header.mask() else ~@as(u32, 0); | 1604 | const mask: u32 = if (self.index_header) |header| header.mask() else ~@as(u32, 0); |
| 1606 | while (i < slice.len) : (i += 1) { | 1605 | while (i < slice.len) : (i += 1) { |
| 1607 | const hash = if (store_hash) slice.items(.hash)[i] | 1606 | const hash = if (store_hash) slice.items(.hash)[i] else checkedHash(ctx, slice.items(.key)[i]); |
| 1608 | else checkedHash(ctx, slice.items(.key)[i]); | ||
| 1609 | if (store_hash) { | 1607 | if (store_hash) { |
| 1610 | p( | 1608 | p( |
| 1611 | " [{}]: key="++keyFmt++" value="++valueFmt++" hash=0x{x} slot=[0x{x}]\n", | 1609 | " [{}]: key=" ++ keyFmt ++ " value=" ++ valueFmt ++ " hash=0x{x} slot=[0x{x}]\n", |
| 1612 | .{i, slice.items(.key)[i], slice.items(.value)[i], hash, hash & mask}, | 1610 | .{ i, slice.items(.key)[i], slice.items(.value)[i], hash, hash & mask }, |
| 1613 | ); | 1611 | ); |
| 1614 | } else { | 1612 | } else { |
| 1615 | p( | 1613 | p( |
| 1616 | " [{}]: key="++keyFmt++" value="++valueFmt++" slot=[0x{x}]\n", | 1614 | " [{}]: key=" ++ keyFmt ++ " value=" ++ valueFmt ++ " slot=[0x{x}]\n", |
| 1617 | .{i, slice.items(.key)[i], slice.items(.value)[i], hash & mask}, | 1615 | .{ i, slice.items(.key)[i], slice.items(.value)[i], hash & mask }, |
| 1618 | ); | 1616 | ); |
| 1619 | } | 1617 | } |
| 1620 | } | 1618 | } |
| ... | @@ -1629,7 +1627,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1629,7 +1627,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1629 | } | 1627 | } |
| 1630 | fn dumpIndex(self: Self, header: *IndexHeader, comptime I: type) void { | 1628 | fn dumpIndex(self: Self, header: *IndexHeader, comptime I: type) void { |
| 1631 | const p = std.debug.print; | 1629 | const p = std.debug.print; |
| 1632 | p(" index len=0x{x} type={}\n", .{header.length(), header.capacityIndexType()}); | 1630 | p(" index len=0x{x} type={}\n", .{ header.length(), header.capacityIndexType() }); |
| 1633 | const indexes = header.indexes(I); | 1631 | const indexes = header.indexes(I); |
| 1634 | if (indexes.len == 0) return; | 1632 | if (indexes.len == 0) return; |
| 1635 | var is_empty = false; | 1633 | var is_empty = false; |
| ... | @@ -1641,7 +1639,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1641,7 +1639,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1641 | is_empty = false; | 1639 | is_empty = false; |
| 1642 | p(" ...\n", .{}); | 1640 | p(" ...\n", .{}); |
| 1643 | } | 1641 | } |
| 1644 | p(" [0x{x}]: [{}] +{}\n", .{i, idx.entry_index, idx.distance_from_start_index}); | 1642 | p(" [0x{x}]: [{}] +{}\n", .{ i, idx.entry_index, idx.distance_from_start_index }); |
| 1645 | } | 1643 | } |
| 1646 | } | 1644 | } |
| 1647 | if (is_empty) { | 1645 | if (is_empty) { |
| ... | @@ -1730,7 +1728,7 @@ const max_capacity = (1 << max_bit_index) - 1; | ... | @@ -1730,7 +1728,7 @@ const max_capacity = (1 << max_bit_index) - 1; |
| 1730 | const index_capacities = blk: { | 1728 | const index_capacities = blk: { |
| 1731 | var caps: [max_bit_index + 1]u32 = undefined; | 1729 | var caps: [max_bit_index + 1]u32 = undefined; |
| 1732 | for (caps[0..max_bit_index]) |*item, i| { | 1730 | for (caps[0..max_bit_index]) |*item, i| { |
| 1733 | item.* = (1<<i) * 3 / 5; | 1731 | item.* = (1 << i) * 3 / 5; |
| 1734 | } | 1732 | } |
| 1735 | caps[max_bit_index] = max_capacity; | 1733 | caps[max_bit_index] = max_capacity; |
| 1736 | break :blk caps; | 1734 | break :blk caps; |
lib/std/hash_map.zig+52-52| ... | @@ -116,20 +116,20 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -116,20 +116,20 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 116 | switch (@typeInfo(Context)) { | 116 | switch (@typeInfo(Context)) { |
| 117 | .Struct, .Union, .Enum => {}, | 117 | .Struct, .Union, .Enum => {}, |
| 118 | // Special-case .Opaque for a better error message | 118 | // Special-case .Opaque for a better error message |
| 119 | .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."), | 119 | .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."), |
| 120 | .Pointer => |ptr| { | 120 | .Pointer => |ptr| { |
| 121 | if (ptr.size != .One) { | 121 | if (ptr.size != .One) { |
| 122 | @compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context)++" because it is not a single pointer."); | 122 | @compileError("Hash context must be a type with hash and eql member functions. Cannot use " ++ @typeName(Context) ++ " because it is not a single pointer."); |
| 123 | } | 123 | } |
| 124 | Context = ptr.child; | 124 | Context = ptr.child; |
| 125 | allow_const_ptr = true; | 125 | allow_const_ptr = true; |
| 126 | allow_mutable_ptr = !ptr.is_const; | 126 | allow_mutable_ptr = !ptr.is_const; |
| 127 | switch (@typeInfo(Context)) { | 127 | switch (@typeInfo(Context)) { |
| 128 | .Struct, .Union, .Enum, .Opaque => {}, | 128 | .Struct, .Union, .Enum, .Opaque => {}, |
| 129 | else => @compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context)), | 129 | else => @compileError("Hash context must be a type with hash and eql member functions. Cannot use " ++ @typeName(Context)), |
| 130 | } | 130 | } |
| 131 | }, | 131 | }, |
| 132 | else => @compileError("Hash context must be a type with hash and eql member functions. Cannot use "++@typeName(Context)), | 132 | else => @compileError("Hash context must be a type with hash and eql member functions. Cannot use " ++ @typeName(Context)), |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | // Keep track of multiple errors so we can report them all. | 135 | // Keep track of multiple errors so we can report them all. |
| ... | @@ -140,12 +140,12 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -140,12 +140,12 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 140 | const lazy = struct { | 140 | const lazy = struct { |
| 141 | const prefix = "\n "; | 141 | const prefix = "\n "; |
| 142 | const deep_prefix = prefix ++ " "; | 142 | const deep_prefix = prefix ++ " "; |
| 143 | const hash_signature = "fn (self, "++@typeName(PseudoKey)++") "++@typeName(Hash); | 143 | const hash_signature = "fn (self, " ++ @typeName(PseudoKey) ++ ") " ++ @typeName(Hash); |
| 144 | const eql_signature = "fn (self, "++@typeName(PseudoKey)++", "++@typeName(Key)++") bool"; | 144 | const eql_signature = "fn (self, " ++ @typeName(PseudoKey) ++ ", " ++ @typeName(Key) ++ ") bool"; |
| 145 | const err_invalid_hash_signature = prefix ++ @typeName(Context) ++ ".hash must be " ++ hash_signature ++ | 145 | const err_invalid_hash_signature = prefix ++ @typeName(Context) ++ ".hash must be " ++ hash_signature ++ |
| 146 | deep_prefix ++ "but is actually " ++ @typeName(@TypeOf(Context.hash)); | 146 | deep_prefix ++ "but is actually " ++ @typeName(@TypeOf(Context.hash)); |
| 147 | const err_invalid_eql_signature = prefix ++ @typeName(Context) ++ ".eql must be " ++ eql_signature ++ | 147 | const err_invalid_eql_signature = prefix ++ @typeName(Context) ++ ".eql must be " ++ eql_signature ++ |
| 148 | deep_prefix ++ "but is actually " ++ @typeName(@TypeOf(Context.eql)); | 148 | deep_prefix ++ "but is actually " ++ @typeName(@TypeOf(Context.eql)); |
| 149 | }; | 149 | }; |
| 150 | 150 | ||
| 151 | // Verify Context.hash(self, PseudoKey) => Hash | 151 | // Verify Context.hash(self, PseudoKey) => Hash |
| ... | @@ -167,7 +167,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -167,7 +167,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 167 | errors = errors ++ lazy.err_invalid_hash_signature; | 167 | errors = errors ++ lazy.err_invalid_hash_signature; |
| 168 | emitted_signature = true; | 168 | emitted_signature = true; |
| 169 | } | 169 | } |
| 170 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context)++", but is "++@typeName(Self); | 170 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context) ++ ", but is " ++ @typeName(Self); |
| 171 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; | 171 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; |
| 172 | } | 172 | } |
| 173 | } else if (Self == *Context) { | 173 | } else if (Self == *Context) { |
| ... | @@ -177,10 +177,10 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -177,10 +177,10 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 177 | emitted_signature = true; | 177 | emitted_signature = true; |
| 178 | } | 178 | } |
| 179 | if (!allow_const_ptr) { | 179 | if (!allow_const_ptr) { |
| 180 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context)++", but is "++@typeName(Self); | 180 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context) ++ ", but is " ++ @typeName(Self); |
| 181 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; | 181 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; |
| 182 | } else { | 182 | } else { |
| 183 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context)++" or "++@typeName(*const Context)++", but is "++@typeName(Self); | 183 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context) ++ " or " ++ @typeName(*const Context) ++ ", but is " ++ @typeName(Self); |
| 184 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be non-const because it is passed by const pointer."; | 184 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be non-const because it is passed by const pointer."; |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| ... | @@ -189,14 +189,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -189,14 +189,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 189 | errors = errors ++ lazy.err_invalid_hash_signature; | 189 | errors = errors ++ lazy.err_invalid_hash_signature; |
| 190 | emitted_signature = true; | 190 | emitted_signature = true; |
| 191 | } | 191 | } |
| 192 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context); | 192 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context); |
| 193 | if (allow_const_ptr) { | 193 | if (allow_const_ptr) { |
| 194 | errors = errors++" or "++@typeName(*const Context); | 194 | errors = errors ++ " or " ++ @typeName(*const Context); |
| 195 | if (allow_mutable_ptr) { | 195 | if (allow_mutable_ptr) { |
| 196 | errors = errors++" or "++@typeName(*Context); | 196 | errors = errors ++ " or " ++ @typeName(*Context); |
| 197 | } | 197 | } |
| 198 | } | 198 | } |
| 199 | errors = errors++", but is "++@typeName(Self); | 199 | errors = errors ++ ", but is " ++ @typeName(Self); |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| 202 | if (func.args[1].arg_type != null and func.args[1].arg_type.? != PseudoKey) { | 202 | if (func.args[1].arg_type != null and func.args[1].arg_type.? != PseudoKey) { |
| ... | @@ -204,14 +204,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -204,14 +204,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 204 | errors = errors ++ lazy.err_invalid_hash_signature; | 204 | errors = errors ++ lazy.err_invalid_hash_signature; |
| 205 | emitted_signature = true; | 205 | emitted_signature = true; |
| 206 | } | 206 | } |
| 207 | errors = errors ++ lazy.deep_prefix ++ "Second parameter must be "++@typeName(PseudoKey)++", but is "++@typeName(func.args[1].arg_type.?); | 207 | errors = errors ++ lazy.deep_prefix ++ "Second parameter must be " ++ @typeName(PseudoKey) ++ ", but is " ++ @typeName(func.args[1].arg_type.?); |
| 208 | } | 208 | } |
| 209 | if (func.return_type != null and func.return_type.? != Hash) { | 209 | if (func.return_type != null and func.return_type.? != Hash) { |
| 210 | if (!emitted_signature) { | 210 | if (!emitted_signature) { |
| 211 | errors = errors ++ lazy.err_invalid_hash_signature; | 211 | errors = errors ++ lazy.err_invalid_hash_signature; |
| 212 | emitted_signature = true; | 212 | emitted_signature = true; |
| 213 | } | 213 | } |
| 214 | errors = errors ++ lazy.deep_prefix ++ "Return type must be "++@typeName(Hash)++", but was "++@typeName(func.return_type.?); | 214 | errors = errors ++ lazy.deep_prefix ++ "Return type must be " ++ @typeName(Hash) ++ ", but was " ++ @typeName(func.return_type.?); |
| 215 | } | 215 | } |
| 216 | // If any of these are generic (null), we cannot verify them. | 216 | // If any of these are generic (null), we cannot verify them. |
| 217 | // The call sites check the return type, but cannot check the | 217 | // The call sites check the return type, but cannot check the |
| ... | @@ -243,7 +243,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -243,7 +243,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 243 | errors = errors ++ lazy.err_invalid_eql_signature; | 243 | errors = errors ++ lazy.err_invalid_eql_signature; |
| 244 | emitted_signature = true; | 244 | emitted_signature = true; |
| 245 | } | 245 | } |
| 246 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context)++", but is "++@typeName(Self); | 246 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context) ++ ", but is " ++ @typeName(Self); |
| 247 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; | 247 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; |
| 248 | } | 248 | } |
| 249 | } else if (Self == *Context) { | 249 | } else if (Self == *Context) { |
| ... | @@ -253,10 +253,10 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -253,10 +253,10 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 253 | emitted_signature = true; | 253 | emitted_signature = true; |
| 254 | } | 254 | } |
| 255 | if (!allow_const_ptr) { | 255 | if (!allow_const_ptr) { |
| 256 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context)++", but is "++@typeName(Self); | 256 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context) ++ ", but is " ++ @typeName(Self); |
| 257 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; | 257 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value."; |
| 258 | } else { | 258 | } else { |
| 259 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context)++" or "++@typeName(*const Context)++", but is "++@typeName(Self); | 259 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context) ++ " or " ++ @typeName(*const Context) ++ ", but is " ++ @typeName(Self); |
| 260 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be non-const because it is passed by const pointer."; | 260 | errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be non-const because it is passed by const pointer."; |
| 261 | } | 261 | } |
| 262 | } | 262 | } |
| ... | @@ -265,14 +265,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -265,14 +265,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 265 | errors = errors ++ lazy.err_invalid_eql_signature; | 265 | errors = errors ++ lazy.err_invalid_eql_signature; |
| 266 | emitted_signature = true; | 266 | emitted_signature = true; |
| 267 | } | 267 | } |
| 268 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context); | 268 | errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context); |
| 269 | if (allow_const_ptr) { | 269 | if (allow_const_ptr) { |
| 270 | errors = errors++" or "++@typeName(*const Context); | 270 | errors = errors ++ " or " ++ @typeName(*const Context); |
| 271 | if (allow_mutable_ptr) { | 271 | if (allow_mutable_ptr) { |
| 272 | errors = errors++" or "++@typeName(*Context); | 272 | errors = errors ++ " or " ++ @typeName(*Context); |
| 273 | } | 273 | } |
| 274 | } | 274 | } |
| 275 | errors = errors++", but is "++@typeName(Self); | 275 | errors = errors ++ ", but is " ++ @typeName(Self); |
| 276 | } | 276 | } |
| 277 | } | 277 | } |
| 278 | if (func.args[1].arg_type.? != PseudoKey) { | 278 | if (func.args[1].arg_type.? != PseudoKey) { |
| ... | @@ -280,21 +280,21 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -280,21 +280,21 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 280 | errors = errors ++ lazy.err_invalid_eql_signature; | 280 | errors = errors ++ lazy.err_invalid_eql_signature; |
| 281 | emitted_signature = true; | 281 | emitted_signature = true; |
| 282 | } | 282 | } |
| 283 | errors = errors ++ lazy.deep_prefix ++ "Second parameter must be "++@typeName(PseudoKey)++", but is "++@typeName(func.args[1].arg_type.?); | 283 | errors = errors ++ lazy.deep_prefix ++ "Second parameter must be " ++ @typeName(PseudoKey) ++ ", but is " ++ @typeName(func.args[1].arg_type.?); |
| 284 | } | 284 | } |
| 285 | if (func.args[2].arg_type.? != Key) { | 285 | if (func.args[2].arg_type.? != Key) { |
| 286 | if (!emitted_signature) { | 286 | if (!emitted_signature) { |
| 287 | errors = errors ++ lazy.err_invalid_eql_signature; | 287 | errors = errors ++ lazy.err_invalid_eql_signature; |
| 288 | emitted_signature = true; | 288 | emitted_signature = true; |
| 289 | } | 289 | } |
| 290 | errors = errors ++ lazy.deep_prefix ++ "Third parameter must be "++@typeName(Key)++", but is "++@typeName(func.args[2].arg_type.?); | 290 | errors = errors ++ lazy.deep_prefix ++ "Third parameter must be " ++ @typeName(Key) ++ ", but is " ++ @typeName(func.args[2].arg_type.?); |
| 291 | } | 291 | } |
| 292 | if (func.return_type.? != bool) { | 292 | if (func.return_type.? != bool) { |
| 293 | if (!emitted_signature) { | 293 | if (!emitted_signature) { |
| 294 | errors = errors ++ lazy.err_invalid_eql_signature; | 294 | errors = errors ++ lazy.err_invalid_eql_signature; |
| 295 | emitted_signature = true; | 295 | emitted_signature = true; |
| 296 | } | 296 | } |
| 297 | errors = errors ++ lazy.deep_prefix ++ "Return type must be bool, but was "++@typeName(func.return_type.?); | 297 | errors = errors ++ lazy.deep_prefix ++ "Return type must be bool, but was " ++ @typeName(func.return_type.?); |
| 298 | } | 298 | } |
| 299 | // If any of these are generic (null), we cannot verify them. | 299 | // If any of these are generic (null), we cannot verify them. |
| 300 | // The call sites check the return type, but cannot check the | 300 | // The call sites check the return type, but cannot check the |
| ... | @@ -309,7 +309,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti | ... | @@ -309,7 +309,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti |
| 309 | 309 | ||
| 310 | if (errors.len != 0) { | 310 | if (errors.len != 0) { |
| 311 | // errors begins with a newline (from lazy.prefix) | 311 | // errors begins with a newline (from lazy.prefix) |
| 312 | @compileError("Problems found with hash context type "++@typeName(Context)++":"++errors); | 312 | @compileError("Problems found with hash context type " ++ @typeName(Context) ++ ":" ++ errors); |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| 315 | } | 315 | } |
| ... | @@ -790,7 +790,7 @@ pub fn HashMapUnmanaged( | ... | @@ -790,7 +790,7 @@ pub fn HashMapUnmanaged( |
| 790 | 790 | ||
| 791 | pub fn promote(self: Self, allocator: *Allocator) Managed { | 791 | pub fn promote(self: Self, allocator: *Allocator) Managed { |
| 792 | if (@sizeOf(Context) != 0) | 792 | if (@sizeOf(Context) != 0) |
| 793 | @compileError("Cannot infer context "++@typeName(Context)++", call promoteContext instead."); | 793 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); |
| 794 | return promoteContext(self, allocator, undefined); | 794 | return promoteContext(self, allocator, undefined); |
| 795 | } | 795 | } |
| 796 | 796 | ||
| ... | @@ -819,7 +819,7 @@ pub fn HashMapUnmanaged( | ... | @@ -819,7 +819,7 @@ pub fn HashMapUnmanaged( |
| 819 | 819 | ||
| 820 | pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void { | 820 | pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void { |
| 821 | if (@sizeOf(Context) != 0) | 821 | if (@sizeOf(Context) != 0) |
| 822 | @compileError("Cannot infer context "++@typeName(Context)++", call ensureCapacityContext instead."); | 822 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureCapacityContext instead."); |
| 823 | return ensureCapacityContext(self, allocator, new_size, undefined); | 823 | return ensureCapacityContext(self, allocator, new_size, undefined); |
| 824 | } | 824 | } |
| 825 | pub fn ensureCapacityContext(self: *Self, allocator: *Allocator, new_size: Size, ctx: Context) !void { | 825 | pub fn ensureCapacityContext(self: *Self, allocator: *Allocator, new_size: Size, ctx: Context) !void { |
| ... | @@ -902,7 +902,7 @@ pub fn HashMapUnmanaged( | ... | @@ -902,7 +902,7 @@ pub fn HashMapUnmanaged( |
| 902 | /// Insert an entry in the map. Assumes it is not already present. | 902 | /// Insert an entry in the map. Assumes it is not already present. |
| 903 | pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 903 | pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void { |
| 904 | if (@sizeOf(Context) != 0) | 904 | if (@sizeOf(Context) != 0) |
| 905 | @compileError("Cannot infer context "++@typeName(Context)++", call putNoClobberContext instead."); | 905 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); |
| 906 | return self.putNoClobberContext(allocator, key, value, undefined); | 906 | return self.putNoClobberContext(allocator, key, value, undefined); |
| 907 | } | 907 | } |
| 908 | pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 908 | pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { |
| ... | @@ -917,7 +917,7 @@ pub fn HashMapUnmanaged( | ... | @@ -917,7 +917,7 @@ pub fn HashMapUnmanaged( |
| 917 | /// existing data, see `getOrPutAssumeCapacity`. | 917 | /// existing data, see `getOrPutAssumeCapacity`. |
| 918 | pub fn putAssumeCapacity(self: *Self, key: K, value: V) void { | 918 | pub fn putAssumeCapacity(self: *Self, key: K, value: V) void { |
| 919 | if (@sizeOf(Context) != 0) | 919 | if (@sizeOf(Context) != 0) |
| 920 | @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityContext instead."); | 920 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityContext instead."); |
| 921 | return self.putAssumeCapacityContext(key, value, undefined); | 921 | return self.putAssumeCapacityContext(key, value, undefined); |
| 922 | } | 922 | } |
| 923 | pub fn putAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) void { | 923 | pub fn putAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) void { |
| ... | @@ -929,7 +929,7 @@ pub fn HashMapUnmanaged( | ... | @@ -929,7 +929,7 @@ pub fn HashMapUnmanaged( |
| 929 | /// and that no allocation is needed. | 929 | /// and that no allocation is needed. |
| 930 | pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void { | 930 | pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void { |
| 931 | if (@sizeOf(Context) != 0) | 931 | if (@sizeOf(Context) != 0) |
| 932 | @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityNoClobberContext instead."); | 932 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityNoClobberContext instead."); |
| 933 | return self.putAssumeCapacityNoClobberContext(key, value, undefined); | 933 | return self.putAssumeCapacityNoClobberContext(key, value, undefined); |
| 934 | } | 934 | } |
| 935 | pub fn putAssumeCapacityNoClobberContext(self: *Self, key: K, value: V, ctx: Context) void { | 935 | pub fn putAssumeCapacityNoClobberContext(self: *Self, key: K, value: V, ctx: Context) void { |
| ... | @@ -961,7 +961,7 @@ pub fn HashMapUnmanaged( | ... | @@ -961,7 +961,7 @@ pub fn HashMapUnmanaged( |
| 961 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. | 961 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. |
| 962 | pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV { | 962 | pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV { |
| 963 | if (@sizeOf(Context) != 0) | 963 | if (@sizeOf(Context) != 0) |
| 964 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutContext instead."); | 964 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); |
| 965 | return self.fetchPutContext(allocator, key, value, undefined); | 965 | return self.fetchPutContext(allocator, key, value, undefined); |
| 966 | } | 966 | } |
| 967 | pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV { | 967 | pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV { |
| ... | @@ -981,7 +981,7 @@ pub fn HashMapUnmanaged( | ... | @@ -981,7 +981,7 @@ pub fn HashMapUnmanaged( |
| 981 | /// If insertion happens, asserts there is enough capacity without allocating. | 981 | /// If insertion happens, asserts there is enough capacity without allocating. |
| 982 | pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV { | 982 | pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV { |
| 983 | if (@sizeOf(Context) != 0) | 983 | if (@sizeOf(Context) != 0) |
| 984 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutAssumeCapacityContext instead."); | 984 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutAssumeCapacityContext instead."); |
| 985 | return self.fetchPutAssumeCapacityContext(key, value, undefined); | 985 | return self.fetchPutAssumeCapacityContext(key, value, undefined); |
| 986 | } | 986 | } |
| 987 | pub fn fetchPutAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) ?KV { | 987 | pub fn fetchPutAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) ?KV { |
| ... | @@ -1001,7 +1001,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1001,7 +1001,7 @@ pub fn HashMapUnmanaged( |
| 1001 | /// the hash map, and then returned from this function. | 1001 | /// the hash map, and then returned from this function. |
| 1002 | pub fn fetchRemove(self: *Self, key: K) ?KV { | 1002 | pub fn fetchRemove(self: *Self, key: K) ?KV { |
| 1003 | if (@sizeOf(Context) != 0) | 1003 | if (@sizeOf(Context) != 0) |
| 1004 | @compileError("Cannot infer context "++@typeName(Context)++", call fetchRemoveContext instead."); | 1004 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchRemoveContext instead."); |
| 1005 | return self.fetchRemoveContext(key, undefined); | 1005 | return self.fetchRemoveContext(key, undefined); |
| 1006 | } | 1006 | } |
| 1007 | pub fn fetchRemoveContext(self: *Self, key: K, ctx: Context) ?KV { | 1007 | pub fn fetchRemoveContext(self: *Self, key: K, ctx: Context) ?KV { |
| ... | @@ -1033,7 +1033,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1033,7 +1033,7 @@ pub fn HashMapUnmanaged( |
| 1033 | /// fuse the basic blocks after the branch to the basic blocks | 1033 | /// fuse the basic blocks after the branch to the basic blocks |
| 1034 | /// from this function. To encourage that, this function is | 1034 | /// from this function. To encourage that, this function is |
| 1035 | /// marked as inline. | 1035 | /// marked as inline. |
| 1036 | fn getIndex(self: Self, key: anytype, ctx: anytype) callconv(.Inline) ?usize { | 1036 | inline fn getIndex(self: Self, key: anytype, ctx: anytype) ?usize { |
| 1037 | comptime verifyContext(@TypeOf(ctx), @TypeOf(key), K, Hash); | 1037 | comptime verifyContext(@TypeOf(ctx), @TypeOf(key), K, Hash); |
| 1038 | 1038 | ||
| 1039 | if (self.size == 0) { | 1039 | if (self.size == 0) { |
| ... | @@ -1046,7 +1046,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1046,7 +1046,7 @@ pub fn HashMapUnmanaged( |
| 1046 | // verifyContext can't verify the return type of generic hash functions, | 1046 | // verifyContext can't verify the return type of generic hash functions, |
| 1047 | // so we need to double-check it here. | 1047 | // so we need to double-check it here. |
| 1048 | if (@TypeOf(hash) != Hash) { | 1048 | if (@TypeOf(hash) != Hash) { |
| 1049 | @compileError("Context "++@typeName(@TypeOf(ctx))++" has a generic hash function that returns the wrong type! "++@typeName(Hash)++" was expected, but found "++@typeName(@TypeOf(hash))); | 1049 | @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic hash function that returns the wrong type! " ++ @typeName(Hash) ++ " was expected, but found " ++ @typeName(@TypeOf(hash))); |
| 1050 | } | 1050 | } |
| 1051 | const mask = self.capacity() - 1; | 1051 | const mask = self.capacity() - 1; |
| 1052 | const fingerprint = Metadata.takeFingerprint(hash); | 1052 | const fingerprint = Metadata.takeFingerprint(hash); |
| ... | @@ -1062,7 +1062,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1062,7 +1062,7 @@ pub fn HashMapUnmanaged( |
| 1062 | // verifyContext can't verify the return type of generic eql functions, | 1062 | // verifyContext can't verify the return type of generic eql functions, |
| 1063 | // so we need to double-check it here. | 1063 | // so we need to double-check it here. |
| 1064 | if (@TypeOf(eql) != bool) { | 1064 | if (@TypeOf(eql) != bool) { |
| 1065 | @compileError("Context "++@typeName(@TypeOf(ctx))++" has a generic eql function that returns the wrong type! bool was expected, but found "++@typeName(@TypeOf(eql))); | 1065 | @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic eql function that returns the wrong type! bool was expected, but found " ++ @typeName(@TypeOf(eql))); |
| 1066 | } | 1066 | } |
| 1067 | if (eql) { | 1067 | if (eql) { |
| 1068 | return idx; | 1068 | return idx; |
| ... | @@ -1078,7 +1078,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1078,7 +1078,7 @@ pub fn HashMapUnmanaged( |
| 1078 | 1078 | ||
| 1079 | pub fn getEntry(self: Self, key: K) ?Entry { | 1079 | pub fn getEntry(self: Self, key: K) ?Entry { |
| 1080 | if (@sizeOf(Context) != 0) | 1080 | if (@sizeOf(Context) != 0) |
| 1081 | @compileError("Cannot infer context "++@typeName(Context)++", call getEntryContext instead."); | 1081 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getEntryContext instead."); |
| 1082 | return self.getEntryContext(key, undefined); | 1082 | return self.getEntryContext(key, undefined); |
| 1083 | } | 1083 | } |
| 1084 | pub fn getEntryContext(self: Self, key: K, ctx: Context) ?Entry { | 1084 | pub fn getEntryContext(self: Self, key: K, ctx: Context) ?Entry { |
| ... | @@ -1097,7 +1097,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1097,7 +1097,7 @@ pub fn HashMapUnmanaged( |
| 1097 | /// Insert an entry if the associated key is not already present, otherwise update preexisting value. | 1097 | /// Insert an entry if the associated key is not already present, otherwise update preexisting value. |
| 1098 | pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 1098 | pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void { |
| 1099 | if (@sizeOf(Context) != 0) | 1099 | if (@sizeOf(Context) != 0) |
| 1100 | @compileError("Cannot infer context "++@typeName(Context)++", call putContext instead."); | 1100 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); |
| 1101 | return self.putContext(allocator, key, value, undefined); | 1101 | return self.putContext(allocator, key, value, undefined); |
| 1102 | } | 1102 | } |
| 1103 | pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 1103 | pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { |
| ... | @@ -1108,7 +1108,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1108,7 +1108,7 @@ pub fn HashMapUnmanaged( |
| 1108 | /// Get an optional pointer to the value associated with key, if present. | 1108 | /// Get an optional pointer to the value associated with key, if present. |
| 1109 | pub fn getPtr(self: Self, key: K) ?*V { | 1109 | pub fn getPtr(self: Self, key: K) ?*V { |
| 1110 | if (@sizeOf(Context) != 0) | 1110 | if (@sizeOf(Context) != 0) |
| 1111 | @compileError("Cannot infer context "++@typeName(Context)++", call getPtrContext instead."); | 1111 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getPtrContext instead."); |
| 1112 | return self.getPtrContext(key, undefined); | 1112 | return self.getPtrContext(key, undefined); |
| 1113 | } | 1113 | } |
| 1114 | pub fn getPtrContext(self: Self, key: K, ctx: Context) ?*V { | 1114 | pub fn getPtrContext(self: Self, key: K, ctx: Context) ?*V { |
| ... | @@ -1124,7 +1124,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1124,7 +1124,7 @@ pub fn HashMapUnmanaged( |
| 1124 | /// Get a copy of the value associated with key, if present. | 1124 | /// Get a copy of the value associated with key, if present. |
| 1125 | pub fn get(self: Self, key: K) ?V { | 1125 | pub fn get(self: Self, key: K) ?V { |
| 1126 | if (@sizeOf(Context) != 0) | 1126 | if (@sizeOf(Context) != 0) |
| 1127 | @compileError("Cannot infer context "++@typeName(Context)++", call getContext instead."); | 1127 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getContext instead."); |
| 1128 | return self.getContext(key, undefined); | 1128 | return self.getContext(key, undefined); |
| 1129 | } | 1129 | } |
| 1130 | pub fn getContext(self: Self, key: K, ctx: Context) ?V { | 1130 | pub fn getContext(self: Self, key: K, ctx: Context) ?V { |
| ... | @@ -1139,7 +1139,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1139,7 +1139,7 @@ pub fn HashMapUnmanaged( |
| 1139 | 1139 | ||
| 1140 | pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult { | 1140 | pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult { |
| 1141 | if (@sizeOf(Context) != 0) | 1141 | if (@sizeOf(Context) != 0) |
| 1142 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContext instead."); | 1142 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); |
| 1143 | return self.getOrPutContext(allocator, key, undefined); | 1143 | return self.getOrPutContext(allocator, key, undefined); |
| 1144 | } | 1144 | } |
| 1145 | pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult { | 1145 | pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult { |
| ... | @@ -1151,7 +1151,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1151,7 +1151,7 @@ pub fn HashMapUnmanaged( |
| 1151 | } | 1151 | } |
| 1152 | pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { | 1152 | pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { |
| 1153 | if (@sizeOf(Context) != 0) | 1153 | if (@sizeOf(Context) != 0) |
| 1154 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContextAdapted instead."); | 1154 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); |
| 1155 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); | 1155 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); |
| 1156 | } | 1156 | } |
| 1157 | pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { | 1157 | pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { |
| ... | @@ -1171,7 +1171,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1171,7 +1171,7 @@ pub fn HashMapUnmanaged( |
| 1171 | 1171 | ||
| 1172 | pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult { | 1172 | pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult { |
| 1173 | if (@sizeOf(Context) != 0) | 1173 | if (@sizeOf(Context) != 0) |
| 1174 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutAssumeCapacityContext instead."); | 1174 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutAssumeCapacityContext instead."); |
| 1175 | return self.getOrPutAssumeCapacityContext(key, undefined); | 1175 | return self.getOrPutAssumeCapacityContext(key, undefined); |
| 1176 | } | 1176 | } |
| 1177 | pub fn getOrPutAssumeCapacityContext(self: *Self, key: K, ctx: Context) GetOrPutResult { | 1177 | pub fn getOrPutAssumeCapacityContext(self: *Self, key: K, ctx: Context) GetOrPutResult { |
| ... | @@ -1190,7 +1190,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1190,7 +1190,7 @@ pub fn HashMapUnmanaged( |
| 1190 | // verifyContext can't verify the return type of generic hash functions, | 1190 | // verifyContext can't verify the return type of generic hash functions, |
| 1191 | // so we need to double-check it here. | 1191 | // so we need to double-check it here. |
| 1192 | if (@TypeOf(hash) != Hash) { | 1192 | if (@TypeOf(hash) != Hash) { |
| 1193 | @compileError("Context "++@typeName(@TypeOf(ctx))++" has a generic hash function that returns the wrong type! "++@typeName(Hash)++" was expected, but found "++@typeName(@TypeOf(hash))); | 1193 | @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic hash function that returns the wrong type! " ++ @typeName(Hash) ++ " was expected, but found " ++ @typeName(@TypeOf(hash))); |
| 1194 | } | 1194 | } |
| 1195 | const mask = self.capacity() - 1; | 1195 | const mask = self.capacity() - 1; |
| 1196 | const fingerprint = Metadata.takeFingerprint(hash); | 1196 | const fingerprint = Metadata.takeFingerprint(hash); |
| ... | @@ -1207,7 +1207,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1207,7 +1207,7 @@ pub fn HashMapUnmanaged( |
| 1207 | // verifyContext can't verify the return type of generic eql functions, | 1207 | // verifyContext can't verify the return type of generic eql functions, |
| 1208 | // so we need to double-check it here. | 1208 | // so we need to double-check it here. |
| 1209 | if (@TypeOf(eql) != bool) { | 1209 | if (@TypeOf(eql) != bool) { |
| 1210 | @compileError("Context "++@typeName(@TypeOf(ctx))++" has a generic eql function that returns the wrong type! bool was expected, but found "++@typeName(@TypeOf(eql))); | 1210 | @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic eql function that returns the wrong type! bool was expected, but found " ++ @typeName(@TypeOf(eql))); |
| 1211 | } | 1211 | } |
| 1212 | if (eql) { | 1212 | if (eql) { |
| 1213 | return GetOrPutResult{ | 1213 | return GetOrPutResult{ |
| ... | @@ -1249,7 +1249,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1249,7 +1249,7 @@ pub fn HashMapUnmanaged( |
| 1249 | 1249 | ||
| 1250 | pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !Entry { | 1250 | pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !Entry { |
| 1251 | if (@sizeOf(Context) != 0) | 1251 | if (@sizeOf(Context) != 0) |
| 1252 | @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutValueContext instead."); | 1252 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); |
| 1253 | return self.getOrPutValueContext(allocator, key, value, undefined); | 1253 | return self.getOrPutValueContext(allocator, key, value, undefined); |
| 1254 | } | 1254 | } |
| 1255 | pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !Entry { | 1255 | pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !Entry { |
| ... | @@ -1264,7 +1264,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1264,7 +1264,7 @@ pub fn HashMapUnmanaged( |
| 1264 | /// Return true if there is a value associated with key in the map. | 1264 | /// Return true if there is a value associated with key in the map. |
| 1265 | pub fn contains(self: *const Self, key: K) bool { | 1265 | pub fn contains(self: *const Self, key: K) bool { |
| 1266 | if (@sizeOf(Context) != 0) | 1266 | if (@sizeOf(Context) != 0) |
| 1267 | @compileError("Cannot infer context "++@typeName(Context)++", call containsContext instead."); | 1267 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call containsContext instead."); |
| 1268 | return self.containsContext(key, undefined); | 1268 | return self.containsContext(key, undefined); |
| 1269 | } | 1269 | } |
| 1270 | pub fn containsContext(self: *const Self, key: K, ctx: Context) bool { | 1270 | pub fn containsContext(self: *const Self, key: K, ctx: Context) bool { |
| ... | @@ -1279,7 +1279,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1279,7 +1279,7 @@ pub fn HashMapUnmanaged( |
| 1279 | /// function returns false. | 1279 | /// function returns false. |
| 1280 | pub fn remove(self: *Self, key: K) bool { | 1280 | pub fn remove(self: *Self, key: K) bool { |
| 1281 | if (@sizeOf(Context) != 0) | 1281 | if (@sizeOf(Context) != 0) |
| 1282 | @compileError("Cannot infer context "++@typeName(Context)++", call removeContext instead."); | 1282 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call removeContext instead."); |
| 1283 | return self.removeContext(key, undefined); | 1283 | return self.removeContext(key, undefined); |
| 1284 | } | 1284 | } |
| 1285 | pub fn removeContext(self: *Self, key: K, ctx: Context) bool { | 1285 | pub fn removeContext(self: *Self, key: K, ctx: Context) bool { |
| ... | @@ -1317,7 +1317,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1317,7 +1317,7 @@ pub fn HashMapUnmanaged( |
| 1317 | 1317 | ||
| 1318 | pub fn clone(self: Self, allocator: *Allocator) !Self { | 1318 | pub fn clone(self: Self, allocator: *Allocator) !Self { |
| 1319 | if (@sizeOf(Context) != 0) | 1319 | if (@sizeOf(Context) != 0) |
| 1320 | @compileError("Cannot infer context "++@typeName(Context)++", call cloneContext instead."); | 1320 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); |
| 1321 | return self.cloneContext(allocator, @as(Context, undefined)); | 1321 | return self.cloneContext(allocator, @as(Context, undefined)); |
| 1322 | } | 1322 | } |
| 1323 | pub fn cloneContext(self: Self, allocator: *Allocator, new_ctx: anytype) !HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage) { | 1323 | pub fn cloneContext(self: Self, allocator: *Allocator, new_ctx: anytype) !HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage) { |
lib/std/math.zig+2-2| ... | @@ -1087,14 +1087,14 @@ fn testCeilPowerOfTwo() !void { | ... | @@ -1087,14 +1087,14 @@ fn testCeilPowerOfTwo() !void { |
| 1087 | 1087 | ||
| 1088 | pub fn log2_int(comptime T: type, x: T) Log2Int(T) { | 1088 | pub fn log2_int(comptime T: type, x: T) Log2Int(T) { |
| 1089 | if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) | 1089 | if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) |
| 1090 | @compileError("log2_int requires an unsigned integer, found "++@typeName(T)); | 1090 | @compileError("log2_int requires an unsigned integer, found " ++ @typeName(T)); |
| 1091 | assert(x != 0); | 1091 | assert(x != 0); |
| 1092 | return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(T, x)); | 1092 | return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(T, x)); |
| 1093 | } | 1093 | } |
| 1094 | 1094 | ||
| 1095 | pub fn log2_int_ceil(comptime T: type, x: T) Log2IntCeil(T) { | 1095 | pub fn log2_int_ceil(comptime T: type, x: T) Log2IntCeil(T) { |
| 1096 | if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) | 1096 | if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) |
| 1097 | @compileError("log2_int_ceil requires an unsigned integer, found "++@typeName(T)); | 1097 | @compileError("log2_int_ceil requires an unsigned integer, found " ++ @typeName(T)); |
| 1098 | assert(x != 0); | 1098 | assert(x != 0); |
| 1099 | if (x == 1) return 0; | 1099 | if (x == 1) return 0; |
| 1100 | const log2_val: Log2IntCeil(T) = log2_int(T, x - 1); | 1100 | const log2_val: Log2IntCeil(T) = log2_int(T, x - 1); |
lib/std/multi_array_list.zig+8-9| ... | @@ -46,8 +46,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -46,8 +46,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 46 | return &[_]F{}; | 46 | return &[_]F{}; |
| 47 | } | 47 | } |
| 48 | const byte_ptr = self.ptrs[@enumToInt(field)]; | 48 | const byte_ptr = self.ptrs[@enumToInt(field)]; |
| 49 | const casted_ptr: [*]F = if (@sizeOf([*]F) == 0) undefined | 49 | const casted_ptr: [*]F = if (@sizeOf([*]F) == 0) undefined else @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr)); |
| 50 | else @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr)); | ||
| 51 | return casted_ptr[0..self.len]; | 50 | return casted_ptr[0..self.len]; |
| 52 | } | 51 | } |
| 53 | 52 | ||
| ... | @@ -197,7 +196,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -197,7 +196,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 197 | try self.ensureCapacity(gpa, self.len + 1); | 196 | try self.ensureCapacity(gpa, self.len + 1); |
| 198 | self.insertAssumeCapacity(index, elem); | 197 | self.insertAssumeCapacity(index, elem); |
| 199 | } | 198 | } |
| 200 | 199 | ||
| 201 | /// Inserts an item into an ordered list which has room for it. | 200 | /// Inserts an item into an ordered list which has room for it. |
| 202 | /// Shifts all elements after and including the specified index | 201 | /// Shifts all elements after and including the specified index |
| 203 | /// back by one and sets the given index to the specified element. | 202 | /// back by one and sets the given index to the specified element. |
| ... | @@ -209,9 +208,9 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -209,9 +208,9 @@ pub fn MultiArrayList(comptime S: type) type { |
| 209 | const slices = self.slice(); | 208 | const slices = self.slice(); |
| 210 | inline for (fields) |field_info, field_index| { | 209 | inline for (fields) |field_info, field_index| { |
| 211 | const field_slice = slices.items(@intToEnum(Field, field_index)); | 210 | const field_slice = slices.items(@intToEnum(Field, field_index)); |
| 212 | var i: usize = self.len-1; | 211 | var i: usize = self.len - 1; |
| 213 | while (i > index) : (i -= 1) { | 212 | while (i > index) : (i -= 1) { |
| 214 | field_slice[i] = field_slice[i-1]; | 213 | field_slice[i] = field_slice[i - 1]; |
| 215 | } | 214 | } |
| 216 | field_slice[index] = @field(elem, field_info.name); | 215 | field_slice[index] = @field(elem, field_info.name); |
| 217 | } | 216 | } |
| ... | @@ -224,8 +223,8 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -224,8 +223,8 @@ pub fn MultiArrayList(comptime S: type) type { |
| 224 | const slices = self.slice(); | 223 | const slices = self.slice(); |
| 225 | inline for (fields) |field_info, i| { | 224 | inline for (fields) |field_info, i| { |
| 226 | const field_slice = slices.items(@intToEnum(Field, i)); | 225 | const field_slice = slices.items(@intToEnum(Field, i)); |
| 227 | field_slice[index] = field_slice[self.len-1]; | 226 | field_slice[index] = field_slice[self.len - 1]; |
| 228 | field_slice[self.len-1] = undefined; | 227 | field_slice[self.len - 1] = undefined; |
| 229 | } | 228 | } |
| 230 | self.len -= 1; | 229 | self.len -= 1; |
| 231 | } | 230 | } |
| ... | @@ -237,8 +236,8 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -237,8 +236,8 @@ pub fn MultiArrayList(comptime S: type) type { |
| 237 | inline for (fields) |field_info, field_index| { | 236 | inline for (fields) |field_info, field_index| { |
| 238 | const field_slice = slices.items(@intToEnum(Field, field_index)); | 237 | const field_slice = slices.items(@intToEnum(Field, field_index)); |
| 239 | var i = index; | 238 | var i = index; |
| 240 | while (i < self.len-1) : (i += 1) { | 239 | while (i < self.len - 1) : (i += 1) { |
| 241 | field_slice[i] = field_slice[i+1]; | 240 | field_slice[i] = field_slice[i + 1]; |
| 242 | } | 241 | } |
| 243 | field_slice[i] = undefined; | 242 | field_slice[i] = undefined; |
| 244 | } | 243 | } |
lib/std/os.zig+1-1| ... | @@ -6121,7 +6121,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { | ... | @@ -6121,7 +6121,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { |
| 6121 | } | 6121 | } |
| 6122 | } | 6122 | } |
| 6123 | 6123 | ||
| 6124 | pub const SetrlimitError = error{PermissionDenied, LimitTooBig} || UnexpectedError; | 6124 | pub const SetrlimitError = error{ PermissionDenied, LimitTooBig } || UnexpectedError; |
| 6125 | 6125 | ||
| 6126 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { | 6126 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { |
| 6127 | const setrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc) | 6127 | const setrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc) |
src/Compilation.zig+1-1| ... | @@ -1844,7 +1844,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -1844,7 +1844,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 1844 | 1844 | ||
| 1845 | for (keys[1..]) |key, i| { | 1845 | for (keys[1..]) |key, i| { |
| 1846 | err_msg.notes[i] = .{ | 1846 | err_msg.notes[i] = .{ |
| 1847 | .src_loc = key.nodeOffsetSrcLoc(values[i+1]), | 1847 | .src_loc = key.nodeOffsetSrcLoc(values[i + 1]), |
| 1848 | .msg = "also here", | 1848 | .msg = "also here", |
| 1849 | }; | 1849 | }; |
| 1850 | } | 1850 | } |
src/codegen/spirv.zig+6-9| ... | @@ -885,10 +885,7 @@ pub const DeclGen = struct { | ... | @@ -885,10 +885,7 @@ pub const DeclGen = struct { |
| 885 | if (inst.operand.ty.hasCodeGenBits()) { | 885 | if (inst.operand.ty.hasCodeGenBits()) { |
| 886 | const operand_id = try self.resolve(inst.operand); | 886 | const operand_id = try self.resolve(inst.operand); |
| 887 | // current_block_label_id should not be undefined here, lest there is a br or br_void in the function's body. | 887 | // current_block_label_id should not be undefined here, lest there is a br or br_void in the function's body. |
| 888 | try target.incoming_blocks.append(self.spv.gpa, .{ | 888 | try target.incoming_blocks.append(self.spv.gpa, .{ .src_label_id = self.current_block_label_id, .break_value_id = operand_id }); |
| 889 | .src_label_id = self.current_block_label_id, | ||
| 890 | .break_value_id = operand_id | ||
| 891 | }); | ||
| 892 | } | 889 | } |
| 893 | 890 | ||
| 894 | try writeInstruction(&self.code, .OpBranch, &[_]Word{target.label_id}); | 891 | try writeInstruction(&self.code, .OpBranch, &[_]Word{target.label_id}); |
| ... | @@ -936,9 +933,9 @@ pub const DeclGen = struct { | ... | @@ -936,9 +933,9 @@ pub const DeclGen = struct { |
| 936 | const result_id = self.spv.allocResultId(); | 933 | const result_id = self.spv.allocResultId(); |
| 937 | 934 | ||
| 938 | const operands = if (inst.base.ty.isVolatilePtr()) | 935 | const operands = if (inst.base.ty.isVolatilePtr()) |
| 939 | &[_]Word{ result_type_id, result_id, operand_id, @bitCast(u32, spec.MemoryAccess{.Volatile = true}) } | 936 | &[_]Word{ result_type_id, result_id, operand_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) } |
| 940 | else | 937 | else |
| 941 | &[_]Word{ result_type_id, result_id, operand_id}; | 938 | &[_]Word{ result_type_id, result_id, operand_id }; |
| 942 | 939 | ||
| 943 | try writeInstruction(&self.code, .OpLoad, operands); | 940 | try writeInstruction(&self.code, .OpLoad, operands); |
| 944 | 941 | ||
| ... | @@ -950,14 +947,14 @@ pub const DeclGen = struct { | ... | @@ -950,14 +947,14 @@ pub const DeclGen = struct { |
| 950 | const loop_label_id = self.spv.allocResultId(); | 947 | const loop_label_id = self.spv.allocResultId(); |
| 951 | 948 | ||
| 952 | // Jump to the loop entry point | 949 | // Jump to the loop entry point |
| 953 | try writeInstruction(&self.code, .OpBranch, &[_]Word{ loop_label_id }); | 950 | try writeInstruction(&self.code, .OpBranch, &[_]Word{loop_label_id}); |
| 954 | 951 | ||
| 955 | // TODO: Look into OpLoopMerge. | 952 | // TODO: Look into OpLoopMerge. |
| 956 | 953 | ||
| 957 | try self.beginSPIRVBlock(loop_label_id); | 954 | try self.beginSPIRVBlock(loop_label_id); |
| 958 | try self.genBody(inst.body); | 955 | try self.genBody(inst.body); |
| 959 | 956 | ||
| 960 | try writeInstruction(&self.code, .OpBranch, &[_]Word{ loop_label_id }); | 957 | try writeInstruction(&self.code, .OpBranch, &[_]Word{loop_label_id}); |
| 961 | } | 958 | } |
| 962 | 959 | ||
| 963 | fn genRet(self: *DeclGen, inst: *Inst.UnOp) !void { | 960 | fn genRet(self: *DeclGen, inst: *Inst.UnOp) !void { |
| ... | @@ -976,7 +973,7 @@ pub const DeclGen = struct { | ... | @@ -976,7 +973,7 @@ pub const DeclGen = struct { |
| 976 | const src_val_id = try self.resolve(inst.rhs); | 973 | const src_val_id = try self.resolve(inst.rhs); |
| 977 | 974 | ||
| 978 | const operands = if (inst.lhs.ty.isVolatilePtr()) | 975 | const operands = if (inst.lhs.ty.isVolatilePtr()) |
| 979 | &[_]Word{ dst_ptr_id, src_val_id, @bitCast(u32, spec.MemoryAccess{.Volatile = true}) } | 976 | &[_]Word{ dst_ptr_id, src_val_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) } |
| 980 | else | 977 | else |
| 981 | &[_]Word{ dst_ptr_id, src_val_id }; | 978 | &[_]Word{ dst_ptr_id, src_val_id }; |
| 982 | 979 |
src/link/MachO.zig+1-1| ... | @@ -2517,7 +2517,7 @@ fn allocatedSizeLinkedit(self: *MachO, start: u64) u64 { | ... | @@ -2517,7 +2517,7 @@ fn allocatedSizeLinkedit(self: *MachO, start: u64) u64 { |
| 2517 | 2517 | ||
| 2518 | return min_pos - start; | 2518 | return min_pos - start; |
| 2519 | } | 2519 | } |
| 2520 | fn checkForCollision(start: u64, end: u64, off: u64, size: u64) callconv(.Inline) ?u64 { | 2520 | inline fn checkForCollision(start: u64, end: u64, off: u64, size: u64) ?u64 { |
| 2521 | const increased_size = padToIdeal(size); | 2521 | const increased_size = padToIdeal(size); |
| 2522 | const test_end = off + increased_size; | 2522 | const test_end = off + increased_size; |
| 2523 | if (end > off and start < test_end) { | 2523 | if (end > off and start < test_end) { |
src/link/SpirV.zig+1-4| ... | @@ -187,10 +187,7 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void { | ... | @@ -187,10 +187,7 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void { |
| 187 | var iovc_buffers: [buffers.len]std.os.iovec_const = undefined; | 187 | var iovc_buffers: [buffers.len]std.os.iovec_const = undefined; |
| 188 | for (iovc_buffers) |*iovc, i| { | 188 | for (iovc_buffers) |*iovc, i| { |
| 189 | const bytes = std.mem.sliceAsBytes(buffers[i]); | 189 | const bytes = std.mem.sliceAsBytes(buffers[i]); |
| 190 | iovc.* = .{ | 190 | iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len }; |
| 191 | .iov_base = bytes.ptr, | ||
| 192 | .iov_len = bytes.len | ||
| 193 | }; | ||
| 194 | } | 191 | } |
| 195 | 192 | ||
| 196 | var file_size: u64 = 0; | 193 | var file_size: u64 = 0; |
test/behavior.zig-1| ... | @@ -55,7 +55,6 @@ comptime { | ... | @@ -55,7 +55,6 @@ comptime { |
| 55 | _ = @import("behavior/bugs/4560.zig"); | 55 | _ = @import("behavior/bugs/4560.zig"); |
| 56 | _ = @import("behavior/bugs/4769_a.zig"); | 56 | _ = @import("behavior/bugs/4769_a.zig"); |
| 57 | _ = @import("behavior/bugs/4769_b.zig"); | 57 | _ = @import("behavior/bugs/4769_b.zig"); |
| 58 | _ = @import("behavior/bugs/4769_c.zig"); | ||
| 59 | _ = @import("behavior/bugs/4954.zig"); | 58 | _ = @import("behavior/bugs/4954.zig"); |
| 60 | _ = @import("behavior/bugs/5398.zig"); | 59 | _ = @import("behavior/bugs/5398.zig"); |
| 61 | _ = @import("behavior/bugs/5413.zig"); | 60 | _ = @import("behavior/bugs/5413.zig"); |
test/behavior/bugs/4769_c.zig deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | /// | ||
| \ No newline at end of file | |||
test/behavior/fn.zig+1-1| ... | @@ -114,7 +114,7 @@ test "assign inline fn to const variable" { | ... | @@ -114,7 +114,7 @@ test "assign inline fn to const variable" { |
| 114 | a(); | 114 | a(); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | fn inlineFn() callconv(.Inline) void {} | 117 | inline fn inlineFn() void {} |
| 118 | 118 | ||
| 119 | test "pass by non-copying value" { | 119 | test "pass by non-copying value" { |
| 120 | try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3); | 120 | try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3); |
test/behavior/type.zig+1-1| ... | @@ -182,7 +182,7 @@ test "Type.Optional" { | ... | @@ -182,7 +182,7 @@ test "Type.Optional" { |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | test "Type.ErrorUnion" { | 184 | test "Type.ErrorUnion" { |
| 185 | try testTypes(&[_]type{ | 185 | try testTypes(&[_]type{ |
| 186 | error{}!void, | 186 | error{}!void, |
| 187 | error{Error}!void, | 187 | error{Error}!void, |
| 188 | }); | 188 | }); |
test/standalone/c_compiler/build.zig+1-1| ... | @@ -30,7 +30,7 @@ pub fn build(b: *Builder) void { | ... | @@ -30,7 +30,7 @@ pub fn build(b: *Builder) void { |
| 30 | exe_cpp.linkSystemLibrary("c++"); | 30 | exe_cpp.linkSystemLibrary("c++"); |
| 31 | 31 | ||
| 32 | // disable broken LTO links: | 32 | // disable broken LTO links: |
| 33 | switch(target.getOsTag()) { | 33 | switch (target.getOsTag()) { |
| 34 | .windows => { | 34 | .windows => { |
| 35 | exe_cpp.want_lto = false; | 35 | exe_cpp.want_lto = false; |
| 36 | }, | 36 | }, |
tools/gen_spirv_spec.zig+11-10| ... | @@ -15,7 +15,7 @@ pub fn main() !void { | ... | @@ -15,7 +15,7 @@ pub fn main() !void { |
| 15 | const spec = try std.fs.cwd().readFileAlloc(allocator, spec_path, std.math.maxInt(usize)); | 15 | const spec = try std.fs.cwd().readFileAlloc(allocator, spec_path, std.math.maxInt(usize)); |
| 16 | 16 | ||
| 17 | var tokens = std.json.TokenStream.init(spec); | 17 | var tokens = std.json.TokenStream.init(spec); |
| 18 | var registry = try std.json.parse(g.Registry, &tokens, .{.allocator = allocator}); | 18 | var registry = try std.json.parse(g.Registry, &tokens, .{ .allocator = allocator }); |
| 19 | 19 | ||
| 20 | var bw = std.io.bufferedWriter(std.io.getStdOut().writer()); | 20 | var bw = std.io.bufferedWriter(std.io.getStdOut().writer()); |
| 21 | try render(bw.writer(), registry); | 21 | try render(bw.writer(), registry); |
| ... | @@ -36,7 +36,8 @@ fn render(writer: anytype, registry: g.Registry) !void { | ... | @@ -36,7 +36,8 @@ fn render(writer: anytype, registry: g.Registry) !void { |
| 36 | \\pub const version = Version{{ .major = {}, .minor = {}, .patch = {} }}; | 36 | \\pub const version = Version{{ .major = {}, .minor = {}, .patch = {} }}; |
| 37 | \\pub const magic_number: u32 = {s}; | 37 | \\pub const magic_number: u32 = {s}; |
| 38 | \\ | 38 | \\ |
| 39 | , .{ core_reg.major_version, core_reg.minor_version, core_reg.revision, core_reg.magic_number }, | 39 | , |
| 40 | .{ core_reg.major_version, core_reg.minor_version, core_reg.revision, core_reg.magic_number }, | ||
| 40 | ); | 41 | ); |
| 41 | try renderOpcodes(writer, core_reg.instructions); | 42 | try renderOpcodes(writer, core_reg.instructions); |
| 42 | try renderOperandKinds(writer, core_reg.operand_kinds); | 43 | try renderOperandKinds(writer, core_reg.operand_kinds); |
| ... | @@ -45,11 +46,12 @@ fn render(writer: anytype, registry: g.Registry) !void { | ... | @@ -45,11 +46,12 @@ fn render(writer: anytype, registry: g.Registry) !void { |
| 45 | try writer.print( | 46 | try writer.print( |
| 46 | \\pub const version = Version{{ .major = {}, .minor = 0, .patch = {} }}; | 47 | \\pub const version = Version{{ .major = {}, .minor = 0, .patch = {} }}; |
| 47 | \\ | 48 | \\ |
| 48 | , .{ ext_reg.version, ext_reg.revision }, | 49 | , |
| 50 | .{ ext_reg.version, ext_reg.revision }, | ||
| 49 | ); | 51 | ); |
| 50 | try renderOpcodes(writer, ext_reg.instructions); | 52 | try renderOpcodes(writer, ext_reg.instructions); |
| 51 | try renderOperandKinds(writer, ext_reg.operand_kinds); | 53 | try renderOperandKinds(writer, ext_reg.operand_kinds); |
| 52 | } | 54 | }, |
| 53 | } | 55 | } |
| 54 | } | 56 | } |
| 55 | 57 | ||
| ... | @@ -72,7 +74,7 @@ fn renderOperandKinds(writer: anytype, kinds: []const g.OperandKind) !void { | ... | @@ -72,7 +74,7 @@ fn renderOperandKinds(writer: anytype, kinds: []const g.OperandKind) !void { |
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | fn renderValueEnum(writer: anytype, enumeration: g.OperandKind) !void { | 76 | fn renderValueEnum(writer: anytype, enumeration: g.OperandKind) !void { |
| 75 | try writer.print("pub const {s} = extern enum(u32) {{\n", .{ enumeration.kind }); | 77 | try writer.print("pub const {s} = extern enum(u32) {{\n", .{enumeration.kind}); |
| 76 | 78 | ||
| 77 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; | 79 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; |
| 78 | for (enumerants) |enumerant| { | 80 | for (enumerants) |enumerant| { |
| ... | @@ -85,7 +87,7 @@ fn renderValueEnum(writer: anytype, enumeration: g.OperandKind) !void { | ... | @@ -85,7 +87,7 @@ fn renderValueEnum(writer: anytype, enumeration: g.OperandKind) !void { |
| 85 | } | 87 | } |
| 86 | 88 | ||
| 87 | fn renderBitEnum(writer: anytype, enumeration: g.OperandKind) !void { | 89 | fn renderBitEnum(writer: anytype, enumeration: g.OperandKind) !void { |
| 88 | try writer.print("pub const {s} = packed struct {{\n", .{ enumeration.kind }); | 90 | try writer.print("pub const {s} = packed struct {{\n", .{enumeration.kind}); |
| 89 | 91 | ||
| 90 | var flags_by_bitpos = [_]?[]const u8{null} ** 32; | 92 | var flags_by_bitpos = [_]?[]const u8{null} ** 32; |
| 91 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; | 93 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; |
| ... | @@ -97,7 +99,7 @@ fn renderBitEnum(writer: anytype, enumeration: g.OperandKind) !void { | ... | @@ -97,7 +99,7 @@ fn renderBitEnum(writer: anytype, enumeration: g.OperandKind) !void { |
| 97 | } | 99 | } |
| 98 | 100 | ||
| 99 | var bitpos = std.math.log2_int(u32, value); | 101 | var bitpos = std.math.log2_int(u32, value); |
| 100 | if (flags_by_bitpos[bitpos]) |*existing|{ | 102 | if (flags_by_bitpos[bitpos]) |*existing| { |
| 101 | // Keep the shortest | 103 | // Keep the shortest |
| 102 | if (enumerant.enumerant.len < existing.len) | 104 | if (enumerant.enumerant.len < existing.len) |
| 103 | existing.* = enumerant.enumerant; | 105 | existing.* = enumerant.enumerant; |
| ... | @@ -128,7 +130,7 @@ fn parseHexInt(text: []const u8) !u31 { | ... | @@ -128,7 +130,7 @@ fn parseHexInt(text: []const u8) !u31 { |
| 128 | const prefix = "0x"; | 130 | const prefix = "0x"; |
| 129 | if (!std.mem.startsWith(u8, text, prefix)) | 131 | if (!std.mem.startsWith(u8, text, prefix)) |
| 130 | return error.InvalidHexInt; | 132 | return error.InvalidHexInt; |
| 131 | return try std.fmt.parseInt(u31, text[prefix.len ..], 16); | 133 | return try std.fmt.parseInt(u31, text[prefix.len..], 16); |
| 132 | } | 134 | } |
| 133 | 135 | ||
| 134 | fn usageAndExit(file: std.fs.File, arg0: []const u8, code: u8) noreturn { | 136 | fn usageAndExit(file: std.fs.File, arg0: []const u8, code: u8) noreturn { |
| ... | @@ -142,7 +144,6 @@ fn usageAndExit(file: std.fs.File, arg0: []const u8, code: u8) noreturn { | ... | @@ -142,7 +144,6 @@ fn usageAndExit(file: std.fs.File, arg0: []const u8, code: u8) noreturn { |
| 142 | \\The relevant specifications can be obtained from the SPIR-V registry: | 144 | \\The relevant specifications can be obtained from the SPIR-V registry: |
| 143 | \\https://github.com/KhronosGroup/SPIRV-Headers/blob/master/include/spirv/unified1/ | 145 | \\https://github.com/KhronosGroup/SPIRV-Headers/blob/master/include/spirv/unified1/ |
| 144 | \\ | 146 | \\ |
| 145 | , .{arg0} | 147 | , .{arg0}) catch std.process.exit(1); |
| 146 | ) catch std.process.exit(1); | ||
| 147 | std.process.exit(code); | 148 | std.process.exit(code); |
| 148 | } | 149 | } |
tools/update_spirv_features.zig+25-30| ... | @@ -1,8 +1,3 @@ | ... | @@ -1,8 +1,3 @@ |
| 1 | const std = @import("std"); | ||
| 2 | const fs = std.fs; | ||
| 3 | const Allocator = std.mem.Allocator; | ||
| 4 | const g = @import("spirv/grammar.zig"); | ||
| 5 | |||
| 6 | //! This tool generates SPIR-V features from the grammar files in the SPIRV-Headers | 1 | //! This tool generates SPIR-V features from the grammar files in the SPIRV-Headers |
| 7 | //! (https://github.com/KhronosGroup/SPIRV-Headers/) and SPIRV-Registry (https://github.com/KhronosGroup/SPIRV-Registry/) | 2 | //! (https://github.com/KhronosGroup/SPIRV-Headers/) and SPIRV-Registry (https://github.com/KhronosGroup/SPIRV-Registry/) |
| 8 | //! repositories. Currently it only generates a basic feature set definition consisting of versions, extensions and capabilities. | 3 | //! repositories. Currently it only generates a basic feature set definition consisting of versions, extensions and capabilities. |
| ... | @@ -14,6 +9,11 @@ const g = @import("spirv/grammar.zig"); | ... | @@ -14,6 +9,11 @@ const g = @import("spirv/grammar.zig"); |
| 14 | //! from an intel project (https://github.com/intel/llvm/, https://github.com/intel/llvm/tree/sycl/sycl/doc/extensions/SPIRV), | 9 | //! from an intel project (https://github.com/intel/llvm/, https://github.com/intel/llvm/tree/sycl/sycl/doc/extensions/SPIRV), |
| 15 | //! and so ONLY extensions in the SPIRV-Registry should be included. | 10 | //! and so ONLY extensions in the SPIRV-Registry should be included. |
| 16 | 11 | ||
| 12 | const std = @import("std"); | ||
| 13 | const fs = std.fs; | ||
| 14 | const Allocator = std.mem.Allocator; | ||
| 15 | const g = @import("spirv/grammar.zig"); | ||
| 16 | |||
| 17 | const Version = struct { | 17 | const Version = struct { |
| 18 | major: u32, | 18 | major: u32, |
| 19 | minor: u32, | 19 | minor: u32, |
| ... | @@ -38,9 +38,9 @@ const Version = struct { | ... | @@ -38,9 +38,9 @@ const Version = struct { |
| 38 | 38 | ||
| 39 | fn lessThan(ctx: void, a: Version, b: Version) bool { | 39 | fn lessThan(ctx: void, a: Version, b: Version) bool { |
| 40 | return if (a.major == b.major) | 40 | return if (a.major == b.major) |
| 41 | a.minor < b.minor | 41 | a.minor < b.minor |
| 42 | else | 42 | else |
| 43 | a.major < b.major; | 43 | a.major < b.major; |
| 44 | } | 44 | } |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| ... | @@ -103,11 +103,11 @@ pub fn main() !void { | ... | @@ -103,11 +103,11 @@ pub fn main() !void { |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | for (extensions) |ext| { | 105 | for (extensions) |ext| { |
| 106 | try w.print(" {},\n", .{ std.zig.fmtId(ext) }); | 106 | try w.print(" {},\n", .{std.zig.fmtId(ext)}); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | for (capabilities) |cap| { | 109 | for (capabilities) |cap| { |
| 110 | try w.print(" {},\n", .{ std.zig.fmtId(cap.enumerant) }); | 110 | try w.print(" {},\n", .{std.zig.fmtId(cap.enumerant)}); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | try w.writeAll( | 113 | try w.writeAll( |
| ... | @@ -129,8 +129,7 @@ pub fn main() !void { | ... | @@ -129,8 +129,7 @@ pub fn main() !void { |
| 129 | \\ .llvm_name = null, | 129 | \\ .llvm_name = null, |
| 130 | \\ .description = "SPIR-V version {0}.{1}", | 130 | \\ .description = "SPIR-V version {0}.{1}", |
| 131 | \\ | 131 | \\ |
| 132 | , .{ ver.major, ver.minor } | 132 | , .{ ver.major, ver.minor }); |
| 133 | ); | ||
| 134 | 133 | ||
| 135 | if (i == 0) { | 134 | if (i == 0) { |
| 136 | try w.writeAll( | 135 | try w.writeAll( |
| ... | @@ -145,8 +144,7 @@ pub fn main() !void { | ... | @@ -145,8 +144,7 @@ pub fn main() !void { |
| 145 | \\ }}), | 144 | \\ }}), |
| 146 | \\ }}; | 145 | \\ }}; |
| 147 | \\ | 146 | \\ |
| 148 | , .{ versions[i - 1].major, versions[i - 1].minor } | 147 | , .{ versions[i - 1].major, versions[i - 1].minor }); |
| 149 | ); | ||
| 150 | } | 148 | } |
| 151 | } | 149 | } |
| 152 | 150 | ||
| ... | @@ -159,11 +157,10 @@ pub fn main() !void { | ... | @@ -159,11 +157,10 @@ pub fn main() !void { |
| 159 | \\ .dependencies = featureSet(&[_]Feature{{}}), | 157 | \\ .dependencies = featureSet(&[_]Feature{{}}), |
| 160 | \\ }}; | 158 | \\ }}; |
| 161 | \\ | 159 | \\ |
| 162 | , .{ | 160 | , .{ |
| 163 | std.zig.fmtId(ext), | 161 | std.zig.fmtId(ext), |
| 164 | ext, | 162 | ext, |
| 165 | } | 163 | }); |
| 166 | ); | ||
| 167 | } | 164 | } |
| 168 | 165 | ||
| 169 | // TODO: Capability extension dependencies. | 166 | // TODO: Capability extension dependencies. |
| ... | @@ -174,11 +171,10 @@ pub fn main() !void { | ... | @@ -174,11 +171,10 @@ pub fn main() !void { |
| 174 | \\ .description = "Enable SPIR-V capability {s}", | 171 | \\ .description = "Enable SPIR-V capability {s}", |
| 175 | \\ .dependencies = featureSet(&[_]Feature{{ | 172 | \\ .dependencies = featureSet(&[_]Feature{{ |
| 176 | \\ | 173 | \\ |
| 177 | , .{ | 174 | , .{ |
| 178 | std.zig.fmtId(cap.enumerant), | 175 | std.zig.fmtId(cap.enumerant), |
| 179 | cap.enumerant, | 176 | cap.enumerant, |
| 180 | } | 177 | }); |
| 181 | ); | ||
| 182 | 178 | ||
| 183 | if (cap.version) |ver_str| { | 179 | if (cap.version) |ver_str| { |
| 184 | if (!std.mem.eql(u8, ver_str, "None")) { | 180 | if (!std.mem.eql(u8, ver_str, "None")) { |
| ... | @@ -188,7 +184,7 @@ pub fn main() !void { | ... | @@ -188,7 +184,7 @@ pub fn main() !void { |
| 188 | } | 184 | } |
| 189 | 185 | ||
| 190 | for (cap.capabilities) |cap_dep| { | 186 | for (cap.capabilities) |cap_dep| { |
| 191 | try w.print(" .{},\n", .{ std.zig.fmtId(cap_dep) }); | 187 | try w.print(" .{},\n", .{std.zig.fmtId(cap_dep)}); |
| 192 | } | 188 | } |
| 193 | 189 | ||
| 194 | try w.writeAll( | 190 | try w.writeAll( |
| ... | @@ -198,7 +194,7 @@ pub fn main() !void { | ... | @@ -198,7 +194,7 @@ pub fn main() !void { |
| 198 | ); | 194 | ); |
| 199 | } | 195 | } |
| 200 | 196 | ||
| 201 | try w.writeAll( | 197 | try w.writeAll( |
| 202 | \\ const ti = @typeInfo(Feature); | 198 | \\ const ti = @typeInfo(Feature); |
| 203 | \\ for (result) |*elem, i| { | 199 | \\ for (result) |*elem, i| { |
| 204 | \\ elem.index = i; | 200 | \\ elem.index = i; |
| ... | @@ -217,7 +213,7 @@ pub fn main() !void { | ... | @@ -217,7 +213,7 @@ pub fn main() !void { |
| 217 | /// registered ones. | 213 | /// registered ones. |
| 218 | /// TODO: Unfortunately, neither repository contains a machine-readable list of extension dependencies. | 214 | /// TODO: Unfortunately, neither repository contains a machine-readable list of extension dependencies. |
| 219 | fn gather_extensions(allocator: *Allocator, spirv_registry_root: []const u8) ![]const []const u8 { | 215 | fn gather_extensions(allocator: *Allocator, spirv_registry_root: []const u8) ![]const []const u8 { |
| 220 | const extensions_path = try fs.path.join(allocator, &.{spirv_registry_root, "extensions"}); | 216 | const extensions_path = try fs.path.join(allocator, &.{ spirv_registry_root, "extensions" }); |
| 221 | var extensions_dir = try fs.cwd().openDir(extensions_path, .{ .iterate = true }); | 217 | var extensions_dir = try fs.cwd().openDir(extensions_path, .{ .iterate = true }); |
| 222 | defer extensions_dir.close(); | 218 | defer extensions_dir.close(); |
| 223 | 219 | ||
| ... | @@ -262,7 +258,7 @@ fn gather_extensions(allocator: *Allocator, spirv_registry_root: []const u8) ![] | ... | @@ -262,7 +258,7 @@ fn gather_extensions(allocator: *Allocator, spirv_registry_root: []const u8) ![] |
| 262 | } | 258 | } |
| 263 | 259 | ||
| 264 | const ext_end = std.mem.indexOfScalarPos(u8, ext_spec, ext_start, '\n') orelse return error.InvalidRegistry; | 260 | const ext_end = std.mem.indexOfScalarPos(u8, ext_spec, ext_start, '\n') orelse return error.InvalidRegistry; |
| 265 | const ext = ext_spec[ext_start .. ext_end]; | 261 | const ext = ext_spec[ext_start..ext_end]; |
| 266 | 262 | ||
| 267 | std.debug.assert(std.mem.startsWith(u8, ext, "SPV_")); // Sanity check, all extensions should have a name like SPV_VENDOR_extension. | 263 | std.debug.assert(std.mem.startsWith(u8, ext, "SPV_")); // Sanity check, all extensions should have a name like SPV_VENDOR_extension. |
| 268 | 264 | ||
| ... | @@ -315,7 +311,6 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn { | ... | @@ -315,7 +311,6 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn { |
| 315 | \\SPIRV-Headers can be cloned from https://github.com/KhronosGroup/SPIRV-Headers, | 311 | \\SPIRV-Headers can be cloned from https://github.com/KhronosGroup/SPIRV-Headers, |
| 316 | \\SPIRV-Registry can be cloned from https://github.com/KhronosGroup/SPIRV-Registry. | 312 | \\SPIRV-Registry can be cloned from https://github.com/KhronosGroup/SPIRV-Registry. |
| 317 | \\ | 313 | \\ |
| 318 | , .{arg0} | 314 | , .{arg0}) catch std.process.exit(1); |
| 319 | ) catch std.process.exit(1); | ||
| 320 | std.process.exit(code); | 315 | std.process.exit(code); |
| 321 | } | 316 | } |