diff --git a/.github/workflows/docker-shared.yml b/.github/workflows/docker-shared.yml index 618690b4a3..a2a0eb7cae 100644 --- a/.github/workflows/docker-shared.yml +++ b/.github/workflows/docker-shared.yml @@ -18,7 +18,7 @@ jobs: - uses: mlugg/setup-zig@v1 with: - version: 0.13.0 + version: 0.14.0 # # BUILD diff --git a/.github/workflows/shared.yml b/.github/workflows/shared.yml index 865cf3c847..6f2a55d585 100644 --- a/.github/workflows/shared.yml +++ b/.github/workflows/shared.yml @@ -74,7 +74,7 @@ jobs: - uses: mlugg/setup-zig@v1 with: - version: 0.13.0 + version: 0.14.0 - name: Build binaries run: | diff --git a/.gitignore b/.gitignore index f7267dc16c..69db6955cc 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,14 @@ MODULE.bazel MODULE.bazel.lock +# Zig **/.zig-cache **/zig-out +# clangd +**/.cache +compile_commands.json + # Swap files. *.swo *.swp diff --git a/INSTALL.md b/INSTALL.md index 6c01a93ce9..759a8069f1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -17,7 +17,7 @@ Additional targets: ## Prerequisites -Install version 0.13.0 of `zig` with the package manager of your choosing, e.g., `brew install zig`, or download the binary from [here][zig-download]. +Install version 0.14.0 of `zig` with the package manager of your choosing, e.g., `brew install zig`, or download the binary from [here][zig-download]. ### macOS debugger diff --git a/build.zig b/build.zig index ffeaf1307f..0cae4640e4 100644 --- a/build.zig +++ b/build.zig @@ -1,21 +1,25 @@ const std = @import("std"); -const VERSION = "3.3"; +const VERSION = "3.4"; -const main_targets = .{ +const main_targets: []const std.Target.Query = &[_]std.Target.Query{ .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = null }, .{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = null }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, }; -const supported_targets: []const std.Target.Query = &(main_targets ++ .{ +const supported_targets: []const std.Target.Query = &[_]std.Target.Query{ + .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = null }, + .{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = null }, + .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu, .glibc_version = std.SemanticVersion{ .major = 2, .minor = 27, .patch = 0 } }, -}); +}; -const targets: []const std.Target.Query = &main_targets; +const targets: []const std.Target.Query = main_targets; const BuildCfg = struct { version: []const u8, @@ -395,7 +399,7 @@ fn buildBinary( }); b.getInstallStep().dependOn(&target_output.step); - if (target.result.isDarwin() and !target.query.isNative()) { + if (target.result.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, @@ -425,7 +429,7 @@ fn buildBinary( urbit.linkLibrary(whereami.artifact("whereami")); urbit.linkLibrary(wasm3.artifact("wasm3")); - if (t.isDarwin()) { + if (t.os.tag.isDarwin()) { // Requires llvm@18 homebrew installation if (cfg.asan or cfg.ubsan) urbit.addLibraryPath(.{ @@ -582,7 +586,7 @@ fn buildBinary( .optimize = optimize, }); - if (t.isDarwin() and !target.query.isNative()) { + if (t.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, diff --git a/build.zig.zon b/build.zig.zon index a038ed9e12..02726c661c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,10 +1,11 @@ .{ - .name = "urbit", + .name = .urbit, .version = "0.0.1", + .fingerprint = 0x9e228a3003a2736b, .dependencies = .{ .macos_sdk = .{ .url = "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz", - .hash = "122033a9c16c63f66ba4c83d6c61f487b06a6435ed57201eaccb4c5703ce4cdd956e", + .hash = "N-V-__8AAKtK4FMzqcFsY_ZrpMg9bGH0h7BqZDXtVyAerMtM", .lazy = true, }, .pkg_c3 = .{ @@ -54,7 +55,7 @@ }, .zlib = .{ .url = "https://github.com/allyourcodebase/zlib/archive/0918e87b7629b9c6a50a08edd0ce30d849758faf.tar.gz", - .hash = "122034ab2a12adf8016ffa76e48b4be3245ffd305193edba4d83058adbcfa749c107", + .hash = "zlib-1.3.1-AAAAACEMAAA0qyoSrfgBb_p25ItL4yRf_TBRk-26TYMF", }, .wasm3 = .{ .path = "./ext/wasm3", diff --git a/ext/avahi/build.zig b/ext/avahi/build.zig index 44fe568090..a389a95633 100644 --- a/ext/avahi/build.zig +++ b/ext/avahi/build.zig @@ -538,7 +538,7 @@ pub fn build(b: *std.Build) void { avahi.root_module.addCMacro("HAVE_DBUS_CONNECTION_CLOSE", "0"); avahi.root_module.addCMacro("HAVE_EXPAT_H", "1"); avahi.root_module.addCMacro("HAVE_CONFIG_H", "1"); - if (!t.isGnu()) + if (!t.isGnuLibC()) avahi.root_module.addCMacro("HAVE_STRLCPY", "1"); const avahi_config_h = b.addConfigHeader(.{ diff --git a/ext/avahi/build.zig.zon b/ext/avahi/build.zig.zon index 47ff422e19..58ac25b4e2 100644 --- a/ext/avahi/build.zig.zon +++ b/ext/avahi/build.zig.zon @@ -4,15 +4,16 @@ .dependencies = .{ .avahi = .{ .url = "https://github.com/lathiat/avahi/releases/download/v0.8/avahi-0.8.tar.gz", - .hash = "1220df62c88bd00f3a397a83b5fc8b4ab657884bbc452a653892790ce213aa6fd900", + .hash = "N-V-__8AAOLVeQDfYsiL0A86OXqDtfyLSrZXiEu8RSplOJJ5", }, .dbus = .{ - .url = "https://src.fedoraproject.org/repo/pkgs/dbus/dbus-1.14.8.tar.xz/sha512/f3dfc73da28cbe20449d15bbe4166c3574f0e551dfd15fca7cce2b8c71e778360ed2dd391ee5c414a7a47ff4b958727b26ef4cabfee70564f8d0a34bf5ad2386/dbus-1.14.8.tar.xz", - .hash = "122083df329bed83b1383e11ff9d40038d643730f7d610f002608d9a48c4500719a3", + .url = "https://distfiles.alpinelinux.org/distfiles/v3.17/dbus-1.14.8.tar.xz", + // .url = "https://src.fedoraproject.org/repo/pkgs/dbus/dbus-1.14.8.tar.xz/sha512/f3dfc73da28cbe20449d15bbe4166c3574f0e551dfd15fca7cce2b8c71e778360ed2dd391ee5c414a7a47ff4b958727b26ef4cabfee70564f8d0a34bf5ad2386/dbus-1.14.8.tar.xz", + .hash = "N-V-__8AAEB_jACD3zKb7YOxOD4R_51AA41kNzD31hDwAmCN", }, .expat = .{ .url = "https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-2.5.0.tar.xz", - .hash = "1220b1874d568d61688789eb2f1f2fe1ed06f66bb0480000df645c476472e31ae30f", + .hash = "N-V-__8AABFoMgCxh01WjWFoh4nrLx8v4e0G9muwSAAA32Rc", }, }, .paths = .{ diff --git a/ext/backtrace/build.zig b/ext/backtrace/build.zig index d18947984c..84645dc3fe 100644 --- a/ext/backtrace/build.zig +++ b/ext/backtrace/build.zig @@ -81,7 +81,7 @@ pub fn build(b: *std.Build) void { ._POSIX_SOURCE = null, }); - if (t.isDarwin()) { + if (t.os.tag.isDarwin()) { config_h.addValues(.{ .HAVE_MACH_O_DYLD_H = 1, }); diff --git a/ext/backtrace/build.zig.zon b/ext/backtrace/build.zig.zon index f42f65d6a2..13b1682b98 100644 --- a/ext/backtrace/build.zig.zon +++ b/ext/backtrace/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .backtrace = .{ .url = "https://github.com/ianlancetaylor/libbacktrace/archive/4ead348bb45f753121ca0bd44170ff8352d4c514.tar.gz", - .hash = "12205a46d567bd07761595d56787a1abb487c321e204bf3148e3657203bb2329160e", + .hash = "N-V-__8AADzSKgBaRtVnvQd2FZXVZ4ehq7SHwyHiBL8xSONl", }, }, .paths = .{ diff --git a/ext/curl/build.zig b/ext/curl/build.zig index f1493380ff..9ba69f907c 100644 --- a/ext/curl/build.zig +++ b/ext/curl/build.zig @@ -70,12 +70,9 @@ pub fn build(b: *std.Build) void { if (target.result.os.tag == .windows) { curl.linkSystemLibrary("bcrypt"); } else { - curl.root_module.addCMacro( - "CURL_EXTERN_SYMBOL", - "__attribute__ ((__visibility__ (\"default\"))" - ); + curl.root_module.addCMacro("CURL_EXTERN_SYMBOL", "__attribute__ ((__visibility__ (\"default\"))"); - const isDarwin = target.result.isDarwin(); + const isDarwin = target.result.os.tag.isDarwin(); if (!isDarwin) curl.root_module.addCMacro("ENABLE_IPV6", "1"); curl.root_module.addCMacro("HAVE_ALARM", "1"); diff --git a/ext/curl/build.zig.zon b/ext/curl/build.zig.zon index 12ae0e3db9..cae43971c7 100644 --- a/ext/curl/build.zig.zon +++ b/ext/curl/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .curl = .{ .url = "https://github.com/curl/curl/releases/download/curl-8_9_1/curl-8.9.1.tar.gz", - .hash = "1220f36375f7a423b8dc41b14612d685f48e030b25d0f6eb69011179e9b68e4584e0", + .hash = "N-V-__8AAFnEQQHzY3X3pCO43EGxRhLWhfSOAwsl0PbraQER", }, .openssl = .{ .path = "../openssl", diff --git a/ext/gmp/build.zig.zon b/ext/gmp/build.zig.zon index 47538723d8..8925443e6f 100644 --- a/ext/gmp/build.zig.zon +++ b/ext/gmp/build.zig.zon @@ -3,8 +3,8 @@ .version = "0.0.1", .dependencies = .{ .gmp = .{ - .url = "https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.gz", - .hash = "1220d46202c17aa35ab5848a7f7a812b797c9f07698f263c8a02b4ad9640a1bbe0e3", + .url = "https://ftp.fr.openbsd.org/pub/OpenBSD/distfiles/gmp-6.3.0.tar.xz", + .hash = "N-V-__8AAE5fAwHUYgLBeqNatYSKf3qBK3l8nwdpjyY8igK0", }, }, .paths = .{ diff --git a/ext/h2o/build.zig b/ext/h2o/build.zig index c2bfc15b41..0149ef8bf4 100644 --- a/ext/h2o/build.zig +++ b/ext/h2o/build.zig @@ -55,7 +55,7 @@ pub fn build(b: *std.Build) !void { .files = &.{"cloexec.c"}, .flags = &.{ "-fno-sanitize=all", - if (t.isGnu()) + if (t.isGnuLibC()) "-D_GNU_SOURCE" else "", diff --git a/ext/h2o/build.zig.zon b/ext/h2o/build.zig.zon index aba19ec223..ba1f83d6b0 100644 --- a/ext/h2o/build.zig.zon +++ b/ext/h2o/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .h2o = .{ .url = "https://github.com/h2o/h2o/archive/refs/tags/v2.2.6.tar.gz", - .hash = "12206fb50c715a131282752c7cd92abe3f5647f3ac28ae5c56fdd231896c44fdb86d", + .hash = "N-V-__8AAFCFqAJvtQxxWhMSgnUsfNkqvj9WR_OsKK5cVv3S", }, .libuv = .{ .path = "../libuv", @@ -17,11 +17,11 @@ }, .zlib = .{ .url = "https://github.com/allyourcodebase/zlib/archive/0918e87b7629b9c6a50a08edd0ce30d849758faf.tar.gz", - .hash = "122034ab2a12adf8016ffa76e48b4be3245ffd305193edba4d83058adbcfa749c107", + .hash = "zlib-1.3.1-AAAAACEMAAA0qyoSrfgBb_p25ItL4yRf_TBRk-26TYMF", }, .sse2neon = .{ .url = "https://github.com/DLTcollab/sse2neon/archive/refs/tags/v1.5.1.tar.gz", - .hash = "1220ced40ef8af4a4565aa1a7de678d43478df9b26483c062db2dbdc58b42c822268", + .hash = "N-V-__8AAPihCgDO1A74r0pFZaoafeZ41DR435smSDwGLbLb", }, .patches = .{ .path = "./patches", diff --git a/ext/libuv/build.zig.zon b/ext/libuv/build.zig.zon index d8a37a7409..a0c83dc76d 100644 --- a/ext/libuv/build.zig.zon +++ b/ext/libuv/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .libuv = .{ .url = "https://dist.libuv.org/dist/v1.50.0/libuv-v1.50.0.tar.gz", - .hash = "12207ac22e5e40afe515b7c319237785113c97ee84a75f7c66c1a0e7cc6e743debeb", + .hash = "N-V-__8AAH34QwB6wi5eQK_lFbfDGSN3hRE8l-6Ep198ZsGg", }, }, .paths = .{ diff --git a/ext/lmdb/build.zig.zon b/ext/lmdb/build.zig.zon index 142bd2d99b..8e874310f2 100644 --- a/ext/lmdb/build.zig.zon +++ b/ext/lmdb/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .lmdb = .{ .url = "https://github.com/LMDB/lmdb/archive/refs/tags/LMDB_0.9.29.tar.gz", - .hash = "122008e42c2b9e46f8251038a22f7968dddc17ad2ec9c278d9032014073c0f584fac", + .hash = "N-V-__8AAHEmCAAI5Cwrnkb4JRA4oi95aN3cF60uycJ42QMg", }, }, .paths = .{ diff --git a/ext/murmur3/build.zig.zon b/ext/murmur3/build.zig.zon index c4f0ec46e5..05ab23ecaa 100644 --- a/ext/murmur3/build.zig.zon +++ b/ext/murmur3/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .murmur3 = .{ .url = "https://github.com/PeterScott/murmur3/archive/dae94be0c0f54a399d23ea6cbe54bca5a4e93ce4.tar.gz", - .hash = "12201b70bb970bb8e197936edd9be02fa67699d517515c8077031affc4f25226dcdf", + .hash = "N-V-__8AABE5AAAbcLuXC7jhl5Nu3ZvgL6Z2mdUXUVyAdwMa", }, }, .paths = .{ diff --git a/ext/natpmp/build.zig.zon b/ext/natpmp/build.zig.zon index 76d822b995..038468f39f 100644 --- a/ext/natpmp/build.zig.zon +++ b/ext/natpmp/build.zig.zon @@ -3,8 +3,9 @@ .version = "0.0.1", .dependencies = .{ .natpmp = .{ - .url = "https://debian.mirror.root.lu/debian/pool/main/libn/libnatpmp/libnatpmp_20230423.orig.tar.gz", - .hash = "12203f777796f1df1db24c4194bcc6060d2a7bee2eea88527c2336bbf455d4108239", + .url = "https://mirrors.wikimedia.org/ubuntu/ubuntu/pool/main/libn/libnatpmp/libnatpmp_20230423.orig.tar.gz", + // .url = "https://debian.mirror.root.lu/debian/pool/main/libn/libnatpmp/libnatpmp_20230423.orig.tar.gz", + .hash = "N-V-__8AAKudAQA_d3eW8d8dskxBlLzGBg0qe-4u6ohSfCM2", }, }, .paths = .{ diff --git a/ext/openssl/build.zig b/ext/openssl/build.zig index 54187fd8cf..12d57ac5dd 100644 --- a/ext/openssl/build.zig +++ b/ext/openssl/build.zig @@ -18,9 +18,9 @@ pub fn build(b: *std.Build) !void { b, target, optimize, - if (target.result.isDarwin()) &macos_cflags else &linux_cflags, + if (target.result.os.tag.isDarwin()) &macos_cflags else &linux_cflags, ); - if (target.result.isDarwin() and !target.query.isNative()) { + if (target.result.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, @@ -37,7 +37,7 @@ pub fn build(b: *std.Build) !void { b, target, optimize, - if (target.result.isDarwin()) &macos_cflags else &linux_cflags, + if (target.result.os.tag.isDarwin()) &macos_cflags else &linux_cflags, )); } @@ -76,13 +76,6 @@ fn libcrypto( lib.addIncludePath(dep.path("crypto/modes")); lib.addIncludePath(dep.path("include")); - // lib.root_module.addCMacro("__APPLE__", ""); - // lib.root_module.addCMacro("__ARMEB__", ""); - if (t.cpu.arch.isAARCH64()) - lib.root_module.addCMacro("__ILP32__", ""); - // lib.root_module.addCMacro("__AARCH64EB__", ""); - // lib.root_module.addCMacro("__KERNEL__", ""); - lib.root_module.addCMacro("L_ENDIAN", ""); lib.root_module.addCMacro("OPENSSL_PIC", ""); lib.root_module.addCMacro("OPENSSL_CPUID_OBJ", ""); @@ -113,7 +106,7 @@ fn libcrypto( // lib.root_module.addCMacro("OPENSSL_NO_STDIO", ""); // lib.root_module.addCMacro("OSSL_PKEY_PARAM_RSA_DERIVE_FROM_PQ", "1"); - if (t.isDarwin() and t.cpu.arch.isAARCH64()) { + if (t.os.tag.isDarwin() and t.cpu.arch.isAARCH64()) { lib.addIncludePath(b.path("gen/macos-aarch64/include")); lib.addIncludePath(b.path("gen/macos-aarch64/include/crypto")); lib.addIncludePath(b.path("gen/macos-aarch64/include/openssl")); @@ -163,7 +156,7 @@ fn libcrypto( }); } - if (t.isDarwin() and t.cpu.arch == .x86_64) { + if (t.os.tag.isDarwin() and t.cpu.arch == .x86_64) { lib.addIncludePath(b.path("gen/macos-x86_64/include")); lib.addIncludePath(b.path("gen/macos-x86_64/include/crypto")); lib.addIncludePath(b.path("gen/macos-x86_64/include/openssl")); @@ -329,7 +322,7 @@ fn libssl( lib.addIncludePath(dep.path("include/internal")); lib.addIncludePath(dep.path("include/openssl")); - if (t.isDarwin() and t.cpu.arch.isAARCH64()) { + if (t.os.tag.isDarwin() and t.cpu.arch.isAARCH64()) { lib.addIncludePath(b.path("gen/macos-aarch64/include")); lib.addIncludePath(b.path("gen/macos-aarch64/include/openssl")); lib.installHeadersDirectory(b.path("gen/macos-aarch64/include/openssl"), "openssl", .{}); @@ -341,7 +334,7 @@ fn libssl( lib.installHeadersDirectory(b.path("gen/linux-aarch64/include/openssl"), "openssl", .{}); } - if (t.isDarwin() and t.cpu.arch == .x86_64) { + if (t.os.tag.isDarwin() and t.cpu.arch == .x86_64) { lib.addIncludePath(b.path("gen/macos-x86_64/include")); lib.addIncludePath(b.path("gen/macos-x86_64/include/openssl")); lib.installHeadersDirectory(b.path("gen/macos-x86_64/include/openssl"), "openssl", .{}); @@ -353,8 +346,8 @@ fn libssl( lib.installHeadersDirectory(b.path("gen/linux-x86_64/include/openssl"), "openssl", .{}); } - lib.defineCMacro("OPENSSLDIR", "\"\""); - lib.defineCMacro("ENGINESDIR", "\"\""); + lib.root_module.addCMacro("OPENSSLDIR", "\"\""); + lib.root_module.addCMacro("ENGINESDIR", "\"\""); lib.addCSourceFiles(.{ .root = dep.path(""), diff --git a/ext/openssl/build.zig.zon b/ext/openssl/build.zig.zon index 6d9fe0d23f..57d01714af 100644 --- a/ext/openssl/build.zig.zon +++ b/ext/openssl/build.zig.zon @@ -1,15 +1,16 @@ .{ - .name = "openssl", + .name = .openssl, + .fingerprint = 0x773a47f1e2d96f2e, .version = "0.0.1", .dependencies = .{ .macos_sdk = .{ .url = "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz", - .hash = "122033a9c16c63f66ba4c83d6c61f487b06a6435ed57201eaccb4c5703ce4cdd956e", + .hash = "N-V-__8AAKtK4FMzqcFsY_ZrpMg9bGH0h7BqZDXtVyAerMtM", .lazy = true, }, .openssl = .{ .url = "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz", - .hash = "122042b0a69fc3deee3c603b11046f15693046e5cfcf56858e028b9ea4dc4b78b81a", + .hash = "N-V-__8AANidegJCsKafw97uPGA7EQRvFWkwRuXPz1aFjgKL", }, }, .paths = .{ diff --git a/ext/openssl/gen/macos-aarch64/crypto/chacha/chacha-armv8.S b/ext/openssl/gen/macos-aarch64/crypto/chacha/chacha-armv8.S index 81e4da5ac3..3bf82d69af 100644 --- a/ext/openssl/gen/macos-aarch64/crypto/chacha/chacha-armv8.S +++ b/ext/openssl/gen/macos-aarch64/crypto/chacha/chacha-armv8.S @@ -14,7 +14,7 @@ LOPENSSL_armcap_P: #ifdef __ILP32__ .long _OPENSSL_armcap_P-. #else -.quad _OPENSSL_armcap_P-. +.quad ARMV7_NEON #endif .byte 67,104,97,67,104,97,50,48,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 diff --git a/ext/openssl/gen/macos-aarch64/crypto/poly1305/poly1305-armv8.S b/ext/openssl/gen/macos-aarch64/crypto/poly1305/poly1305-armv8.S index 1729cec6d2..32e46864ed 100644 --- a/ext/openssl/gen/macos-aarch64/crypto/poly1305/poly1305-armv8.S +++ b/ext/openssl/gen/macos-aarch64/crypto/poly1305/poly1305-armv8.S @@ -863,7 +863,7 @@ LOPENSSL_armcap_P: #ifdef __ILP32__ .long _OPENSSL_armcap_P-. #else -.quad _OPENSSL_armcap_P-. +.quad ARMV7_NEON #endif .byte 80,111,108,121,49,51,48,53,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 diff --git a/ext/openssl/gen/macos-aarch64/crypto/sha/sha1-armv8.S b/ext/openssl/gen/macos-aarch64/crypto/sha/sha1-armv8.S index d64987d2fa..d5a5fc6d41 100644 --- a/ext/openssl/gen/macos-aarch64/crypto/sha/sha1-armv8.S +++ b/ext/openssl/gen/macos-aarch64/crypto/sha/sha1-armv8.S @@ -1214,7 +1214,7 @@ LOPENSSL_armcap_P: #ifdef __ILP32__ .long _OPENSSL_armcap_P-. #else -.quad _OPENSSL_armcap_P-. +.quad ARMV7_NEON #endif .byte 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 diff --git a/ext/openssl/gen/macos-aarch64/crypto/sha/sha256-armv8.S b/ext/openssl/gen/macos-aarch64/crypto/sha/sha256-armv8.S index 7936328dac..2439362b89 100644 --- a/ext/openssl/gen/macos-aarch64/crypto/sha/sha256-armv8.S +++ b/ext/openssl/gen/macos-aarch64/crypto/sha/sha256-armv8.S @@ -1069,7 +1069,7 @@ LOPENSSL_armcap_P: # ifdef __ILP32__ .long _OPENSSL_armcap_P-. # else -.quad _OPENSSL_armcap_P-. +.quad ARMV7_NEON # endif #endif .byte 83,72,65,50,53,54,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 diff --git a/ext/openssl/gen/macos-aarch64/crypto/sha/sha512-armv8.S b/ext/openssl/gen/macos-aarch64/crypto/sha/sha512-armv8.S index 2460c4ad45..aa812a09d1 100644 --- a/ext/openssl/gen/macos-aarch64/crypto/sha/sha512-armv8.S +++ b/ext/openssl/gen/macos-aarch64/crypto/sha/sha512-armv8.S @@ -1091,7 +1091,7 @@ LOPENSSL_armcap_P: # ifdef __ILP32__ .long _OPENSSL_armcap_P-. # else -.quad _OPENSSL_armcap_P-. +.quad ARMV7_NEON # endif #endif .byte 83,72,65,53,49,50,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 diff --git a/ext/pdjson/build.zig.zon b/ext/pdjson/build.zig.zon index 142e2d3e30..1774d5b1a6 100644 --- a/ext/pdjson/build.zig.zon +++ b/ext/pdjson/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .pdjson = .{ .url = "https://github.com/skeeto/pdjson/archive/67108d883061043e55d0fb13961ac1b6fc8a485c.tar.gz", - .hash = "1220a7789c7b4539bd1ee8bb182609d9076ff19fc25026c9a61ca2df624d3170a7b0", + .hash = "N-V-__8AADC9AACneJx7RTm9Hui7GCYJ2Qdv8Z_CUCbJphyi", }, }, .paths = .{ diff --git a/ext/sigsegv/build.zig b/ext/sigsegv/build.zig index cfc7c0f6cb..d7f885967b 100644 --- a/ext/sigsegv/build.zig +++ b/ext/sigsegv/build.zig @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - if (target.result.isDarwin() and !target.query.isNative()) { + if (target.result.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, @@ -30,7 +30,7 @@ pub fn build(b: *std.Build) void { lib.linkLibC(); - lib.defineCMacro("HAVE_CONFIG_H", null); + lib.root_module.addCMacro("HAVE_CONFIG_H", &[_]u8{}); const config_h = b.addConfigHeader(.{ .style = .{ diff --git a/ext/sigsegv/build.zig.zon b/ext/sigsegv/build.zig.zon index 1ef5aaafd7..39f2c583a2 100644 --- a/ext/sigsegv/build.zig.zon +++ b/ext/sigsegv/build.zig.zon @@ -4,12 +4,12 @@ .dependencies = .{ .macos_sdk = .{ .url = "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz", - .hash = "122033a9c16c63f66ba4c83d6c61f487b06a6435ed57201eaccb4c5703ce4cdd956e", + .hash = "N-V-__8AAKtK4FMzqcFsY_ZrpMg9bGH0h7BqZDXtVyAerMtM", .lazy = true, }, .sigsegv = .{ - .url = "https://ftp.gnu.org/gnu/libsigsegv/libsigsegv-2.14.tar.gz", - .hash = "122082332294b5084ed0032c635f36227fb0408c175617a73aa9798036ead4c22c79", + .url = "https://ftp.fr.openbsd.org/pub/OpenBSD/distfiles/libsigsegv-2.14.tar.gz", + .hash = "N-V-__8AAHQhHwCCMyKUtQhO0AMsY182In-wQIwXVhenOql5", }, }, .paths = .{ diff --git a/ext/softblas/build.zig.zon b/ext/softblas/build.zig.zon index 431171b53b..a05aa5f8e8 100644 --- a/ext/softblas/build.zig.zon +++ b/ext/softblas/build.zig.zon @@ -7,7 +7,7 @@ }, .softblas = .{ .url = "https://github.com/urbit/SoftBLAS/archive/cbffb33f19ea02f9ffbd184d445123c57929ec53.tar.gz", - .hash = "1220617c11d869ef2316571a430f51f93470e2d714141deb3bdfaa6b578cf151f258", + .hash = "N-V-__8AAJD5MgBhfBHYae8jFlcaQw9R-TRw4tcUFB3rO9-q", }, }, .paths = .{ diff --git a/ext/softfloat/build.zig.zon b/ext/softfloat/build.zig.zon index fcb318807a..11f753d89d 100644 --- a/ext/softfloat/build.zig.zon +++ b/ext/softfloat/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .softfloat = .{ .url = "https://github.com/ucb-bar/berkeley-softfloat-3/archive/5c06db33fc1e2130f67c045327b0ec949032df1d.tar.gz", - .hash = "1220a4d2ebf2da3f160133eb6caf4a99b9e7b9879820de8f3bd9e56b2448c5688a07", + .hash = "N-V-__8AAJjNHACk0uvy2j8WATPrbK9KmbnnuYeYIN6PO9nl", }, }, .paths = .{ diff --git a/ext/unwind/build.zig.zon b/ext/unwind/build.zig.zon index 1ec070d557..5ebfff4aad 100644 --- a/ext/unwind/build.zig.zon +++ b/ext/unwind/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .unwind = .{ .url = "https://github.com/libunwind/libunwind/archive/7cc4c20fbcf65a9c855fb9d950fad8d0e29b092e.tar.gz", - .hash = "1220c7280ef49dc581a2f8ba029c58380410b9bbb1701afacba13205324d2ec8225a", + .hash = "N-V-__8AAA54RADHKA70ncWBovi6ApxYOAQQubuxcBr6y6Ey", }, }, .paths = .{ diff --git a/ext/urcrypt/build.zig.zon b/ext/urcrypt/build.zig.zon index a7866adde4..e32b027102 100644 --- a/ext/urcrypt/build.zig.zon +++ b/ext/urcrypt/build.zig.zon @@ -4,18 +4,18 @@ .dependencies = .{ .aes_siv = .{ .url = "https://github.com/dfoxfranke/libaes_siv/archive/9681279cfaa6e6399bb7ca3afbbc27fc2e19df4b.tar.gz", - .hash = "1220a898068525a4bda3be4139c68555ec3a9cef03ed94c63115dde4a5204126f69a", + .hash = "N-V-__8AADRgAQComAaFJaS9o75BOcaFVew6nO8D7ZTGMRXd", }, .openssl = .{ .path = "../openssl", }, .secp256k1 = .{ .url = "https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.5.1.tar.gz", - .hash = "1220bb683a6df744e618f58a008eaae3eb62b70a78334cec676bd82b1b9e8e944eeb", + .hash = "N-V-__8AAJ4DSwC7aDpt90TmGPWKAI6q4-titwp4M0zsZ2vY", }, .urcrypt = .{ .url = "https://github.com/urbit/urcrypt/archive/465aad6262f2710f76f75adfe74effb5751c5ab3.tar.gz", - .hash = "1220c0f7141ab0aeb4164c5c2ae42848035e5b2fdff52c66c57d5744e3e3751e12c8", + .hash = "N-V-__8AAL3OSQDA9xQasK60FkxcKuQoSANeWy_f9SxmxX1X", }, }, .paths = .{ diff --git a/ext/wasm3/build.zig.zon b/ext/wasm3/build.zig.zon index 55d9473907..d669115ee0 100644 --- a/ext/wasm3/build.zig.zon +++ b/ext/wasm3/build.zig.zon @@ -8,7 +8,7 @@ .wasm3 = .{ // .path = "../../../../wasm3" .url = "https://github.com/urbit/wasm3/archive/5b74cbca01793cda71ebf707b0587616c32cc88c.tar.gz", - .hash = "12200fb06246d1956d73684cddbf84e819e4a0d7b1817bf5934b836466d194e3c60d", + .hash = "N-V-__8AAMKiSAAPsGJG0ZVtc2hM3b-E6BnkoNexgXv1k0uD", }, }, .paths = .{ diff --git a/ext/whereami/build.zig.zon b/ext/whereami/build.zig.zon index 82294555eb..42cb792b2e 100644 --- a/ext/whereami/build.zig.zon +++ b/ext/whereami/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .whereami = .{ .url = "https://github.com/gpakosz/whereami/archive/ba364cd54fd431c76c045393b6522b4bff547f50.tar.gz", - .hash = "122044406f3ffcdba6c41cdcbf8c2cfe3197db3560c6f1baa7a82c651a8a20dac35b", + .hash = "N-V-__8AALQtAQBEQG8__NumxBzcv4ws_jGX2zVgxvG6p6gs", }, }, .paths = .{ diff --git a/pkg/c3/build.zig b/pkg/c3/build.zig index 866007559f..387a3bcd0c 100644 --- a/pkg/c3/build.zig +++ b/pkg/c3/build.zig @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - if (target.result.isDarwin() and !target.query.isNative()) { + if (target.result.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, diff --git a/pkg/c3/build.zig.zon b/pkg/c3/build.zig.zon index 4e62a8027c..857a5164dc 100644 --- a/pkg/c3/build.zig.zon +++ b/pkg/c3/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .macos_sdk = .{ .url = "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz", - .hash = "122033a9c16c63f66ba4c83d6c61f487b06a6435ed57201eaccb4c5703ce4cdd956e", + .hash = "N-V-__8AAKtK4FMzqcFsY_ZrpMg9bGH0h7BqZDXtVyAerMtM", .lazy = true, }, }, diff --git a/pkg/noun/build.zig b/pkg/noun/build.zig index c46f1029ab..1e7ffd947f 100644 --- a/pkg/noun/build.zig +++ b/pkg/noun/build.zig @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); - if (target.result.isDarwin() and !target.query.isNative()) { + if (target.result.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, @@ -139,7 +139,7 @@ pub fn build(b: *std.Build) !void { var flags = std.ArrayList([]const u8).init(b.allocator); defer flags.deinit(); try flags.appendSlice(&.{ - "-pedantic", + // "-pedantic", "-std=gnu23", }); try flags.appendSlice(copts); diff --git a/pkg/noun/build.zig.zon b/pkg/noun/build.zig.zon index 3982a2a467..7b4c408a16 100644 --- a/pkg/noun/build.zig.zon +++ b/pkg/noun/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .macos_sdk = .{ .url = "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz", - .hash = "122033a9c16c63f66ba4c83d6c61f487b06a6435ed57201eaccb4c5703ce4cdd956e", + .hash = "N-V-__8AAKtK4FMzqcFsY_ZrpMg9bGH0h7BqZDXtVyAerMtM", .lazy = true, }, .pkg_c3 = .{ @@ -51,7 +51,7 @@ }, .zlib = .{ .url = "https://github.com/allyourcodebase/zlib/archive/0918e87b7629b9c6a50a08edd0ce30d849758faf.tar.gz", - .hash = "122034ab2a12adf8016ffa76e48b4be3245ffd305193edba4d83058adbcfa749c107", + .hash = "zlib-1.3.1-AAAAACEMAAA0qyoSrfgBb_p25ItL4yRf_TBRk-26TYMF", }, .wasm3 = .{ .path = "../../ext/wasm3", diff --git a/pkg/noun/urth.c b/pkg/noun/urth.c index 6eb6f8fcc3..81c542da8a 100644 --- a/pkg/noun/urth.c +++ b/pkg/noun/urth.c @@ -12,6 +12,7 @@ #include "imprison.h" #include "jets.h" #include "manage.h" +#include "options.h" #include "retrieve.h" #include "serial.h" #include "ur/ur.h" @@ -460,6 +461,136 @@ u3u_meld(void) } #endif +/* BEGIN helper functions for u3u_melt + ------------------------------------------------------------------- +*/ +/* _cj_warm_tap(): tap war_p to rel +*/ +static void +_cj_warm_tap(u3_noun kev, void* wit) +{ + u3_noun* rel = wit; + *rel = u3nc(u3k(kev), *rel); +} + +static inline u3_weak +_cu_melt_get(u3p(u3h_root) set_p, u3_noun som) +{ + u3_post hav_p = u3h_git(set_p, som); + + if ( u3_none == hav_p ) { + return u3_none; + } + + // restore tag bits from [som] + // + return (hav_p >> u3a_vits) | (som & 0xc0000000); +} + +static inline void +_cu_melt_put(u3p(u3h_root) set_p, u3_noun som) +{ + // strip tag bits from [som] to skip refcounts + // + u3_post hav_p = u3a_to_off(som); + u3h_put(set_p, som, hav_p); +} + +static void +_cu_melt_noun(u3p(u3h_root) set_p, u3_noun* mos) +{ + u3_noun som = *mos; + u3_weak hav; + + // skip direct atoms + // + if ( c3y == u3a_is_cat(som) ) { + return; + } + + // [som] equals [hav], and [hav] is canonical + // + if ( u3_none != (hav = _cu_melt_get(set_p, som)) ) { + if ( hav != som ) { + u3z(som); + *mos = u3k(hav); + } + return; + } + + // traverse subtrees + // + if ( c3y == u3a_is_cell(som) ) { + u3a_cell *cel_u = u3a_to_ptr(som); + _cu_melt_noun(set_p, &cel_u->hed); + _cu_melt_noun(set_p, &cel_u->tel); + } + + // [som] is canonical + // + _cu_melt_put(set_p, som); +} + +/* u3u_melt(): globally deduplicate memory and pack in-place. +*/ +c3_w +u3u_melt(void) +{ + c3_w pre_w = u3a_open(u3R); + + // Verify that we're on the main road. + // + u3_assert( &(u3H->rod_u) == u3R ); + + // Store a cons list of the cold jet registrations in `cod` + // + u3_noun cod = u3_nul; + u3h_walk_with(u3R->jed.cod_p, _cj_warm_tap, &cod); + + u3m_reclaim(); // refresh the byte-code interpreter. + + u3h_free(u3R->cax.per_p); + u3R->cax.per_p = u3h_new_cache(u3C.per_w); + + u3h_free(u3R->jed.cod_p); + u3R->jed.cod_p = u3h_new(); + + { + u3p(u3h_root) set_p = u3h_new(); // temp hashtable + + _cu_melt_noun(set_p, &cod); // melt the jets + _cu_melt_noun(set_p, &u3A->roc); // melt the kernel + + u3h_free(set_p); // release the temp hashtable + } + + // re-initialize the jets + // + u3j_boot(c3y); + + // Put the jet registrations back. Loop over cod putting them back into the cold jet + // dashboard. Then re-run the garbage collector. + // + { + u3_noun codc = cod; + + while(u3_nul != cod) { + u3_noun kev = u3h(cod); + u3h_put(u3R->jed.cod_p, u3h(kev), u3k(u3t(kev))); + cod = u3t(cod); + } + + u3z(codc); + } + + // remove free space + // + u3j_ream(); + u3m_pack(); + + return (u3a_open(u3R) - pre_w); +} + /* _cu_rock_path(): format rock path. */ static c3_o diff --git a/pkg/noun/urth.h b/pkg/noun/urth.h index e2ab3e6f44..a11b9aa824 100644 --- a/pkg/noun/urth.h +++ b/pkg/noun/urth.h @@ -10,7 +10,12 @@ /* u3u_meld(): globally deduplicate memory, returns u3a_open delta. */ c3_w - u3u_meld(void); + u3u_meld(void) __attribute__ ((deprecated)); + + /* u3u_melt(): globally deduplicate memory and pack in-place. + */ + c3_w + u3u_melt(void) __attribute__ ((deprecated)); /* u3u_cram(): globably deduplicate memory, and write a rock to disk. */ diff --git a/pkg/vere/build.zig b/pkg/vere/build.zig index cb1668e175..119907ccbd 100644 --- a/pkg/vere/build.zig +++ b/pkg/vere/build.zig @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); - if (target.result.isDarwin() and !target.query.isNative()) { + if (target.result.os.tag.isDarwin() and !target.query.isNative()) { const macos_sdk = b.lazyDependency("macos_sdk", .{ .target = target, .optimize = optimize, @@ -224,6 +224,7 @@ const c_source_files = [_][]const u8{ "lord.c", "mars.c", "mdns.c", + "melt.c", "newt.c", "pier.c", "save.c", diff --git a/pkg/vere/build.zig.zon b/pkg/vere/build.zig.zon index bfcac8e59a..f368d3c55c 100644 --- a/pkg/vere/build.zig.zon +++ b/pkg/vere/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .macos_sdk = .{ .url = "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.sdk.tar.xz", - .hash = "122033a9c16c63f66ba4c83d6c61f487b06a6435ed57201eaccb4c5703ce4cdd956e", + .hash = "N-V-__8AAKtK4FMzqcFsY_ZrpMg9bGH0h7BqZDXtVyAerMtM", .lazy = true, }, .pkg_c3 = .{ @@ -48,7 +48,7 @@ }, .zlib = .{ .url = "https://github.com/allyourcodebase/zlib/archive/0918e87b7629b9c6a50a08edd0ce30d849758faf.tar.gz", - .hash = "122034ab2a12adf8016ffa76e48b4be3245ffd305193edba4d83058adbcfa749c107", + .hash = "zlib-1.3.1-AAAAACEMAAA0qyoSrfgBb_p25ItL4yRf_TBRk-26TYMF", }, }, .paths = .{ diff --git a/pkg/vere/main.c b/pkg/vere/main.c index a8469c10b8..f4463111d2 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -800,7 +800,8 @@ _cw_usage(c3_c* bin_c) " %s dock %.*s copy binary:\n", " %s grab %.*s measure memory usage:\n", " %s info %.*s print pier info:\n", - " %s meld %.*s deduplicate snapshot:\n", + " %s meld %.*s deduplicate and minimize snapshot:\n", + " %s melt %.*s deduplicate snapshot:\n", " %s pack %.*s defragment snapshot:\n", " %s play %.*s recompute events:\n", " %s prep %.*s prepare for upgrade:\n", @@ -2005,7 +2006,7 @@ _cw_queu(c3_i argc, c3_c* argv[]) } } -/* _cw_uniq(): deduplicate persistent nouns +/* _cw_meld(): canonicalize persistent nouns and compact state. */ static void _cw_meld(c3_i argc, c3_c* argv[]) @@ -2094,7 +2095,95 @@ _cw_meld(c3_i argc, c3_c* argv[]) u3_Host.eve_d = u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y); u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock - u3a_print_memory(stderr, "urbit: meld: gained", u3u_meld()); + u3a_print_memory(stderr, "urbit: meld: gained", u3_meld_all(stderr)); + + u3m_save(); + u3_disk_exit(log_u); + u3m_stop(); +} + +/* _cw_melt(): canonicalize persistent nouns. +*/ +static void +_cw_melt(c3_i argc, c3_c* argv[]) +{ + c3_i ch_i, lid_i; + c3_w arg_w; + + static struct option lop_u[] = { + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "gc-early", no_argument, NULL, 9 }, + { NULL, 0, NULL, 0 } + }; + + u3_Host.dir_c = _main_pier_run(argv[0]); + + while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) { + switch ( ch_i ) { + case c3__loom: { + if (_main_readw_loom("loom", &u3_Host.ops_u.lom_y)) { + exit(1); + } + } break; + + case 6: { // no-demand + u3_Host.ops_u.map = c3n; + u3C.wag_w |= u3o_no_demand; + } break; + + case 7: { // swap + u3_Host.ops_u.eph = c3y; + u3C.wag_w |= u3o_swap; + } break; + + case 8: { // swap-to + u3_Host.ops_u.eph = c3y; + u3C.wag_w |= u3o_swap; + u3C.eph_c = strdup(optarg); + break; + } + + case 9: { // gc-early + u3C.wag_w |= u3o_check_corrupt; + break; + } + + case '?': { + fprintf(stderr, "invalid argument\r\n"); + exit(1); + } break; + } + } + + // argv[optind] is always "melt" + // + + if ( !u3_Host.dir_c ) { + if ( optind + 1 < argc ) { + u3_Host.dir_c = argv[optind + 1]; + } + else { + fprintf(stderr, "invalid command, pier required\r\n"); + exit(1); + } + + optind++; + } + + if ( optind + 1 != argc ) { + fprintf(stderr, "invalid command\r\n"); + exit(1); + } + + u3C.wag_w |= u3o_hashless; + + u3_Host.eve_d = u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y); + u3_disk* log_u = _cw_disk_init(u3_Host.dir_c); // XX s/b try_aquire lock + + u3a_print_memory(stderr, "urbit: melt: gained", u3_melt_all(stderr)); u3m_save(); u3_disk_exit(log_u); @@ -3147,6 +3236,7 @@ _cw_utils(c3_i argc, c3_c* argv[]) case c3__info: _cw_info(argc, argv); return 1; case c3__meld: _cw_meld(argc, argv); return 1; + case c3__melt: _cw_melt(argc, argv); return 1; case c3__next: _cw_next(argc, argv); return 2; // continue on case c3__pack: _cw_pack(argc, argv); return 1; case c3__play: _cw_play(argc, argv); return 1; diff --git a/pkg/vere/mars.c b/pkg/vere/mars.c index 6d4af05420..17588c4ff1 100644 --- a/pkg/vere/mars.c +++ b/pkg/vere/mars.c @@ -190,24 +190,24 @@ _mars_do_boot(u3_disk* log_u, c3_d eve_d) // // XX support -J // - { - c3_d len_d = u3_Ivory_pill_len; - c3_y* byt_y = u3_Ivory_pill; - u3_cue_xeno* sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); - u3_weak pil; + /* { */ + /* c3_d len_d = u3_Ivory_pill_len; */ + /* c3_y* byt_y = u3_Ivory_pill; */ + /* u3_cue_xeno* sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); */ + /* u3_weak pil; */ - if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) { - u3l_log("lite: unable to cue ivory pill"); - exit(1); - } + /* if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) { */ + /* u3l_log("lite: unable to cue ivory pill"); */ + /* exit(1); */ + /* } */ - u3s_cue_xeno_done(sil_u); + /* u3s_cue_xeno_done(sil_u); */ - if ( c3n == u3v_boot_lite(pil)) { - u3l_log("lite: boot failed"); - exit(1); - } - } + /* if ( c3n == u3v_boot_lite(pil)) { */ + /* u3l_log("lite: boot failed"); */ + /* exit(1); */ + /* } */ + /* } */ u3l_log("--------------- bootstrap starting ----------------"); @@ -349,7 +349,7 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) // XX pack before meld? // if ( u3C.wag_w & u3o_auto_meld ) { - u3a_print_memory(stderr, "mars: meld: gained", u3u_meld()); + u3a_print_memory(stderr, "mars: meld: gained", u3_meld_all(stderr)); } else { u3a_print_memory(stderr, "mars: pack: gained", u3m_pack()); diff --git a/pkg/vere/melt.c b/pkg/vere/melt.c new file mode 100644 index 0000000000..113a08c317 --- /dev/null +++ b/pkg/vere/melt.c @@ -0,0 +1,217 @@ +#include "allocate.h" +#include "hashtable.h" +#include "jets.h" +#include "options.h" +#include "retrieve.h" +#include "vortex.h" + +static c3_d +_melt_hash(u3_noun foo) +{ + return u3r_mug(foo) * 11400714819323198485ULL; +} + +static c3_i +_melt_cmp_atoms(u3_atom a, u3_atom b) +{ + if ( a == b ) return 1; + + // XX assume(c3y == u3a_is_pug(a) && c3y == u3a_is_pug(b)) + u3a_atom *a_u = u3a_to_ptr(a); + u3a_atom *b_u = u3a_to_ptr(b); + + // XX assume( a_u->mug_w && b_u->mug_w ) + if ( a_u->mug_w != b_u->mug_w ) return 0; + + if ( a_u->len_w != b_u->len_w ) return 0; + + return 0 == memcmp(a_u->buf_w, b_u->buf_w, a_u->len_w << 2); +} + +#define NAME _coins +#define KEY_TY u3_atom +#define HASH_FN _melt_hash +#define CMPR_FN _melt_cmp_atoms +#include "verstable.h" + +static c3_i +_melt_cmp_cells(u3_cell a, u3_cell b) +{ + if ( a == b ) return 1; + + u3a_cell *a_u = u3a_to_ptr(a); + u3a_cell *b_u = u3a_to_ptr(b); + + // XX assume( a_u->mug_w && b_u->mug_w ) + if ( a_u->mug_w != b_u->mug_w ) return 0; + + c3_d *a_d = (c3_d*)&(a_u->hed); + c3_d *b_d = (c3_d*)&(b_u->hed); + + return *a_d == *b_d; +} + +#define NAME _cells +#define KEY_TY u3_cell +#define HASH_FN _melt_hash +#define CMPR_FN _melt_cmp_cells +#include "verstable.h" + +typedef struct { + _coins vat_u; + _cells cel_u; + c3_w len_w; + c3_w siz_w; + u3_noun *tac; +} _melt_ctx; + +static u3_noun +_melt_canon_next(_melt_ctx *can_u, u3_noun som) +{ + _coins_itr vit_u; + _cells_itr cit_u; + + while ( 1 ) { + if ( c3y == u3a_is_cat(som) ) return som; + + if ( c3n == u3a_is_cell(som) ) { + vit_u = vt_get_or_insert(&can_u->vat_u, som); + u3_assert( !vt_is_end(vit_u) ); // OOM + return vit_u.data->key; + } + + cit_u = vt_get(&can_u->cel_u, som); + if ( !vt_is_end(cit_u) ) return cit_u.data->key; + + if ( can_u->len_w == can_u->siz_w ) { + can_u->siz_w += c3_min(can_u->siz_w, 1024); + can_u->tac = c3_realloc(can_u->tac, sizeof(*can_u->tac) * can_u->siz_w); + } + + can_u->tac[can_u->len_w++] = u3a_to_off(som) >> u3a_vits; + som = u3h(som); + continue; + } +} + +static inline void __attribute__((always_inline)) +_melt_xchange(u3_noun new, u3_noun *som) +{ + u3_noun old = *som; + + if ( old != new ) { + *som = u3k(new); + u3z(old); + } +} + +static u3_noun +_melt_canon(_melt_ctx *can_u, u3_noun can) +{ + _cells_itr cit_u; + u3a_cell *cel_u; + u3_noun *top; + + can_u->len_w = 0; + + can = _melt_canon_next(can_u, can); + + while ( can_u->len_w ) { + top = &(can_u->tac[can_u->len_w - 1]); + + if ( !(*top >> 31) ) { // head frame + cel_u = u3to(u3a_cell, *top << u3a_vits); + _melt_xchange(can, &cel_u->hed); + *top |= 1U << 31; // tail frame + can = _melt_canon_next(can_u, cel_u->tel); + } + else { + *top &= (1U << 31) - 1; + *top <<= u3a_vits; + cel_u = u3to(u3a_cell, *top); + _melt_xchange(can, &cel_u->tel); + cit_u = vt_get_or_insert(&can_u->cel_u, u3a_to_pom(*top)); + u3_assert( !vt_is_end(cit_u) ); // OOM + can = cit_u.data->key; + + can_u->len_w--; + } + } + + return can; +} + +static void +_melt_canon_ptr(_melt_ctx *can_u, u3_noun *som) +{ + u3_noun can = _melt_canon(can_u, *som); + _melt_xchange(can, som); +} + +static void +_melt_walk_hamt(u3_noun kev, void* ptr_v) +{ + _melt_ctx *can_u = ptr_v; + (void)_melt_canon(can_u, kev); +} + +c3_w +u3_melt_all(FILE *fil_u) +{ + c3_w pre_w = u3a_idle(u3R); + _melt_ctx can_u = {0}; + + // Verify that we're on the main road. + // + u3_assert( &(u3H->rod_u) == u3R ); + + can_u.siz_w = 32; + can_u.tac = c3_malloc(sizeof(*can_u.tac) * can_u.siz_w); + + vt_init(&can_u.vat_u); + vt_init(&can_u.cel_u); + + u3m_reclaim(); + + // XX packed struct + // + { + u3_noun roc = u3A->roc; + _melt_canon_ptr(&can_u, &roc); + u3A->roc = roc; + } + + u3h_walk_with(u3R->jed.cod_p, _melt_walk_hamt, &can_u); + u3h_walk_with(u3R->cax.per_p, _melt_walk_hamt, &can_u); + + u3j_boot(c3n); + u3j_ream(); + + if ( fil_u ) { + fprintf(fil_u, "atoms (%zu)", vt_size(&can_u.vat_u)); + u3a_print_memory(fil_u, "", (c3_w)vt_bucket_count(&can_u.vat_u)); + fprintf(fil_u, "cells (%zu)", vt_size(&can_u.cel_u)); + u3a_print_memory(fil_u, "", (c3_w)vt_bucket_count(&can_u.cel_u)); + } + + vt_cleanup(&can_u.vat_u); + vt_cleanup(&can_u.cel_u); + + c3_free(can_u.tac); + + return u3a_idle(u3R) - pre_w; +} + +c3_w +u3_meld_all(FILE *fil_u) +{ + c3_w pre_w = u3a_open(u3R); + + u3h_free(u3R->cax.per_p); + u3R->cax.per_p = u3h_new_cache(u3C.per_w); + + (void)u3_melt_all(fil_u); + (void)u3m_pack(); + + return u3a_open(u3R) - pre_w; +} diff --git a/pkg/vere/serf.c b/pkg/vere/serf.c index 4ea6cebfb2..38b5494e70 100644 --- a/pkg/vere/serf.c +++ b/pkg/vere/serf.c @@ -1069,7 +1069,7 @@ u3_serf_live(u3_serf* sef_u, u3_noun com, u3_noun* ret) } else { u3z(com); - u3a_print_memory(stderr, "serf: meld: gained", u3u_meld()); + u3a_print_memory(stderr, "serf: meld: gained", u3_meld_all(stderr)); *ret = u3nc(c3__live, u3_nul); return c3y; } diff --git a/pkg/vere/vere.h b/pkg/vere/vere.h index afc3571584..3aced7b491 100644 --- a/pkg/vere/vere.h +++ b/pkg/vere/vere.h @@ -1607,4 +1607,14 @@ c3_w u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); + /* u3_melt_all(): canonicalize persistent state + */ + c3_w + u3_melt_all(FILE*); + + /* u3_meld_all(): canonicalize persistent nouns and compact state. + */ + c3_w + u3_meld_all(FILE*); + #endif /* ifndef U3_VERE_H */