From 84604888e9cb8b8ef43fd49165e3db9bc15937cb Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 28 Aug 2025 04:24:04 -0700 Subject: [PATCH] Private fields (#22189) ZLS was tested manually and works with private fields (after restarting) Zig diff: https://github.com/oven-sh/zig/compare/d1a4e0b0ddc75f37c6a090b97eef0cbb6335556e..ebe0cdac3170b0462a39caff4d1d7252b608e98d ZLS diff: https://github.com/pfgithub/zls/compare/15730e8e5ddbd50e37c0ba88b72d1bb047911071..3733f39c8dadfd37bb2a5487894e3ed467a5d895 Increases `zig build check` time by maybe 10ms? --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .github/workflows/format.yml | 18 ++++++++-------- cmake/tools/SetupZig.cmake | 2 +- src/ptr/owned.zig | 42 ++++++++++++++++++------------------ 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index d414d1fa8c..29219364ea 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -43,7 +43,7 @@ jobs: echo "::group::Prettier" (bun run prettier 2>&1 | sed 's/^/[prettier] /' || echo "[prettier] Failed with exit code $?") & PRETTIER_PID=$! - + # Start clang-format installation and formatting in background with prefixed output echo "::group::Clang-format" ( @@ -56,13 +56,13 @@ jobs: LLVM_VERSION_MAJOR=${{ env.LLVM_VERSION_MAJOR }} ./scripts/run-clang-format.sh format 2>&1 | sed 's/^/[clang-format] /' ) & CLANG_PID=$! - + # Setup Zig in temp directory and run zig fmt in background with prefixed output echo "::group::Zig fmt" ( ZIG_TEMP=$(mktemp -d) echo "[zig] Downloading Zig (musl build)..." - wget -q -O "$ZIG_TEMP/zig.zip" https://github.com/oven-sh/zig/releases/download/autobuild-d1a4e0b0ddc75f37c6a090b97eef0cbb6335556e/bootstrap-x86_64-linux-musl.zip + wget -q -O "$ZIG_TEMP/zig.zip" https://github.com/oven-sh/zig/releases/download/autobuild-ebe0cdac3170b0462a39caff4d1d7252b608e98d/bootstrap-x86_64-linux-musl.zip unzip -q -d "$ZIG_TEMP" "$ZIG_TEMP/zig.zip" export PATH="$ZIG_TEMP/bootstrap-x86_64-linux-musl:$PATH" echo "[zig] Running zig fmt..." @@ -72,36 +72,36 @@ jobs: rm -rf "$ZIG_TEMP" ) & ZIG_PID=$! - + # Wait for all formatting tasks to complete echo "" echo "Running formatters in parallel..." FAILED=0 - + if ! wait $PRETTIER_PID; then echo "::error::Prettier failed" FAILED=1 fi echo "::endgroup::" - + if ! wait $CLANG_PID; then echo "::error::Clang-format failed" FAILED=1 fi echo "::endgroup::" - + if ! wait $ZIG_PID; then echo "::error::Zig fmt failed" FAILED=1 fi echo "::endgroup::" - + # Exit with error if any formatter failed if [ $FAILED -eq 1 ]; then echo "::error::One or more formatters failed" exit 1 fi - + echo "✅ All formatters completed successfully" - name: Ban Words run: | diff --git a/cmake/tools/SetupZig.cmake b/cmake/tools/SetupZig.cmake index 607e43c2e8..f1cec22678 100644 --- a/cmake/tools/SetupZig.cmake +++ b/cmake/tools/SetupZig.cmake @@ -20,7 +20,7 @@ else() unsupported(CMAKE_SYSTEM_NAME) endif() -set(ZIG_COMMIT "edc6229b1fafb1701a25fb4e17114cc756991546") +set(ZIG_COMMIT "ebe0cdac3170b0462a39caff4d1d7252b608e98d") optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET}) if(CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/src/ptr/owned.zig b/src/ptr/owned.zig index 7033834609..702bd9c927 100644 --- a/src/ptr/owned.zig +++ b/src/ptr/owned.zig @@ -57,7 +57,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { return struct { const Self = @This(); - unsafe_raw_pointer: Pointer, + #unsafe_raw_pointer: Pointer, unsafe_allocator: if (options.allocator == null) Allocator else void, /// An unmanaged version of this owned pointer. This type doesn't store the allocator and @@ -134,7 +134,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { /// * `data` must not be freed for the life of the owned pointer. pub fn fromRawOwned(data: NonOptionalPointer, allocator: Allocator) Self { return .{ - .unsafe_raw_pointer = data, + .#unsafe_raw_pointer = data, .unsafe_allocator = allocator, }; } @@ -147,7 +147,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { /// * `data` must not be freed for the life of the owned pointer. pub fn fromRawOwned(data: NonOptionalPointer) Self { return .{ - .unsafe_raw_pointer = data, + .#unsafe_raw_pointer = data, .unsafe_allocator = {}, }; } @@ -160,9 +160,9 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { /// be disabled in `options`. pub fn deinit(self: Self) void { const data = if (comptime info.isOptional()) - self.unsafe_raw_pointer orelse return + self.#unsafe_raw_pointer orelse return else - self.unsafe_raw_pointer; + self.#unsafe_raw_pointer; if (comptime options.deinit and std.meta.hasFn(Child, "deinit")) { switch (comptime info.kind()) { .single => data.deinit(), @@ -179,7 +179,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { /// Returns the inner pointer or slice. pub fn get(self: SelfOrPtr) Pointer { - return self.unsafe_raw_pointer; + return self.#unsafe_raw_pointer; } /// Returns a const version of the inner pointer or slice. @@ -187,7 +187,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { /// This method is not provided if the pointer is already const; use `get` in that case. pub const getConst = if (!info.isConst()) struct { pub fn getConst(self: Self) AddConst(Pointer) { - return self.unsafe_raw_pointer; + return self.#unsafe_raw_pointer; } }.getConst; @@ -197,15 +197,15 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { /// This method invalidates `self`. pub const intoRawOwned = (if (options.allocator != null) struct { pub fn intoRawOwned(self: Self) Pointer { - return self.unsafe_raw_pointer; + return self.#unsafe_raw_pointer; } } else if (info.isOptional()) struct { pub fn intoRawOwned(self: Self) ?struct { NonOptionalPointer, Allocator } { - return .{ self.unsafe_raw_pointer orelse return null, self.unsafe_allocator }; + return .{ self.#unsafe_raw_pointer orelse return null, self.unsafe_allocator }; } } else struct { pub fn intoRawOwned(self: Self) struct { Pointer, Allocator } { - return .{ self.unsafe_raw_pointer, self.unsafe_allocator }; + return .{ self.#unsafe_raw_pointer, self.unsafe_allocator }; } }).intoRawOwned; @@ -216,7 +216,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { pub const initNull = if (info.isOptional()) struct { pub fn initNull() Self { return .{ - .unsafe_raw_pointer = null, + .#unsafe_raw_pointer = null, .unsafe_allocator = undefined, }; } @@ -234,7 +234,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { pub fn take(self: *Self) ?OwnedNonOptional { defer self.* = .initNull(); return .{ - .unsafe_raw_pointer = self.unsafe_raw_pointer orelse return null, + .#unsafe_raw_pointer = self.#unsafe_raw_pointer orelse return null, .unsafe_allocator = self.unsafe_allocator, }; } @@ -248,7 +248,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { pub const toOptional = if (!info.isOptional()) struct { pub fn toOptional(self: Self) OwnedOptional { return .{ - .unsafe_raw_pointer = self.unsafe_raw_pointer, + .#unsafe_raw_pointer = self.#unsafe_raw_pointer, .unsafe_allocator = self.unsafe_allocator, }; } @@ -263,7 +263,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { pub const toUnmanaged = if (options.allocator == null) struct { pub fn toUnmanaged(self: Self) Self.Unmanaged { return .{ - .unsafe_raw_pointer = self.unsafe_raw_pointer, + .#unsafe_raw_pointer = self.#unsafe_raw_pointer, }; } }.toUnmanaged; @@ -279,7 +279,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { pub const toDynamic = if (options.allocator) |allocator| struct { pub fn toDynamic(self: Self) DynamicOwned { return .{ - .unsafe_raw_pointer = self.unsafe_raw_pointer, + .#unsafe_raw_pointer = self.#unsafe_raw_pointer, .unsafe_allocator = allocator, }; } @@ -287,7 +287,7 @@ pub fn WithOptions(comptime Pointer: type, comptime options: Options) type { fn rawInit(data: NonOptionalPointer, allocator: Allocator) Self { return .{ - .unsafe_raw_pointer = data, + .#unsafe_raw_pointer = data, .unsafe_allocator = if (comptime options.allocator == null) allocator, }; } @@ -328,7 +328,7 @@ fn Unmanaged(comptime Pointer: type, comptime options: Options) type { return struct { const Self = @This(); - unsafe_raw_pointer: Pointer, + #unsafe_raw_pointer: Pointer, const Managed = WithOptions(Pointer, options); @@ -337,9 +337,9 @@ fn Unmanaged(comptime Pointer: type, comptime options: Options) type { /// `allocator` must be the allocator that was used to allocate the pointer. pub fn toManaged(self: Self, allocator: Allocator) Managed { const data = if (comptime info.isOptional()) - self.unsafe_raw_pointer orelse return .initNull() + self.#unsafe_raw_pointer orelse return .initNull() else - self.unsafe_raw_pointer; + self.#unsafe_raw_pointer; return .fromRawOwned(data, allocator); } @@ -354,7 +354,7 @@ fn Unmanaged(comptime Pointer: type, comptime options: Options) type { /// Returns the inner pointer or slice. pub fn get(self: SelfOrPtr) Pointer { - return self.unsafe_raw_pointer; + return self.#unsafe_raw_pointer; } /// Returns a const version of the inner pointer or slice. @@ -362,7 +362,7 @@ fn Unmanaged(comptime Pointer: type, comptime options: Options) type { /// This method is not provided if the pointer is already const; use `get` in that case. pub const getConst = if (!info.isConst()) struct { pub fn getConst(self: Self) AddConst(Pointer) { - return self.unsafe_raw_pointer; + return self.#unsafe_raw_pointer; } }.getConst; };