authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-11 10:28:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-11 10:28:42-07:00
logec4c60c4812d4ed850841b85c59e24ea3f73c355
tree0db200bb02e8ad38e4e08058b6a3396d7b086589
parent29386f0d3021f4868ac021f05ff47455f011d674

zig fmt


16 files changed, 165 insertions(+), 180 deletions(-)

lib/std/array_hash_map.zig+54-56
......@@ -124,7 +124,7 @@ pub fn ArrayHashMap(
124124 /// Create an ArrayHashMap instance which will use a specified allocator.
125125 pub fn init(allocator: *Allocator) Self {
126126 if (@sizeOf(Context) != 0)
127 @compileError("Cannot infer context "++@typeName(Context)++", call initContext instead.");
127 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call initContext instead.");
128128 return initContext(allocator, undefined);
129129 }
130130 pub fn initContext(allocator: *Allocator, ctx: Context) Self {
......@@ -518,7 +518,7 @@ pub fn ArrayHashMapUnmanaged(
518518 /// the promoted map should no longer be used.
519519 pub fn promote(self: Self, allocator: *Allocator) Managed {
520520 if (@sizeOf(Context) != 0)
521 @compileError("Cannot infer context "++@typeName(Context)++", call promoteContext instead.");
521 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead.");
522522 return self.promoteContext(allocator, undefined);
523523 }
524524 pub fn promoteContext(self: Self, allocator: *Allocator, ctx: Context) Managed {
......@@ -618,7 +618,7 @@ pub fn ArrayHashMapUnmanaged(
618618 /// the value (but not the key).
619619 pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult {
620620 if (@sizeOf(Context) != 0)
621 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContext instead.");
621 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead.");
622622 return self.getOrPutContext(allocator, key, undefined);
623623 }
624624 pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult {
......@@ -630,7 +630,7 @@ pub fn ArrayHashMapUnmanaged(
630630 }
631631 pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult {
632632 if (@sizeOf(Context) != 0)
633 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContextAdapted instead.");
633 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead.");
634634 return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined);
635635 }
636636 pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult {
......@@ -658,7 +658,7 @@ pub fn ArrayHashMapUnmanaged(
658658 /// is enough capacity to store it.
659659 pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult {
660660 if (@sizeOf(Context) != 0)
661 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutAssumeCapacityContext instead.");
661 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutAssumeCapacityContext instead.");
662662 return self.getOrPutAssumeCapacityContext(key, undefined);
663663 }
664664 pub fn getOrPutAssumeCapacityContext(self: *Self, key: K, ctx: Context) GetOrPutResult {
......@@ -716,7 +716,7 @@ pub fn ArrayHashMapUnmanaged(
716716
717717 pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !GetOrPutResult {
718718 if (@sizeOf(Context) != 0)
719 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutValueContext instead.");
719 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead.");
720720 return self.getOrPutValueContext(allocator, key, value, undefined);
721721 }
722722 pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !GetOrPutResult {
......@@ -735,7 +735,7 @@ pub fn ArrayHashMapUnmanaged(
735735 /// `expected_count` will not cause an allocation, and therefore cannot fail.
736736 pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void {
737737 if (@sizeOf(ByIndexContext) != 0)
738 @compileError("Cannot infer context "++@typeName(Context)++", call ensureTotalCapacityContext instead.");
738 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead.");
739739 return self.ensureTotalCapacityContext(allocator, new_capacity, undefined);
740740 }
741741 pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void {
......@@ -769,7 +769,7 @@ pub fn ArrayHashMapUnmanaged(
769769 additional_capacity: usize,
770770 ) !void {
771771 if (@sizeOf(ByIndexContext) != 0)
772 @compileError("Cannot infer context "++@typeName(Context)++", call ensureTotalCapacityContext instead.");
772 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead.");
773773 return self.ensureUnusedCapacityContext(allocator, additional_capacity, undefined);
774774 }
775775 pub fn ensureUnusedCapacityContext(
......@@ -794,7 +794,7 @@ pub fn ArrayHashMapUnmanaged(
794794 /// existing data, see `getOrPut`.
795795 pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void {
796796 if (@sizeOf(Context) != 0)
797 @compileError("Cannot infer context "++@typeName(Context)++", call putContext instead.");
797 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead.");
798798 return self.putContext(allocator, key, value, undefined);
799799 }
800800 pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void {
......@@ -806,7 +806,7 @@ pub fn ArrayHashMapUnmanaged(
806806 /// entry with the same key is already present
807807 pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void {
808808 if (@sizeOf(Context) != 0)
809 @compileError("Cannot infer context "++@typeName(Context)++", call putNoClobberContext instead.");
809 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead.");
810810 return self.putNoClobberContext(allocator, key, value, undefined);
811811 }
812812 pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void {
......@@ -820,7 +820,7 @@ pub fn ArrayHashMapUnmanaged(
820820 /// existing data, see `getOrPutAssumeCapacity`.
821821 pub fn putAssumeCapacity(self: *Self, key: K, value: V) void {
822822 if (@sizeOf(Context) != 0)
823 @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityContext instead.");
823 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityContext instead.");
824824 return self.putAssumeCapacityContext(key, value, undefined);
825825 }
826826 pub fn putAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) void {
......@@ -833,7 +833,7 @@ pub fn ArrayHashMapUnmanaged(
833833 /// To detect if a put would clobber existing data, see `getOrPutAssumeCapacity`.
834834 pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void {
835835 if (@sizeOf(Context) != 0)
836 @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityNoClobberContext instead.");
836 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityNoClobberContext instead.");
837837 return self.putAssumeCapacityNoClobberContext(key, value, undefined);
838838 }
839839 pub fn putAssumeCapacityNoClobberContext(self: *Self, key: K, value: V, ctx: Context) void {
......@@ -845,7 +845,7 @@ pub fn ArrayHashMapUnmanaged(
845845 /// Inserts a new `Entry` into the hash map, returning the previous one, if any.
846846 pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV {
847847 if (@sizeOf(Context) != 0)
848 @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutContext instead.");
848 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead.");
849849 return self.fetchPutContext(allocator, key, value, undefined);
850850 }
851851 pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV {
......@@ -865,7 +865,7 @@ pub fn ArrayHashMapUnmanaged(
865865 /// If insertion happens, asserts there is enough capacity without allocating.
866866 pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV {
867867 if (@sizeOf(Context) != 0)
868 @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutAssumeCapacityContext instead.");
868 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutAssumeCapacityContext instead.");
869869 return self.fetchPutAssumeCapacityContext(key, value, undefined);
870870 }
871871 pub fn fetchPutAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) ?KV {
......@@ -884,7 +884,7 @@ pub fn ArrayHashMapUnmanaged(
884884 /// Finds pointers to the key and value storage associated with a key.
885885 pub fn getEntry(self: Self, key: K) ?Entry {
886886 if (@sizeOf(Context) != 0)
887 @compileError("Cannot infer context "++@typeName(Context)++", call getEntryContext instead.");
887 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getEntryContext instead.");
888888 return self.getEntryContext(key, undefined);
889889 }
890890 pub fn getEntryContext(self: Self, key: K, ctx: Context) ?Entry {
......@@ -903,7 +903,7 @@ pub fn ArrayHashMapUnmanaged(
903903 /// Finds the index in the `entries` array where a key is stored
904904 pub fn getIndex(self: Self, key: K) ?usize {
905905 if (@sizeOf(Context) != 0)
906 @compileError("Cannot infer context "++@typeName(Context)++", call getIndexContext instead.");
906 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getIndexContext instead.");
907907 return self.getIndexContext(key, undefined);
908908 }
909909 pub fn getIndexContext(self: Self, key: K, ctx: Context) ?usize {
......@@ -938,7 +938,7 @@ pub fn ArrayHashMapUnmanaged(
938938 /// Find the value associated with a key
939939 pub fn get(self: Self, key: K) ?V {
940940 if (@sizeOf(Context) != 0)
941 @compileError("Cannot infer context "++@typeName(Context)++", call getContext instead.");
941 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getContext instead.");
942942 return self.getContext(key, undefined);
943943 }
944944 pub fn getContext(self: Self, key: K, ctx: Context) ?V {
......@@ -952,7 +952,7 @@ pub fn ArrayHashMapUnmanaged(
952952 /// Find a pointer to the value associated with a key
953953 pub fn getPtr(self: Self, key: K) ?*V {
954954 if (@sizeOf(Context) != 0)
955 @compileError("Cannot infer context "++@typeName(Context)++", call getPtrContext instead.");
955 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getPtrContext instead.");
956956 return self.getPtrContext(key, undefined);
957957 }
958958 pub fn getPtrContext(self: Self, key: K, ctx: Context) ?*V {
......@@ -967,7 +967,7 @@ pub fn ArrayHashMapUnmanaged(
967967 /// Check whether a key is stored in the map
968968 pub fn contains(self: Self, key: K) bool {
969969 if (@sizeOf(Context) != 0)
970 @compileError("Cannot infer context "++@typeName(Context)++", call containsContext instead.");
970 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call containsContext instead.");
971971 return self.containsContext(key, undefined);
972972 }
973973 pub fn containsContext(self: Self, key: K, ctx: Context) bool {
......@@ -983,7 +983,7 @@ pub fn ArrayHashMapUnmanaged(
983983 /// element.
984984 pub fn fetchSwapRemove(self: *Self, key: K) ?KV {
985985 if (@sizeOf(Context) != 0)
986 @compileError("Cannot infer context "++@typeName(Context)++", call fetchSwapRemoveContext instead.");
986 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchSwapRemoveContext instead.");
987987 return self.fetchSwapRemoveContext(key, undefined);
988988 }
989989 pub fn fetchSwapRemoveContext(self: *Self, key: K, ctx: Context) ?KV {
......@@ -991,7 +991,7 @@ pub fn ArrayHashMapUnmanaged(
991991 }
992992 pub fn fetchSwapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV {
993993 if (@sizeOf(ByIndexContext) != 0)
994 @compileError("Cannot infer context "++@typeName(Context)++", call fetchSwapRemoveContextAdapted instead.");
994 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchSwapRemoveContextAdapted instead.");
995995 return self.fetchSwapRemoveContextAdapted(key, ctx, undefined);
996996 }
997997 pub fn fetchSwapRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) ?KV {
......@@ -1004,7 +1004,7 @@ pub fn ArrayHashMapUnmanaged(
10041004 /// thereby maintaining the current ordering.
10051005 pub fn fetchOrderedRemove(self: *Self, key: K) ?KV {
10061006 if (@sizeOf(Context) != 0)
1007 @compileError("Cannot infer context "++@typeName(Context)++", call fetchOrderedRemoveContext instead.");
1007 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchOrderedRemoveContext instead.");
10081008 return self.fetchOrderedRemoveContext(key, undefined);
10091009 }
10101010 pub fn fetchOrderedRemoveContext(self: *Self, key: K, ctx: Context) ?KV {
......@@ -1012,7 +1012,7 @@ pub fn ArrayHashMapUnmanaged(
10121012 }
10131013 pub fn fetchOrderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV {
10141014 if (@sizeOf(ByIndexContext) != 0)
1015 @compileError("Cannot infer context "++@typeName(Context)++", call fetchOrderedRemoveContextAdapted instead.");
1015 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchOrderedRemoveContextAdapted instead.");
10161016 return self.fetchOrderedRemoveContextAdapted(key, ctx, undefined);
10171017 }
10181018 pub fn fetchOrderedRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) ?KV {
......@@ -1025,7 +1025,7 @@ pub fn ArrayHashMapUnmanaged(
10251025 /// was removed, false otherwise.
10261026 pub fn swapRemove(self: *Self, key: K) bool {
10271027 if (@sizeOf(Context) != 0)
1028 @compileError("Cannot infer context "++@typeName(Context)++", call swapRemoveContext instead.");
1028 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call swapRemoveContext instead.");
10291029 return self.swapRemoveContext(key, undefined);
10301030 }
10311031 pub fn swapRemoveContext(self: *Self, key: K, ctx: Context) bool {
......@@ -1033,7 +1033,7 @@ pub fn ArrayHashMapUnmanaged(
10331033 }
10341034 pub fn swapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool {
10351035 if (@sizeOf(ByIndexContext) != 0)
1036 @compileError("Cannot infer context "++@typeName(Context)++", call swapRemoveContextAdapted instead.");
1036 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call swapRemoveContextAdapted instead.");
10371037 return self.swapRemoveContextAdapted(key, ctx, undefined);
10381038 }
10391039 pub fn swapRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) bool {
......@@ -1046,7 +1046,7 @@ pub fn ArrayHashMapUnmanaged(
10461046 /// current ordering. Returns true if an entry was removed, false otherwise.
10471047 pub fn orderedRemove(self: *Self, key: K) bool {
10481048 if (@sizeOf(Context) != 0)
1049 @compileError("Cannot infer context "++@typeName(Context)++", call orderedRemoveContext instead.");
1049 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call orderedRemoveContext instead.");
10501050 return self.orderedRemoveContext(key, undefined);
10511051 }
10521052 pub fn orderedRemoveContext(self: *Self, key: K, ctx: Context) bool {
......@@ -1054,7 +1054,7 @@ pub fn ArrayHashMapUnmanaged(
10541054 }
10551055 pub fn orderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool {
10561056 if (@sizeOf(ByIndexContext) != 0)
1057 @compileError("Cannot infer context "++@typeName(Context)++", call orderedRemoveContextAdapted instead.");
1057 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call orderedRemoveContextAdapted instead.");
10581058 return self.orderedRemoveContextAdapted(key, ctx, undefined);
10591059 }
10601060 pub fn orderedRemoveContextAdapted(self: *Self, key: anytype, key_ctx: anytype, ctx: Context) bool {
......@@ -1066,7 +1066,7 @@ pub fn ArrayHashMapUnmanaged(
10661066 /// by swapping it with the last element.
10671067 pub fn swapRemoveAt(self: *Self, index: usize) void {
10681068 if (@sizeOf(ByIndexContext) != 0)
1069 @compileError("Cannot infer context "++@typeName(Context)++", call swapRemoveAtContext instead.");
1069 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call swapRemoveAtContext instead.");
10701070 return self.swapRemoveAtContext(index, undefined);
10711071 }
10721072 pub fn swapRemoveAtContext(self: *Self, index: usize, ctx: Context) void {
......@@ -1079,7 +1079,7 @@ pub fn ArrayHashMapUnmanaged(
10791079 /// current ordering.
10801080 pub fn orderedRemoveAt(self: *Self, index: usize) void {
10811081 if (@sizeOf(ByIndexContext) != 0)
1082 @compileError("Cannot infer context "++@typeName(Context)++", call orderedRemoveAtContext instead.");
1082 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call orderedRemoveAtContext instead.");
10831083 return self.orderedRemoveAtContext(index, undefined);
10841084 }
10851085 pub fn orderedRemoveAtContext(self: *Self, index: usize, ctx: Context) void {
......@@ -1090,7 +1090,7 @@ pub fn ArrayHashMapUnmanaged(
10901090 /// The copy uses the same context and allocator as this instance.
10911091 pub fn clone(self: Self, allocator: *Allocator) !Self {
10921092 if (@sizeOf(ByIndexContext) != 0)
1093 @compileError("Cannot infer context "++@typeName(Context)++", call cloneContext instead.");
1093 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead.");
10941094 return self.cloneContext(allocator, undefined);
10951095 }
10961096 pub fn cloneContext(self: Self, allocator: *Allocator, ctx: Context) !Self {
......@@ -1110,7 +1110,7 @@ pub fn ArrayHashMapUnmanaged(
11101110 /// can call `reIndex` to update the indexes to account for these new entries.
11111111 pub fn reIndex(self: *Self, allocator: *Allocator) !void {
11121112 if (@sizeOf(ByIndexContext) != 0)
1113 @compileError("Cannot infer context "++@typeName(Context)++", call reIndexContext instead.");
1113 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call reIndexContext instead.");
11141114 return self.reIndexContext(allocator, undefined);
11151115 }
11161116 pub fn reIndexContext(self: *Self, allocator: *Allocator, ctx: Context) !void {
......@@ -1128,7 +1128,7 @@ pub fn ArrayHashMapUnmanaged(
11281128 /// index entries. Keeps capacity the same.
11291129 pub fn shrinkRetainingCapacity(self: *Self, new_len: usize) void {
11301130 if (@sizeOf(ByIndexContext) != 0)
1131 @compileError("Cannot infer context "++@typeName(Context)++", call shrinkRetainingCapacityContext instead.");
1131 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkRetainingCapacityContext instead.");
11321132 return self.shrinkRetainingCapacityContext(new_len, undefined);
11331133 }
11341134 pub fn shrinkRetainingCapacityContext(self: *Self, new_len: usize, ctx: Context) void {
......@@ -1147,7 +1147,7 @@ pub fn ArrayHashMapUnmanaged(
11471147 /// index entries. Reduces allocated capacity.
11481148 pub fn shrinkAndFree(self: *Self, allocator: *Allocator, new_len: usize) void {
11491149 if (@sizeOf(ByIndexContext) != 0)
1150 @compileError("Cannot infer context "++@typeName(Context)++", call shrinkAndFreeContext instead.");
1150 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkAndFreeContext instead.");
11511151 return self.shrinkAndFreeContext(allocator, new_len, undefined);
11521152 }
11531153 pub fn shrinkAndFreeContext(self: *Self, allocator: *Allocator, new_len: usize, ctx: Context) void {
......@@ -1165,13 +1165,13 @@ pub fn ArrayHashMapUnmanaged(
11651165 /// Removes the last inserted `Entry` in the hash map and returns it.
11661166 pub fn pop(self: *Self) KV {
11671167 if (@sizeOf(ByIndexContext) != 0)
1168 @compileError("Cannot infer context "++@typeName(Context)++", call popContext instead.");
1168 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call popContext instead.");
11691169 return self.popContext(undefined);
11701170 }
11711171 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);
11731173 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);
11751175 self.entries.len -= 1;
11761176 return .{
11771177 .key = item.key,
......@@ -1276,7 +1276,7 @@ pub fn ArrayHashMapUnmanaged(
12761276 }
12771277
12781278 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
12801280 switch (removal_type) {
12811281 .swap => {
12821282 if (last_index != entry_index) {
......@@ -1358,8 +1358,7 @@ pub fn ArrayHashMapUnmanaged(
13581358
13591359 fn getSlotByIndex(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I)) usize {
13601360 const slice = self.entries.slice();
1361 const h = if (store_hash) slice.items(.hash)[entry_index]
1362 else checkedHash(ctx, slice.items(.key)[entry_index]);
1361 const h = if (store_hash) slice.items(.hash)[entry_index] else checkedHash(ctx, slice.items(.key)[entry_index]);
13631362 const start_index = safeTruncate(usize, h);
13641363 const end_index = start_index +% indexes.len;
13651364
......@@ -1569,30 +1568,30 @@ pub fn ArrayHashMapUnmanaged(
15691568 }
15701569 }
15711570
1572 fn checkedHash(ctx: anytype, key: anytype) callconv(.Inline) u32 {
1571 inline fn checkedHash(ctx: anytype, key: anytype) u32 {
15731572 comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(key), K, u32);
15741573 // If you get a compile error on the next line, it means that
15751574 const hash = ctx.hash(key); // your generic hash function doesn't accept your key
15761575 if (@TypeOf(hash) != u32) {
1577 @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)));
1576 @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic hash function that returns the wrong type!\n" ++
1577 @typeName(u32) ++ " was expected, but found " ++ @typeName(@TypeOf(hash)));
15791578 }
15801579 return hash;
15811580 }
1582 fn checkedEql(ctx: anytype, a: anytype, b: K) callconv(.Inline) bool {
1581 inline fn checkedEql(ctx: anytype, a: anytype, b: K) bool {
15831582 comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(a), K, u32);
15841583 // If you get a compile error on the next line, it means that
15851584 const eql = ctx.eql(a, b); // your generic eql function doesn't accept (self, adapt key, K)
15861585 if (@TypeOf(eql) != bool) {
1587 @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)));
1586 @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic eql function that returns the wrong type!\n" ++
1587 @typeName(bool) ++ " was expected, but found " ++ @typeName(@TypeOf(eql)));
15891588 }
15901589 return eql;
15911590 }
15921591
15931592 fn dumpState(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8) void {
15941593 if (@sizeOf(ByIndexContext) != 0)
1595 @compileError("Cannot infer context "++@typeName(Context)++", call dumpStateContext instead.");
1594 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call dumpStateContext instead.");
15961595 self.dumpStateContext(keyFmt, valueFmt, undefined);
15971596 }
15981597 fn dumpStateContext(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8, ctx: Context) void {
......@@ -1600,21 +1599,20 @@ pub fn ArrayHashMapUnmanaged(
16001599 p("{s}:\n", .{@typeName(Self)});
16011600 const slice = self.entries.slice();
16021601 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 });
16041603 var i: usize = 0;
16051604 const mask: u32 = if (self.index_header) |header| header.mask() else ~@as(u32, 0);
16061605 while (i < slice.len) : (i += 1) {
1607 const hash = if (store_hash) slice.items(.hash)[i]
1608 else checkedHash(ctx, slice.items(.key)[i]);
1606 const hash = if (store_hash) slice.items(.hash)[i] else checkedHash(ctx, slice.items(.key)[i]);
16091607 if (store_hash) {
16101608 p(
1611 " [{}]: key="++keyFmt++" value="++valueFmt++" hash=0x{x} slot=[0x{x}]\n",
1612 .{i, slice.items(.key)[i], slice.items(.value)[i], hash, hash & mask},
1609 " [{}]: key=" ++ keyFmt ++ " value=" ++ valueFmt ++ " hash=0x{x} slot=[0x{x}]\n",
1610 .{ i, slice.items(.key)[i], slice.items(.value)[i], hash, hash & mask },
16131611 );
16141612 } else {
16151613 p(
1616 " [{}]: key="++keyFmt++" value="++valueFmt++" slot=[0x{x}]\n",
1617 .{i, slice.items(.key)[i], slice.items(.value)[i], hash & mask},
1614 " [{}]: key=" ++ keyFmt ++ " value=" ++ valueFmt ++ " slot=[0x{x}]\n",
1615 .{ i, slice.items(.key)[i], slice.items(.value)[i], hash & mask },
16181616 );
16191617 }
16201618 }
......@@ -1629,7 +1627,7 @@ pub fn ArrayHashMapUnmanaged(
16291627 }
16301628 fn dumpIndex(self: Self, header: *IndexHeader, comptime I: type) void {
16311629 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() });
16331631 const indexes = header.indexes(I);
16341632 if (indexes.len == 0) return;
16351633 var is_empty = false;
......@@ -1641,7 +1639,7 @@ pub fn ArrayHashMapUnmanaged(
16411639 is_empty = false;
16421640 p(" ...\n", .{});
16431641 }
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 });
16451643 }
16461644 }
16471645 if (is_empty) {
......@@ -1730,7 +1728,7 @@ const max_capacity = (1 << max_bit_index) - 1;
17301728const index_capacities = blk: {
17311729 var caps: [max_bit_index + 1]u32 = undefined;
17321730 for (caps[0..max_bit_index]) |*item, i| {
1733 item.* = (1<<i) * 3 / 5;
1731 item.* = (1 << i) * 3 / 5;
17341732 }
17351733 caps[max_bit_index] = max_capacity;
17361734 break :blk caps;
lib/std/hash_map.zig+52-52
......@@ -116,20 +116,20 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
116116 switch (@typeInfo(Context)) {
117117 .Struct, .Union, .Enum => {},
118118 // 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."),
120120 .Pointer => |ptr| {
121121 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.");
123123 }
124124 Context = ptr.child;
125125 allow_const_ptr = true;
126126 allow_mutable_ptr = !ptr.is_const;
127127 switch (@typeInfo(Context)) {
128128 .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)),
130130 }
131131 },
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)),
133133 }
134134
135135 // 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
140140 const lazy = struct {
141141 const prefix = "\n ";
142142 const deep_prefix = prefix ++ " ";
143 const hash_signature = "fn (self, "++@typeName(PseudoKey)++") "++@typeName(Hash);
144 const eql_signature = "fn (self, "++@typeName(PseudoKey)++", "++@typeName(Key)++") bool";
143 const hash_signature = "fn (self, " ++ @typeName(PseudoKey) ++ ") " ++ @typeName(Hash);
144 const eql_signature = "fn (self, " ++ @typeName(PseudoKey) ++ ", " ++ @typeName(Key) ++ ") bool";
145145 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));
147147 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));
149149 };
150150
151151 // Verify Context.hash(self, PseudoKey) => Hash
......@@ -167,7 +167,7 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
167167 errors = errors ++ lazy.err_invalid_hash_signature;
168168 emitted_signature = true;
169169 }
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);
171171 errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value.";
172172 }
173173 } else if (Self == *Context) {
......@@ -177,10 +177,10 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
177177 emitted_signature = true;
178178 }
179179 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);
181181 errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value.";
182182 } 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);
184184 errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be non-const because it is passed by const pointer.";
185185 }
186186 }
......@@ -189,14 +189,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
189189 errors = errors ++ lazy.err_invalid_hash_signature;
190190 emitted_signature = true;
191191 }
192 errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context);
192 errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context);
193193 if (allow_const_ptr) {
194 errors = errors++" or "++@typeName(*const Context);
194 errors = errors ++ " or " ++ @typeName(*const Context);
195195 if (allow_mutable_ptr) {
196 errors = errors++" or "++@typeName(*Context);
196 errors = errors ++ " or " ++ @typeName(*Context);
197197 }
198198 }
199 errors = errors++", but is "++@typeName(Self);
199 errors = errors ++ ", but is " ++ @typeName(Self);
200200 }
201201 }
202202 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
204204 errors = errors ++ lazy.err_invalid_hash_signature;
205205 emitted_signature = true;
206206 }
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.?);
208208 }
209209 if (func.return_type != null and func.return_type.? != Hash) {
210210 if (!emitted_signature) {
211211 errors = errors ++ lazy.err_invalid_hash_signature;
212212 emitted_signature = true;
213213 }
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.?);
215215 }
216216 // If any of these are generic (null), we cannot verify them.
217217 // 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
243243 errors = errors ++ lazy.err_invalid_eql_signature;
244244 emitted_signature = true;
245245 }
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);
247247 errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value.";
248248 }
249249 } else if (Self == *Context) {
......@@ -253,10 +253,10 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
253253 emitted_signature = true;
254254 }
255255 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);
257257 errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be a pointer because it is passed by value.";
258258 } 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);
260260 errors = errors ++ lazy.deep_prefix ++ "Note: Cannot be non-const because it is passed by const pointer.";
261261 }
262262 }
......@@ -265,14 +265,14 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
265265 errors = errors ++ lazy.err_invalid_eql_signature;
266266 emitted_signature = true;
267267 }
268 errors = errors ++ lazy.deep_prefix ++ "First parameter must be "++@typeName(Context);
268 errors = errors ++ lazy.deep_prefix ++ "First parameter must be " ++ @typeName(Context);
269269 if (allow_const_ptr) {
270 errors = errors++" or "++@typeName(*const Context);
270 errors = errors ++ " or " ++ @typeName(*const Context);
271271 if (allow_mutable_ptr) {
272 errors = errors++" or "++@typeName(*Context);
272 errors = errors ++ " or " ++ @typeName(*Context);
273273 }
274274 }
275 errors = errors++", but is "++@typeName(Self);
275 errors = errors ++ ", but is " ++ @typeName(Self);
276276 }
277277 }
278278 if (func.args[1].arg_type.? != PseudoKey) {
......@@ -280,21 +280,21 @@ pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, compti
280280 errors = errors ++ lazy.err_invalid_eql_signature;
281281 emitted_signature = true;
282282 }
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.?);
284284 }
285285 if (func.args[2].arg_type.? != Key) {
286286 if (!emitted_signature) {
287287 errors = errors ++ lazy.err_invalid_eql_signature;
288288 emitted_signature = true;
289289 }
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.?);
291291 }
292292 if (func.return_type.? != bool) {
293293 if (!emitted_signature) {
294294 errors = errors ++ lazy.err_invalid_eql_signature;
295295 emitted_signature = true;
296296 }
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.?);
298298 }
299299 // If any of these are generic (null), we cannot verify them.
300300 // 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
309309
310310 if (errors.len != 0) {
311311 // 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);
313313 }
314314 }
315315}
......@@ -790,7 +790,7 @@ pub fn HashMapUnmanaged(
790790
791791 pub fn promote(self: Self, allocator: *Allocator) Managed {
792792 if (@sizeOf(Context) != 0)
793 @compileError("Cannot infer context "++@typeName(Context)++", call promoteContext instead.");
793 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead.");
794794 return promoteContext(self, allocator, undefined);
795795 }
796796
......@@ -819,7 +819,7 @@ pub fn HashMapUnmanaged(
819819
820820 pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void {
821821 if (@sizeOf(Context) != 0)
822 @compileError("Cannot infer context "++@typeName(Context)++", call ensureCapacityContext instead.");
822 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureCapacityContext instead.");
823823 return ensureCapacityContext(self, allocator, new_size, undefined);
824824 }
825825 pub fn ensureCapacityContext(self: *Self, allocator: *Allocator, new_size: Size, ctx: Context) !void {
......@@ -902,7 +902,7 @@ pub fn HashMapUnmanaged(
902902 /// Insert an entry in the map. Assumes it is not already present.
903903 pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void {
904904 if (@sizeOf(Context) != 0)
905 @compileError("Cannot infer context "++@typeName(Context)++", call putNoClobberContext instead.");
905 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead.");
906906 return self.putNoClobberContext(allocator, key, value, undefined);
907907 }
908908 pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void {
......@@ -917,7 +917,7 @@ pub fn HashMapUnmanaged(
917917 /// existing data, see `getOrPutAssumeCapacity`.
918918 pub fn putAssumeCapacity(self: *Self, key: K, value: V) void {
919919 if (@sizeOf(Context) != 0)
920 @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityContext instead.");
920 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityContext instead.");
921921 return self.putAssumeCapacityContext(key, value, undefined);
922922 }
923923 pub fn putAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) void {
......@@ -929,7 +929,7 @@ pub fn HashMapUnmanaged(
929929 /// and that no allocation is needed.
930930 pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void {
931931 if (@sizeOf(Context) != 0)
932 @compileError("Cannot infer context "++@typeName(Context)++", call putAssumeCapacityNoClobberContext instead.");
932 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putAssumeCapacityNoClobberContext instead.");
933933 return self.putAssumeCapacityNoClobberContext(key, value, undefined);
934934 }
935935 pub fn putAssumeCapacityNoClobberContext(self: *Self, key: K, value: V, ctx: Context) void {
......@@ -961,7 +961,7 @@ pub fn HashMapUnmanaged(
961961 /// Inserts a new `Entry` into the hash map, returning the previous one, if any.
962962 pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV {
963963 if (@sizeOf(Context) != 0)
964 @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutContext instead.");
964 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead.");
965965 return self.fetchPutContext(allocator, key, value, undefined);
966966 }
967967 pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV {
......@@ -981,7 +981,7 @@ pub fn HashMapUnmanaged(
981981 /// If insertion happens, asserts there is enough capacity without allocating.
982982 pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV {
983983 if (@sizeOf(Context) != 0)
984 @compileError("Cannot infer context "++@typeName(Context)++", call fetchPutAssumeCapacityContext instead.");
984 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutAssumeCapacityContext instead.");
985985 return self.fetchPutAssumeCapacityContext(key, value, undefined);
986986 }
987987 pub fn fetchPutAssumeCapacityContext(self: *Self, key: K, value: V, ctx: Context) ?KV {
......@@ -1001,7 +1001,7 @@ pub fn HashMapUnmanaged(
10011001 /// the hash map, and then returned from this function.
10021002 pub fn fetchRemove(self: *Self, key: K) ?KV {
10031003 if (@sizeOf(Context) != 0)
1004 @compileError("Cannot infer context "++@typeName(Context)++", call fetchRemoveContext instead.");
1004 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchRemoveContext instead.");
10051005 return self.fetchRemoveContext(key, undefined);
10061006 }
10071007 pub fn fetchRemoveContext(self: *Self, key: K, ctx: Context) ?KV {
......@@ -1033,7 +1033,7 @@ pub fn HashMapUnmanaged(
10331033 /// fuse the basic blocks after the branch to the basic blocks
10341034 /// from this function. To encourage that, this function is
10351035 /// 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 {
10371037 comptime verifyContext(@TypeOf(ctx), @TypeOf(key), K, Hash);
10381038
10391039 if (self.size == 0) {
......@@ -1046,7 +1046,7 @@ pub fn HashMapUnmanaged(
10461046 // verifyContext can't verify the return type of generic hash functions,
10471047 // so we need to double-check it here.
10481048 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)));
10501050 }
10511051 const mask = self.capacity() - 1;
10521052 const fingerprint = Metadata.takeFingerprint(hash);
......@@ -1062,7 +1062,7 @@ pub fn HashMapUnmanaged(
10621062 // verifyContext can't verify the return type of generic eql functions,
10631063 // so we need to double-check it here.
10641064 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)));
10661066 }
10671067 if (eql) {
10681068 return idx;
......@@ -1078,7 +1078,7 @@ pub fn HashMapUnmanaged(
10781078
10791079 pub fn getEntry(self: Self, key: K) ?Entry {
10801080 if (@sizeOf(Context) != 0)
1081 @compileError("Cannot infer context "++@typeName(Context)++", call getEntryContext instead.");
1081 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getEntryContext instead.");
10821082 return self.getEntryContext(key, undefined);
10831083 }
10841084 pub fn getEntryContext(self: Self, key: K, ctx: Context) ?Entry {
......@@ -1097,7 +1097,7 @@ pub fn HashMapUnmanaged(
10971097 /// Insert an entry if the associated key is not already present, otherwise update preexisting value.
10981098 pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void {
10991099 if (@sizeOf(Context) != 0)
1100 @compileError("Cannot infer context "++@typeName(Context)++", call putContext instead.");
1100 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead.");
11011101 return self.putContext(allocator, key, value, undefined);
11021102 }
11031103 pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void {
......@@ -1108,7 +1108,7 @@ pub fn HashMapUnmanaged(
11081108 /// Get an optional pointer to the value associated with key, if present.
11091109 pub fn getPtr(self: Self, key: K) ?*V {
11101110 if (@sizeOf(Context) != 0)
1111 @compileError("Cannot infer context "++@typeName(Context)++", call getPtrContext instead.");
1111 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getPtrContext instead.");
11121112 return self.getPtrContext(key, undefined);
11131113 }
11141114 pub fn getPtrContext(self: Self, key: K, ctx: Context) ?*V {
......@@ -1124,7 +1124,7 @@ pub fn HashMapUnmanaged(
11241124 /// Get a copy of the value associated with key, if present.
11251125 pub fn get(self: Self, key: K) ?V {
11261126 if (@sizeOf(Context) != 0)
1127 @compileError("Cannot infer context "++@typeName(Context)++", call getContext instead.");
1127 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getContext instead.");
11281128 return self.getContext(key, undefined);
11291129 }
11301130 pub fn getContext(self: Self, key: K, ctx: Context) ?V {
......@@ -1139,7 +1139,7 @@ pub fn HashMapUnmanaged(
11391139
11401140 pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult {
11411141 if (@sizeOf(Context) != 0)
1142 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContext instead.");
1142 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead.");
11431143 return self.getOrPutContext(allocator, key, undefined);
11441144 }
11451145 pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult {
......@@ -1151,7 +1151,7 @@ pub fn HashMapUnmanaged(
11511151 }
11521152 pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult {
11531153 if (@sizeOf(Context) != 0)
1154 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutContextAdapted instead.");
1154 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead.");
11551155 return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined);
11561156 }
11571157 pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult {
......@@ -1171,7 +1171,7 @@ pub fn HashMapUnmanaged(
11711171
11721172 pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult {
11731173 if (@sizeOf(Context) != 0)
1174 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutAssumeCapacityContext instead.");
1174 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutAssumeCapacityContext instead.");
11751175 return self.getOrPutAssumeCapacityContext(key, undefined);
11761176 }
11771177 pub fn getOrPutAssumeCapacityContext(self: *Self, key: K, ctx: Context) GetOrPutResult {
......@@ -1190,7 +1190,7 @@ pub fn HashMapUnmanaged(
11901190 // verifyContext can't verify the return type of generic hash functions,
11911191 // so we need to double-check it here.
11921192 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)));
11941194 }
11951195 const mask = self.capacity() - 1;
11961196 const fingerprint = Metadata.takeFingerprint(hash);
......@@ -1207,7 +1207,7 @@ pub fn HashMapUnmanaged(
12071207 // verifyContext can't verify the return type of generic eql functions,
12081208 // so we need to double-check it here.
12091209 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)));
12111211 }
12121212 if (eql) {
12131213 return GetOrPutResult{
......@@ -1249,7 +1249,7 @@ pub fn HashMapUnmanaged(
12491249
12501250 pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !Entry {
12511251 if (@sizeOf(Context) != 0)
1252 @compileError("Cannot infer context "++@typeName(Context)++", call getOrPutValueContext instead.");
1252 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead.");
12531253 return self.getOrPutValueContext(allocator, key, value, undefined);
12541254 }
12551255 pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !Entry {
......@@ -1264,7 +1264,7 @@ pub fn HashMapUnmanaged(
12641264 /// Return true if there is a value associated with key in the map.
12651265 pub fn contains(self: *const Self, key: K) bool {
12661266 if (@sizeOf(Context) != 0)
1267 @compileError("Cannot infer context "++@typeName(Context)++", call containsContext instead.");
1267 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call containsContext instead.");
12681268 return self.containsContext(key, undefined);
12691269 }
12701270 pub fn containsContext(self: *const Self, key: K, ctx: Context) bool {
......@@ -1279,7 +1279,7 @@ pub fn HashMapUnmanaged(
12791279 /// function returns false.
12801280 pub fn remove(self: *Self, key: K) bool {
12811281 if (@sizeOf(Context) != 0)
1282 @compileError("Cannot infer context "++@typeName(Context)++", call removeContext instead.");
1282 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call removeContext instead.");
12831283 return self.removeContext(key, undefined);
12841284 }
12851285 pub fn removeContext(self: *Self, key: K, ctx: Context) bool {
......@@ -1317,7 +1317,7 @@ pub fn HashMapUnmanaged(
13171317
13181318 pub fn clone(self: Self, allocator: *Allocator) !Self {
13191319 if (@sizeOf(Context) != 0)
1320 @compileError("Cannot infer context "++@typeName(Context)++", call cloneContext instead.");
1320 @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead.");
13211321 return self.cloneContext(allocator, @as(Context, undefined));
13221322 }
13231323 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 {
10871087
10881088pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
10891089 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));
10911091 assert(x != 0);
10921092 return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(T, x));
10931093}
10941094
10951095pub fn log2_int_ceil(comptime T: type, x: T) Log2IntCeil(T) {
10961096 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));
10981098 assert(x != 0);
10991099 if (x == 1) return 0;
11001100 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 {
4646 return &[_]F{};
4747 }
4848 const byte_ptr = self.ptrs[@enumToInt(field)];
49 const casted_ptr: [*]F = if (@sizeOf([*]F) == 0) undefined
50 else @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
49 const casted_ptr: [*]F = if (@sizeOf([*]F) == 0) undefined else @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
5150 return casted_ptr[0..self.len];
5251 }
5352
......@@ -197,7 +196,7 @@ pub fn MultiArrayList(comptime S: type) type {
197196 try self.ensureCapacity(gpa, self.len + 1);
198197 self.insertAssumeCapacity(index, elem);
199198 }
200
199
201200 /// Inserts an item into an ordered list which has room for it.
202201 /// Shifts all elements after and including the specified index
203202 /// back by one and sets the given index to the specified element.
......@@ -209,9 +208,9 @@ pub fn MultiArrayList(comptime S: type) type {
209208 const slices = self.slice();
210209 inline for (fields) |field_info, field_index| {
211210 const field_slice = slices.items(@intToEnum(Field, field_index));
212 var i: usize = self.len-1;
211 var i: usize = self.len - 1;
213212 while (i > index) : (i -= 1) {
214 field_slice[i] = field_slice[i-1];
213 field_slice[i] = field_slice[i - 1];
215214 }
216215 field_slice[index] = @field(elem, field_info.name);
217216 }
......@@ -224,8 +223,8 @@ pub fn MultiArrayList(comptime S: type) type {
224223 const slices = self.slice();
225224 inline for (fields) |field_info, i| {
226225 const field_slice = slices.items(@intToEnum(Field, i));
227 field_slice[index] = field_slice[self.len-1];
228 field_slice[self.len-1] = undefined;
226 field_slice[index] = field_slice[self.len - 1];
227 field_slice[self.len - 1] = undefined;
229228 }
230229 self.len -= 1;
231230 }
......@@ -237,8 +236,8 @@ pub fn MultiArrayList(comptime S: type) type {
237236 inline for (fields) |field_info, field_index| {
238237 const field_slice = slices.items(@intToEnum(Field, field_index));
239238 var i = index;
240 while (i < self.len-1) : (i += 1) {
241 field_slice[i] = field_slice[i+1];
239 while (i < self.len - 1) : (i += 1) {
240 field_slice[i] = field_slice[i + 1];
242241 }
243242 field_slice[i] = undefined;
244243 }
lib/std/os.zig+1-1
......@@ -6121,7 +6121,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
61216121 }
61226122}
61236123
6124pub const SetrlimitError = error{PermissionDenied, LimitTooBig} || UnexpectedError;
6124pub const SetrlimitError = error{ PermissionDenied, LimitTooBig } || UnexpectedError;
61256125
61266126pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
61276127 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 {
18441844
18451845 for (keys[1..]) |key, i| {
18461846 err_msg.notes[i] = .{
1847 .src_loc = key.nodeOffsetSrcLoc(values[i+1]),
1847 .src_loc = key.nodeOffsetSrcLoc(values[i + 1]),
18481848 .msg = "also here",
18491849 };
18501850 }
src/codegen/spirv.zig+6-9
......@@ -885,10 +885,7 @@ pub const DeclGen = struct {
885885 if (inst.operand.ty.hasCodeGenBits()) {
886886 const operand_id = try self.resolve(inst.operand);
887887 // 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, .{
889 .src_label_id = self.current_block_label_id,
890 .break_value_id = operand_id
891 });
888 try target.incoming_blocks.append(self.spv.gpa, .{ .src_label_id = self.current_block_label_id, .break_value_id = operand_id });
892889 }
893890
894891 try writeInstruction(&self.code, .OpBranch, &[_]Word{target.label_id});
......@@ -936,9 +933,9 @@ pub const DeclGen = struct {
936933 const result_id = self.spv.allocResultId();
937934
938935 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 }) }
940937 else
941 &[_]Word{ result_type_id, result_id, operand_id};
938 &[_]Word{ result_type_id, result_id, operand_id };
942939
943940 try writeInstruction(&self.code, .OpLoad, operands);
944941
......@@ -950,14 +947,14 @@ pub const DeclGen = struct {
950947 const loop_label_id = self.spv.allocResultId();
951948
952949 // 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});
954951
955952 // TODO: Look into OpLoopMerge.
956953
957954 try self.beginSPIRVBlock(loop_label_id);
958955 try self.genBody(inst.body);
959956
960 try writeInstruction(&self.code, .OpBranch, &[_]Word{ loop_label_id });
957 try writeInstruction(&self.code, .OpBranch, &[_]Word{loop_label_id});
961958 }
962959
963960 fn genRet(self: *DeclGen, inst: *Inst.UnOp) !void {
......@@ -976,7 +973,7 @@ pub const DeclGen = struct {
976973 const src_val_id = try self.resolve(inst.rhs);
977974
978975 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 }) }
980977 else
981978 &[_]Word{ dst_ptr_id, src_val_id };
982979
src/link/MachO.zig+1-1
......@@ -2517,7 +2517,7 @@ fn allocatedSizeLinkedit(self: *MachO, start: u64) u64 {
25172517
25182518 return min_pos - start;
25192519}
2520fn checkForCollision(start: u64, end: u64, off: u64, size: u64) callconv(.Inline) ?u64 {
2520inline fn checkForCollision(start: u64, end: u64, off: u64, size: u64) ?u64 {
25212521 const increased_size = padToIdeal(size);
25222522 const test_end = off + increased_size;
25232523 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 {
187187 var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;
188188 for (iovc_buffers) |*iovc, i| {
189189 const bytes = std.mem.sliceAsBytes(buffers[i]);
190 iovc.* = .{
191 .iov_base = bytes.ptr,
192 .iov_len = bytes.len
193 };
190 iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };
194191 }
195192
196193 var file_size: u64 = 0;
test/behavior.zig-1
......@@ -55,7 +55,6 @@ comptime {
5555 _ = @import("behavior/bugs/4560.zig");
5656 _ = @import("behavior/bugs/4769_a.zig");
5757 _ = @import("behavior/bugs/4769_b.zig");
58 _ = @import("behavior/bugs/4769_c.zig");
5958 _ = @import("behavior/bugs/4954.zig");
6059 _ = @import("behavior/bugs/5398.zig");
6160 _ = @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" {
114114 a();
115115}
116116
117fn inlineFn() callconv(.Inline) void {}
117inline fn inlineFn() void {}
118118
119119test "pass by non-copying value" {
120120 try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
test/behavior/type.zig+1-1
......@@ -182,7 +182,7 @@ test "Type.Optional" {
182182}
183183
184184test "Type.ErrorUnion" {
185 try testTypes(&[_]type{
185 try testTypes(&[_]type{
186186 error{}!void,
187187 error{Error}!void,
188188 });
test/standalone/c_compiler/build.zig+1-1
......@@ -30,7 +30,7 @@ pub fn build(b: *Builder) void {
3030 exe_cpp.linkSystemLibrary("c++");
3131
3232 // disable broken LTO links:
33 switch(target.getOsTag()) {
33 switch (target.getOsTag()) {
3434 .windows => {
3535 exe_cpp.want_lto = false;
3636 },
tools/gen_spirv_spec.zig+11-10
......@@ -15,7 +15,7 @@ pub fn main() !void {
1515 const spec = try std.fs.cwd().readFileAlloc(allocator, spec_path, std.math.maxInt(usize));
1616
1717 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 });
1919
2020 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
2121 try render(bw.writer(), registry);
......@@ -36,7 +36,8 @@ fn render(writer: anytype, registry: g.Registry) !void {
3636 \\pub const version = Version{{ .major = {}, .minor = {}, .patch = {} }};
3737 \\pub const magic_number: u32 = {s};
3838 \\
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 },
4041 );
4142 try renderOpcodes(writer, core_reg.instructions);
4243 try renderOperandKinds(writer, core_reg.operand_kinds);
......@@ -45,11 +46,12 @@ fn render(writer: anytype, registry: g.Registry) !void {
4546 try writer.print(
4647 \\pub const version = Version{{ .major = {}, .minor = 0, .patch = {} }};
4748 \\
48 , .{ ext_reg.version, ext_reg.revision },
49 ,
50 .{ ext_reg.version, ext_reg.revision },
4951 );
5052 try renderOpcodes(writer, ext_reg.instructions);
5153 try renderOperandKinds(writer, ext_reg.operand_kinds);
52 }
54 },
5355 }
5456}
5557
......@@ -72,7 +74,7 @@ fn renderOperandKinds(writer: anytype, kinds: []const g.OperandKind) !void {
7274}
7375
7476fn 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});
7678
7779 const enumerants = enumeration.enumerants orelse return error.InvalidRegistry;
7880 for (enumerants) |enumerant| {
......@@ -85,7 +87,7 @@ fn renderValueEnum(writer: anytype, enumeration: g.OperandKind) !void {
8587}
8688
8789fn 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});
8991
9092 var flags_by_bitpos = [_]?[]const u8{null} ** 32;
9193 const enumerants = enumeration.enumerants orelse return error.InvalidRegistry;
......@@ -97,7 +99,7 @@ fn renderBitEnum(writer: anytype, enumeration: g.OperandKind) !void {
9799 }
98100
99101 var bitpos = std.math.log2_int(u32, value);
100 if (flags_by_bitpos[bitpos]) |*existing|{
102 if (flags_by_bitpos[bitpos]) |*existing| {
101103 // Keep the shortest
102104 if (enumerant.enumerant.len < existing.len)
103105 existing.* = enumerant.enumerant;
......@@ -128,7 +130,7 @@ fn parseHexInt(text: []const u8) !u31 {
128130 const prefix = "0x";
129131 if (!std.mem.startsWith(u8, text, prefix))
130132 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);
132134}
133135
134136fn 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 {
142144 \\The relevant specifications can be obtained from the SPIR-V registry:
143145 \\https://github.com/KhronosGroup/SPIRV-Headers/blob/master/include/spirv/unified1/
144146 \\
145 , .{arg0}
146 ) catch std.process.exit(1);
147 , .{arg0}) catch std.process.exit(1);
147148 std.process.exit(code);
148149}
tools/update_spirv_features.zig+25-30
......@@ -1,8 +1,3 @@
1const std = @import("std");
2const fs = std.fs;
3const Allocator = std.mem.Allocator;
4const g = @import("spirv/grammar.zig");
5
61//! This tool generates SPIR-V features from the grammar files in the SPIRV-Headers
72//! (https://github.com/KhronosGroup/SPIRV-Headers/) and SPIRV-Registry (https://github.com/KhronosGroup/SPIRV-Registry/)
83//! 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");
149//! from an intel project (https://github.com/intel/llvm/, https://github.com/intel/llvm/tree/sycl/sycl/doc/extensions/SPIRV),
1510//! and so ONLY extensions in the SPIRV-Registry should be included.
1611
12const std = @import("std");
13const fs = std.fs;
14const Allocator = std.mem.Allocator;
15const g = @import("spirv/grammar.zig");
16
1717const Version = struct {
1818 major: u32,
1919 minor: u32,
......@@ -38,9 +38,9 @@ const Version = struct {
3838
3939 fn lessThan(ctx: void, a: Version, b: Version) bool {
4040 return if (a.major == b.major)
41 a.minor < b.minor
42 else
43 a.major < b.major;
41 a.minor < b.minor
42 else
43 a.major < b.major;
4444 }
4545};
4646
......@@ -103,11 +103,11 @@ pub fn main() !void {
103103 }
104104
105105 for (extensions) |ext| {
106 try w.print(" {},\n", .{ std.zig.fmtId(ext) });
106 try w.print(" {},\n", .{std.zig.fmtId(ext)});
107107 }
108108
109109 for (capabilities) |cap| {
110 try w.print(" {},\n", .{ std.zig.fmtId(cap.enumerant) });
110 try w.print(" {},\n", .{std.zig.fmtId(cap.enumerant)});
111111 }
112112
113113 try w.writeAll(
......@@ -129,8 +129,7 @@ pub fn main() !void {
129129 \\ .llvm_name = null,
130130 \\ .description = "SPIR-V version {0}.{1}",
131131 \\
132 , .{ ver.major, ver.minor }
133 );
132 , .{ ver.major, ver.minor });
134133
135134 if (i == 0) {
136135 try w.writeAll(
......@@ -145,8 +144,7 @@ pub fn main() !void {
145144 \\ }}),
146145 \\ }};
147146 \\
148 , .{ versions[i - 1].major, versions[i - 1].minor }
149 );
147 , .{ versions[i - 1].major, versions[i - 1].minor });
150148 }
151149 }
152150
......@@ -159,11 +157,10 @@ pub fn main() !void {
159157 \\ .dependencies = featureSet(&[_]Feature{{}}),
160158 \\ }};
161159 \\
162 , .{
163 std.zig.fmtId(ext),
164 ext,
165 }
166 );
160 , .{
161 std.zig.fmtId(ext),
162 ext,
163 });
167164 }
168165
169166 // TODO: Capability extension dependencies.
......@@ -174,11 +171,10 @@ pub fn main() !void {
174171 \\ .description = "Enable SPIR-V capability {s}",
175172 \\ .dependencies = featureSet(&[_]Feature{{
176173 \\
177 , .{
178 std.zig.fmtId(cap.enumerant),
179 cap.enumerant,
180 }
181 );
174 , .{
175 std.zig.fmtId(cap.enumerant),
176 cap.enumerant,
177 });
182178
183179 if (cap.version) |ver_str| {
184180 if (!std.mem.eql(u8, ver_str, "None")) {
......@@ -188,7 +184,7 @@ pub fn main() !void {
188184 }
189185
190186 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)});
192188 }
193189
194190 try w.writeAll(
......@@ -198,7 +194,7 @@ pub fn main() !void {
198194 );
199195 }
200196
201 try w.writeAll(
197 try w.writeAll(
202198 \\ const ti = @typeInfo(Feature);
203199 \\ for (result) |*elem, i| {
204200 \\ elem.index = i;
......@@ -217,7 +213,7 @@ pub fn main() !void {
217213/// registered ones.
218214/// TODO: Unfortunately, neither repository contains a machine-readable list of extension dependencies.
219215fn 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" });
221217 var extensions_dir = try fs.cwd().openDir(extensions_path, .{ .iterate = true });
222218 defer extensions_dir.close();
223219
......@@ -262,7 +258,7 @@ fn gather_extensions(allocator: *Allocator, spirv_registry_root: []const u8) ![]
262258 }
263259
264260 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];
266262
267263 std.debug.assert(std.mem.startsWith(u8, ext, "SPV_")); // Sanity check, all extensions should have a name like SPV_VENDOR_extension.
268264
......@@ -315,7 +311,6 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
315311 \\SPIRV-Headers can be cloned from https://github.com/KhronosGroup/SPIRV-Headers,
316312 \\SPIRV-Registry can be cloned from https://github.com/KhronosGroup/SPIRV-Registry.
317313 \\
318 , .{arg0}
319 ) catch std.process.exit(1);
314 , .{arg0}) catch std.process.exit(1);
320315 std.process.exit(code);
321316}