From 2e9488501e8b60cba224ad1d6fd82029f30f9565 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 21 Oct 2026 08:09:52 +0200 Subject: [PATCH] chore: zig 0.17.0 --- .github/workflows/ci.yaml | 16 +-- CHANGELOG.md | 2 +- README.md | 2 +- build.zig | 73 +++++------- build.zig.zon | 14 +-- build/compiler_rt/atomics.zig | 4 +- build/compiler_rt/cmpdf2.zig | 2 +- build/compiler_rt/cmphf2.zig | 2 +- build/compiler_rt/cmpsf2.zig | 2 +- build/compiler_rt/cmptf2.zig | 16 +-- build/compiler_rt/cmpxf2.zig | 2 +- build/compiler_rt/common.zig | 4 +- build/compiler_rt/float_from_int.zig | 4 +- build/compiler_rt/gedf2.zig | 2 +- build/compiler_rt/gehf2.zig | 2 +- build/compiler_rt/gesf2.zig | 2 +- build/compiler_rt/getf2.zig | 2 +- build/compiler_rt/gexf2.zig | 2 +- build/compiler_rt/int_from_float.zig | 5 +- build/compiler_rt/memcpy.zig | 2 +- build/compiler_rt/memmove.zig | 2 +- build/compiler_rt/ssp.zig | 2 +- src/Codegen.zig | 10 +- src/Debugger.zig | 4 +- src/FFI.zig | 5 +- src/GC.zig | 4 +- src/Jit.zig | 160 +++++++++++++-------------- src/Package.zig | 2 +- src/Parser.zig | 22 ++-- src/Perf.zig | 14 +-- src/Reporter.zig | 4 +- src/TypeChecker.zig | 4 +- src/behavior.zig | 6 +- src/builtin/pattern.zig | 4 +- src/buzz_api.zig | 4 +- src/disassembler.zig | 2 +- src/lib/buzz_api.zig | 4 +- src/lib/buzz_fs.zig | 5 +- src/lib/buzz_http.zig | 5 +- src/lib/buzz_os.zig | 7 +- src/lib/errors.buzz | 1 + src/lib/http.buzz | 2 + src/lsp.zig | 23 ++-- src/main.zig | 4 +- src/obj.zig | 2 +- src/renderer.zig | 8 +- src/repl.zig | 2 +- src/vm.zig | 14 +-- src/zigtypes.zig | 16 +-- 49 files changed, 251 insertions(+), 251 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5fa644b7..95d49f0f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,13 +12,13 @@ jobs: fail-fast: false matrix: zig-version: - - "0.16.0" + - "0.17.0" operating-system: [ ubuntu-latest, macos-latest, windows-latest ] optimize: - - "Debug" - - "ReleaseSafe" - - "ReleaseFast" - - "ReleaseSmall" + - "debug" + - "safe" + - "fast" + - "small" options: - "" - "-Djit_always_on -Djit_asynchronous=false" @@ -50,9 +50,9 @@ jobs: - name: Setup nightly Zig uses: mlugg/setup-zig@v2.2.1 with: - version: ${{ matrix.zig-version }} + version: "0.17.0" - name: Build for wasm - run: zig build -Dtarget=wasm32-freestanding -Doptimize=ReleaseSmall + run: zig build -Dtarget=wasm32-freestanding -Doptimize=small lint: runs-on: macos-latest @@ -61,5 +61,5 @@ jobs: - name: Setup Zig uses: mlugg/setup-zig@v2.2.1 with: - version: ${{ matrix.zig-version }} + version: "0.17.0" - run: zig fmt --check src/*.zig src/**/*.zig diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4f0613..d433d883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ This release brings a lot of useful tools to write buzz code: LSP, formatter and DAP support. > [!NOTE] -> This release builds with zig 0.16.0. We will only use tagged version of zig from now on. +> This release builds with zig 0.17.0. We will only use tagged version of zig from now on. ## Added diff --git a/README.md b/README.md index 8a8be4d9..9995a09e 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ A small/lightweight statically typed scripting language written in Zig ## How to build and install ### Requirements -- Zig 0.16.0 +- Zig 0.17.0 - Since this is built with Zig, you should be able to build buzz on a wide variety of architectures even though this has only been tested on x86/M1. - Supports linux, macOS or windows - libc diff --git a/build.zig b/build.zig index ec3b9ada..37d20943 100644 --- a/build.zig +++ b/build.zig @@ -76,7 +76,7 @@ pub fn build(b: *Build) !void { }, ); if (is_wasm) { - exe.global_base = 6560; + exe.global_base = std.wasm.page_size; exe.entry = .disabled; exe.rdynamic = true; exe.import_memory = true; @@ -95,9 +95,7 @@ pub fn build(b: *Build) !void { const run_exe = b.addRunArtifact(exe); run_exe.step.dependOn(install_step); - if (b.args) |args| { - run_exe.addArgs(args); - } + run_exe.addPassthruArgs(); b.step("run", "run buzz").dependOn(&run_exe.step); // buzz_behavior @@ -123,9 +121,7 @@ pub fn build(b: *Build) !void { b.installArtifact(behavior_exe.?); run_behavior = b.addRunArtifact(behavior_exe.?); run_behavior.?.step.dependOn(install_step); - if (b.args) |args| { - run_behavior.?.addArgs(args); - } + run_behavior.?.addPassthruArgs(); b.step("test-behavior", "Test behavior").dependOn(&run_behavior.?.step); } @@ -180,9 +176,7 @@ pub fn build(b: *Build) !void { b.installArtifact(lsp_exe.?); const run_lsp_exe = b.addRunArtifact(lsp_exe.?); run_lsp_exe.step.dependOn(install_step); - if (b.args) |args| { - run_lsp_exe.addArgs(args); - } + run_lsp_exe.addPassthruArgs(); b.step("lsp", "run buzz lsp").dependOn(&run_lsp_exe.step); } const lsp_tests = if (!is_wasm and target.result.os.tag != .windows) @@ -245,9 +239,7 @@ pub fn build(b: *Build) !void { }, ); const run_update_std_docs = b.addRunArtifact(update_std_docs_exe); - if (b.args) |args| { - run_update_std_docs.addArgs(args); - } + run_update_std_docs.addPassthruArgs(); b.step("update-std-docs", "Regenerate standard library reference docs").dependOn(&run_update_std_docs.step); // Building buzz api library @@ -321,7 +313,7 @@ pub fn build(b: *Build) !void { const test_step = b.step("test", "Run all the tests"); const run_tests = b.addRunArtifact(tests); run_tests.cwd = b.path("."); - run_tests.setEnvironmentVariable("BUZZ_PATH", b.graph.environ_map.get("BUZZ_PATH") orelse std.fs.path.dirname(b.exe_dir).?); + run_tests.setEnvironmentVariable("BUZZ_PATH", b.graph.environ_map.get("BUZZ_PATH") orelse "zig-out"); run_tests.step.dependOn(install_step); // wait for libraries to be installed test_step.dependOn(&run_tests.step); if (lsp_tests) |lsp_test_exe| { @@ -384,14 +376,7 @@ pub fn build(b: *Build) !void { /// Creates an internal step that installs all Buzz std headers. fn createBuzzHeaderInstallStep(b: *Build) *Build.Step { - const step = b.allocator.create(Build.Step) catch @panic("OOM"); - step.* = Build.Step.init( - .{ - .id = .custom, - .name = "install buzz headers", - .owner = b, - }, - ); + const step = b.step("install-buzz-headers", "Install buzz headers"); for (static_headers.all) |header| { const install_header = b.addInstallLibFile( @@ -412,7 +397,7 @@ fn createBuzzHeaderInstallStep(b: *Build) *Build.Step { return step; } -pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { +pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optimize) !*Build.Step.Compile { const copyFiles = b.addWriteFiles(); _ = copyFiles.addCopyFile( b.path("vendors/pcre2/src/config.h.generic"), @@ -494,7 +479,7 @@ pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin return lib; } -pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { +pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optimize) !*Build.Step.Compile { const lib = b.addLibrary( .{ .name = "mimalloc", @@ -533,7 +518,7 @@ pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.buil "./vendors/mimalloc/src/stats.c", "./vendors/mimalloc/src/prim/prim.c", }, - .flags = if (lib.root_module.optimize != .Debug) + .flags = if (lib.root_module.optimize != .debug) &.{ "-DNDEBUG=1", "-DMI_SECURE=0", @@ -557,7 +542,7 @@ pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.buil return lib; } -pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { +pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optimize) !*Build.Step.Compile { const lib = b.addLibrary( .{ .name = "linenoise", @@ -594,7 +579,7 @@ pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.bui fn buildTestLibraries( b: *Build, target: Build.ResolvedTarget, - optimize: std.builtin.OptimizeMode, + optimize: std.lang.Optimize, build_option_module: *Build.Module, buzz_lib: *Build.Step.Compile, ) *Build.Step { @@ -695,8 +680,8 @@ pub fn buildWasmReplDemo(b: *Build, exe: *Build.Step.Compile) void { const esbuild = b.addSystemCommand( &.{ - b.pathFromRoot("node_modules/.bin/esbuild"), - b.pathFromRoot("src/wasm.ts"), + b.pathJoin(&.{"node_modules/.bin/esbuild"}), + b.pathJoin(&.{"src/wasm.ts"}), "--bundle", "--format=esm", // This replaces all occurrences of '__WASM_ARTIFACT_FILENAME' in TypeScript source files @@ -709,7 +694,7 @@ pub fn buildWasmReplDemo(b: *Build, exe: *Build.Step.Compile) void { b.fmt( "--outdir={s}", .{ - b.getInstallPath(.bin, ""), + b.pathJoin(&.{"zig-out/bin"}), }, ), }, @@ -725,7 +710,7 @@ pub fn buildWasmReplDemo(b: *Build, exe: *Build.Step.Compile) void { b.getInstallStep().dependOn(©Repl.step); } -pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile { +pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optimize) !*Build.Step.Compile { const lib = b.addLibrary( .{ .name = "mir", @@ -773,7 +758,7 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O pub fn buildFuzz( b: *Build, target: Build.ResolvedTarget, - optimize: std.builtin.OptimizeMode, + optimize: std.lang.Optimize, ext_deps: []const *std.Build.Step.Compile, ) *Build.Step.Compile { // Define a step for generating fuzzing tooling: @@ -807,24 +792,18 @@ pub fn buildFuzz( }) orelse return null; const install_tools = b.addInstallDirectory(.{ - .source_dir = std.Build.LazyPath{ - .cwd_relative = afl.builder.install_path, - }, + .source_dir = afl.path("zig-out"), .install_dir = .prefix, .install_subdir = "AFLplusplus", }); install_tools.step.dependOn(afl.builder.getInstallStep()); - run_afl_cc = b.addSystemCommand(&.{ - b.pathJoin(&.{ afl.builder.exe_dir, "afl-cc" }), - "-O3", - "-o", - }); + run_afl_cc = b.addRunFile(afl.path("zig-out/bin/afl-cc")); + run_afl_cc.addArgs(&.{ "-O3", "-o" }); for (ext_deps) |dep| { run_afl_cc.addArg("-L"); - run_afl_cc.addFileArg(dep.getEmittedBin()); + run_afl_cc.addFileArg2(dep.getEmittedBin(), .{}); } - run_afl_cc.step.dependOn(&afl.builder.top_level_steps.get("llvm_exes").?.step); run_afl_cc.step.dependOn(&install_tools.step); } else { run_afl_cc = b.addSystemCommand( @@ -836,7 +815,7 @@ pub fn buildFuzz( _ = afl_obj.getEmittedBin(); // hack around build system bug for (ext_deps) |dep| { - run_afl_cc.addFileArg(dep.getEmittedBin()); + run_afl_cc.addFileArg2(dep.getEmittedBin(), .{}); } // On darwin we need compiler-rt @@ -857,7 +836,7 @@ pub fn buildFuzz( }, ); - run_afl_cc.addFileArg(compiler_rt.getEmittedBin()); + run_afl_cc.addFileArg2(compiler_rt.getEmittedBin(), .{}); } run_afl_cc.addArgs( @@ -868,9 +847,9 @@ pub fn buildFuzz( ); } - const fuzz_exe = run_afl_cc.addOutputFileArg(afl_obj.name); - run_afl_cc.addFileArg(b.path("src/afl.c")); - run_afl_cc.addFileArg(afl_obj.getEmittedLlvmBc()); + const fuzz_exe = run_afl_cc.addOutputFileArg2(afl_obj.name, .{}); + run_afl_cc.addFileArg2(b.path("src/afl.c"), .{}); + run_afl_cc.addFileArg2(afl_obj.getEmittedLlvmBc(), .{}); // Install it fuzz.dependOn(&b.addInstallBinFile(fuzz_exe, "fuzz_afl").step); diff --git a/build.zig.zon b/build.zig.zon index 6af56467..d45ef482 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,19 +2,19 @@ .name = .buzz, .fingerprint = 0x87514371589e863a, .version = "0.6.0", - .minimum_zig_version = "0.16.0", + .minimum_zig_version = "0.17.0", .dependencies = .{ .clap = .{ - .url = "git+https://github.com/Hejsil/zig-clap.git#fc1e5cc3f6d9d3001112385ee6256d694e959d2f", - .hash = "clap-0.11.0-oBajB7foAQC3Iyn4IVCkUdYaOVVng5IZkSncySTjNig1", + .url = "git+https://github.com/Hejsil/zig-clap.git#05faf3905e8548f5cc269a8836e154065e70128d", + .hash = "clap-0.12.0-oBajB4XpAQCF1WRKnD5KOKPsnwwT_NNdAJ7Ww3irYJac", }, .lsp_kit = .{ - .url = "git+https://github.com/zigtools/lsp-kit.git#b886a2b0d5cee85ecbcc3089b863f7517cc9ff7f", - .hash = "lsp_kit-0.1.0-bi_PL3IyDACfp1xdTnkiOHEok2YpPCCCJHuuOcNzjl1D", + .url = "git+https://github.com/zigtools/lsp-kit.git#3e1058db66079911fdde82f833fdce6856e0a706", + .hash = "lsp_kit-0.1.0-bi_PL9o2DADHS1PDra3MGz1MXnsboN_ewNvrc419z7Fb", }, .dap_kit = .{ - .url = "git+https://github.com/buzz-language/dap-kit.git#478f2adf40b70f2f8e669352d5c419e6192f1a51", - .hash = "dap_kit-0.0.0-OvEgyANhAgAMRFGjEEJoqlAKKzuxV2VNRqsb6cO0nFUV", + .url = "git+https://github.com/buzz-language/dap-kit.git#9e05d263a1412b7392eebabd9a570da0b7a7460e", + .hash = "dap_kit-0.0.0-OvEgyAVjAgCgtawOjYZvMmUKmM0BCFSvY5DQGxiYAyvm", }, }, .paths = .{""}, diff --git a/build/compiler_rt/atomics.zig b/build/compiler_rt/atomics.zig index 09fd1c2c..15a9e238 100644 --- a/build/compiler_rt/atomics.zig +++ b/build/compiler_rt/atomics.zig @@ -94,7 +94,7 @@ const SpinlockTable = struct { } }; - list: [max_spinlocks]Spinlock = [_]Spinlock{.{}} ** max_spinlocks, + list: [max_spinlocks]Spinlock = @splat(.{}), // The spinlock table behaves as a really simple hash table, mapping // addresses to spinlocks. The mapping is not unique but that's only a @@ -341,7 +341,7 @@ fn __atomic_compare_exchange_16(ptr: *u128, expected: *u128, desired: u128, succ return atomic_compare_exchange_N(u128, ptr, expected, desired, success, failure); } -inline fn fetch_op_N(comptime T: type, comptime op: std.builtin.AtomicRmwOp, ptr: *T, val: T, model: i32) T { +inline fn fetch_op_N(comptime T: type, comptime op: std.lang.AtomicRmwOp, ptr: *T, val: T, model: i32) T { _ = model; const Updater = struct { fn update(new: T, old: T) T { diff --git a/build/compiler_rt/cmpdf2.zig b/build/compiler_rt/cmpdf2.zig index a0338c7a..4c149de5 100644 --- a/build/compiler_rt/cmpdf2.zig +++ b/build/compiler_rt/cmpdf2.zig @@ -26,7 +26,7 @@ comptime { /// Note that this matches the definition of `__ledf2`, `__eqdf2`, `__nedf2`, `__cmpdf2`, /// and `__ltdf2`. fn __cmpdf2(a: f64, b: f64) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f64, comparef.LE, a, b)); + return @backingInt(comparef.cmpf2(f64, comparef.LE, a, b)); } /// "These functions return a value less than or equal to zero if neither argument is NaN, diff --git a/build/compiler_rt/cmphf2.zig b/build/compiler_rt/cmphf2.zig index 9fcc1e24..173895d6 100644 --- a/build/compiler_rt/cmphf2.zig +++ b/build/compiler_rt/cmphf2.zig @@ -20,7 +20,7 @@ comptime { /// Note that this matches the definition of `__lehf2`, `__eqhf2`, `__nehf2`, `__cmphf2`, /// and `__lthf2`. fn __cmphf2(a: f16, b: f16) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f16, comparef.LE, a, b)); + return @backingInt(comparef.cmpf2(f16, comparef.LE, a, b)); } /// "These functions return a value less than or equal to zero if neither argument is NaN, diff --git a/build/compiler_rt/cmpsf2.zig b/build/compiler_rt/cmpsf2.zig index 371319b0..40f5df34 100644 --- a/build/compiler_rt/cmpsf2.zig +++ b/build/compiler_rt/cmpsf2.zig @@ -26,7 +26,7 @@ comptime { /// Note that this matches the definition of `__lesf2`, `__eqsf2`, `__nesf2`, `__cmpsf2`, /// and `__ltsf2`. fn __cmpsf2(a: f32, b: f32) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f32, comparef.LE, a, b)); + return @backingInt(comparef.cmpf2(f32, comparef.LE, a, b)); } /// "These functions return a value less than or equal to zero if neither argument is NaN, diff --git a/build/compiler_rt/cmptf2.zig b/build/compiler_rt/cmptf2.zig index d5ee7970..ffbbaf99 100644 --- a/build/compiler_rt/cmptf2.zig +++ b/build/compiler_rt/cmptf2.zig @@ -34,7 +34,7 @@ comptime { /// Note that this matches the definition of `__letf2`, `__eqtf2`, `__netf2`, `__cmptf2`, /// and `__lttf2`. fn __cmptf2(a: f128, b: f128) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f128, comparef.LE, a, b)); + return @backingInt(comparef.cmpf2(f128, comparef.LE, a, b)); } /// "These functions return a value less than or equal to zero if neither argument is NaN, @@ -71,34 +71,34 @@ const SparcFCMP = enum(i32) { }; fn _Qp_cmp(a: *const f128, b: *const f128) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f128, SparcFCMP, a.*, b.*)); + return @backingInt(comparef.cmpf2(f128, SparcFCMP, a.*, b.*)); } fn _Qp_feq(a: *const f128, b: *const f128) callconv(.c) bool { - return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) == .Equal; + return @as(SparcFCMP, @fromBackingInt(@intCast(_Qp_cmp(a, b)))) == .Equal; } fn _Qp_fne(a: *const f128, b: *const f128) callconv(.c) bool { - return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) != .Equal; + return @as(SparcFCMP, @fromBackingInt(@intCast(_Qp_cmp(a, b)))) != .Equal; } fn _Qp_flt(a: *const f128, b: *const f128) callconv(.c) bool { - return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) == .Less; + return @as(SparcFCMP, @fromBackingInt(@intCast(_Qp_cmp(a, b)))) == .Less; } fn _Qp_fgt(a: *const f128, b: *const f128) callconv(.c) bool { - return @as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b))) == .Greater; + return @as(SparcFCMP, @fromBackingInt(@intCast(_Qp_cmp(a, b)))) == .Greater; } fn _Qp_fge(a: *const f128, b: *const f128) callconv(.c) bool { - return switch (@as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b)))) { + return switch (@as(SparcFCMP, @fromBackingInt(@intCast(_Qp_cmp(a, b))))) { .Equal, .Greater => true, .Less, .Unordered => false, }; } fn _Qp_fle(a: *const f128, b: *const f128) callconv(.c) bool { - return switch (@as(SparcFCMP, @enumFromInt(_Qp_cmp(a, b)))) { + return switch (@as(SparcFCMP, @fromBackingInt(@intCast(_Qp_cmp(a, b))))) { .Equal, .Less => true, .Greater, .Unordered => false, }; diff --git a/build/compiler_rt/cmpxf2.zig b/build/compiler_rt/cmpxf2.zig index dc90f87c..d5e2662c 100644 --- a/build/compiler_rt/cmpxf2.zig +++ b/build/compiler_rt/cmpxf2.zig @@ -20,7 +20,7 @@ comptime { /// Note that this matches the definition of `__lexf2`, `__eqxf2`, `__nexf2`, `__cmpxf2`, /// and `__ltxf2`. fn __cmpxf2(a: f80, b: f80) callconv(.c) i32 { - return @intFromEnum(comparef.cmp_f80(comparef.LE, a, b)); + return @backingInt(comparef.cmp_f80(comparef.LE, a, b)); } /// "These functions return a value less than or equal to zero if neither argument is NaN, diff --git a/build/compiler_rt/common.zig b/build/compiler_rt/common.zig index 87747db2..b5b71d2e 100644 --- a/build/compiler_rt/common.zig +++ b/build/compiler_rt/common.zig @@ -6,7 +6,7 @@ const ofmt_c = builtin.object_format == .c; /// For now, we prefer weak linkage because some of the routines we implement here may also be /// provided by system/dynamic libc. Eventually we should be more disciplined about this on a /// per-symbol, per-target basis: https://github.com/ziglang/zig/issues/11883 -pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) +pub const linkage: std.lang.GlobalLinkage = if (builtin.is_test) .internal else if (ofmt_c) .strong @@ -16,7 +16,7 @@ else /// Determines the symbol's visibility to other objects. /// For WebAssembly this allows the symbol to be resolved to other modules, but will not /// export it to the host runtime. -pub const visibility: std.builtin.SymbolVisibility = if (linkage == .internal or builtin.link_mode == .dynamic) +pub const visibility: std.lang.SymbolVisibility = if (linkage == .internal or builtin.link_mode == .dynamic) .default else .hidden; diff --git a/build/compiler_rt/float_from_int.zig b/build/compiler_rt/float_from_int.zig index 98659d27..4f3fb46f 100644 --- a/build/compiler_rt/float_from_int.zig +++ b/build/compiler_rt/float_from_int.zig @@ -62,7 +62,7 @@ inline fn limb(limbs: []const u32, index: usize) u32 { }; } -pub inline fn floatFromBigInt(comptime T: type, comptime signedness: std.builtin.Signedness, x: []const u32) T { +pub inline fn floatFromBigInt(comptime T: type, comptime signedness: std.lang.Signedness, x: []const u32) T { switch (x.len) { 0 => return 0, inline 1...4 => |limbs_len| return @floatFromInt(@as( @@ -98,7 +98,7 @@ pub inline fn floatFromBigInt(comptime T: type, comptime signedness: std.builtin if (limb(x, limb_index) != 0) break true; } else limb(x, exponent_limb) & ((@as(u32, 1) << @truncate(exponent)) - 1) != 0; return math.ldexp(@as(T, @floatFromInt( - std.mem.readPackedIntNative(I, std.mem.sliceAsBytes(x), exponent) | @intFromBool(sticky), + std.mem.readPackedInt(I, std.mem.sliceAsBytes(x), exponent, endian) | @intFromBool(sticky), )), @intCast(exponent)); } diff --git a/build/compiler_rt/gedf2.zig b/build/compiler_rt/gedf2.zig index 33b4fa99..ec45baf5 100644 --- a/build/compiler_rt/gedf2.zig +++ b/build/compiler_rt/gedf2.zig @@ -18,7 +18,7 @@ comptime { /// "These functions return a value greater than or equal to zero if neither /// argument is NaN, and a is greater than or equal to b." pub fn __gedf2(a: f64, b: f64) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f64, comparef.GE, a, b)); + return @backingInt(comparef.cmpf2(f64, comparef.GE, a, b)); } /// "These functions return a value greater than zero if neither argument is NaN, diff --git a/build/compiler_rt/gehf2.zig b/build/compiler_rt/gehf2.zig index 12eccf98..e9ad1cd2 100644 --- a/build/compiler_rt/gehf2.zig +++ b/build/compiler_rt/gehf2.zig @@ -13,7 +13,7 @@ comptime { /// "These functions return a value greater than or equal to zero if neither /// argument is NaN, and a is greater than or equal to b." pub fn __gehf2(a: f16, b: f16) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f16, comparef.GE, a, b)); + return @backingInt(comparef.cmpf2(f16, comparef.GE, a, b)); } /// "These functions return a value greater than zero if neither argument is NaN, diff --git a/build/compiler_rt/gesf2.zig b/build/compiler_rt/gesf2.zig index 5f9aefef..f79fb84f 100644 --- a/build/compiler_rt/gesf2.zig +++ b/build/compiler_rt/gesf2.zig @@ -18,7 +18,7 @@ comptime { /// "These functions return a value greater than or equal to zero if neither /// argument is NaN, and a is greater than or equal to b." pub fn __gesf2(a: f32, b: f32) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f32, comparef.GE, a, b)); + return @backingInt(comparef.cmpf2(f32, comparef.GE, a, b)); } /// "These functions return a value greater than zero if neither argument is NaN, diff --git a/build/compiler_rt/getf2.zig b/build/compiler_rt/getf2.zig index 3a178437..70b369ad 100644 --- a/build/compiler_rt/getf2.zig +++ b/build/compiler_rt/getf2.zig @@ -20,7 +20,7 @@ comptime { /// "These functions return a value greater than or equal to zero if neither /// argument is NaN, and a is greater than or equal to b." fn __getf2(a: f128, b: f128) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f128, comparef.GE, a, b)); + return @backingInt(comparef.cmpf2(f128, comparef.GE, a, b)); } /// "These functions return a value greater than zero if neither argument is NaN, diff --git a/build/compiler_rt/gexf2.zig b/build/compiler_rt/gexf2.zig index 7ea0d6ee..44e99676 100644 --- a/build/compiler_rt/gexf2.zig +++ b/build/compiler_rt/gexf2.zig @@ -9,7 +9,7 @@ comptime { } fn __gexf2(a: f80, b: f80) callconv(.c) i32 { - return @intFromEnum(comparef.cmp_f80(comparef.GE, a, b)); + return @backingInt(comparef.cmp_f80(comparef.GE, a, b)); } fn __gtxf2(a: f80, b: f80) callconv(.c) i32 { diff --git a/build/compiler_rt/int_from_float.zig b/build/compiler_rt/int_from_float.zig index 0c2c73bb..e87e3049 100644 --- a/build/compiler_rt/int_from_float.zig +++ b/build/compiler_rt/int_from_float.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const endian = @import("builtin").cpu.arch.endian(); const Int = std.meta.Int; const math = std.math; const Log2Int = math.Log2Int; @@ -51,7 +52,7 @@ pub inline fn intFromFloat(comptime I: type, a: anytype) I { return result; } -pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, result: []u32, a: anytype) void { +pub inline fn bigIntFromFloat(comptime signedness: std.lang.Signedness, result: []u32, a: anytype) void { switch (result.len) { 0 => return, inline 1...4 => |limbs_len| { @@ -99,7 +100,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul }, .unsigned => @memset(result, 0), } - std.mem.writePackedIntNative(I, std.mem.sliceAsBytes(result), exponent, int); + std.mem.writePackedInt(I, std.mem.sliceAsBytes(result), exponent, int, endian); } test { diff --git a/build/compiler_rt/memcpy.zig b/build/compiler_rt/memcpy.zig index a31bbe62..b2e82612 100644 --- a/build/compiler_rt/memcpy.zig +++ b/build/compiler_rt/memcpy.zig @@ -5,7 +5,7 @@ const builtin = @import("builtin"); comptime { if (builtin.object_format != .c) { - const export_options: std.builtin.ExportOptions = .{ + const export_options: std.lang.ExportOptions = .{ .name = "memcpy", .linkage = common.linkage, .visibility = common.visibility, diff --git a/build/compiler_rt/memmove.zig b/build/compiler_rt/memmove.zig index c57ba9c3..d80bf972 100644 --- a/build/compiler_rt/memmove.zig +++ b/build/compiler_rt/memmove.zig @@ -8,7 +8,7 @@ const Element = common.PreferredLoadStoreElement; comptime { if (builtin.object_format != .c) { - const export_options: std.builtin.ExportOptions = .{ + const export_options: std.lang.ExportOptions = .{ .name = "memmove", .linkage = common.linkage, .visibility = common.visibility, diff --git a/build/compiler_rt/ssp.zig b/build/compiler_rt/ssp.zig index f0882cff..d72a0cda 100644 --- a/build/compiler_rt/ssp.zig +++ b/build/compiler_rt/ssp.zig @@ -43,7 +43,7 @@ fn __chk_fail() callconv(.c) noreturn { // TODO: Initialize the canary with random data var __stack_chk_guard: usize = blk: { - var buf = [1]u8{0} ** @sizeOf(usize); + var buf: [@sizeOf(usize)]u8 = @splat(0); buf[@sizeOf(usize) - 1] = 255; buf[@sizeOf(usize) - 2] = '\n'; break :blk @as(usize, @bitCast(buf)); diff --git a/src/Codegen.zig b/src/Codegen.zig index aa7754d5..e79c1712 100644 --- a/src/Codegen.zig +++ b/src/Codegen.zig @@ -235,7 +235,7 @@ pub fn emitTwo(self: *Self, location: Ast.TokenIndex, a: u8, b: u24) !void { pub fn emitCodeArg(self: *Self, location: Ast.TokenIndex, code: Chunk.OpCode, arg: u24) !void { try self.emit( location, - (@as(u32, @intCast(@intFromEnum(code))) << 24) | @as(u32, @intCast(arg)), + (@as(u32, @intCast(@backingInt(code))) << 24) | @as(u32, @intCast(arg)), ); } @@ -243,12 +243,12 @@ pub fn emitCodeArg(self: *Self, location: Ast.TokenIndex, code: Chunk.OpCode, ar pub fn emitCodeArgs(self: *Self, location: Ast.TokenIndex, code: Chunk.OpCode, a: u8, b: u16) !void { try self.emit( location, - (@as(u32, @intCast(@intFromEnum(code))) << 24) | (@as(u32, @intCast(a)) << 16) | (@as(u32, @intCast(b))), + (@as(u32, @intCast(@backingInt(code))) << 24) | (@as(u32, @intCast(a)) << 16) | (@as(u32, @intCast(b))), ); } pub fn emitOpCode(self: *Self, location: Ast.TokenIndex, code: Chunk.OpCode) !void { - try self.emit(location, @as(u32, @intCast(@intFromEnum(code))) << 24); + try self.emit(location, @as(u32, @intCast(@backingInt(code))) << 24); } pub fn emitLoop(self: *Self, location: Ast.TokenIndex, loop_start: usize) !void { @@ -269,7 +269,7 @@ pub fn emitJump(self: *Self, location: Ast.TokenIndex, instruction: Chunk.OpCode pub fn patchJumpOrLoop(self: *Self, offset: usize, loop_start: ?usize) !void { const original = self.current.?.function.?.chunk.code.items[offset]; const instruction: u8 = @intCast(original >> 24); - const code: Chunk.OpCode = @enumFromInt(instruction); + const code: Chunk.OpCode = @fromBackingInt(@intCast(instruction)); if (code == .OP_LOOP) { // Patching a continue statement std.debug.assert(loop_start != null); @@ -494,7 +494,7 @@ fn hasLoopJump(self: *Self, jumps: *const Breaks, loop_node: Ast.Node.Index, kin const is_continue = is_it: { const original = self.current.?.function.?.chunk.code.items[jump.ip]; const instruction: u8 = @intCast(original >> 24); - break :is_it @as(Chunk.OpCode, @enumFromInt(instruction)) == .OP_LOOP; + break :is_it @as(Chunk.OpCode, @fromBackingInt(@intCast(instruction))) == .OP_LOOP; }; const matches_kind = switch (kind) { .@"break" => !is_continue, diff --git a/src/Debugger.zig b/src/Debugger.zig index b2f948b4..cd70d0d4 100644 --- a/src/Debugger.zig +++ b/src/Debugger.zig @@ -23,7 +23,7 @@ var log_file: std.Io.File = undefined; var log_mutex = std.Io.Mutex.init; pub const std_options: std.Options = .{ - .log_level = if (builtin.mode == .Debug) .debug else .info, + .log_level = if (builtin.mode == .debug) .debug else .info, .logFn = logFn, }; @@ -1295,7 +1295,7 @@ fn valueChildren(self: *Debugger, value: Value, result: *std.ArrayList(ProtocolM } pub fn main(init: std.process.Init) !u8 { - const allocator: std.mem.Allocator = if (builtin.mode == .Debug) + const allocator: std.mem.Allocator = if (builtin.mode == .debug) init.gpa else if (BuildOptions.mimalloc) @import("mimalloc.zig").mim_allocator diff --git a/src/FFI.zig b/src/FFI.zig index 1daf809b..e2b14080 100644 --- a/src/FFI.zig +++ b/src/FFI.zig @@ -245,9 +245,10 @@ pub fn parseTypeExpr(self: *Self, ztype: []const u8) !?*Zdef { pub fn parse(self: *Self, parser: ?*Parser, source: Ast.TokenIndex, type_expr: ?[]const u8) !?[]*Zdef { // TODO: maybe an Arena allocator for those kinds of things that can live for the whole process lifetime - const duped = self.gc.allocator.dupeZ( + const duped = self.gc.allocator.dupeSentinel( u8, type_expr orelse parser.?.ast.tokens.items(.literal)[source].String, + 0, ) catch @panic("Out of memory"); // defer self.gc.allocator.free(duped); @@ -272,7 +273,7 @@ pub fn parse(self: *Self, parser: ?*Parser, source: Ast.TokenIndex, type_expr: ? .ast = Ast.parse( self.gc.allocator, duped, - .zig, + .{ .mode = .zig }, ) catch @panic("Could not parse zdef"), }; defer { diff --git a/src/GC.zig b/src/GC.zig index 54009aa8..74e011c2 100644 --- a/src/GC.zig +++ b/src/GC.zig @@ -41,8 +41,8 @@ strings: std.StringHashMapUnmanaged(*o.ObjString) = .empty, type_registry: TypeRegistry, bytes_allocated: usize = 0, // next_gc == next_full_gc at first so the first cycle is a full gc -next_gc: usize = if (builtin.mode == .Debug) 1024 else 1024 * BuildOptions.initial_gc, -next_full_gc: usize = if (builtin.mode == .Debug) 1024 else 1024 * BuildOptions.initial_gc, +next_gc: usize = if (builtin.mode == .debug) 1024 else 1024 * BuildOptions.initial_gc, +next_full_gc: usize = if (builtin.mode == .debug) 1024 else 1024 * BuildOptions.initial_gc, last_gc: ?Mode = null, objects: std.DoublyLinkedList = .{}, gray_stack: std.ArrayList(*o.Obj) = .empty, diff --git a/src/Jit.zig b/src/Jit.zig index a07535d8..6a31f846 100644 --- a/src/Jit.zig +++ b/src/Jit.zig @@ -939,7 +939,7 @@ fn patchOptJumps(self: *Self, node: Ast.Node.Index, value: m.MIR_op_t) !m.MIR_op current_insn, m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BEQ), + @backingInt(m.MIR_Instruction.BEQ), 3, &.{ m.MIR_new_label_op(self.ctx, out_label), @@ -2068,7 +2068,7 @@ fn buildExternApiCall(self: *Self, method: ExternApi, dest: ?m.MIR_op_t, args: [ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.CALL), + @backingInt(m.MIR_Instruction.CALL), off + args.len, &self.state.?.args_buffer, ), @@ -2672,7 +2672,7 @@ fn generateCall(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.CALL), + @backingInt(m.MIR_Instruction.CALL), 4, &.{ m.MIR_new_ref_op( @@ -5117,7 +5117,7 @@ fn generateUnwrap(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t { const current_insn = m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.MOV), + @backingInt(m.MIR_Instruction.MOV), 2, &.{ m.MIR_new_reg_op( @@ -5702,7 +5702,7 @@ fn generateFunction(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t { } // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const ctx_name = try self.gc.allocator.dupeZ(u8, "ctx"); + const ctx_name = try self.gc.allocator.dupeSentinel(u8, "ctx", 0); defer self.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, @@ -5784,7 +5784,7 @@ fn generateHotspotFunction(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t const qualified_name = try self.getQualifiedName(node, false); defer self.gc.allocator.free(qualified_name); - const ctx_name = try self.gc.allocator.dupeZ(u8, "ctx"); + const ctx_name = try self.gc.allocator.dupeSentinel(u8, "ctx", 0); defer self.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, @@ -5927,7 +5927,7 @@ fn generateNativeFn(self: *Self, node: Ast.Node.Index, raw_fn: m.MIR_item_t) !m. defer self.gc.allocator.free(nativefn_qualified_name); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const ctx_name = try self.gc.allocator.dupeZ(u8, "ctx"); + const ctx_name = try self.gc.allocator.dupeSentinel(u8, "ctx", 0); defer self.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, @@ -6044,7 +6044,7 @@ fn generateNativeFn(self: *Self, node: Ast.Node.Index, raw_fn: m.MIR_item_t) !m. function, m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.CALL), + @backingInt(m.MIR_Instruction.CALL), 4, &.{ m.MIR_new_ref_op(self.ctx, try ExternApi.RawFn.declare(self)), @@ -6365,7 +6365,7 @@ pub fn compileZdef(self: *Self, gc: *GC, buzz_ast: Ast.Slice, zdef: Ast.Zdef.Zde try wrapper_name.writer.print("zdef_{s}\x00", .{zdef.zdef.name}); - const dupped_symbol = try self.gc.allocator.dupeZ(u8, zdef.zdef.name); + const dupped_symbol = try self.gc.allocator.dupeSentinel(u8, zdef.zdef.name, 0); defer self.gc.allocator.free(dupped_symbol); const module = m.MIR_new_module(self.ctx, @ptrCast(wrapper_name.written().ptr)); @@ -6479,11 +6479,11 @@ fn buildZdefWrapper(self: *Self, zdef_element: Ast.Zdef.ZdefElement) Error!m.MIR try wrapper_protocol_name.writer.print("p_zdef_{s}\x00", .{zdef_element.zdef.name}); - const dupped_symbol = try self.gc.allocator.dupeZ(u8, zdef_element.zdef.name); + const dupped_symbol = try self.gc.allocator.dupeSentinel(u8, zdef_element.zdef.name, 0); defer self.gc.allocator.free(dupped_symbol); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const ctx_name = try self.gc.allocator.dupeZ(u8, "ctx"); + const ctx_name = try self.gc.allocator.dupeSentinel(u8, "ctx", 0); defer self.gc.allocator.free(ctx_name); const function = m.MIR_new_func_arr( self.ctx, @@ -6639,7 +6639,7 @@ fn buildZdefWrapper(self: *Self, zdef_element: Ast.Zdef.ZdefElement) Error!m.MIR self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.CALL), + @backingInt(m.MIR_Instruction.CALL), full_args.items.len, full_args.items.ptr, ), @@ -6691,9 +6691,9 @@ fn buildZdefUnionGetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const vm_name = try self.gc.allocator.dupeZ(u8, "vm"); + const vm_name = try self.gc.allocator.dupeSentinel(u8, "vm", 0); defer self.gc.allocator.free(vm_name); - const data_name = try self.gc.allocator.dupeZ(u8, "data"); + const data_name = try self.gc.allocator.dupeSentinel(u8, "data", 0); defer self.gc.allocator.free(data_name); const function = m.MIR_new_func_arr( self.ctx, @@ -6795,11 +6795,11 @@ fn buildZdefUnionSetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const vm_name = try self.gc.allocator.dupeZ(u8, "vm"); + const vm_name = try self.gc.allocator.dupeSentinel(u8, "vm", 0); defer self.gc.allocator.free(vm_name); - const data_name = try self.gc.allocator.dupeZ(u8, "data"); + const data_name = try self.gc.allocator.dupeSentinel(u8, "data", 0); defer self.gc.allocator.free(data_name); - const new_value_name = try self.gc.allocator.dupeZ(u8, "new_value"); + const new_value_name = try self.gc.allocator.dupeSentinel(u8, "new_value", 0); defer self.gc.allocator.free(new_value_name); const function = m.MIR_new_func_arr( self.ctx, @@ -6902,9 +6902,9 @@ fn buildZdefContainerGetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const vm_name = try self.gc.allocator.dupeZ(u8, "vm"); + const vm_name = try self.gc.allocator.dupeSentinel(u8, "vm", 0); defer self.gc.allocator.free(vm_name); - const data_name = try self.gc.allocator.dupeZ(u8, "data"); + const data_name = try self.gc.allocator.dupeSentinel(u8, "data", 0); defer self.gc.allocator.free(data_name); const function = m.MIR_new_func_arr( self.ctx, @@ -6990,11 +6990,11 @@ fn buildZdefContainerSetter( ); // FIXME: I don't get why we need this: a simple constant becomes rubbish as soon as we enter MIR_new_func_arr if we don't - const vm_name = try self.gc.allocator.dupeZ(u8, "vm"); + const vm_name = try self.gc.allocator.dupeSentinel(u8, "vm", 0); defer self.gc.allocator.free(vm_name); - const data_name = try self.gc.allocator.dupeZ(u8, "data"); + const data_name = try self.gc.allocator.dupeSentinel(u8, "data", 0); defer self.gc.allocator.free(data_name); - const new_value_name = try self.gc.allocator.dupeZ(u8, "new_value"); + const new_value_name = try self.gc.allocator.dupeSentinel(u8, "new_value", 0); defer self.gc.allocator.free(new_value_name); const function = m.MIR_new_func_arr( self.ctx, @@ -7092,7 +7092,7 @@ inline fn MOV(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.MOV), + @backingInt(m.MIR_Instruction.MOV), 2, &.{ dest, @@ -7106,7 +7106,7 @@ inline fn DMOV(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DMOV), + @backingInt(m.MIR_Instruction.DMOV), 2, &.{ dest, @@ -7120,7 +7120,7 @@ inline fn FMOV(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.FMOV), + @backingInt(m.MIR_Instruction.FMOV), 2, &.{ dest, @@ -7134,7 +7134,7 @@ inline fn EQ(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.EQ), + @backingInt(m.MIR_Instruction.EQ), 3, &.{ dest, @@ -7149,7 +7149,7 @@ inline fn EQS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.EQS), + @backingInt(m.MIR_Instruction.EQS), 3, &.{ dest, @@ -7164,7 +7164,7 @@ inline fn DEQ(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DEQ), + @backingInt(m.MIR_Instruction.DEQ), 3, &.{ dest, @@ -7179,7 +7179,7 @@ inline fn GT(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.GT), + @backingInt(m.MIR_Instruction.GT), 3, &.{ dest, @@ -7194,7 +7194,7 @@ inline fn GTS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.GTS), + @backingInt(m.MIR_Instruction.GTS), 3, &.{ dest, @@ -7209,7 +7209,7 @@ inline fn DGT(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DGT), + @backingInt(m.MIR_Instruction.DGT), 3, &.{ dest, @@ -7224,7 +7224,7 @@ inline fn LT(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.LT), + @backingInt(m.MIR_Instruction.LT), 3, &.{ dest, @@ -7239,7 +7239,7 @@ inline fn LTS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.LTS), + @backingInt(m.MIR_Instruction.LTS), 3, &.{ dest, @@ -7254,7 +7254,7 @@ inline fn DLT(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DLT), + @backingInt(m.MIR_Instruction.DLT), 3, &.{ dest, @@ -7269,7 +7269,7 @@ inline fn GE(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.GE), + @backingInt(m.MIR_Instruction.GE), 3, &.{ dest, @@ -7284,7 +7284,7 @@ inline fn GES(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.GES), + @backingInt(m.MIR_Instruction.GES), 3, &.{ dest, @@ -7299,7 +7299,7 @@ inline fn DGE(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DGE), + @backingInt(m.MIR_Instruction.DGE), 3, &.{ dest, @@ -7314,7 +7314,7 @@ inline fn LE(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.LE), + @backingInt(m.MIR_Instruction.LE), 3, &.{ dest, @@ -7329,7 +7329,7 @@ inline fn LES(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.LES), + @backingInt(m.MIR_Instruction.LES), 3, &.{ dest, @@ -7344,7 +7344,7 @@ inline fn DLE(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DLE), + @backingInt(m.MIR_Instruction.DLE), 3, &.{ dest, @@ -7359,7 +7359,7 @@ inline fn NE(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.NE), + @backingInt(m.MIR_Instruction.NE), 3, &.{ dest, @@ -7374,7 +7374,7 @@ inline fn NES(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.NES), + @backingInt(m.MIR_Instruction.NES), 3, &.{ dest, @@ -7389,7 +7389,7 @@ inline fn DNE(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DNE), + @backingInt(m.MIR_Instruction.DNE), 3, &.{ dest, @@ -7404,7 +7404,7 @@ inline fn BEQ(self: *Self, label: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BEQ), + @backingInt(m.MIR_Instruction.BEQ), 3, &.{ label, @@ -7419,7 +7419,7 @@ inline fn BLT(self: *Self, label: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BLT), + @backingInt(m.MIR_Instruction.BLT), 3, &.{ label, @@ -7434,7 +7434,7 @@ inline fn BGT(self: *Self, label: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BGT), + @backingInt(m.MIR_Instruction.BGT), 3, &.{ label, @@ -7449,7 +7449,7 @@ inline fn BNE(self: *Self, label: m.MIR_insn_t, left: m.MIR_op_t, right: m.MIR_o self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BNE), + @backingInt(m.MIR_Instruction.BNE), 3, &.{ m.MIR_new_label_op(self.ctx, label), @@ -7464,7 +7464,7 @@ inline fn JMP(self: *Self, label: m.MIR_insn_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.JMP), + @backingInt(m.MIR_Instruction.JMP), 1, &.{ m.MIR_new_label_op(self.ctx, label), @@ -7477,7 +7477,7 @@ inline fn ADD(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.ADD), + @backingInt(m.MIR_Instruction.ADD), 3, &.{ dest, @@ -7492,7 +7492,7 @@ inline fn DADD(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DADD), + @backingInt(m.MIR_Instruction.DADD), 3, &.{ dest, @@ -7507,7 +7507,7 @@ inline fn ADDS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.ADDS), + @backingInt(m.MIR_Instruction.ADDS), 3, &.{ dest, @@ -7522,7 +7522,7 @@ inline fn SUB(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.SUB), + @backingInt(m.MIR_Instruction.SUB), 3, &.{ dest, @@ -7537,7 +7537,7 @@ inline fn SUBS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.SUBS), + @backingInt(m.MIR_Instruction.SUBS), 3, &.{ dest, @@ -7552,7 +7552,7 @@ inline fn DSUB(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DSUB), + @backingInt(m.MIR_Instruction.DSUB), 3, &.{ dest, @@ -7567,7 +7567,7 @@ inline fn MUL(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.MUL), + @backingInt(m.MIR_Instruction.MUL), 3, &.{ dest, @@ -7582,7 +7582,7 @@ inline fn MULS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.MULS), + @backingInt(m.MIR_Instruction.MULS), 3, &.{ dest, @@ -7597,7 +7597,7 @@ inline fn DMUL(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DMUL), + @backingInt(m.MIR_Instruction.DMUL), 3, &.{ dest, @@ -7612,7 +7612,7 @@ inline fn DIV(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DIV), + @backingInt(m.MIR_Instruction.DIV), 3, &.{ dest, @@ -7627,7 +7627,7 @@ inline fn DIVS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DIVS), + @backingInt(m.MIR_Instruction.DIVS), 3, &.{ dest, @@ -7642,7 +7642,7 @@ inline fn DDIV(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DDIV), + @backingInt(m.MIR_Instruction.DDIV), 3, &.{ dest, @@ -7657,7 +7657,7 @@ inline fn MOD(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.MOD), + @backingInt(m.MIR_Instruction.MOD), 3, &.{ dest, @@ -7672,7 +7672,7 @@ inline fn MODS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.MODS), + @backingInt(m.MIR_Instruction.MODS), 3, &.{ dest, @@ -7687,7 +7687,7 @@ inline fn AND(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.AND), + @backingInt(m.MIR_Instruction.AND), 3, &.{ dest, @@ -7702,7 +7702,7 @@ inline fn ANDS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_ self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.ANDS), + @backingInt(m.MIR_Instruction.ANDS), 3, &.{ dest, @@ -7717,7 +7717,7 @@ inline fn OR(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t) self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.OR), + @backingInt(m.MIR_Instruction.OR), 3, &.{ dest, @@ -7732,7 +7732,7 @@ inline fn ORS(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.ORS), + @backingInt(m.MIR_Instruction.ORS), 3, &.{ dest, @@ -7747,7 +7747,7 @@ inline fn XOR(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.XOR), + @backingInt(m.MIR_Instruction.XOR), 3, &.{ dest, @@ -7762,7 +7762,7 @@ inline fn SHL(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.LSH), + @backingInt(m.MIR_Instruction.LSH), 3, &.{ dest, @@ -7777,7 +7777,7 @@ inline fn SHR(self: *Self, dest: m.MIR_op_t, left: m.MIR_op_t, right: m.MIR_op_t self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.RSH), + @backingInt(m.MIR_Instruction.RSH), 3, &.{ dest, @@ -7792,7 +7792,7 @@ inline fn NOT(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.XOR), + @backingInt(m.MIR_Instruction.XOR), 3, &.{ dest, @@ -7807,7 +7807,7 @@ inline fn NOTS(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.XORS), + @backingInt(m.MIR_Instruction.XORS), 3, &.{ dest, @@ -7822,7 +7822,7 @@ inline fn I2D(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.I2D), + @backingInt(m.MIR_Instruction.I2D), 2, &.{ dest, @@ -7836,7 +7836,7 @@ inline fn UI2D(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.UI2D), + @backingInt(m.MIR_Instruction.UI2D), 2, &.{ dest, @@ -7850,7 +7850,7 @@ inline fn D2I(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.D2I), + @backingInt(m.MIR_Instruction.D2I), 2, &.{ dest, @@ -7864,7 +7864,7 @@ inline fn NEG(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.NEG), + @backingInt(m.MIR_Instruction.NEG), 2, &.{ dest, @@ -7878,7 +7878,7 @@ inline fn DNEG(self: *Self, dest: m.MIR_op_t, value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.DNEG), + @backingInt(m.MIR_Instruction.DNEG), 2, &.{ dest, @@ -7892,7 +7892,7 @@ inline fn RET(self: *Self, return_value: m.MIR_op_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.RET), + @backingInt(m.MIR_Instruction.RET), 1, &.{ return_value, @@ -7905,7 +7905,7 @@ inline fn ALLOCA(self: *Self, reg: m.MIR_reg_t, size: usize) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.ALLOCA), + @backingInt(m.MIR_Instruction.ALLOCA), 2, &.{ m.MIR_new_reg_op(self.ctx, reg), @@ -7919,7 +7919,7 @@ inline fn BSTART(self: *Self, into: m.MIR_reg_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BSTART), + @backingInt(m.MIR_Instruction.BSTART), 1, &.{ m.MIR_new_reg_op(self.ctx, into), @@ -7932,7 +7932,7 @@ inline fn BEND(self: *Self, from: m.MIR_reg_t) void { self.append( m.MIR_new_insn_arr( self.ctx, - @intFromEnum(m.MIR_Instruction.BEND), + @backingInt(m.MIR_Instruction.BEND), 1, &.{ m.MIR_new_reg_op(self.ctx, from), diff --git a/src/Package.zig b/src/Package.zig index b0744b05..b537d69e 100644 --- a/src/Package.zig +++ b/src/Package.zig @@ -1221,7 +1221,7 @@ pub const Manifest = struct { .patch = @intCast(version_instance.get(v.Integer, comptime "3")), } else null, .constraint = if (version) |version_instance| - @enumFromInt(@as(u8, @intCast(version_instance.get(v.Integer, "0")))) + @fromBackingInt(@intCast(@as(u8, @intCast(version_instance.get(v.Integer, "0"))))) else .equalTo, }; diff --git a/src/Parser.zig b/src/Parser.zig index 024b2130..052c6c1b 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -65,7 +65,7 @@ const WindowsDynLib = struct { /// Opens a Windows DLL at `path`. pub fn open(allocator: std.mem.Allocator, path: []const u8) !WindowsDynLib { - const path_z = try allocator.dupeZ(u8, path); + const path_z = try allocator.dupeSentinel(u8, path, 0); defer allocator.free(path_z); return .{ @@ -94,7 +94,7 @@ pub const Dlib = struct { pub fn lookup(self: *Dlib, gc: *GC, symbol: []const u8) !?*obj.ObjNative { return self.symbols.get(symbol) orelse load: { - const ssymbol = try gc.allocator.dupeZ(u8, symbol); + const ssymbol = try gc.allocator.dupeSentinel(u8, symbol, 0); defer gc.allocator.free(ssymbol); if (self.lookup_fn(ssymbol)) |resolved| { @@ -1349,8 +1349,8 @@ fn beginFrame(self: *Self, function_type: obj.ObjFunction.FunctionType, function const enclosing = self.current; const frame = try self.gc.allocator.create(Frame); frame.* = Frame{ - .locals = [_]Local{undefined} ** 255, - .upvalues = [_]UpValue{undefined} ** 255, + .locals = @splat(undefined), + .upvalues = @splat(undefined), .enclosing = enclosing, .function_node = function_node, }; @@ -1607,15 +1607,15 @@ fn parsePrecedence(self: *Self, precedence: Precedence, hanging: bool) Error!Ast return CompileError.Unrecoverable; } - const canAssign = @intFromEnum(precedence) <= @intFromEnum(Precedence.Assignment); + const canAssign = @backingInt(precedence) <= @backingInt(Precedence.Assignment); var node = try prefixRule.?(self, canAssign); - while (@intFromEnum(rules.get(self.ast.tokens.items(.tag)[self.current_token.?]).precedence) >= @intFromEnum(precedence)) { + while (@backingInt(rules.get(self.ast.tokens.items(.tag)[self.current_token.?]).precedence) >= @backingInt(precedence)) { // Patch optional jumps if (self.opt_jumps) |*jumps| { std.debug.assert(jumps.items.len > 0); // If precedence is less than the precedence that started the nullable chain, stop the chain there - if (@intFromEnum(rules.get(self.ast.tokens.items(.tag)[self.current_token.?]).precedence) < @intFromEnum(jumps.items[0])) { + if (@backingInt(rules.get(self.ast.tokens.items(.tag)[self.current_token.?]).precedence) < @backingInt(jumps.items[0])) { jumps.deinit(self.gc.allocator); self.opt_jumps = null; @@ -2048,7 +2048,7 @@ fn addGlobal( // A function declares a global with an incomplete typedef so that it can handle recursion // The placeholder resolution occurs after we parsed the functions body in `funDeclaration` - if (global_type.resolved_type != null or @intFromEnum(global_type.def_type) < @intFromEnum(obj.ObjTypeDef.Type.ObjectInstance)) { + if (global_type.resolved_type != null or @backingInt(global_type.def_type) < @backingInt(obj.ObjTypeDef.Type.ObjectInstance)) { if (BuildOptions.debug_placeholders) { print( self.process.io, @@ -7527,7 +7527,7 @@ fn binary(self: *Self, _: bool, left: Ast.Node.Index) Error!Ast.Node.Index { const rule = rules.get(operator); const right = try self.parsePrecedence( - @enumFromInt(@intFromEnum(rule.precedence) + 1), + @fromBackingInt(@intCast(@backingInt(rule.precedence) + 1)), false, ); @@ -9717,7 +9717,7 @@ fn openNativeLibraryAt(self: *Self, library_path: []const u8, library_name: []co var lib = DynLib.open(self.gc.allocator, library_path) catch return null; errdefer lib.close(); - const name = try self.gc.allocator.dupeZ(u8, library_name); + const name = try self.gc.allocator.dupeSentinel(u8, library_name, 0); defer self.gc.allocator.free(name); if (lib.lookup(Dlib.LookupFn, name)) |lookup_fn| { @@ -10134,7 +10134,7 @@ fn zdefStatement(self: *Self) Error!Ast.Node.Index { if (lib) |*dlib| { // Convert symbol names to zig slices - const symbol = try self.gc.allocator.dupeZ(u8, zdef.name); + const symbol = try self.gc.allocator.dupeSentinel(u8, zdef.name, 0); defer self.gc.allocator.free(symbol); // Lookup symbol diff --git a/src/Perf.zig b/src/Perf.zig index 20dc57e8..05d85020 100644 --- a/src/Perf.zig +++ b/src/Perf.zig @@ -44,7 +44,7 @@ pub const Scope = struct { } }; -const component_count = @typeInfo(Component).@"enum".fields.len; +const component_count = @typeInfo(Component).@"enum".field_names.len; const default_order = defaultOrder(); const max_stack = 64; @@ -63,8 +63,8 @@ const StackState = if (builtin.cpu.arch.isWasm()) struct { io: bz_io.Io, started_at: std.Io.Clock.Timestamp, mutex: std.Io.Mutex = .init, -totals: [component_count]i128 = [_]i128{0} ** component_count, -children: [component_count][component_count]i128 = [_][component_count]i128{[_]i128{0} ** component_count} ** component_count, +totals: [component_count]i128 = @splat(0), +children: [component_count][component_count]i128 = @splat(@splat(0)), pub fn init(io: bz_io.Io) Self { return .{ @@ -141,7 +141,7 @@ pub fn report(self: *Self) void { continue; } - const component: Component = @enumFromInt(component_index); + const component: Component = @fromBackingInt(@intCast(component_index)); const percent: u128 = @intCast(@divTrunc(duration * 100, elapsed)); var duration_buffer: [32]u8 = undefined; const duration_string = formatDuration(&duration_buffer, duration) catch return; @@ -174,7 +174,7 @@ fn recordDuration(self: *Self, component: Component, parent: ?Component, duratio return; } - const component_index = @intFromEnum(component); + const component_index = @backingInt(component); self.mutex.lockUncancelable(self.io); defer self.mutex.unlock(self.io); @@ -182,7 +182,7 @@ fn recordDuration(self: *Self, component: Component, parent: ?Component, duratio self.totals[component_index] += duration; if (parent) |p| { - self.children[@intFromEnum(p)][component_index] += duration; + self.children[@backingInt(p)][component_index] += duration; } } @@ -256,7 +256,7 @@ fn tryPrintChildren(out: *std.Io.Writer, component_children: [component_count]i1 try out.writeAll(", "); } - try out.print("{s} ", .{label(@enumFromInt(index))}); + try out.print("{s} ", .{label(@fromBackingInt(@intCast(index)))}); try printDuration(out, duration); } } diff --git a/src/Reporter.zig b/src/Reporter.zig index ab2d01d3..3e542061 100644 --- a/src/Reporter.zig +++ b/src/Reporter.zig @@ -330,7 +330,7 @@ pub const Report = struct { main_item.end_location.column, main_item.kind.color(), main_item.kind.prefix(), - @intFromEnum(self.error_type), + @backingInt(self.error_type), if (reporter.error_prefix) |prefix| prefix else @@ -350,7 +350,7 @@ pub const Report = struct { main_item.end_location.line + 1, main_item.end_location.column, main_item.kind.prefix(), - @intFromEnum(self.error_type), + @backingInt(self.error_type), if (reporter.error_prefix) |prefix| prefix else diff --git a/src/TypeChecker.zig b/src/TypeChecker.zig index 997c53a7..cb016195 100644 --- a/src/TypeChecker.zig +++ b/src/TypeChecker.zig @@ -15,7 +15,7 @@ const NodeCheck = *const fn ( node: Ast.Node.Index, ) error{OutOfMemory}!bool; -const checkers = [@typeInfo(Ast.Node.Tag).@"enum".fields.len]?NodeCheck{ +const checkers = [@typeInfo(Ast.Node.Tag).@"enum".field_names.len]?NodeCheck{ null, // AnonymousObjectType null, // AnonymousEnumCase null, // As @@ -85,7 +85,7 @@ const checkers = [@typeInfo(Ast.Node.Tag).@"enum".fields.len]?NodeCheck{ /// Typecheck the node (but does not typecheck its leaf) pub fn check(ast: Ast.Slice, reporter: *Reporter, gc: *GC, current_function_node: ?Ast.Node.Index, node: Ast.Node.Index) error{OutOfMemory}!bool { - return if (checkers[@intFromEnum(ast.nodes.items(.tag)[node])]) |checker| + return if (checkers[@backingInt(ast.nodes.items(.tag)[node])]) |checker| try checker(ast, reporter, gc, current_function_node, node) else false; diff --git a/src/behavior.zig b/src/behavior.zig index 9ae9f2a5..971fbb2b 100644 --- a/src/behavior.zig +++ b/src/behavior.zig @@ -142,7 +142,7 @@ fn testCompileErrors(process: std.process.Init, allocator: std.mem.Allocator, fa file_name.written(), .{ .mode = .read_only }, ); - var buffer = [_]u8{0} ** 255; + var buffer: [255]u8 = @splat(0); var file_reader = test_file.reader(process.io, buffer[0..]); var reader = bz_io.AllocatedReader.init( allocator, @@ -325,8 +325,8 @@ fn printFileStatus(io: std.Io, file_name: []const u8, status: Status) void { pub fn main(init: std.process.Init) !u8 { // DebugAllocator recently got super slow, will put this back on once its fixed - // var gpa = std.heap.DebugAllocator(.{ .safety = builtin.mode == .Debug }){}; - // const allocator = if (builtin.mode == .Debug or is_wasm) + // var gpa = std.heap.DebugAllocator(.{ .safety = builtin.mode == .debug }){}; + // const allocator = if (builtin.mode == .debug or is_wasm) // gpa.allocator() // else const allocator = if (BuildOptions.mimalloc) diff --git a/src/builtin/pattern.zig b/src/builtin/pattern.zig index d9a086ff..d5f75a2d 100644 --- a/src/builtin/pattern.zig +++ b/src/builtin/pattern.zig @@ -151,7 +151,7 @@ pub fn rawMatch(self: *o.ObjPattern, vm: *VM, subject: *o.ObjString, offset: *us ); switch (rc) { - @intFromEnum(pcre.MatchingError.DFA_UINVALID_UTF)...@intFromEnum(pcre.MatchingError.NOMATCH) => {}, + @backingInt(pcre.MatchingError.DFA_UINVALID_UTF)...@backingInt(pcre.MatchingError.NOMATCH) => {}, // TODO: handle ouptut_vector too small 0 => { vm.panic("Could not match pattern"); @@ -294,7 +294,7 @@ fn rawReplace(self: *o.ObjPattern, vm: *VM, subject: *o.ObjString, replacement: ); switch (rc) { - @intFromEnum(pcre.MatchingError.DFA_UINVALID_UTF)...@intFromEnum(pcre.MatchingError.NOMATCH) => return subject, + @backingInt(pcre.MatchingError.DFA_UINVALID_UTF)...@backingInt(pcre.MatchingError.NOMATCH) => return subject, // TODO: handle ouptut_vector too small 0 => { vm.panic("Could not match pattern"); diff --git a/src/buzz_api.zig b/src/buzz_api.zig index ea3f9718..1c69dd1a 100644 --- a/src/buzz_api.zig +++ b/src/buzz_api.zig @@ -26,10 +26,10 @@ else std.os; var gpa = std.heap.DebugAllocator(.{ - .safety = builtin.mode == .Debug, + .safety = builtin.mode == .debug, }){}; -pub const allocator: std.mem.Allocator = if (builtin.mode == .Debug or is_wasm) +pub const allocator: std.mem.Allocator = if (builtin.mode == .debug or is_wasm) gpa.allocator() else if (BuildOptions.mimalloc) @import("mimalloc.zig").mim_allocator diff --git a/src/disassembler.zig b/src/disassembler.zig index 9ff11ae0..53115ec4 100644 --- a/src/disassembler.zig +++ b/src/disassembler.zig @@ -225,7 +225,7 @@ pub fn disassembleInstruction(chunk: *Chunk, offset: usize) usize { } const full_instruction: u32 = chunk.code.items[offset]; - const instruction: OpCode = @enumFromInt(@as(u8, @intCast(full_instruction >> 24))); + const instruction: OpCode = @fromBackingInt(@intCast(@as(u8, @intCast(full_instruction >> 24)))); const arg: u24 = @intCast(0x00ffffff & full_instruction); return switch (instruction) { .OP_NULL, diff --git a/src/lib/buzz_api.zig b/src/lib/buzz_api.zig index 90c941ee..3e56903a 100644 --- a/src/lib/buzz_api.zig +++ b/src/lib/buzz_api.zig @@ -241,10 +241,10 @@ pub const ZigType = opaque { pub const VM = opaque { var gpa = std.heap.DebugAllocator(.{ - .safety = builtin.mode == .Debug, + .safety = builtin.mode == .debug, }){}; - pub const allocator = if (builtin.mode == .Debug or is_wasm) + pub const allocator = if (builtin.mode == .debug or is_wasm) gpa.allocator() else if (BuildOptions.mimalloc) @import("mimalloc.zig").mim_allocator diff --git a/src/lib/buzz_fs.zig b/src/lib/buzz_fs.zig index 5c927c49..067d96f5 100644 --- a/src/lib/buzz_fs.zig +++ b/src/lib/buzz_fs.zig @@ -4,7 +4,10 @@ const api = @import("buzz_api.zig"); /// Maps current-directory lookup failures to Buzz errors. fn handleCurrentDirectoryError(ctx: *api.NativeCtx, err: std.process.CurrentPathAllocError) void { switch (err) { - error.Canceled => ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)), + error.Canceled, + error.NameTooLong, + error.PathExceedsLimit, + => ctx.vm.pushErrorEnum("errors.FileSystemError", @errorName(err)), error.CurrentDirUnlinked => ctx.vm.pushErrorEnum("errors.FileSystemError", "BadPathName"), error.Unexpected => ctx.vm.pushError("errors.UnexpectedError", null), error.OutOfMemory => { diff --git a/src/lib/buzz_http.zig b/src/lib/buzz_http.zig index fb4c3688..653dfd07 100644 --- a/src/lib/buzz_http.zig +++ b/src/lib/buzz_http.zig @@ -51,6 +51,8 @@ fn innerHttpClientNew(ctx: *api.NativeCtx) !c_int { pub export fn HttpClientNew(ctx: *api.NativeCtx) callconv(.c) c_int { return innerHttpClientNew(ctx) catch |err| { switch (err) { + error.Canceled, + error.NameTooLong, error.InvalidHostName, error.UriMissingHost, error.UnexpectedCharacter, @@ -270,7 +272,7 @@ fn innerHttpRequestWait(ctx: *api.NativeCtx) !c_int { // Set status response.bz_setObjectInstanceProperty( 3, - api.Value.fromInteger(@intFromEnum(http_response.head.status)), + api.Value.fromInteger(@backingInt(http_response.head.status)), ctx.vm, ); @@ -379,6 +381,7 @@ pub export fn HttpRequestWait(ctx: *api.NativeCtx) callconv(.c) c_int { error.HttpChunkTruncated, error.HttpHeadersOversize, error.HttpRequestTruncated, + error.InvalidHostName, error.HttpConnectionClosing, error.TlsInitializationFailed, error.UnsupportedUriScheme, diff --git a/src/lib/buzz_os.zig b/src/lib/buzz_os.zig index b2d942a5..1c334ad3 100644 --- a/src/lib/buzz_os.zig +++ b/src/lib/buzz_os.zig @@ -35,7 +35,7 @@ pub export fn env(ctx: *api.NativeCtx) callconv(.c) c_int { return 1; } - const key_slice = api.VM.allocator.dupeZ(u8, key.?[0..len]) catch { + const key_slice = api.VM.allocator.dupeSentinel(u8, key.?[0..len], 0) catch { ctx.vm.bz_panic("Out of memory", "Out of memory".len); unreachable; }; @@ -252,7 +252,6 @@ pub export fn execute(ctx: *api.NativeCtx) callconv(.c) c_int { ctx.getIo(), .{ .argv = command.items, - .disable_aslr = builtin.target.os.tag.isDarwin(), }, ) catch |err| { handleSpawnError(ctx, err); @@ -266,7 +265,7 @@ pub export fn execute(ctx: *api.NativeCtx) callconv(.c) c_int { return -1; }; - ctx.vm.bz_push(.fromInteger(@intFromEnum(term))); + ctx.vm.bz_push(.fromInteger(@backingInt(term))); return 1; } @@ -318,6 +317,7 @@ fn handleConnectUnixError(ctx: *api.NativeCtx, err: std.Io.net.UnixAddress.Conne error.ProtocolUnsupportedBySystem, error.SocketModeUnsupported, error.Canceled, + error.ConnectionRefused, => ctx.vm.pushErrorEnum("errors.SocketError", @errorName(err)), error.AccessDenied, @@ -656,6 +656,7 @@ pub export fn SocketServerStart(ctx: *api.NativeCtx) callconv(.c) c_int { }, ) catch |err| { switch (err) { + error.AccessDenied, error.Canceled, error.SystemResources, error.ProcessFdQuotaExceeded, diff --git a/src/lib/errors.buzz b/src/lib/errors.buzz index 413b84f3..cebafa46 100644 --- a/src/lib/errors.buzz +++ b/src/lib/errors.buzz @@ -27,6 +27,7 @@ export enum FileSystemError { IsDir, LinkQuotaExceeded, NameTooLong, + PathExceedsLimit, NetworkSubsystemFailed, NetworkNotFound, NoDevice, diff --git a/src/lib/http.buzz b/src/lib/http.buzz index a9674b79..295be536 100644 --- a/src/lib/http.buzz +++ b/src/lib/http.buzz @@ -5,6 +5,7 @@ import "buzz:errors"; /// Errors raised by HTTP client operations. export enum HttpError { + Canceled, CertificateBundleLoadFailure, ClientCollected, CompressionInitializationFailed, @@ -32,6 +33,7 @@ export enum HttpError { InvalidContentLength, InvalidFormat, InvalidHostName, + NameTooLong, InvalidPort, InvalidTrailers, MalformedUri, diff --git a/src/lsp.zig b/src/lsp.zig index 2f9b67c1..25e79a8b 100644 --- a/src/lsp.zig +++ b/src/lsp.zig @@ -153,13 +153,13 @@ const Document = struct { errdefer arena.deinit(); const allocator = arena.allocator(); - const owned_src = try allocator.dupeZ(u8, src); + const owned_src = try allocator.dupeSentinel(u8, src, 0); const owned_uri = try allocator.dupe(u8, uri); const package_document_kind = try packageDocumentKind(allocator, owned_uri, owned_src); const parse_src = if (package_document_kind) |kind| switch (kind) { - .manifest => try allocator.dupeZ(u8, try Package.wrapManifest(allocator, owned_src)), - .manifest_lock => try allocator.dupeZ(u8, try Package.wrapManifestLock(allocator, owned_src)), + .manifest => try allocator.dupeSentinel(u8, try Package.wrapManifest(allocator, owned_src), 0), + .manifest_lock => try allocator.dupeSentinel(u8, try Package.wrapManifestLock(allocator, owned_src), 0), } else owned_src; @@ -1544,7 +1544,7 @@ const Document = struct { extern fn getpid() std.os.linux.pid_t; pub fn main(init: std.process.Init) !void { - const allocator: std.mem.Allocator = if (builtin.mode == .Debug or is_wasm) + const allocator: std.mem.Allocator = if (builtin.mode == .debug or is_wasm) init.gpa else if (BuildOptions.mimalloc) @import("mimalloc.zig").mim_allocator @@ -1553,7 +1553,7 @@ pub fn main(init: std.process.Init) !void { log.debug("Buzz LSP started with PID {}", .{getpid()}); - var read_buffer = [_]u8{0} ** 256; + var read_buffer: [256]u8 = @splat(0); var stdio_transport = lsp.Transport.Stdio.init( read_buffer[0..], std.Io.File.stdin(), @@ -1810,7 +1810,7 @@ const Handler = struct { .warning => .Warning, .hint => .Hint, }, - .message = item.message, + .message = .{ .string = item.message }, .tags = tags, }, ); @@ -1886,8 +1886,17 @@ const Handler = struct { allocator: std.mem.Allocator, notification: lsp.types.notifications.get("textDocument/didChange").?.Params.?, ) !void { - errdefer |e| log.err("changeDocument failed: {any}", .{e}); + return self.changeDocument(allocator, notification) catch |err| { + log.err("changeDocument failed: {any}", .{err}); + return err; + }; + } + fn changeDocument( + self: *Handler, + allocator: std.mem.Allocator, + notification: lsp.types.notifications.get("textDocument/didChange").?.Params.?, + ) !void { if (notification.contentChanges.len == 0) { return; } diff --git a/src/main.zig b/src/main.zig index 166ab521..e94d8585 100644 --- a/src/main.zig +++ b/src/main.zig @@ -670,8 +670,8 @@ fn help(init: Init, stderr: *std.Io.Writer, subcommand_opt: ?[]const u8) u8 { io.print(init.io, "\n\n", .{}); io.print(init.io, "Commands:\n", .{}); - inline for (std.meta.fields(@TypeOf(command_summaries))) |field| { - const command = @field(command_summaries, field.name); + inline for (@typeInfo(@TypeOf(command_summaries)).@"struct".field_names) |field_name| { + const command = @field(command_summaries, field_name); io.print(init.io, " {s:<11} {s}\n", .{ command.name, command.description, diff --git a/src/obj.zig b/src/obj.zig index 707b074c..b02de2d8 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -314,7 +314,7 @@ pub const Obj = struct { var it = container_def.fields.iterator(); while (it.next()) |kv| { - const dupped = try vm.gc.allocator.dupeZ(u8, kv.key_ptr.*); + const dupped = try vm.gc.allocator.dupeSentinel(u8, kv.key_ptr.*, 0); defer vm.gc.allocator.free(dupped); try serialized_instance.set( diff --git a/src/renderer.zig b/src/renderer.zig index 75c7d6e8..47b6e192 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -157,12 +157,12 @@ pub const Renderer = struct { /// Returns the stricter of two minimum break priorities. fn stricterBreakPriority(left: BreakPriority, right: BreakPriority) BreakPriority { - return if (@intFromEnum(left) > @intFromEnum(right)) left else right; + return if (@backingInt(left) > @backingInt(right)) left else right; } /// Returns true when `priority` is allowed to introduce a width-based break. fn canBreakAt(self: *Self, priority: BreakPriority) bool { - return @intFromEnum(priority) >= @intFromEnum(self.minimum_break_priority); + return @backingInt(priority) >= @backingInt(self.minimum_break_priority); } /// Returns the width-break priority for a binary operator. @@ -471,7 +471,7 @@ pub const Renderer = struct { } fn renderExpectedToken(self: *Self, token: Ast.TokenIndex, expected: Token.Tag, space: Space) Error!void { - if (builtin.mode == .Debug and self.ast.tokens.items(.tag)[token] != expected) { + if (builtin.mode == .debug and self.ast.tokens.items(.tag)[token] != expected) { std.debug.print( "\nExpected {s} got {s} at {} `{s}`\n", .{ @@ -575,7 +575,7 @@ pub const Renderer = struct { if (space == .Semicolon or space == .Comma) self.ais.enableSpaceMode(space); defer self.ais.disableSpaceMode(); - if (builtin.mode == .Debug and has_next_token and offsets[next_token] < offsets[token] + lexeme_len) { + if (builtin.mode == .debug and has_next_token and offsets[next_token] < offsets[token] + lexeme_len) { std.debug.print( "\nToken overlap: {s}#{} at {}-{} {} `{s}` and {s}#{} at {}-{} {} `{s}`\n{s}\n", .{ diff --git a/src/repl.zig b/src/repl.zig index f965a278..fb48a201 100644 --- a/src/repl.zig +++ b/src/repl.zig @@ -37,7 +37,7 @@ pub fn printBanner(out: *std.Io.Writer, full: bool) void { .{ builtin.zig_version, @tagName(builtin.mode), - if (builtin.mode == .Debug or is_wasm) + if (builtin.mode == .debug or is_wasm) "gpa" else if (BuildOptions.mimalloc) "mimalloc" diff --git a/src/vm.zig b/src/vm.zig index 5e566231..e7b0f354 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -13,7 +13,7 @@ const JIT = if (!is_wasm) @import("Jit.zig") else void; const Token = @import("Token.zig"); const Reporter = @import("Reporter.zig"); const FFI = if (!is_wasm) @import("FFI.zig") else void; -const dispatch_call_modifier: std.builtin.CallModifier = if (!is_wasm) .always_tail else .auto; +const dispatch_call_modifier: std.lang.CallModifier = if (!is_wasm) .always_tail else .auto; const print = @import("io.zig").print; const Debugger = if (!is_wasm) @import("Debugger.zig") else void; const TypeRegistry = @import("TypeRegistry.zig"); @@ -655,11 +655,11 @@ pub const VM = struct { } pub fn getCode(instruction: u32) Chunk.OpCode { - return @enumFromInt(@as(u8, @intCast(instruction >> 24))); + return @fromBackingInt(@intCast(@as(u8, @intCast(instruction >> 24)))); } fn replaceCode(instruction: u32, new_code: Chunk.OpCode) u32 { - return (@as(u32, @intCast(@intFromEnum(new_code))) << 24) | @as(u32, @intCast(getArg(instruction))); + return (@as(u32, @intCast(@backingInt(new_code))) << 24) | @as(u32, @intCast(getArg(instruction))); } fn getArg(instruction: u32) u24 { @@ -5596,8 +5596,8 @@ pub const VM = struct { // In order to not fuck up any other ip absolute instructions (like OP_JUMP, etc.), we only put the revelant // new bytecode at the end of the range and jump to it. const hotspot_call = [_]u32{ - (@as(u32, @intCast(@intFromEnum(Chunk.OpCode.OP_CONSTANT))) << 24) | @as(u32, @intCast(constant)), - (@as(u32, @intCast(@intFromEnum(Chunk.OpCode.OP_HOTSPOT_CALL))) << 24), + (@as(u32, @intCast(@backingInt(Chunk.OpCode.OP_CONSTANT))) << 24) | @as(u32, @intCast(constant)), + (@as(u32, @intCast(@backingInt(Chunk.OpCode.OP_HOTSPOT_CALL))) << 24), }; try chunk.code.replaceRange( @@ -5620,14 +5620,14 @@ pub const VM = struct { const hotspot_call_start = to - hotspot_call.len; // In the event that we are in a nested loop, we put a jump instruction in place of OP_HOTSPOT - chunk.code.items[frame.ip - 2] = (@as(u32, @intCast(@intFromEnum(Chunk.OpCode.OP_JUMP))) << 24) | @as( + chunk.code.items[frame.ip - 2] = (@as(u32, @intCast(@backingInt(Chunk.OpCode.OP_JUMP))) << 24) | @as( u32, @intCast( hotspot_call_start - (frame.ip - 2) - 1, // -2 because OP_HOTSPOT has one more instruction for the node index ), ); // To avoid the disassembler being lost we replace the OP_HOTSPOT's node index instruction with OP_VOID - chunk.code.items[frame.ip - 1] = (@as(u32, @intCast(@intFromEnum(Chunk.OpCode.OP_VOID))) << 24); + chunk.code.items[frame.ip - 1] = (@as(u32, @intCast(@backingInt(Chunk.OpCode.OP_VOID))) << 24); // Jump to it frame.ip = hotspot_call_start; diff --git a/src/zigtypes.zig b/src/zigtypes.zig index be342fe2..2c2b045d 100644 --- a/src/zigtypes.zig +++ b/src/zigtypes.zig @@ -1,7 +1,7 @@ const std = @import("std"); -// std.builtin.Type can't be used at runtime, so we make our own non-comptime types -// We use std.builtin things when we can +// std.lang.Type can't be used at runtime, so we make our own non-comptime types +// We use std.lang things when we can pub const Type = union(enum) { Type: void, @@ -122,7 +122,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const IntType = struct { - signedness: std.builtin.Signedness, + signedness: std.lang.Signedness, bits: u16, }; @@ -135,11 +135,11 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const PointerType = struct { - size: std.builtin.Type.Pointer.Size, + size: std.lang.Type.Pointer.Size, is_const: bool, is_volatile: bool, alignment: u16, - address_space: std.builtin.AddressSpace, + address_space: std.lang.AddressSpace, child: *const Type, is_allowzero: bool, @@ -174,7 +174,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const StructType = struct { - layout: std.builtin.Type.ContainerLayout, + layout: std.lang.Type.ContainerLayout, /// Only valid if layout is .Packed backing_integer: ?*const Type = null, fields: []const StructField, @@ -232,7 +232,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const UnionType = struct { - layout: std.builtin.Type.ContainerLayout, + layout: std.lang.Type.ContainerLayout, tag_type: ?*const Type, fields: []const UnionField, decls: []const Declaration, @@ -241,7 +241,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const FnType = struct { - calling_convention: std.builtin.CallingConvention, + calling_convention: std.lang.CallingConvention, alignment: u16, is_generic: bool, is_var_args: bool,