authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-01-24 22:51:39+11:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-02-20 09:09:06+11:00
logab18adf5c38e2640411039600f8de7de817ac200
treedcd6f558d02b83193ae427fcbd97879becc93f99
parentd40b135e958b0f2195bd9bcf2a44cb9952ba51fc

std.compress.zstandard: remove debug logging


1 files changed, 0 insertions(+), 122 deletions(-)

lib/std/compress/zstandard/decompress.zig-122
......@@ -14,8 +14,6 @@ fn readVarInt(comptime T: type, bytes: []const u8) T {
1414 return std.mem.readVarInt(T, bytes, .Little);
1515}
1616
17const log = std.log.scoped(.Decompress);
18
1917fn isSkippableMagic(magic: u32) bool {
2018 return frame.Skippable.magic_number_min <= magic and magic <= frame.Skippable.magic_number_max;
2119}
......@@ -136,11 +134,6 @@ pub const DecodeState = struct {
136134 self.literal.state = try bit_reader.readBitsNoEof(u9, self.literal.accuracy_log);
137135 self.offset.state = try bit_reader.readBitsNoEof(u8, self.offset.accuracy_log);
138136 self.match.state = try bit_reader.readBitsNoEof(u9, self.match.accuracy_log);
139 log.debug("initial decoder state: literal = {d}, offset = {d} match = {d}", .{
140 self.literal.state,
141 self.offset.state,
142 self.match.state,
143 });
144137 }
145138
146139 fn updateRepeatOffset(self: *DecodeState, offset: u32) void {
......@@ -208,10 +201,6 @@ pub const DecodeState = struct {
208201 );
209202 @field(self, field_name).table = .{ .fse = @field(self, field_name ++ "_fse_buffer")[0..table_size] };
210203 @field(self, field_name).accuracy_log = std.math.log2_int_ceil(usize, table_size);
211 log.debug("decoded fse " ++ field_name ++ " table '{}'", .{
212 std.fmt.fmtSliceHexUpper(src[0..counting_reader.bytes_read]),
213 });
214 dumpFseTable(field_name, @field(self, field_name).table.fse);
215204 return counting_reader.bytes_read;
216205 },
217206 .repeat => return if (self.fse_tables_undefined) error.RepeatModeFirst else 0,
......@@ -227,7 +216,6 @@ pub const DecodeState = struct {
227216 fn nextSequence(self: *DecodeState, bit_reader: anytype) !Sequence {
228217 const raw_code = self.getCode(.offset);
229218 const offset_code = std.math.cast(u5, raw_code) orelse {
230 log.err("got offset code of {d}", .{raw_code});
231219 return error.OffsetCodeTooLarge;
232220 };
233221 const offset_value = (@as(u32, 1) << offset_code) + try bit_reader.readBitsNoEof(u32, offset_code);
......@@ -256,7 +244,6 @@ pub const DecodeState = struct {
256244 break :offset self.useRepeatOffset(offset_value - 1);
257245 };
258246
259 log.debug("sequence = ({d}, {d}, {d})", .{ literal_length, offset, match_length });
260247 return .{
261248 .literal_length = literal_length,
262249 .match_length = match_length,
......@@ -310,9 +297,6 @@ pub const DecodeState = struct {
310297 if (sequence_length > sequence_size_limit) return error.MalformedSequence;
311298
312299 try self.executeSequenceSlice(dest, write_pos, literals, sequence);
313 log.debug("sequence decompressed into '{x}'", .{
314 std.fmt.fmtSliceHexUpper(dest[write_pos .. write_pos + sequence.literal_length + sequence.match_length]),
315 });
316300 if (!last_sequence) {
317301 try self.updateState(.literal, bit_reader);
318302 try self.updateState(.match, bit_reader);
......@@ -334,13 +318,6 @@ pub const DecodeState = struct {
334318 if (sequence_length > sequence_size_limit) return error.MalformedSequence;
335319
336320 try self.executeSequenceRingBuffer(dest, literals, sequence);
337 if (std.options.log_level == .debug) {
338 const written_slice = dest.sliceLast(sequence_length);
339 log.debug("sequence decompressed into '{x}{x}'", .{
340 std.fmt.fmtSliceHexUpper(written_slice.first),
341 std.fmt.fmtSliceHexUpper(written_slice.second),
342 });
343 }
344321 if (!last_sequence) {
345322 try self.updateState(.literal, bit_reader);
346323 try self.updateState(.match, bit_reader);
......@@ -355,7 +332,6 @@ pub const DecodeState = struct {
355332 }
356333
357334 fn initLiteralStream(self: *DecodeState, bytes: []const u8) !void {
358 log.debug("initing literal stream: {}", .{std.fmt.fmtSliceHexUpper(bytes)});
359335 try self.literal_stream_reader.init(bytes);
360336 }
361337
......@@ -372,7 +348,6 @@ pub const DecodeState = struct {
372348 while (i < len) : (i += 1) {
373349 dest[i] = literals.streams.one[0];
374350 }
375 log.debug("rle: {}", .{std.fmt.fmtSliceHexUpper(dest[0..len])});
376351 self.literal_written_count += len;
377352 },
378353 .compressed, .treeless => {
......@@ -538,7 +513,6 @@ pub fn decodeZStandardFrame(dest: []u8, src: []const u8, verify_checksum: bool)
538513 const hash = hash_state.final();
539514 const hash_low_bytes = hash & 0xFFFFFFFF;
540515 if (checksum != hash_low_bytes) {
541 std.log.err("expected checksum {x}, got {x} (full hash {x})", .{ checksum, hash_low_bytes, hash });
542516 return error.ChecksumFailure;
543517 }
544518 }
......@@ -556,13 +530,11 @@ pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8,
556530 if (frame_header.descriptor.dictionary_id_flag != 0) return error.DictionaryIdFlagUnsupported;
557531
558532 const window_size = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown;
559 log.debug("window size = {d}", .{window_size});
560533
561534 const should_compute_checksum = frame_header.descriptor.content_checksum_flag and verify_checksum;
562535 var hash = if (should_compute_checksum) std.hash.XxHash64.init(0) else null;
563536
564537 const block_size_maximum = @min(1 << 17, window_size);
565 log.debug("block size maximum = {d}", .{block_size_maximum});
566538
567539 var window_data = try allocator.alloc(u8, window_size);
568540 defer allocator.free(window_data);
......@@ -680,7 +652,6 @@ pub fn decodeFrameBlocks(dest: []u8, src: []const u8, consumed_count: *usize, ha
680652
681653fn decodeRawBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count: *usize) !usize {
682654 if (src.len < block_size) return error.MalformedBlockSize;
683 log.debug("writing raw block - size {d}", .{block_size});
684655 const data = src[0..block_size];
685656 std.mem.copy(u8, dest, data);
686657 consumed_count.* += block_size;
......@@ -689,7 +660,6 @@ fn decodeRawBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count:
689660
690661fn decodeRawBlockRingBuffer(dest: *RingBuffer, src: []const u8, block_size: u21, consumed_count: *usize) !usize {
691662 if (src.len < block_size) return error.MalformedBlockSize;
692 log.debug("writing raw block - size {d}", .{block_size});
693663 const data = src[0..block_size];
694664 dest.writeSliceAssumeCapacity(data);
695665 consumed_count.* += block_size;
......@@ -698,7 +668,6 @@ fn decodeRawBlockRingBuffer(dest: *RingBuffer, src: []const u8, block_size: u21,
698668
699669fn decodeRleBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count: *usize) !usize {
700670 if (src.len < 1) return error.MalformedRleBlock;
701 log.debug("writing rle block - '{x}'x{d}", .{ src[0], block_size });
702671 var write_pos: usize = 0;
703672 while (write_pos < block_size) : (write_pos += 1) {
704673 dest[write_pos] = src[0];
......@@ -709,7 +678,6 @@ fn decodeRleBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count:
709678
710679fn decodeRleBlockRingBuffer(dest: *RingBuffer, src: []const u8, block_size: u21, consumed_count: *usize) !usize {
711680 if (src.len < 1) return error.MalformedRleBlock;
712 log.debug("writing rle block - '{x}'x{d}", .{ src[0], block_size });
713681 var write_pos: usize = 0;
714682 while (write_pos < block_size) : (write_pos += 1) {
715683 dest.writeAssumeCapacity(src[0]);
......@@ -751,7 +719,6 @@ pub fn decodeBlock(
751719 var sequence_size_limit = block_size_max;
752720 var i: usize = 0;
753721 while (i < sequences_header.sequence_count) : (i += 1) {
754 log.debug("decoding sequence {d}", .{i});
755722 const write_pos = written_count + bytes_written;
756723 const decompressed_size = try decode_state.decodeSequenceSlice(
757724 dest,
......@@ -769,13 +736,8 @@ pub fn decodeBlock(
769736 }
770737
771738 if (decode_state.literal_written_count < literals.header.regenerated_size) {
772 log.debug("decoding remaining literals", .{});
773739 const len = literals.header.regenerated_size - decode_state.literal_written_count;
774740 try decode_state.decodeLiteralsSlice(dest[written_count + bytes_written ..], literals, len);
775 log.debug("remaining decoded literals at {d}: {}", .{
776 written_count,
777 std.fmt.fmtSliceHexUpper(dest[written_count .. written_count + len]),
778 });
779741 bytes_written += len;
780742 }
781743
......@@ -820,7 +782,6 @@ pub fn decodeBlockRingBuffer(
820782 var sequence_size_limit = block_size_max;
821783 var i: usize = 0;
822784 while (i < sequences_header.sequence_count) : (i += 1) {
823 log.debug("decoding sequence {d}", .{i});
824785 const decompressed_size = try decode_state.decodeSequenceRingBuffer(
825786 dest,
826787 literals,
......@@ -836,15 +797,8 @@ pub fn decodeBlockRingBuffer(
836797 }
837798
838799 if (decode_state.literal_written_count < literals.header.regenerated_size) {
839 log.debug("decoding remaining literals", .{});
840800 const len = literals.header.regenerated_size - decode_state.literal_written_count;
841801 try decode_state.decodeLiteralsRingBuffer(dest, literals, len);
842 const written_slice = dest.sliceLast(len);
843 log.debug("remaining decoded literals at {d}: {}{}", .{
844 bytes_written,
845 std.fmt.fmtSliceHexUpper(written_slice.first),
846 std.fmt.fmtSliceHexUpper(written_slice.second),
847 });
848802 bytes_written += len;
849803 }
850804
......@@ -922,22 +876,6 @@ pub fn decodeZStandardHeader(src: []const u8, consumed_count: ?*usize) !frame.ZS
922876 .dictionary_id = dictionary_id,
923877 .content_size = content_size,
924878 };
925 log.debug(
926 "decoded ZStandard frame header {x}: " ++
927 "desc = (d={d},c={},r={},u={},s={},cs={d}), win_desc = {?x}, dict_id = {?x}, content_size = {?d}",
928 .{
929 std.fmt.fmtSliceHexUpper(src[0..bytes_read_count]),
930 header.descriptor.dictionary_id_flag,
931 header.descriptor.content_checksum_flag,
932 header.descriptor.reserved,
933 header.descriptor.unused,
934 header.descriptor.single_segment_flag,
935 header.descriptor.content_size_flag,
936 header.window_descriptor,
937 header.dictionary_id,
938 header.content_size,
939 },
940 );
941879 return header;
942880}
943881
......@@ -945,12 +883,6 @@ pub fn decodeBlockHeader(src: *const [3]u8) frame.ZStandard.Block.Header {
945883 const last_block = src[0] & 1 == 1;
946884 const block_type = @intToEnum(frame.ZStandard.Block.Type, (src[0] & 0b110) >> 1);
947885 const block_size = ((src[0] & 0b11111000) >> 3) + (@as(u21, src[1]) << 5) + (@as(u21, src[2]) << 13);
948 log.debug("decoded block header {}: last = {}, type = {s}, size = {d}", .{
949 std.fmt.fmtSliceHexUpper(src),
950 last_block,
951 @tagName(block_type),
952 block_size,
953 });
954886 return .{
955887 .last_block = last_block,
956888 .block_type = block_type,
......@@ -990,8 +922,6 @@ pub fn decodeLiteralsSection(src: []const u8, consumed_count: *usize) !LiteralsS
990922 null;
991923 const huffman_tree_size = bytes_read - huffman_tree_start;
992924 const total_streams_size = @as(usize, header.compressed_size.?) - huffman_tree_size;
993 log.debug("huffman tree size = {}, total streams size = {}", .{ huffman_tree_size, total_streams_size });
994 if (huffman_tree) |tree| dumpHuffmanTree(tree);
995925
996926 if (src.len < bytes_read + total_streams_size) return error.MalformedLiteralsSection;
997927 const stream_data = src[bytes_read .. bytes_read + total_streams_size];
......@@ -1007,7 +937,6 @@ pub fn decodeLiteralsSection(src: []const u8, consumed_count: *usize) !LiteralsS
1007937
1008938 if (stream_data.len < 6) return error.MalformedLiteralsSection;
1009939
1010 log.debug("jump table: {}", .{std.fmt.fmtSliceHexUpper(stream_data[0..6])});
1011940 const stream_1_length = @as(usize, readInt(u16, stream_data[0..2]));
1012941 const stream_2_length = @as(usize, readInt(u16, stream_data[2..4]));
1013942 const stream_3_length = @as(usize, readInt(u16, stream_data[4..6]));
......@@ -1059,8 +988,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
1059988 var huff_bits: ReverseBitReader = undefined;
1060989 try huff_bits.init(huff_data);
1061990
1062 dumpFseTable("huffman", entries[0..table_size]);
1063
1064991 var i: usize = 0;
1065992 var even_state: u32 = try huff_bits.readBitsNoEof(u32, accuracy_log);
1066993 var odd_state: u32 = try huff_bits.readBitsNoEof(u32, accuracy_log);
......@@ -1073,7 +1000,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
10731000 i += 1;
10741001 if (read_bits < even_data.bits) {
10751002 weights[i] = std.math.cast(u4, entries[odd_state].symbol) orelse return error.MalformedHuffmanTree;
1076 log.debug("overflow condition: setting weights[{d}] = {d}", .{ i, weights[i] });
10771003 i += 1;
10781004 break;
10791005 }
......@@ -1087,7 +1013,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
10871013 if (read_bits < odd_data.bits) {
10881014 if (i == 256) return error.MalformedHuffmanTree;
10891015 weights[i] = std.math.cast(u4, entries[even_state].symbol) orelse return error.MalformedHuffmanTree;
1090 log.debug("overflow condition: setting weights[{d}] = {d}", .{ i, weights[i] });
10911016 i += 1;
10921017 break;
10931018 }
......@@ -1099,19 +1024,12 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
10991024 } else {
11001025 const encoded_symbol_count = header - 127;
11011026 symbol_count = encoded_symbol_count + 1;
1102 log.debug("huffman tree symbol count = {d}", .{symbol_count});
11031027 const weights_byte_count = (encoded_symbol_count + 1) / 2;
1104 log.debug("decoding direct huffman tree: {}|{}", .{
1105 std.fmt.fmtSliceHexUpper(src[0..1]),
1106 std.fmt.fmtSliceHexUpper(src[1 .. weights_byte_count + 1]),
1107 });
11081028 if (src.len < weights_byte_count) return error.MalformedHuffmanTree;
11091029 var i: usize = 0;
11101030 while (i < weights_byte_count) : (i += 1) {
11111031 weights[2 * i] = @intCast(u4, src[i + 1] >> 4);
11121032 weights[2 * i + 1] = @intCast(u4, src[i + 1] & 0xF);
1113 log.debug("weights[{d}] = {d}", .{ 2 * i, weights[2 * i] });
1114 log.debug("weights[{d}] = {d}", .{ 2 * i + 1, weights[2 * i + 1] });
11151033 }
11161034 bytes_read += weights_byte_count;
11171035 }
......@@ -1121,13 +1039,11 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
11211039 weight_power_sum += @as(u16, 1) << (value - 1);
11221040 }
11231041 }
1124 log.debug("weight power sum = {d}", .{weight_power_sum});
11251042
11261043 // advance to next power of two (even if weight_power_sum is a power of 2)
11271044 max_number_of_bits = std.math.log2_int(u16, weight_power_sum) + 1;
11281045 const next_power_of_two = @as(u16, 1) << max_number_of_bits;
11291046 weights[symbol_count - 1] = std.math.log2_int(u16, next_power_of_two - weight_power_sum) + 1;
1130 log.debug("weights[{d}] = {d}", .{ symbol_count - 1, weights[symbol_count - 1] });
11311047
11321048 var weight_sorted_prefixed_symbols: [256]LiteralsSection.HuffmanTree.PrefixedSymbol = undefined;
11331049 for (weight_sorted_prefixed_symbols[0..symbol_count]) |_, i| {
......@@ -1177,7 +1093,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
11771093 .symbol_count_minus_one = @intCast(u8, prefixed_symbol_count - 1),
11781094 .nodes = weight_sorted_prefixed_symbols,
11791095 };
1180 log.debug("decoded huffman tree {}:", .{std.fmt.fmtSliceHexUpper(src[0..bytes_read])});
11811096 return tree;
11821097}
11831098
......@@ -1194,7 +1109,6 @@ fn lessThanByWeight(
11941109
11951110pub fn decodeLiteralsHeader(src: []const u8, consumed_count: *usize) !LiteralsSection.Header {
11961111 if (src.len == 0) return error.MalformedLiteralsSection;
1197 const start = consumed_count.*;
11981112 const byte0 = src[0];
11991113 const block_type = @intToEnum(LiteralsSection.BlockType, byte0 & 0b11);
12001114 const size_format = @intCast(u2, (byte0 & 0b1100) >> 2);
......@@ -1250,16 +1164,6 @@ pub fn decodeLiteralsHeader(src: []const u8, consumed_count: *usize) !LiteralsSe
12501164 }
12511165 },
12521166 }
1253 log.debug(
1254 "decoded literals section header '{}': type = {s}, size_format = {}, regen_size = {d}, compressed size = {?d}",
1255 .{
1256 std.fmt.fmtSliceHexUpper(src[0 .. consumed_count.* - start]),
1257 @tagName(block_type),
1258 size_format,
1259 regenerated_size,
1260 compressed_size,
1261 },
1262 );
12631167 return LiteralsSection.Header{
12641168 .block_type = block_type,
12651169 .size_format = size_format,
......@@ -1276,7 +1180,6 @@ pub fn decodeSequencesHeader(src: []const u8, consumed_count: *usize) !Sequences
12761180 const byte0 = src[0];
12771181 if (byte0 == 0) {
12781182 bytes_read += 1;
1279 log.debug("decoded sequences header '{}': sequence count = 0", .{std.fmt.fmtSliceHexUpper(src[0..bytes_read])});
12801183 consumed_count.* += bytes_read;
12811184 return SequencesSection.Header{
12821185 .sequence_count = 0,
......@@ -1305,13 +1208,6 @@ pub fn decodeSequencesHeader(src: []const u8, consumed_count: *usize) !Sequences
13051208 const matches_mode = @intToEnum(SequencesSection.Header.Mode, (compression_modes & 0b00001100) >> 2);
13061209 const offsets_mode = @intToEnum(SequencesSection.Header.Mode, (compression_modes & 0b00110000) >> 4);
13071210 const literal_mode = @intToEnum(SequencesSection.Header.Mode, (compression_modes & 0b11000000) >> 6);
1308 log.debug("decoded sequences header '{}': (sc={d},o={s},m={s},l={s})", .{
1309 std.fmt.fmtSliceHexUpper(src[0..bytes_read]),
1310 sequence_count,
1311 @tagName(offsets_mode),
1312 @tagName(matches_mode),
1313 @tagName(literal_mode),
1314 });
13151211 if (compression_modes & 0b11 != 0) return error.ReservedBitSet;
13161212
13171213 return SequencesSection.Header{
......@@ -1383,10 +1279,7 @@ fn decodeFseTable(
13831279 max_accuracy_log: u4,
13841280 entries: []Table.Fse,
13851281) !usize {
1386 log.debug("decoding fse table {d} {d}", .{ max_accuracy_log, expected_symbol_count });
1387
13881282 const accuracy_log_biased = try bit_reader.readBitsNoEof(u4, 4);
1389 log.debug("accuracy_log_biased = {d}", .{accuracy_log_biased});
13901283 if (accuracy_log_biased > max_accuracy_log -| 5) return error.MalformedAccuracyLog;
13911284 const accuracy_log = accuracy_log_biased + 5;
13921285
......@@ -1394,7 +1287,6 @@ fn decodeFseTable(
13941287 var value_count: usize = 0;
13951288
13961289 const total_probability = @as(u16, 1) << accuracy_log;
1397 log.debug("total probability = {d}", .{total_probability});
13981290 var accumulated_probability: u16 = 0;
13991291
14001292 while (accumulated_probability < total_probability) {
......@@ -1549,17 +1441,3 @@ test buildFseTable {
15491441 try buildFseTable(&offset_codes_default_values, entries[0..32]);
15501442 try std.testing.expectEqualSlices(Table.Fse, types.compressed_block.predefined_offset_fse_table.fse, entries[0..32]);
15511443}
1552
1553fn dumpFseTable(prefix: []const u8, table: []const Table.Fse) void {
1554 log.debug("{s} fse table:", .{prefix});
1555 for (table) |entry, i| {
1556 log.debug("state = {d} symbol = {d} bl = {d}, bits = {d}", .{ i, entry.symbol, entry.baseline, entry.bits });
1557 }
1558}
1559
1560fn dumpHuffmanTree(tree: LiteralsSection.HuffmanTree) void {
1561 log.debug("Huffman tree: max bit count = {}, symbol count = {}", .{ tree.max_bit_count, tree.symbol_count_minus_one + 1 });
1562 for (tree.nodes[0 .. tree.symbol_count_minus_one + 1]) |node| {
1563 log.debug("symbol = {[symbol]d}, prefix = {[prefix]d}, weight = {[weight]d}", node);
1564 }
1565}