Skip to content

Commit

Permalink
Merge branch 'master' into feat/cmake_config_diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDmitry authored Oct 14, 2024
2 parents 0638721 + 3bf89f5 commit 6a26941
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 1,013 deletions.
44 changes: 22 additions & 22 deletions lib/compiler/aro/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
try pp.ensureTotalTokenCapacity(pp.tokens.len + estimated_token_count);

var if_level: u8 = 0;
var if_kind = std.PackedIntArray(u2, 256).init([1]u2{0} ** 256);
var if_kind: [64]u8 = .{0} ** 64;
const until_else = 0;
const until_endif = 1;
const until_endif_seen_else = 2;
Expand Down Expand Up @@ -430,12 +430,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if_level = sum;

if (try pp.expr(&tokenizer)) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #if", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #if", .{});
Expand All @@ -451,12 +451,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) != null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #ifdef", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #ifdef", .{});
Expand All @@ -472,23 +472,23 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) == null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
}
},
.keyword_elif => {
if (if_level == 0) {
try pp.err(directive, .elif_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => if (try pp.expr(&tokenizer)) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elif", .{});
}
Expand All @@ -510,28 +510,28 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
}
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) != null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifdef", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
Expand All @@ -551,28 +551,28 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
}
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) == null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifndef", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
Expand All @@ -596,9 +596,9 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
if_kind.set(if_level, until_endif_seen_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif_seen_else);
if (pp.verbose) {
pp.verboseLog(directive, "#else branch here", .{});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/compress/zstandard/decode/block.zig
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub const DecodeState = struct {
};
fn readLiteralsBits(
self: *DecodeState,
bit_count_to_read: usize,
bit_count_to_read: u16,
) LiteralBitsError!u16 {
return self.literal_stream_reader.readBitsNoEof(u16, bit_count_to_read) catch bits: {
if (self.literal_streams == .four and self.literal_stream_index < 3) {
Expand Down
4 changes: 2 additions & 2 deletions lib/std/compress/zstandard/decode/huffman.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: *

fn assignWeights(
huff_bits: *readers.ReverseBitReader,
accuracy_log: usize,
accuracy_log: u16,
entries: *[1 << 6]Table.Fse,
weights: *[256]u4,
) !usize {
Expand All @@ -73,7 +73,7 @@ fn assignWeights(

while (i < 254) {
const even_data = entries[even_state];
var read_bits: usize = 0;
var read_bits: u16 = 0;
const even_bits = huff_bits.readBits(u32, even_data.bits, &read_bits) catch unreachable;
weights[i] = std.math.cast(u4, even_data.symbol) orelse return error.MalformedHuffmanTree;
i += 1;
Expand Down
10 changes: 5 additions & 5 deletions lib/std/compress/zstandard/readers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ pub const ReverseBitReader = struct {
if (i == 8) return error.BitStreamHasNoStartBit;
}

pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: usize) error{EndOfStream}!U {
pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: u16) error{EndOfStream}!U {
return self.bit_reader.readBitsNoEof(U, num_bits);
}

pub fn readBits(self: *@This(), comptime U: type, num_bits: usize, out_bits: *usize) error{}!U {
pub fn readBits(self: *@This(), comptime U: type, num_bits: u16, out_bits: *u16) error{}!U {
return try self.bit_reader.readBits(U, num_bits, out_bits);
}

Expand All @@ -55,19 +55,19 @@ pub const ReverseBitReader = struct {
}

pub fn isEmpty(self: ReverseBitReader) bool {
return self.byte_reader.remaining_bytes == 0 and self.bit_reader.bit_count == 0;
return self.byte_reader.remaining_bytes == 0 and self.bit_reader.count == 0;
}
};

pub fn BitReader(comptime Reader: type) type {
return struct {
underlying: std.io.BitReader(.little, Reader),

pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: usize) !U {
pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: u16) !U {
return self.underlying.readBitsNoEof(U, num_bits);
}

pub fn readBits(self: *@This(), comptime U: type, num_bits: usize, out_bits: *usize) !U {
pub fn readBits(self: *@This(), comptime U: type, num_bits: u16, out_bits: *u16) !U {
return self.underlying.readBits(U, num_bits, out_bits);
}

Expand Down
10 changes: 4 additions & 6 deletions lib/std/heap/WasmPageAllocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const PageStatus = enum(u1) {
const FreeBlock = struct {
data: []u128,

const Io = std.packed_int_array.PackedIntIo(u1, .little);

fn totalPages(self: FreeBlock) usize {
return self.data.len * 128;
}
Expand All @@ -39,15 +37,15 @@ const FreeBlock = struct {
}

fn getBit(self: FreeBlock, idx: usize) PageStatus {
const bit_offset = 0;
return @as(PageStatus, @enumFromInt(Io.get(mem.sliceAsBytes(self.data), idx, bit_offset)));
const bit = mem.readPackedInt(u1, mem.sliceAsBytes(self.data), idx, .little);
return @as(PageStatus, @enumFromInt(bit));
}

fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {
const bit_offset = 0;
var i: usize = 0;
const bytes = mem.sliceAsBytes(self.data);
while (i < len) : (i += 1) {
Io.set(mem.sliceAsBytes(self.data), start_idx + i, bit_offset, @intFromEnum(val));
mem.writePackedInt(u1, bytes, start_idx + i, @intFromEnum(val), .little);
}
}

Expand Down
Loading

0 comments on commit 6a26941

Please sign in to comment.