peachsim 0.1.2778 → 0.1.2780

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +295 -480
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-RWBIRNWO.mjs → acorn-SPK2673W.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-ZWOS2EDN.mjs → chunk-3BAOVPYB.mjs} +118 -361
  28. package/dist-lib/esm-chunks/{chunk-MRIDS3GE.mjs → chunk-664T7XWT.mjs} +5 -5
  29. package/dist-lib/esm-chunks/{chunk-QKTKE4OX.mjs → chunk-7B4ZRXZW.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-G7UJ4BAC.mjs → chunk-7UJZBQ6G.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-EXU474NE.mjs → chunk-B4DO5WJD.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-IQSFMB4R.mjs → chunk-DO3C6MOG.mjs} +4 -4
  33. package/dist-lib/esm-chunks/{chunk-K3ULPN2R.mjs → chunk-DZZZCBJY.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-5TIUTQ55.mjs → chunk-EEN3DGCH.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-ZDWMPXYI.mjs → chunk-JIGACUAS.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-X25PQNNH.mjs → chunk-JIKQAODQ.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-6YHF4VYF.mjs → chunk-MIESONPY.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-3RPELUA2.mjs → chunk-NDMVV5PE.mjs} +6 -6
  39. package/dist-lib/esm-chunks/{chunk-KX7LV722.mjs → chunk-NLIWJ2AO.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-5WASPTSS.mjs → chunk-P7DZLDBL.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-F3OPIKJC.mjs → chunk-RDFBVP4E.mjs} +2 -2
  42. package/dist-lib/esm-chunks/{chunk-DLBUPWTI.mjs → chunk-SWCGFJ5A.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-KLA74B7J.mjs → chunk-T6THDRRU.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-3WQANOYY.mjs → chunk-TBKPPEGS.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-QUVLFF6I.mjs → chunk-UHTFNN5A.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-GSTHJQMW.mjs → chunk-VV2TNQK4.mjs} +115 -18
  47. package/dist-lib/esm-chunks/{chunk-VZ3NXXUC.mjs → chunk-WKE7Z3LU.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-LQVLXDRN.mjs → chunk-WXCV7NSJ.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-KBYVKTVK.mjs → chunk-X2OBXRGN.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{chunk-N2PEXZGL.mjs → chunk-ZDW2NOAO.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{metro-layout-parser-RRIZOLBE.mjs → metro-layout-parser-6N4ZZDLM.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-EIZ7MCKR.mjs → swift-package-prebuilt-GF27A4NU.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-S2LQ4OXD.mjs → swift-sdk-app-module-WWTSGAS7.mjs} +47 -69
  54. package/dist-lib/esm-chunks/{swift-sdk-image-77FFUGXI.mjs → swift-sdk-image-OQMMOQLZ.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-XFSFUXQJ.mjs → swift-sdk-image-producer-NOH5SG6O.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +295 -480
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +301 -486
  61. package/dist-lib/host/fetch-proxy-handler.cjs +22 -11
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +1 -1
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +1 -1
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +86 -86
  87. package/dist-lib/public-origins-lib.json +70 -70
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +301 -486
  95. package/dist-lib/swift-compile.cjs +288 -465
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +2 -0
  123. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +15 -2
  124. package/dist-types/packages/peach-engine/src/render-worker/worklet-wire.d.ts +10 -1
  125. package/package.json +1 -1
  126. package/src/swift-compiler-digest.ts +1 -0
  127. package/src/swift-guest-dyld-functions.ts +1 -11
  128. package/src/swift-guest-dyld-table.ts +2 -9
  129. package/src/swift-guest-image-ledger.ts +9 -35
  130. package/src/swift-guest-source-inputs.ts +5 -22
  131. package/src/swift-icu.ts +15 -28
  132. package/src/swift-link-roots.ts +4 -8
  133. package/src/swift-sdk-app-module.ts +5 -27
  134. package/src/swift-sdk-image-wasm.ts +12 -41
  135. package/src/swift-sdk-surface.ts +1 -0
  136. package/src/swift-shared-sdk.ts +1 -13
  137. package/src/swift-wasm-archive.ts +6 -11
  138. package/src/swift-wasm-prune.ts +22 -100
  139. package/src/wasm-binary-sections.ts +61 -7
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2778 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2780 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -6177,7 +6177,7 @@ var init_swift_objc_sdk_tree = __esm({
6177
6177
 
6178
6178
  // src/swift-compiler-digest.ts
6179
6179
  function swiftArchiveCompilerDigestValue() {
6180
- return true ? "faa13b0ae0340e03d058b765e659f5e07b69f8e94793bf99981b3da7ca3bf2bd" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname, "archive");
6180
+ return true ? "e8ee54259aef0a6a4e89faafc8a3413c810341697abe828044a70a8b46db3c15" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname, "archive");
6181
6181
  }
6182
6182
  var import_node_crypto10, import_node_fs25, import_node_path25, SWIFT_DIGEST_SOURCES, LINKED_IMAGE_SOURCES, SWIFT_ARCHIVE_DIGEST_SOURCES;
6183
6183
  var init_swift_compiler_digest = __esm({
@@ -6206,6 +6206,7 @@ var init_swift_compiler_digest = __esm({
6206
6206
  "swift-objc-prebuilt-catalog.ts",
6207
6207
  "swift-toolchain.ts",
6208
6208
  "swift-shared-sdk.ts",
6209
+ "wasm-binary-sections.ts",
6209
6210
  "swift-distribution-mirror.ts",
6210
6211
  "swift-design-time.ts",
6211
6212
  "binaryen.lock.json",
@@ -6323,13 +6324,13 @@ var init_swift_standin_digest = __esm({
6323
6324
  ];
6324
6325
  RUNTIME_IMPORT = /(?:^|[;\n])[ \t]*(?:import|export)\s+(?!type(?:\s|\{))([\s\S]*?)\s+from\s*['"]([^'"]+)['"]|(?:^|[;\n])[ \t]*import\s+['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
6325
6326
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS, STANDIN_DIGEST_EXCLUDED_FILES);
6326
- STANDIN_SOURCE_DIGEST = true ? "b6aa8eda1952d06a101c0a46227f227fb983255bb2a5f825515d7b9bc6f8650d" : standinSourceDigest();
6327
+ STANDIN_SOURCE_DIGEST = true ? "8b7dccbe4ecedba9dc6511eb4ab2e02ce2922969fcd9eebc93f3280c6529a48b" : standinSourceDigest();
6327
6328
  }
6328
6329
  });
6329
6330
 
6330
6331
  // src/expo-native-compiler-digest.ts
6331
6332
  function expoNativeCompilerDigestValue() {
6332
- return true ? "d396bac9636107aeb95f7657c77fa10e270f50f4ac8935e007b088b2ef65dfc8" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
6333
+ return true ? "4dc23720ffaa03d981b544bb7024c9d2dc67271f54484b348e256cad727bd94f" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
6333
6334
  }
6334
6335
  var import_node_crypto12;
6335
6336
  var init_expo_native_compiler_digest = __esm({
@@ -27972,6 +27973,111 @@ var init_swift_objc_runtime = __esm({
27972
27973
  }
27973
27974
  });
27974
27975
 
27976
+ // src/wasm-binary-sections.ts
27977
+ function encodeWasmNumber(value) {
27978
+ const bytes = [];
27979
+ for (let rest = value; ; ) {
27980
+ const byte = rest % 128;
27981
+ rest = Math.floor(rest / 128);
27982
+ if (rest === 0) return [...bytes, byte];
27983
+ bytes.push(byte | 128);
27984
+ }
27985
+ }
27986
+ function encodeWasmSigned(value) {
27987
+ const out = [];
27988
+ for (; ; ) {
27989
+ const byte = Number(value & 127n);
27990
+ value >>= 7n;
27991
+ if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
27992
+ out.push(byte);
27993
+ return out;
27994
+ }
27995
+ out.push(byte | 128);
27996
+ }
27997
+ }
27998
+ function encodeWasmName(name3) {
27999
+ const bytes = new TextEncoder().encode(name3);
28000
+ return [...encodeWasmNumber(bytes.length), ...bytes];
28001
+ }
28002
+ function readULEB(bytes, offset, end = bytes.length) {
28003
+ if (offset < end) {
28004
+ const first = bytes[offset];
28005
+ if (first < 128) return [first, offset + 1];
28006
+ }
28007
+ let value = 0;
28008
+ for (let shift = 0; ; shift += 7) {
28009
+ if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
28010
+ const byte = bytes[offset++];
28011
+ value += (byte & 127) * 2 ** shift;
28012
+ if (!(byte & 128)) return [value, offset];
28013
+ }
28014
+ }
28015
+ function readSLEB(bytes, offset, end = bytes.length) {
28016
+ let value = 0n;
28017
+ let shift = 0n;
28018
+ let byte = 0;
28019
+ do {
28020
+ if (offset >= end || shift > 70n) throw new Error("invalid wasm integer");
28021
+ byte = bytes[offset++];
28022
+ value |= BigInt(byte & 127) << shift;
28023
+ shift += 7n;
28024
+ } while (byte & 128);
28025
+ if (byte & 64) value -= 1n << shift;
28026
+ return [value, offset];
28027
+ }
28028
+ function skipLEB(bytes, offset) {
28029
+ while ((bytes[offset++] & 128) !== 0) {
28030
+ }
28031
+ return offset;
28032
+ }
28033
+ function readWasmSection(bytes, start, end) {
28034
+ let at = start;
28035
+ const number4 = () => {
28036
+ const [value, next] = readULEB(bytes, at, end);
28037
+ at = next;
28038
+ return value;
28039
+ };
28040
+ return {
28041
+ number: number4,
28042
+ byte: () => {
28043
+ if (at >= end) throw new Error("truncated wasm section");
28044
+ return bytes[at++];
28045
+ },
28046
+ name: () => {
28047
+ const length = number4();
28048
+ at += length;
28049
+ if (at > end) throw new Error("truncated wasm name");
28050
+ return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
28051
+ },
28052
+ skip: (length) => {
28053
+ at += length;
28054
+ if (at > end) throw new Error("truncated wasm section");
28055
+ },
28056
+ position: () => at,
28057
+ done: () => at === end
28058
+ };
28059
+ }
28060
+ function wasmSections(bytes) {
28061
+ if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
28062
+ throw new Error("not a wasm module");
28063
+ const found2 = [];
28064
+ for (let at = 8; at < bytes.length; ) {
28065
+ const header = readWasmSection(bytes, at, bytes.length);
28066
+ const id = header.byte();
28067
+ const size2 = header.number();
28068
+ const start = header.position();
28069
+ if (start + size2 > bytes.length) throw new Error("truncated wasm section");
28070
+ found2.push({ id, offset: at, start, end: start + size2 });
28071
+ at = start + size2;
28072
+ }
28073
+ return found2;
28074
+ }
28075
+ var init_wasm_binary_sections = __esm({
28076
+ "src/wasm-binary-sections.ts"() {
28077
+ "use strict";
28078
+ }
28079
+ });
28080
+
27975
28081
  // src/swift-shared-sdk.ts
27976
28082
  function swiftSharedSdkSourceRoot(moduleRoot, distribution) {
27977
28083
  return import_node_path53.default.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
@@ -28022,18 +28128,6 @@ function swiftSharedSdkFlags(moduleRoot, distribution) {
28022
28128
  import_node_path53.default.join(root, "usr/include")
28023
28129
  ];
28024
28130
  }
28025
- function readULEB(b, o) {
28026
- let res = 0;
28027
- let shift = 0;
28028
- let p = o;
28029
- while (true) {
28030
- const byte = b[p++];
28031
- res |= (byte & 127) << shift;
28032
- if ((byte & 128) === 0) break;
28033
- shift += 7;
28034
- }
28035
- return [res, p];
28036
- }
28037
28131
  function weakenFoundationSymbolsInWasmObj(buf) {
28038
28132
  let pos = 8;
28039
28133
  while (pos < buf.length) {
@@ -28398,6 +28492,7 @@ var init_swift_shared_sdk = __esm({
28398
28492
  import_node_path53 = __toESM(require("node:path"), 1);
28399
28493
  init_swift_toolchain();
28400
28494
  init_swiftTargetContract();
28495
+ init_wasm_binary_sections();
28401
28496
  SWIFT_DISTRIBUTION_MIRROR_RECORD = ".peach-mirror.json";
28402
28497
  distributionHeaderRoots = /* @__PURE__ */ new Map();
28403
28498
  WEAKEN_FOUNDATION_SYMS = /* @__PURE__ */ new Set([
@@ -29804,16 +29899,12 @@ var init_swift_link_roots = __esm({
29804
29899
  "use strict";
29805
29900
  import_node_fs56 = __toESM(require("node:fs"), 1);
29806
29901
  import_node_path57 = __toESM(require("node:path"), 1);
29902
+ init_wasm_binary_sections();
29807
29903
  OBJC_RUNTIME_LOOKUP_SECTION = "peach_objc_runtime_lookup";
29808
29904
  leb = (bytes, at) => {
29809
- let value = 0;
29810
- let scale = 1;
29811
- for (; ; ) {
29812
- const byte = bytes[at.offset++];
29813
- value += (byte & 127) * scale;
29814
- if (!(byte & 128)) return value;
29815
- scale *= 128;
29816
- }
29905
+ const [value, next] = readULEB(bytes, at.offset);
29906
+ at.offset = next;
29907
+ return value;
29817
29908
  };
29818
29909
  rootsByDistribution = /* @__PURE__ */ new Map();
29819
29910
  }
@@ -30642,68 +30733,6 @@ var init_swift_guest_linked_spans = __esm({
30642
30733
  }
30643
30734
  });
30644
30735
 
30645
- // src/wasm-binary-sections.ts
30646
- function encodeWasmNumber(value) {
30647
- const bytes = [];
30648
- for (let rest = value; ; ) {
30649
- const byte = rest % 128;
30650
- rest = Math.floor(rest / 128);
30651
- if (rest === 0) return [...bytes, byte];
30652
- bytes.push(byte | 128);
30653
- }
30654
- }
30655
- function encodeWasmName(name3) {
30656
- const bytes = new TextEncoder().encode(name3);
30657
- return [...encodeWasmNumber(bytes.length), ...bytes];
30658
- }
30659
- function readWasmSection(bytes, start, end) {
30660
- let at = start;
30661
- const number4 = () => {
30662
- let value = 0;
30663
- for (let shift = 0; ; shift += 7) {
30664
- if (at >= end || shift > 63) throw new Error("invalid wasm integer");
30665
- const byte = bytes[at++];
30666
- value += (byte & 127) * 2 ** shift;
30667
- if (!(byte & 128)) return value;
30668
- }
30669
- };
30670
- return {
30671
- number: number4,
30672
- byte: () => {
30673
- if (at >= end) throw new Error("truncated wasm section");
30674
- return bytes[at++];
30675
- },
30676
- name: () => {
30677
- const length = number4();
30678
- at += length;
30679
- if (at > end) throw new Error("truncated wasm name");
30680
- return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
30681
- },
30682
- position: () => at,
30683
- done: () => at === end
30684
- };
30685
- }
30686
- function wasmSections(bytes) {
30687
- if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
30688
- throw new Error("not a wasm module");
30689
- const found2 = [];
30690
- for (let at = 8; at < bytes.length; ) {
30691
- const header = readWasmSection(bytes, at, bytes.length);
30692
- const id = header.byte();
30693
- const size2 = header.number();
30694
- const start = header.position();
30695
- if (start + size2 > bytes.length) throw new Error("truncated wasm section");
30696
- found2.push({ id, offset: at, start, end: start + size2 });
30697
- at = start + size2;
30698
- }
30699
- return found2;
30700
- }
30701
- var init_wasm_binary_sections = __esm({
30702
- "src/wasm-binary-sections.ts"() {
30703
- "use strict";
30704
- }
30705
- });
30706
-
30707
30736
  // src/wasm-imports.ts
30708
30737
  function readWasmImports(bytes, section2, visit3) {
30709
30738
  const input = readWasmSection(bytes, section2.start, section2.end);
@@ -30987,23 +31016,13 @@ function wasmReader(bytes, start) {
30987
31016
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
30988
31017
  let at = start;
30989
31018
  const u = () => {
30990
- let value = 0;
30991
- for (let shift = 0; ; shift += 7) {
30992
- const byte = bytes[at++];
30993
- value += (byte & 127) * 2 ** shift;
30994
- if (!(byte & 128)) return value;
30995
- }
31019
+ const [value, next] = readULEB(bytes, at);
31020
+ at = next;
31021
+ return value;
30996
31022
  };
30997
31023
  const s = () => {
30998
- let value = 0n;
30999
- let shift = 0n;
31000
- let byte = 0;
31001
- do {
31002
- byte = bytes[at++];
31003
- value |= BigInt(byte & 127) << shift;
31004
- shift += 7n;
31005
- } while (byte & 128);
31006
- if (byte & 64) value -= 1n << shift;
31024
+ const [value, next] = readSLEB(bytes, at);
31025
+ at = next;
31007
31026
  return value;
31008
31027
  };
31009
31028
  return {
@@ -31308,7 +31327,7 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
31308
31327
  else data[entry.name] = value;
31309
31328
  }
31310
31329
  if (entry.kind !== 0 && entry.kind !== 3 || host2.has(entry.name))
31311
- kept.push([...encodedName(entry.name), entry.kind, ...uleb(entry.index)]);
31330
+ kept.push([...encodeWasmName(entry.name), entry.kind, ...encodeWasmNumber(entry.index)]);
31312
31331
  }
31313
31332
  if (guestMap) {
31314
31333
  if (guestMap.code.length !== m.bodies.length)
@@ -31323,19 +31342,19 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
31323
31342
  const er = wasmReader(bytes, elements.start);
31324
31343
  const segments = er.u();
31325
31344
  const replaced = /* @__PURE__ */ new Map([
31326
- [4, [1, 112, 4, ...uleb(tableEnd + added.length)]],
31327
- [7, [...uleb(kept.length), ...kept.flat()]],
31345
+ [4, [1, 112, 4, ...encodeWasmNumber(tableEnd + added.length)]],
31346
+ [7, [...encodeWasmNumber(kept.length), ...kept.flat()]],
31328
31347
  [
31329
31348
  9,
31330
31349
  [
31331
- ...uleb(segments + 1),
31350
+ ...encodeWasmNumber(segments + 1),
31332
31351
  ...bytes.subarray(er.at, elements.end),
31333
31352
  0,
31334
31353
  66,
31335
- ...sleb(BigInt(tableEnd)),
31354
+ ...encodeWasmSigned(BigInt(tableEnd)),
31336
31355
  11,
31337
- ...uleb(added.length),
31338
- ...added.flatMap(uleb)
31356
+ ...encodeWasmNumber(added.length),
31357
+ ...added.flatMap(encodeWasmNumber)
31339
31358
  ]
31340
31359
  ]
31341
31360
  ]);
@@ -31441,33 +31460,33 @@ function codeOnlySdkImage(bytes, constructorMask) {
31441
31460
  if (drop) r.skip(1);
31442
31461
  gated.push(
31443
31462
  66,
31444
- ...sleb(BigInt(constructorMask + index++)),
31463
+ ...encodeWasmSigned(BigInt(constructorMask + index++)),
31445
31464
  45,
31446
31465
  0,
31447
31466
  0,
31448
31467
  4,
31449
31468
  64,
31450
31469
  16,
31451
- ...uleb(callee),
31470
+ ...encodeWasmNumber(callee),
31452
31471
  ...drop ? [26] : [],
31453
31472
  11
31454
31473
  );
31455
31474
  }
31456
31475
  if (index > SWIFT_SDK_CONSTRUCTOR_LIMIT)
31457
31476
  throw new Error(`${index} sdk constructors exceed the mask`);
31458
- gated.push(16, ...uleb(functionIndex("__peach_sdk_register")), 11);
31477
+ gated.push(16, ...encodeWasmNumber(functionIndex("__peach_sdk_register")), 11);
31459
31478
  bodies[constructors] = Uint8Array.from(gated);
31460
31479
  }
31461
- const codeParts = [Uint8Array.from(uleb(bodies.length))];
31462
- for (const body of bodies) codeParts.push(Uint8Array.from(uleb(body.length)), body);
31480
+ const codeParts = [Uint8Array.from(encodeWasmNumber(bodies.length))];
31481
+ for (const body of bodies) codeParts.push(Uint8Array.from(encodeWasmNumber(body.length)), body);
31463
31482
  const codeSize = codeParts.reduce((sum, part) => sum + part.length, 0);
31464
31483
  const tls = passiveSegments(bytes)[0];
31465
31484
  const out = [bytes.subarray(0, 8)];
31466
31485
  for (const s of m.sections) {
31467
31486
  if (s.id === 10) {
31468
- out.push(Uint8Array.from([10, ...uleb(codeSize)]));
31487
+ out.push(Uint8Array.from([10, ...encodeWasmNumber(codeSize)]));
31469
31488
  for (const part of codeParts) out.push(part);
31470
- } else if (s.id === 11) out.push(section(11, [1, 1, ...uleb(tls.length), ...tls]));
31489
+ } else if (s.id === 11) out.push(section(11, [1, 1, ...encodeWasmNumber(tls.length), ...tls]));
31471
31490
  else if (s.id === 12) out.push(section(12, [1]));
31472
31491
  else out.push(bytes.subarray(s.offset, s.end));
31473
31492
  }
@@ -31784,39 +31803,14 @@ function unslottedFunctions(bytes) {
31784
31803
  }
31785
31804
  return definedFuncs - slotted.size;
31786
31805
  }
31787
- var uleb, sleb, encodedName, section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
31806
+ var section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
31788
31807
  var init_swift_sdk_image_wasm = __esm({
31789
31808
  "src/swift-sdk-image-wasm.ts"() {
31790
31809
  "use strict";
31791
31810
  init_swift_sdk_image_map();
31792
31811
  init_swiftSdkLinkContract();
31793
- uleb = (value) => {
31794
- const out = [];
31795
- do {
31796
- let byte = value % 128;
31797
- value = Math.floor(value / 128);
31798
- if (value) byte |= 128;
31799
- out.push(byte);
31800
- } while (value);
31801
- return out;
31802
- };
31803
- sleb = (value) => {
31804
- const out = [];
31805
- for (; ; ) {
31806
- const byte = Number(value & 127n);
31807
- value >>= 7n;
31808
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
31809
- out.push(byte);
31810
- return out;
31811
- }
31812
- out.push(byte | 128);
31813
- }
31814
- };
31815
- encodedName = (name3) => {
31816
- const bytes = [...Buffer.from(name3)];
31817
- return [...uleb(bytes.length), ...bytes];
31818
- };
31819
- section = (id, payload) => Uint8Array.from([id, ...uleb(payload.length), ...payload]);
31812
+ init_wasm_binary_sections();
31813
+ section = (id, payload) => Uint8Array.from([id, ...encodeWasmNumber(payload.length), ...payload]);
31820
31814
  PROCESS_EXPORTS = [
31821
31815
  "_initialize",
31822
31816
  "__wasm_call_ctors",
@@ -31921,20 +31915,12 @@ function localizeDefinedWasmSymbols(bytes, names) {
31921
31915
  const output = new Uint8Array(bytes);
31922
31916
  let cur = 8;
31923
31917
  const readU = () => {
31924
- const b0 = bytes[cur++];
31925
- if (b0 < 128) return b0;
31926
- let res = b0 & 127;
31927
- let shift = 7;
31928
- while (true) {
31929
- const byte = bytes[cur++];
31930
- res |= (byte & 127) << shift;
31931
- if ((byte & 128) === 0) return res;
31932
- shift += 7;
31933
- }
31918
+ const [res, next] = readULEB(bytes, cur);
31919
+ cur = next;
31920
+ return res;
31934
31921
  };
31935
31922
  const skipU = () => {
31936
- while ((bytes[cur++] & 128) !== 0) {
31937
- }
31923
+ cur = skipLEB(bytes, cur);
31938
31924
  };
31939
31925
  const importFuncNames = [];
31940
31926
  const importGlobalNames = [];
@@ -32041,45 +32027,11 @@ function localizeDefinedWasmSymbols(bytes, names) {
32041
32027
  var init_swift_wasm_archive = __esm({
32042
32028
  "src/swift-wasm-archive.ts"() {
32043
32029
  "use strict";
32030
+ init_wasm_binary_sections();
32044
32031
  }
32045
32032
  });
32046
32033
 
32047
32034
  // src/swift-wasm-prune.ts
32048
- function readULEB2(b, o) {
32049
- let res = 0;
32050
- let shift = 0;
32051
- let p = o;
32052
- while (true) {
32053
- const byte = b[p++];
32054
- res |= (byte & 127) << shift;
32055
- if ((byte & 128) === 0) break;
32056
- shift += 7;
32057
- }
32058
- return [res, p];
32059
- }
32060
- function readSLEB(b, o) {
32061
- let res = 0;
32062
- let shift = 0;
32063
- let p = o;
32064
- let byte = 0;
32065
- do {
32066
- byte = b[p++];
32067
- res |= (byte & 127) << shift;
32068
- shift += 7;
32069
- } while (byte & 128);
32070
- if (shift < 32 && byte & 64) res |= ~0 << shift;
32071
- return [res, p];
32072
- }
32073
- function encodeULEB(val) {
32074
- const out = [];
32075
- do {
32076
- let byte = val & 127;
32077
- val >>>= 7;
32078
- if (val !== 0) byte |= 128;
32079
- out.push(byte);
32080
- } while (val !== 0);
32081
- return out;
32082
- }
32083
32035
  function isRootSegName(name3) {
32084
32036
  for (const pref of ROOT_SEG_PREFIXES) {
32085
32037
  if (name3 === pref || name3.startsWith(`${pref}.`)) return true;
@@ -32105,39 +32057,14 @@ function decodeRelocations(buf, sections) {
32105
32057
  for (let k = 0; k < sectionCount; k++, i++) {
32106
32058
  start[i] = length + cur - baseAt;
32107
32059
  const rType = buf[cur++];
32108
- let offset = buf[cur++];
32109
- if (offset >= 128) {
32110
- offset &= 127;
32111
- let shift = 7;
32112
- while (true) {
32113
- const byte = buf[cur++];
32114
- offset |= (byte & 127) << shift;
32115
- if (byte < 128) break;
32116
- shift += 7;
32117
- }
32118
- }
32119
- let symbol2 = buf[cur++];
32120
- if (symbol2 >= 128) {
32121
- symbol2 &= 127;
32122
- let shift = 7;
32123
- while (true) {
32124
- const byte = buf[cur++];
32125
- symbol2 |= (byte & 127) << shift;
32126
- if (byte < 128) break;
32127
- shift += 7;
32128
- }
32129
- }
32060
+ let offset;
32061
+ [offset, cur] = readULEB(buf, cur);
32062
+ let symbol2;
32063
+ [symbol2, cur] = readULEB(buf, cur);
32130
32064
  if (rType < 32 && (ADDEND_RELOC_MASK2 & 1 << rType) !== 0) {
32131
- let byte = buf[cur++];
32132
- let value = byte & 127;
32133
- let shift = 7;
32134
- while (byte >= 128) {
32135
- byte = buf[cur++];
32136
- value |= (byte & 127) << shift;
32137
- shift += 7;
32138
- }
32139
- if (shift < 32 && (byte & 64) !== 0) value |= ~0 << shift;
32140
- addend[i] = value;
32065
+ let value;
32066
+ [value, cur] = readSLEB(buf, cur);
32067
+ addend[i] = Number(BigInt.asIntN(32, value));
32141
32068
  }
32142
32069
  ro[i] = offset;
32143
32070
  rs[i] = symbol2;
@@ -32172,36 +32099,36 @@ function patchSwiftrtObject(src) {
32172
32099
  let pos = 8;
32173
32100
  while (pos < buf.length) {
32174
32101
  const id = buf[pos++];
32175
- const [sz, p] = readULEB2(buf, pos);
32102
+ const [sz, p] = readULEB(buf, pos);
32176
32103
  const end = p + sz;
32177
32104
  if (id === 0) {
32178
- const [nLen, np] = readULEB2(buf, p);
32105
+ const [nLen, np] = readULEB(buf, p);
32179
32106
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
32180
32107
  const cp = np + nLen;
32181
32108
  if (name3 === "linking") {
32182
- let [, lp] = readULEB2(buf, cp);
32109
+ let [, lp] = readULEB(buf, cp);
32183
32110
  while (lp < end) {
32184
32111
  const subId = buf[lp++];
32185
- const [subLen, sp] = readULEB2(buf, lp);
32112
+ const [subLen, sp] = readULEB(buf, lp);
32186
32113
  const subEnd = sp + subLen;
32187
32114
  if (subId === 8) {
32188
- let [cnt, cur] = readULEB2(buf, sp);
32115
+ let [cnt, cur] = readULEB(buf, sp);
32189
32116
  for (let i = 0; i < cnt; i++) {
32190
32117
  const kind = buf[cur++];
32191
32118
  const flPos = cur;
32192
- const [fl, c2] = readULEB2(buf, cur);
32119
+ const [fl, c2] = readULEB(buf, cur);
32193
32120
  cur = c2;
32194
32121
  const isUndef = (fl & 16) !== 0;
32195
32122
  const isExplicitName = (fl & 64) !== 0;
32196
32123
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
32197
- const [, c3] = readULEB2(buf, cur);
32124
+ const [, c3] = readULEB(buf, cur);
32198
32125
  cur = c3;
32199
32126
  if (!isUndef || isExplicitName) {
32200
- const [sLen, c4] = readULEB2(buf, cur);
32127
+ const [sLen, c4] = readULEB(buf, cur);
32201
32128
  cur = c4 + sLen;
32202
32129
  }
32203
32130
  } else if (kind === 1) {
32204
- const [sLen, c3] = readULEB2(buf, cur);
32131
+ const [sLen, c3] = readULEB(buf, cur);
32205
32132
  const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
32206
32133
  if (sName === "_ZN12_GLOBAL__N_18sectionsE") fallbackSymIdx = i;
32207
32134
  for (const prefix of ["__start_", "__stop_"]) {
@@ -32213,13 +32140,13 @@ function patchSwiftrtObject(src) {
32213
32140
  }
32214
32141
  cur = c3 + sLen;
32215
32142
  if (!isUndef) {
32216
- const [, c4] = readULEB2(buf, cur);
32217
- const [, c5] = readULEB2(buf, c4);
32218
- const [, c6] = readULEB2(buf, c5);
32143
+ const [, c4] = readULEB(buf, cur);
32144
+ const [, c5] = readULEB(buf, c4);
32145
+ const [, c6] = readULEB(buf, c5);
32219
32146
  cur = c6;
32220
32147
  }
32221
32148
  } else if (kind === 3) {
32222
- const [, c3] = readULEB2(buf, cur);
32149
+ const [, c3] = readULEB(buf, cur);
32223
32150
  cur = c3;
32224
32151
  }
32225
32152
  }
@@ -32233,26 +32160,25 @@ function patchSwiftrtObject(src) {
32233
32160
  pos = 8;
32234
32161
  while (pos < buf.length) {
32235
32162
  const id = buf[pos++];
32236
- const [sz, p] = readULEB2(buf, pos);
32163
+ const [sz, p] = readULEB(buf, pos);
32237
32164
  const end = p + sz;
32238
32165
  if (id === 0) {
32239
- const [nLen, np] = readULEB2(buf, p);
32166
+ const [nLen, np] = readULEB(buf, p);
32240
32167
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
32241
32168
  const cp = np + nLen;
32242
32169
  if (name3 === "reloc.CODE") {
32243
- const [, r1] = readULEB2(buf, cp);
32244
- let [cnt, cur] = readULEB2(buf, r1);
32170
+ const [, r1] = readULEB(buf, cp);
32171
+ let [cnt, cur] = readULEB(buf, r1);
32245
32172
  for (let i = 0; i < cnt; i++) {
32246
32173
  const rType = buf[cur++];
32247
- const [, c2] = readULEB2(buf, cur);
32248
- const [rs, c3] = readULEB2(buf, c2);
32174
+ const [, c2] = readULEB(buf, cur);
32175
+ const [rs, c3] = readULEB(buf, c2);
32249
32176
  if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
32250
32177
  buf[c2] = fallbackSymIdx;
32251
32178
  }
32252
32179
  cur = c3;
32253
32180
  if (ADDEND_RELOCATIONS.has(rType)) {
32254
- const [, c4] = readSLEB(buf, cur);
32255
- cur = c4;
32181
+ cur = skipLEB(buf, cur);
32256
32182
  }
32257
32183
  }
32258
32184
  }
@@ -32266,25 +32192,14 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
32266
32192
  let pos = 8;
32267
32193
  let cur = 8;
32268
32194
  const readU = () => {
32269
- const b0 = buf[cur++];
32270
- if (b0 < 128) return b0;
32271
- let res = b0 & 127;
32272
- let shift = 7;
32273
- while (true) {
32274
- const byte = buf[cur++];
32275
- res |= (byte & 127) << shift;
32276
- if (byte < 128) return res;
32277
- shift += 7;
32278
- }
32195
+ const [res, next] = readULEB(buf, cur);
32196
+ cur = next;
32197
+ return res;
32279
32198
  };
32280
32199
  const skipU = () => {
32281
- while (buf[cur++] >= 128) {
32282
- }
32283
- };
32284
- const skipS = () => {
32285
- while (buf[cur++] >= 128) {
32286
- }
32200
+ cur = skipLEB(buf, cur);
32287
32201
  };
32202
+ const skipS = skipU;
32288
32203
  let numImportFuncs = 0;
32289
32204
  let importsDlsym = false;
32290
32205
  const importFuncNames = [];
@@ -32882,16 +32797,9 @@ function guestWasmSymbols(bytes) {
32882
32797
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
32883
32798
  let cur = 8;
32884
32799
  const readU = () => {
32885
- const b0 = bytes[cur++];
32886
- if (b0 < 128) return b0;
32887
- let res = b0 & 127;
32888
- let shift = 7;
32889
- while (true) {
32890
- const byte = bytes[cur++];
32891
- res |= (byte & 127) << shift;
32892
- if ((byte & 128) === 0) return res;
32893
- shift += 7;
32894
- }
32800
+ const [res, next] = readULEB(bytes, cur);
32801
+ cur = next;
32802
+ return res;
32895
32803
  };
32896
32804
  let importsDlsym = false;
32897
32805
  const importFuncNames = [];
@@ -34032,7 +33940,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34032
33940
  if (!deadSpecialSegs.has(sIdx)) continue;
34033
33941
  if (!isSpecialSegRelocLive(obj, obj.segNames[sIdx], data.rs[i])) continue;
34034
33942
  const first = relocationBytes(data, i);
34035
- const [, afterRoOff] = readULEB2(first, 1);
33943
+ const [, afterRoOff] = readULEB(first, 1);
34036
33944
  firstLiveInSpecialSeg.set(sIdx, {
34037
33945
  rType: first[0],
34038
33946
  afterRo: first.subarray(afterRoOff)
@@ -34062,7 +33970,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34062
33970
  zeroDataReloc(i);
34063
33971
  } else {
34064
33972
  const repl = firstLiveInSpecialSeg.get(segIdx);
34065
- const roBytes = encodeULEB(data.ro[i]);
33973
+ const roBytes = encodeWasmNumber(data.ro[i]);
34066
33974
  const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length);
34067
33975
  out[0] = repl.rType;
34068
33976
  out.set(roBytes, 1);
@@ -34101,34 +34009,34 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34101
34009
  while (pos < buf.length) {
34102
34010
  const secStart = pos;
34103
34011
  const id = buf[pos++];
34104
- const [sz, p] = readULEB2(buf, pos);
34012
+ const [sz, p] = readULEB(buf, pos);
34105
34013
  const end = p + sz;
34106
34014
  if (id === 0) {
34107
- const [nLen, np] = readULEB2(buf, p);
34015
+ const [nLen, np] = readULEB(buf, p);
34108
34016
  const name3 = rawBuf.toString("utf8", np, np + nLen);
34109
34017
  const cp = np + nLen;
34110
34018
  if (name3 === "linking") {
34111
- const [, lpStart] = readULEB2(buf, cp);
34019
+ const [, lpStart] = readULEB(buf, cp);
34112
34020
  const subChunks = [buf.subarray(p, lpStart)];
34113
34021
  let lp = lpStart;
34114
34022
  while (lp < end) {
34115
34023
  const subStart = lp;
34116
34024
  const subId = buf[lp++];
34117
- const [subLen, sp] = readULEB2(buf, lp);
34025
+ const [subLen, sp] = readULEB(buf, lp);
34118
34026
  const subEnd = sp + subLen;
34119
34027
  if (subId === 5) {
34120
34028
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
34121
- let [cnt, cur] = readULEB2(buf, sp);
34029
+ let [cnt, cur] = readULEB(buf, sp);
34122
34030
  for (let i = 0; i < cnt; i++) {
34123
- const [sLen, s2] = readULEB2(buf, cur);
34031
+ const [sLen, s2] = readULEB(buf, cur);
34124
34032
  const segName = obj.segNames[i];
34125
34033
  const repl = RECORD_SEGS.get(segName);
34126
34034
  const isSpecial = repl !== void 0;
34127
34035
  if (deadSpecialSegs.has(i) && repl !== void 0)
34128
34036
  subCopy.set(Buffer.from(repl, "utf8"), s2 - subStart);
34129
34037
  cur = s2 + sLen;
34130
- const [, s3] = readULEB2(buf, cur);
34131
- const [segFl, s4] = readULEB2(buf, s3);
34038
+ const [, s3] = readULEB(buf, cur);
34039
+ const [segFl, s4] = readULEB(buf, s3);
34132
34040
  const sFlLen = s4 - s3;
34133
34041
  const keepRetain = isSpecial ? !deadSpecialSegs.has(i) : isRootSegName(segName) && !segName.startsWith(".init_array") && sLive[i] === 1;
34134
34042
  const newSegFl = keepRetain ? segFl | 4 : segFl & ~4;
@@ -34142,12 +34050,12 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34142
34050
  }
34143
34051
  subChunks.push(subCopy);
34144
34052
  } else if (subId === 6) {
34145
- let [cnt, cur] = readULEB2(buf, sp);
34053
+ let [cnt, cur] = readULEB(buf, sp);
34146
34054
  const entrySlices = [];
34147
34055
  for (let i = 0; i < cnt; i++) {
34148
34056
  const eStart = cur;
34149
- const [, s2] = readULEB2(buf, cur);
34150
- const [symIdx, s3] = readULEB2(buf, s2);
34057
+ const [, s2] = readULEB(buf, cur);
34058
+ const [symIdx, s3] = readULEB(buf, s2);
34151
34059
  cur = s3;
34152
34060
  if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
34153
34061
  if (fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1) {
@@ -34158,19 +34066,19 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34158
34066
  }
34159
34067
  }
34160
34068
  if (entrySlices.length > 0) {
34161
- const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length));
34069
+ const cntBytes = Uint8Array.from(encodeWasmNumber(entrySlices.length));
34162
34070
  const bodyLen = cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0);
34163
- const lenBytes = Uint8Array.from(encodeULEB(bodyLen));
34071
+ const lenBytes = Uint8Array.from(encodeWasmNumber(bodyLen));
34164
34072
  subChunks.push(Uint8Array.of(6), lenBytes, cntBytes);
34165
34073
  for (const entry of entrySlices) subChunks.push(entry);
34166
34074
  }
34167
34075
  } else if (subId === 8) {
34168
34076
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
34169
- let [cnt, cur] = readULEB2(buf, sp);
34077
+ let [cnt, cur] = readULEB(buf, sp);
34170
34078
  for (let i = 0; i < cnt; i++) {
34171
34079
  const kind = buf[cur++];
34172
34080
  const flOffset = cur - subStart;
34173
- const [fl, c2] = readULEB2(buf, cur);
34081
+ const [fl, c2] = readULEB(buf, cur);
34174
34082
  cur = c2;
34175
34083
  const isUndef = (fl & 16) !== 0;
34176
34084
  const isExplicitName = (fl & 64) !== 0;
@@ -34190,23 +34098,23 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34190
34098
  subCopy[flOffset + 1] = 0;
34191
34099
  }
34192
34100
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
34193
- const [, c3] = readULEB2(buf, cur);
34101
+ const [, c3] = readULEB(buf, cur);
34194
34102
  cur = c3;
34195
34103
  if (!isUndef || isExplicitName) {
34196
- const [sLen, c4] = readULEB2(buf, cur);
34104
+ const [sLen, c4] = readULEB(buf, cur);
34197
34105
  cur = c4 + sLen;
34198
34106
  }
34199
34107
  } else if (kind === 1) {
34200
- const [sLen, c3] = readULEB2(buf, cur);
34108
+ const [sLen, c3] = readULEB(buf, cur);
34201
34109
  cur = c3 + sLen;
34202
34110
  if (!isUndef) {
34203
- const [, c4] = readULEB2(buf, cur);
34204
- const [, c5] = readULEB2(buf, c4);
34205
- const [, c6] = readULEB2(buf, c5);
34111
+ const [, c4] = readULEB(buf, cur);
34112
+ const [, c5] = readULEB(buf, c4);
34113
+ const [, c6] = readULEB(buf, c5);
34206
34114
  cur = c6;
34207
34115
  }
34208
34116
  } else if (kind === 3) {
34209
- const [, c3] = readULEB2(buf, cur);
34117
+ const [, c3] = readULEB(buf, cur);
34210
34118
  cur = c3;
34211
34119
  }
34212
34120
  }
@@ -34217,29 +34125,29 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34217
34125
  lp = subEnd;
34218
34126
  }
34219
34127
  const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0);
34220
- outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeULEB(totalSubLen)));
34128
+ outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeWasmNumber(totalSubLen)));
34221
34129
  for (const chunk of subChunks) outChunks.push(chunk);
34222
34130
  } else if (name3 === "reloc.CODE") {
34223
- const [, r1] = readULEB2(buf, cp);
34131
+ const [, r1] = readULEB(buf, cp);
34224
34132
  const headerSlice = buf.subarray(p, r1);
34225
- const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length));
34133
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptCodeRelocs.length));
34226
34134
  const relSlices = keptCodeRelocs.map((i) => relocationBytes(code, i));
34227
34135
  const totalLen = headerSlice.length + cntBytes.length + relSlices.reduce((a, b) => a + b.length, 0);
34228
34136
  outChunks.push(
34229
34137
  Uint8Array.of(0),
34230
- Uint8Array.from(encodeULEB(totalLen)),
34138
+ Uint8Array.from(encodeWasmNumber(totalLen)),
34231
34139
  headerSlice,
34232
34140
  cntBytes
34233
34141
  );
34234
34142
  for (const relocation of relSlices) outChunks.push(relocation);
34235
34143
  } else if (name3 === "reloc.DATA") {
34236
- const [, r1] = readULEB2(buf, cp);
34144
+ const [, r1] = readULEB(buf, cp);
34237
34145
  const headerSlice = buf.subarray(p, r1);
34238
- const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length));
34146
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptDataRelocBytes.length));
34239
34147
  const totalLen = headerSlice.length + cntBytes.length + keptDataRelocBytes.reduce((a, b) => a + b.length, 0);
34240
34148
  outChunks.push(
34241
34149
  Uint8Array.of(0),
34242
- Uint8Array.from(encodeULEB(totalLen)),
34150
+ Uint8Array.from(encodeWasmNumber(totalLen)),
34243
34151
  headerSlice,
34244
34152
  cntBytes
34245
34153
  );
@@ -34249,15 +34157,15 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34249
34157
  const nameBytes = buf.subarray(p, cp);
34250
34158
  outChunks.push(
34251
34159
  Uint8Array.of(0),
34252
- Uint8Array.from(encodeULEB(nameBytes.length)),
34160
+ Uint8Array.from(encodeWasmNumber(nameBytes.length)),
34253
34161
  nameBytes
34254
34162
  );
34255
34163
  } else if (name3.startsWith("reloc..debug_")) {
34256
- const [, r1] = readULEB2(buf, cp);
34164
+ const [, r1] = readULEB(buf, cp);
34257
34165
  const headerSlice = buf.subarray(p, r1);
34258
34166
  outChunks.push(
34259
34167
  Uint8Array.of(0),
34260
- Uint8Array.from(encodeULEB(headerSlice.length + 1)),
34168
+ Uint8Array.from(encodeWasmNumber(headerSlice.length + 1)),
34261
34169
  headerSlice,
34262
34170
  Uint8Array.of(0)
34263
34171
  );
@@ -34387,6 +34295,7 @@ var init_swift_wasm_prune = __esm({
34387
34295
  init_swift_toolchain();
34388
34296
  init_swift_wasm_archive();
34389
34297
  init_swiftRuntimeProductContract();
34298
+ init_wasm_binary_sections();
34390
34299
  WIDE_DATA_RELOCS = /* @__PURE__ */ new Set([16, 19, 22, 27]);
34391
34300
  ROOT_SEG_PREFIXES = [
34392
34301
  ".init_array",
@@ -34680,34 +34589,11 @@ var init_nativeWasmContract = __esm({
34680
34589
  });
34681
34590
 
34682
34591
  // src/swift-guest-image-ledger.ts
34683
- function readNumber(bytes, position) {
34684
- if (position < bytes.length) {
34685
- const first = bytes[position];
34686
- if (first < 128) return [first, position + 1];
34687
- }
34688
- let value = 0;
34689
- let shift = 0;
34690
- for (; ; ) {
34691
- if (position >= bytes.length || shift > 63) throw new Error("invalid wasm integer");
34692
- const byte = bytes[position++];
34693
- value += (byte & 127) * 2 ** shift;
34694
- if (!(byte & 128)) return [value, position];
34695
- shift += 7;
34696
- }
34697
- }
34698
34592
  function encodeNumber(value) {
34699
- if (value < 128) return Buffer.from([value]);
34700
- const bytes = [];
34701
- do {
34702
- let byte = value % 128;
34703
- value = Math.floor(value / 128);
34704
- if (value) byte |= 128;
34705
- bytes.push(byte);
34706
- } while (value);
34707
- return Buffer.from(bytes);
34593
+ return Buffer.from(encodeWasmNumber(value));
34708
34594
  }
34709
34595
  function readString(bytes, position) {
34710
- const [length, start] = readNumber(bytes, position);
34596
+ const [length, start] = readULEB(bytes, position);
34711
34597
  if (start + length > bytes.length) throw new Error("invalid wasm string");
34712
34598
  return [
34713
34599
  Buffer.from(bytes.buffer, bytes.byteOffset + start, length).toString("utf8"),
@@ -35033,13 +34919,13 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35033
34919
  for (const subsection of subsections) {
35034
34920
  if (subsection.kind === 6 && objcLoader !== void 0) {
35035
34921
  const content = subsection.parts[0];
35036
- const [count, entriesStart] = readNumber(content, 0);
34922
+ const [count, entriesStart] = readULEB(content, 0);
35037
34923
  const initWriter = new ByteWriter(content.length + 16);
35038
34924
  initWriter.bytes(content, 0, entriesStart);
35039
34925
  let entryStart = entriesStart;
35040
34926
  for (let i = 0; i < count; i++) {
35041
- const [, symbolStart] = readNumber(content, entryStart);
35042
- const [symbol2, entryEnd] = readNumber(content, symbolStart);
34927
+ const [, symbolStart] = readULEB(content, entryStart);
34928
+ const [symbol2, entryEnd] = readULEB(content, symbolStart);
35043
34929
  if (symbol2 === objcLoader) {
35044
34930
  initWriter.uleb(1);
35045
34931
  initWriter.bytes(content, symbolStart, entryEnd);
@@ -35109,7 +34995,7 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35109
34995
  if (position < bytes.length && bytes[position] < 128) {
35110
34996
  size2 = bytes[position++];
35111
34997
  } else {
35112
- const [val, next] = readNumber(bytes, position);
34998
+ const [val, next] = readULEB(bytes, position);
35113
34999
  size2 = val;
35114
35000
  position = next;
35115
35001
  }
@@ -35865,7 +35751,7 @@ function nameGuestImageAliases(wasm, symbols) {
35865
35751
  const parts2 = [wasm.subarray(0, 8)];
35866
35752
  let position = 8;
35867
35753
  while (position < wasm.length) {
35868
- const [size2, start] = readNumber(wasm, position + 1);
35754
+ const [size2, start] = readULEB(wasm, position + 1);
35869
35755
  const end = start + size2;
35870
35756
  const custom = wasm[position] === 0 ? readString(wasm, start) : void 0;
35871
35757
  if (custom?.[0] !== "name") {
@@ -35876,17 +35762,17 @@ function nameGuestImageAliases(wasm, symbols) {
35876
35762
  const subsections = [encodedString("name")];
35877
35763
  let at = custom[1];
35878
35764
  while (at < end) {
35879
- const [subSize, subStart] = readNumber(wasm, at + 1);
35765
+ const [subSize, subStart] = readULEB(wasm, at + 1);
35880
35766
  const subEnd = subStart + subSize;
35881
35767
  if (wasm[at] !== 1) {
35882
35768
  subsections.push(wasm.subarray(at, subEnd));
35883
35769
  at = subEnd;
35884
35770
  continue;
35885
35771
  }
35886
- let [count, cursor] = readNumber(wasm, subStart);
35772
+ let [count, cursor] = readULEB(wasm, subStart);
35887
35773
  const entries2 = [encodeNumber(count)];
35888
35774
  for (; count > 0; count--) {
35889
- const [index, next] = readNumber(wasm, cursor);
35775
+ const [index, next] = readULEB(wasm, cursor);
35890
35776
  const [name3, after] = readString(wasm, next);
35891
35777
  cursor = after;
35892
35778
  const symbol2 = symbols[Number(alias.exec(name3)?.[1] ?? -1)];
@@ -35910,6 +35796,7 @@ var init_swift_guest_image_ledger = __esm({
35910
35796
  init_nativeWasmContract();
35911
35797
  init_swift_sdk_image_wasm();
35912
35798
  init_swiftSdkLinkContract();
35799
+ init_wasm_binary_sections();
35913
35800
  ByteWriter = class {
35914
35801
  buf;
35915
35802
  pos = 0;
@@ -35930,16 +35817,13 @@ var init_swift_guest_image_ledger = __esm({
35930
35817
  this.buf[this.pos++] = value;
35931
35818
  }
35932
35819
  uleb(value) {
35933
- this.ensure(10);
35934
- let pos = this.pos;
35935
- const buf = this.buf;
35936
- do {
35937
- let byte = value % 128;
35938
- value = Math.floor(value / 128);
35939
- if (value) byte |= 128;
35940
- buf[pos++] = byte;
35941
- } while (value);
35942
- this.pos = pos;
35820
+ if (value < 128) {
35821
+ this.byte(value);
35822
+ return;
35823
+ }
35824
+ const encoded = encodeWasmNumber(value);
35825
+ this.ensure(encoded.length);
35826
+ for (let i = 0; i < encoded.length; i++) this.buf[this.pos++] = encoded[i];
35943
35827
  }
35944
35828
  bytes(source, start = 0, end = source.length) {
35945
35829
  const len = end - start;
@@ -36457,13 +36341,6 @@ function sha256Buffer(bytes) {
36457
36341
  return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
36458
36342
  return (0, import_node_crypto34.createHash)("sha256").update(bytes).digest();
36459
36343
  }
36460
- function uleb2(value) {
36461
- const bytes = [];
36462
- for (let rest = value; ; rest = Math.floor(rest / 128)) {
36463
- if (rest < 128) return [...bytes, rest];
36464
- bytes.push(rest % 128 | 128);
36465
- }
36466
- }
36467
36344
  function encodeGuestDyldTable(rows) {
36468
36345
  const encoded = rows.map((row) => ({ ...row, bytes: Buffer.from(row.name) })).sort((a, b) => Buffer.compare(a.bytes, b.bytes));
36469
36346
  const packs = [];
@@ -36476,7 +36353,7 @@ function encodeGuestDyldTable(rows) {
36476
36353
  value.writeBigUInt64LE(row.value);
36477
36354
  const bytes = Buffer.concat([
36478
36355
  row.bytes,
36479
- Buffer.from([0, ...uleb2(row.image), row.kind]),
36356
+ Buffer.from([0, ...encodeWasmNumber(row.image), row.kind]),
36480
36357
  value
36481
36358
  ]);
36482
36359
  if (!current2.length) firsts.push(row.bytes);
@@ -36568,6 +36445,7 @@ var init_swift_guest_dyld_table = __esm({
36568
36445
  init_sha256();
36569
36446
  init_swift_guest_image_ledger();
36570
36447
  init_swift_guest_linked_spans();
36448
+ init_wasm_binary_sections();
36571
36449
  init_wasm_narrow_boundary();
36572
36450
  PACK_BYTES = 64 * 1024;
36573
36451
  }
@@ -36662,8 +36540,8 @@ function primaryFunctionTable(bytes) {
36662
36540
  return { name: wasmReader(exported, 0).name(), table64 };
36663
36541
  }
36664
36542
  function vectorSection(id, count, parts2) {
36665
- const body = Buffer.concat([Buffer.from(uleb3(count)), ...parts2]);
36666
- return Buffer.concat([Buffer.from([id, ...uleb3(body.length)]), body]);
36543
+ const body = Buffer.concat([Buffer.from(encodeWasmNumber(count)), ...parts2]);
36544
+ return Buffer.concat([Buffer.from([id, ...encodeWasmNumber(body.length)]), body]);
36667
36545
  }
36668
36546
  function rewriteSections(bytes, sections, changes) {
36669
36547
  const out = [bytes.subarray(0, 8)];
@@ -36719,9 +36597,9 @@ function appendLazyPlacement(bytes, functions, table) {
36719
36597
  vectorSection(2, count + 1, [
36720
36598
  found2 && header ? bytes.subarray(header.at, found2.end) : new Uint8Array(),
36721
36599
  Buffer.from([
36722
- ...uleb3(module2.length),
36600
+ ...encodeWasmNumber(module2.length),
36723
36601
  ...module2,
36724
- ...uleb3(name4.length),
36602
+ ...encodeWasmNumber(name4.length),
36725
36603
  ...name4,
36726
36604
  1,
36727
36605
  112,
@@ -36743,7 +36621,7 @@ function appendLazyPlacement(bytes, functions, table) {
36743
36621
  elements.splice(
36744
36622
  placementIndex,
36745
36623
  0,
36746
- Buffer.from([1, 0, ...uleb3(functions.length), ...functions.flatMap(uleb3)])
36624
+ Buffer.from([1, 0, ...encodeWasmNumber(functions.length), ...functions.flatMap(encodeWasmNumber)])
36747
36625
  );
36748
36626
  const place2 = imports2.functions + declared.length;
36749
36627
  const instructions = [
@@ -36757,7 +36635,7 @@ function appendLazyPlacement(bytes, functions, table) {
36757
36635
  1,
36758
36636
  252,
36759
36637
  12,
36760
- ...uleb3(placementIndex),
36638
+ ...encodeWasmNumber(placementIndex),
36761
36639
  0,
36762
36640
  11
36763
36641
  ];
@@ -36778,14 +36656,14 @@ function appendLazyPlacement(bytes, functions, table) {
36778
36656
  3,
36779
36657
  vectorSection(3, declared.length + 1, [
36780
36658
  ...declared,
36781
- Buffer.from(uleb3(types2.length))
36659
+ Buffer.from(encodeWasmNumber(types2.length))
36782
36660
  ])
36783
36661
  ],
36784
36662
  [
36785
36663
  7,
36786
36664
  vectorSection(7, exports2.length + 1, [
36787
36665
  ...exports2,
36788
- Buffer.from([...uleb3(name3.length), ...name3, 0, ...uleb3(place2)])
36666
+ Buffer.from([...encodeWasmNumber(name3.length), ...name3, 0, ...encodeWasmNumber(place2)])
36789
36667
  ])
36790
36668
  ],
36791
36669
  [9, vectorSection(9, elements.length, elements)],
@@ -36793,7 +36671,7 @@ function appendLazyPlacement(bytes, functions, table) {
36793
36671
  10,
36794
36672
  vectorSection(10, bodies.length + 1, [
36795
36673
  ...bodies,
36796
- Buffer.from([...uleb3(instructions.length), ...instructions])
36674
+ Buffer.from([...encodeWasmNumber(instructions.length), ...instructions])
36797
36675
  ])
36798
36676
  ]
36799
36677
  ])
@@ -36915,40 +36793,31 @@ function nameLazyFunctions(bytes, functions) {
36915
36793
  for (const index of functions) {
36916
36794
  if (names.has(index)) continue;
36917
36795
  const name3 = Buffer.from(String(index - imported));
36918
- names.set(index, Buffer.from([...uleb3(name3.length), ...name3]));
36796
+ names.set(index, Buffer.from([...encodeWasmNumber(name3.length), ...name3]));
36919
36797
  }
36920
36798
  const ordered = [...names].sort(([a], [b]) => a - b);
36921
36799
  const functionNames = Buffer.concat([
36922
- Buffer.from(uleb3(ordered.length)),
36923
- ...ordered.flatMap(([index, name3]) => [Buffer.from(uleb3(index)), name3])
36800
+ Buffer.from(encodeWasmNumber(ordered.length)),
36801
+ ...ordered.flatMap(([index, name3]) => [Buffer.from(encodeWasmNumber(index)), name3])
36924
36802
  ]);
36925
- const content = [...subsections, { id: 1, body: functionNames }].sort((a, b) => a.id - b.id).flatMap(({ id, body }) => [Buffer.from([id, ...uleb3(body.length)]), body]);
36803
+ const content = [...subsections, { id: 1, body: functionNames }].sort((a, b) => a.id - b.id).flatMap(({ id, body }) => [Buffer.from([id, ...encodeWasmNumber(body.length)]), body]);
36926
36804
  const label = Buffer.from("name");
36927
36805
  const payload = Buffer.concat([
36928
- Buffer.from([...uleb3(label.length), ...label]),
36806
+ Buffer.from([...encodeWasmNumber(label.length), ...label]),
36929
36807
  ...content
36930
36808
  ]);
36931
36809
  const out = [bytes.subarray(0, 8)];
36932
36810
  for (const s of sections) if (s !== custom) out.push(bytes.subarray(s.offset, s.end));
36933
- out.push(Buffer.from([0, ...uleb3(payload.length)]), payload);
36811
+ out.push(Buffer.from([0, ...encodeWasmNumber(payload.length)]), payload);
36934
36812
  return Buffer.concat(out);
36935
36813
  }
36936
- var uleb3, SECTION_ORDER, readExport, lastTableElement, exportName;
36814
+ var SECTION_ORDER, readExport, lastTableElement, exportName;
36937
36815
  var init_swift_guest_dyld_functions = __esm({
36938
36816
  "src/swift-guest-dyld-functions.ts"() {
36939
36817
  "use strict";
36940
36818
  init_nativeWasmContract();
36941
36819
  init_swift_sdk_image_wasm();
36942
- uleb3 = (value) => {
36943
- const out = [];
36944
- do {
36945
- let byte = value % 128;
36946
- value = Math.floor(value / 128);
36947
- if (value) byte |= 128;
36948
- out.push(byte);
36949
- } while (value);
36950
- return out;
36951
- };
36820
+ init_wasm_binary_sections();
36952
36821
  SECTION_ORDER = [1, 2, 3, 4, 5, 13, 6, 7, 8, 9, 12, 10, 11];
36953
36822
  readExport = (r) => {
36954
36823
  r.name();
@@ -40274,30 +40143,12 @@ function wasmAutolinkEntries(bytes, out) {
40274
40143
  const len = bytes.length;
40275
40144
  while (pos < len) {
40276
40145
  const id = bytes[pos++];
40277
- let sz = bytes[pos++];
40278
- if (sz >= 128) {
40279
- sz &= 127;
40280
- let shift = 7;
40281
- while (true) {
40282
- const b = bytes[pos++];
40283
- sz |= (b & 127) << shift;
40284
- if (b < 128) break;
40285
- shift += 7;
40286
- }
40287
- }
40146
+ let sz;
40147
+ [sz, pos] = readULEB(bytes, pos, len);
40288
40148
  const end = pos + sz;
40289
40149
  if (id === 0) {
40290
- let nLen = bytes[pos++];
40291
- if (nLen >= 128) {
40292
- nLen &= 127;
40293
- let shift = 7;
40294
- while (true) {
40295
- const b = bytes[pos++];
40296
- nLen |= (b & 127) << shift;
40297
- if (b < 128) break;
40298
- shift += 7;
40299
- }
40300
- }
40150
+ let nLen;
40151
+ [nLen, pos] = readULEB(bytes, pos, end);
40301
40152
  if (nLen === 24 && raw2.toString("ascii", pos, pos + 24) === ".swift1_autolink_entries") {
40302
40153
  const payload = raw2.toString("utf8", pos + 24, end);
40303
40154
  for (const entry of payload.split("\0")) {
@@ -40534,6 +40385,7 @@ var init_swift_guest_source_inputs = __esm({
40534
40385
  init_swift_guest_source_plan();
40535
40386
  init_swift_runtime_products();
40536
40387
  init_swift_wasm_prune();
40388
+ init_wasm_binary_sections();
40537
40389
  CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
40538
40390
  PARALLEL_REPLAY = `
40539
40391
  const { spawn } = require('node:child_process')
@@ -42836,6 +42688,7 @@ function swiftModuleInputFiles(root) {
42836
42688
  ...swiftSharedSdkInputFiles(root),
42837
42689
  "../peachsim/src/admitted-mac-build.ts",
42838
42690
  "../peachsim/src/swift-shared-sdk.ts",
42691
+ "../peachsim/src/wasm-binary-sections.ts",
42839
42692
  "../peachsim/src/swift-runtime-products.ts",
42840
42693
  "../peachsim/src/swiftRuntimeProductContract.ts",
42841
42694
  "../peachsim/src/swiftTargetContract.ts",
@@ -46585,8 +46438,8 @@ function finishSwiftAppModuleFile(file) {
46585
46438
  return;
46586
46439
  }
46587
46440
  const thunks = sdkImportThunks(prefix);
46588
- const nameBytes = Buffer.from(encodedName2(NATIVE_SDK_THUNK_SECTION));
46589
- const header = Buffer.from([0, ...uleb4(nameBytes.length + thunks.length)]);
46441
+ const nameBytes = Buffer.from(encodeWasmName(NATIVE_SDK_THUNK_SECTION));
46442
+ const header = Buffer.from([0, ...encodeWasmNumber(nameBytes.length + thunks.length)]);
46590
46443
  (0, import_node_fs74.appendFileSync)(file, Buffer.concat([header, nameBytes, thunks]));
46591
46444
  }
46592
46445
  function swiftAppModuleInputs(tokens3, buildRoot, sdkLibraries) {
@@ -46938,17 +46791,17 @@ function sdkImportThunks(bytes) {
46938
46791
  for (const { type } of imports2)
46939
46792
  if (!typeIndex.has(type)) typeIndex.set(type, typeIndex.size + 1);
46940
46793
  const loaderType = [96, 1, 127, 0];
46941
- const vector = (items2) => [...uleb4(items2.length), ...items2.flat()];
46942
- const sectionBytes = (id, body) => [id, ...uleb4(body.length), ...body];
46794
+ const vector = (items2) => [...encodeWasmNumber(items2.length), ...items2.flat()];
46795
+ const sectionBytes = (id, body) => [id, ...encodeWasmNumber(body.length), ...body];
46943
46796
  const slotGlobals = imports2.map(({ slot }) => [
46944
- ...encodedName2(NATIVE_SDK_IMPORT_MODULE),
46945
- ...encodedName2(String(slot)),
46797
+ ...encodeWasmName(NATIVE_SDK_IMPORT_MODULE),
46798
+ ...encodeWasmName(String(slot)),
46946
46799
  3,
46947
46800
  127,
46948
46801
  0
46949
46802
  ]);
46950
46803
  const bodies = imports2.map(({ type }, index) => {
46951
- const slotValue = [35, ...uleb4(index)];
46804
+ const slotValue = [35, ...encodeWasmNumber(index)];
46952
46805
  const code = [
46953
46806
  0,
46954
46807
  ...slotValue,
@@ -46961,14 +46814,14 @@ function sdkImportThunks(bytes) {
46961
46814
  16,
46962
46815
  0,
46963
46816
  11,
46964
- ...Array.from({ length: params[type] }, (_, i) => [32, ...uleb4(i)]).flat(),
46817
+ ...Array.from({ length: params[type] }, (_, i) => [32, ...encodeWasmNumber(i)]).flat(),
46965
46818
  ...slotValue,
46966
46819
  17,
46967
- ...uleb4(typeIndex.get(type)),
46820
+ ...encodeWasmNumber(typeIndex.get(type)),
46968
46821
  0,
46969
46822
  11
46970
46823
  ];
46971
- return [...uleb4(code.length), ...code];
46824
+ return [...encodeWasmNumber(code.length), ...code];
46972
46825
  });
46973
46826
  return Uint8Array.from([
46974
46827
  0,
@@ -46986,21 +46839,21 @@ function sdkImportThunks(bytes) {
46986
46839
  ...sectionBytes(
46987
46840
  2,
46988
46841
  vector([
46989
- [...encodedName2("env"), ...encodedName2("__indirect_function_table"), 1, ...table],
46842
+ [...encodeWasmName("env"), ...encodeWasmName("__indirect_function_table"), 1, ...table],
46990
46843
  [
46991
- ...encodedName2(NATIVE_LAZY_IMPORT_MODULE),
46992
- ...encodedName2(NATIVE_LAZY_SLOT_IMPORT),
46844
+ ...encodeWasmName(NATIVE_LAZY_IMPORT_MODULE),
46845
+ ...encodeWasmName(NATIVE_LAZY_SLOT_IMPORT),
46993
46846
  0,
46994
46847
  0
46995
46848
  ],
46996
46849
  ...slotGlobals
46997
46850
  ])
46998
46851
  ),
46999
- ...sectionBytes(3, vector(imports2.map(({ type }) => uleb4(typeIndex.get(type))))),
46852
+ ...sectionBytes(3, vector(imports2.map(({ type }) => encodeWasmNumber(typeIndex.get(type))))),
47000
46853
  ...sectionBytes(
47001
46854
  7,
47002
46855
  vector(
47003
- imports2.map(({ slot }, i) => [...encodedName2(String(slot)), 0, ...uleb4(i + 1)])
46856
+ imports2.map(({ slot }, i) => [...encodeWasmName(String(slot)), 0, ...encodeWasmNumber(i + 1)])
47004
46857
  )
47005
46858
  ),
47006
46859
  ...sectionBytes(10, vector(bodies))
@@ -47120,7 +46973,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47120
46973
  syntheticGlobals.push(type);
47121
46974
  got.set(index, value);
47122
46975
  }
47123
- return [35, ...uleb4(index)];
46976
+ return [35, ...encodeWasmNumber(index)];
47124
46977
  };
47125
46978
  const tlsHelpers = new Map(
47126
46979
  symbols.filter((symbol2) => symbol2.kind === 0 && symbol2.name.startsWith(SDK_TLS_HELPER)).map((symbol2) => [symbol2.name.slice(SDK_TLS_HELPER.length), symbol2.index])
@@ -47172,7 +47025,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47172
47025
  const code = [16];
47173
47026
  for (let i = 0, rest = helper; i < 5; i++, rest >>>= 7)
47174
47027
  code.push(i < 4 ? rest & 127 | 128 : rest & 127);
47175
- if (addend) code.push(66, ...sleb2(addend), 124);
47028
+ if (addend) code.push(66, ...encodeWasmSigned(addend), 124);
47176
47029
  patchCode(at2, 11, code);
47177
47030
  continue;
47178
47031
  }
@@ -47246,7 +47099,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47246
47099
  syntheticGlobals.push(valueType);
47247
47100
  scratchGlobals.set(valueType, scratch2);
47248
47101
  }
47249
- const index = uleb4(scratch2);
47102
+ const index = encodeWasmNumber(scratch2);
47250
47103
  patchCode(at - 2, 12, [
47251
47104
  36,
47252
47105
  ...index,
@@ -47262,7 +47115,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47262
47115
  }
47263
47116
  const encodedNameBuf = (name3) => {
47264
47117
  const raw2 = Buffer.from(name3, "utf8");
47265
- const len = uleb4(raw2.length);
47118
+ const len = encodeWasmNumber(raw2.length);
47266
47119
  const out = Buffer.allocUnsafe(len.length + raw2.length);
47267
47120
  for (let i = 0; i < len.length; i++) out[i] = len[i];
47268
47121
  raw2.copy(out, len.length);
@@ -47307,7 +47160,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47307
47160
  }
47308
47161
  }
47309
47162
  const globalParts = [
47310
- Buffer.from(uleb4(globalCount - 1 + syntheticGlobals.length))
47163
+ Buffer.from(encodeWasmNumber(globalCount - 1 + syntheticGlobals.length))
47311
47164
  ];
47312
47165
  for (let index = 0; index < globalCount; index++) {
47313
47166
  const start = gr.at;
@@ -47352,18 +47205,18 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47352
47205
  }
47353
47206
  }
47354
47207
  const exportParts = [
47355
- Buffer.from(uleb4(exportCount + 1 + got.size)),
47208
+ Buffer.from(encodeWasmNumber(exportCount + 1 + got.size)),
47356
47209
  bytes.subarray(originalExportsStart, exportSection.end)
47357
47210
  ];
47358
47211
  for (const [index, value] of got) {
47359
47212
  exportParts.push(
47360
47213
  encodedNameBuf(`${NATIVE_SDK_GLOBAL_PREFIX}${value}.${index}`),
47361
- Buffer.from([3, ...uleb4(index)])
47214
+ Buffer.from([3, ...encodeWasmNumber(index)])
47362
47215
  );
47363
47216
  }
47364
47217
  exportParts.push(encodedNameBuf("__indirect_function_table"), Buffer.from([1, 0]));
47365
47218
  const replaced = /* @__PURE__ */ new Map([
47366
- [2, Buffer.concat([Buffer.from(uleb4(importEntryCount)), ...importParts])],
47219
+ [2, Buffer.concat([Buffer.from(encodeWasmNumber(importEntryCount)), ...importParts])],
47367
47220
  [6, Buffer.concat(globalParts)],
47368
47221
  [7, Buffer.concat(exportParts)]
47369
47222
  ]);
@@ -47380,7 +47233,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
47380
47233
  if (s.id === 10 && rebuiltCode) {
47381
47234
  parts2.push(rebuiltCode);
47382
47235
  } else if (payload) {
47383
- parts2.push(Buffer.from([s.id, ...uleb4(payload.length)]), payload);
47236
+ parts2.push(Buffer.from([s.id, ...encodeWasmNumber(payload.length)]), payload);
47384
47237
  } else {
47385
47238
  parts2.push(bytes.subarray(s.offset, s.end));
47386
47239
  }
@@ -47396,7 +47249,7 @@ function expandSdkRelocations(bytes, section2, patches) {
47396
47249
  patches.sort((a, b) => a.at - b.at);
47397
47250
  const r = wasmReader(bytes, section2.start);
47398
47251
  const count = r.u();
47399
- const payload = [Uint8Array.from(uleb4(count))];
47252
+ const payload = [Uint8Array.from(encodeWasmNumber(count))];
47400
47253
  let next = 0;
47401
47254
  for (let i = 0; i < count; i++) {
47402
47255
  const start = r.at;
@@ -47416,7 +47269,7 @@ function expandSdkRelocations(bytes, section2, patches) {
47416
47269
  }
47417
47270
  parts2.push(bytes.subarray(at, end));
47418
47271
  payload.push(
47419
- Uint8Array.from(uleb4(parts2.reduce((size3, part) => size3 + part.length, 0))),
47272
+ Uint8Array.from(encodeWasmNumber(parts2.reduce((size3, part) => size3 + part.length, 0))),
47420
47273
  ...parts2
47421
47274
  );
47422
47275
  }
@@ -47425,7 +47278,7 @@ function expandSdkRelocations(bytes, section2, patches) {
47425
47278
  if (next !== patches.length || r.at !== section2.end)
47426
47279
  throw new Error("Swift SDK code relocations exceed the code section");
47427
47280
  return Buffer.concat([
47428
- Uint8Array.from([10, ...uleb4(payload.reduce((size2, part) => size2 + part.length, 0))]),
47281
+ Uint8Array.from([10, ...encodeWasmNumber(payload.reduce((size2, part) => size2 + part.length, 0))]),
47429
47282
  ...payload
47430
47283
  ]);
47431
47284
  }
@@ -48117,7 +47970,7 @@ function partitionParent(section2) {
48117
47970
  "__objc_class_refs"
48118
47971
  ].find((name3) => section2 === name3 || section2.startsWith(`${name3}.`));
48119
47972
  }
48120
- var import_node_child_process38, import_node_crypto45, import_node_fs74, import_node_path74, import_node_util11, import_node_zlib5, run5, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
47973
+ var import_node_child_process38, import_node_crypto45, import_node_fs74, import_node_path74, import_node_util11, import_node_zlib5, run5, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, SCANNED, RUN_GAP;
48121
47974
  var init_swift_sdk_app_module = __esm({
48122
47975
  "src/swift-sdk-app-module.ts"() {
48123
47976
  "use strict";
@@ -48140,6 +47993,7 @@ var init_swift_sdk_app_module = __esm({
48140
47993
  init_swift_wasm_prune();
48141
47994
  init_swiftSdkLinkContract();
48142
47995
  init_swiftTargetContract();
47996
+ init_wasm_binary_sections();
48143
47997
  init_wasm_narrow_boundary();
48144
47998
  init_wasm_optimize();
48145
47999
  run5 = (0, import_node_util11.promisify)(import_node_child_process38.execFile);
@@ -48160,32 +48014,6 @@ var init_swift_sdk_app_module = __esm({
48160
48014
  SDK_TLS_HELPER = "__peach_sdk_tls.";
48161
48015
  SDK_TLS_DELTA = "__peach_sdk_tls_delta.";
48162
48016
  OBJC_SECTION_BOUNDARY = /^__(?:start|stop)_(__objc_(?:selectors|classes|class_refs|cats|protocols|protocol_refs|class_aliases|constant_string))$/;
48163
- uleb4 = (value) => {
48164
- const out = [];
48165
- do {
48166
- let byte = value % 128;
48167
- value = Math.floor(value / 128);
48168
- if (value) byte |= 128;
48169
- out.push(byte);
48170
- } while (value);
48171
- return out;
48172
- };
48173
- sleb2 = (value) => {
48174
- const out = [];
48175
- for (; ; ) {
48176
- const byte = Number(value & 127n);
48177
- value >>= 7n;
48178
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
48179
- out.push(byte);
48180
- return out;
48181
- }
48182
- out.push(byte | 128);
48183
- }
48184
- };
48185
- encodedName2 = (name3) => {
48186
- const bytes = [...Buffer.from(name3)];
48187
- return [...uleb4(bytes.length), ...bytes];
48188
- };
48189
48017
  SCANNED = /* @__PURE__ */ new Set([
48190
48018
  "swift5_protocols",
48191
48019
  "swift5_protocol_conformances",
@@ -49313,36 +49141,22 @@ function archiveMember(archive, name3) {
49313
49141
  throw new Error(`swift-icu: ${name3} is not in the sdk's icu archive`);
49314
49142
  }
49315
49143
  function icuSegment(object9) {
49316
- let at = 8;
49317
- const leb2 = () => {
49318
- let result = 0;
49319
- let shift = 0;
49320
- let byte;
49321
- do {
49322
- byte = object9[at++];
49323
- result += (byte & 127) * 2 ** shift;
49324
- shift += 7;
49325
- } while (byte & 128);
49326
- return result;
49327
- };
49328
49144
  const found2 = [];
49329
- while (at < object9.length) {
49330
- const id = object9[at++];
49331
- const size2 = leb2();
49332
- const end = at + size2;
49333
- if (id === 11) {
49334
- for (let count = leb2(); count > 0; count--) {
49335
- if (leb2() !== 0) throw new Error("swift-icu: unexpected data segment kind");
49336
- at++;
49337
- leb2();
49338
- at++;
49339
- const length = leb2();
49340
- const bytes = object9.subarray(at, at + length);
49341
- if (bytes[2] === 218 && bytes[3] === 39) found2.push(bytes);
49342
- at += length;
49343
- }
49145
+ for (const section2 of wasmSections(object9)) {
49146
+ if (section2.id !== 11) continue;
49147
+ const reader = readWasmSection(object9, section2.start, section2.end);
49148
+ for (let count = reader.number(); count > 0; count--) {
49149
+ if (reader.number() !== 0)
49150
+ throw new Error("swift-icu: unexpected data segment kind");
49151
+ reader.byte();
49152
+ reader.number();
49153
+ reader.byte();
49154
+ const length = reader.number();
49155
+ const start = reader.position();
49156
+ const bytes = object9.subarray(start, start + length);
49157
+ if (bytes[2] === 218 && bytes[3] === 39) found2.push(bytes);
49158
+ reader.skip(length);
49344
49159
  }
49345
- at = end;
49346
49160
  }
49347
49161
  if (found2.length !== 1)
49348
49162
  throw new Error(`swift-icu: expected one icu data segment, found ${found2.length}`);
@@ -49396,6 +49210,7 @@ var init_swift_icu = __esm({
49396
49210
  init_icuData();
49397
49211
  init_swift_toolchain();
49398
49212
  init_swiftTargetContract();
49213
+ init_wasm_binary_sections();
49399
49214
  run6 = (0, import_node_util12.promisify)(import_node_child_process40.execFile);
49400
49215
  deflate = (0, import_node_util12.promisify)(import_node_zlib6.gzip);
49401
49216
  compressBrotli = (0, import_node_util12.promisify)(import_node_zlib6.brotliCompress);
@@ -56052,7 +55867,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
56052
55867
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
56053
55868
  MULTI_MANIFEST_VERSION = 76;
56054
55869
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
56055
- compilerSourceDigest = true ? "3bdbb1d31ba7d202e612a91b60a3b588f9bc94a11990fb114585b3e2521857f5" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
55870
+ compilerSourceDigest = true ? "05ea8272883560029dae1c9aef2497d3f4d9e0d3418ef288c47c562673f5ba19" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
56056
55871
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
56057
55872
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
56058
55873
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -130716,7 +130531,7 @@ var init_nitro_superset = __esm({
130716
130531
  init_nitroContract();
130717
130532
  init_swift_standin_digest();
130718
130533
  NITRO_SUPERSET_ENTRY_NAME = "superset";
130719
- NITRO_COMPILER_DIGEST = true ? "9e51ce132e701d77aa700249b4788f66b041f8f00fbd0bac84d9a3c8ed3a7569" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
130534
+ NITRO_COMPILER_DIGEST = true ? "4a3a6b72ce59c3936e7aa74be126ecd9fae095591d2808e5f7a2cad75c921084" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
130720
130535
  nitroSupersetLock = parseLock(nitro_superset_lock_default);
130721
130536
  nitroSupersetKey = (inputs2) => nativeEntryKey({ ...inputs2, compiler: NITRO_COMPILER_DIGEST });
130722
130537
  published3 = /* @__PURE__ */ new Map();