peachsim 0.1.2589 → 0.1.2590

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 (137) 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 +1172 -446
  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-6FUOY6FX.mjs → acorn-65FNEARV.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-EAIFG4MQ.mjs → chunk-2GUB5OLB.mjs} +3 -3
  28. package/dist-lib/esm-chunks/{chunk-FQQ2DMXS.mjs → chunk-462CWTWI.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-L3OSVIGA.mjs → chunk-4VCRUQ36.mjs} +1178 -452
  30. package/dist-lib/esm-chunks/{chunk-5QWQDXXD.mjs → chunk-5GNGHM5B.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-JLOJZF2Y.mjs → chunk-ADKUIQXX.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-M4KUWGU3.mjs → chunk-BZS5SIYK.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-47K4QPVA.mjs → chunk-EFKDUMB5.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-I22LAVD5.mjs → chunk-GBD26EBV.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-CRIYVOMB.mjs → chunk-HZTK7TP5.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-5EFD2VBY.mjs → chunk-JG4AANWA.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-FMWEI6OI.mjs → chunk-N2II5SRJ.mjs} +4 -4
  38. package/dist-lib/esm-chunks/{chunk-33SCXU3Y.mjs → chunk-NZY4GOG5.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-KFHCRS5K.mjs → chunk-OZJ66CXY.mjs} +2 -2
  40. package/dist-lib/esm-chunks/{chunk-464CBA5U.mjs → chunk-RGC2JNCL.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-57FFWABF.mjs → chunk-SLPXTLBK.mjs} +5 -5
  42. package/dist-lib/esm-chunks/{chunk-Y4PV4HZB.mjs → chunk-SRFKOU76.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-3VNUC4DT.mjs → chunk-V5TTEXYO.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-MKSOJCRT.mjs → chunk-WPDY5IAD.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-WQ73RKJY.mjs → chunk-WYDRQRJL.mjs} +5 -5
  46. package/dist-lib/esm-chunks/{chunk-BSAAJR25.mjs → chunk-X2EKFONU.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-PUBH3EXI.mjs → chunk-XE3VHAU2.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-XTKKROVU.mjs → chunk-YPPH6F77.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{metro-layout-parser-T5QIJTEV.mjs → metro-layout-parser-CRI3GMCM.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{swift-package-prebuilt-AWTZHPDM.mjs → swift-package-prebuilt-5XDZ2HZZ.mjs} +10 -10
  51. package/dist-lib/esm-chunks/{swift-sdk-app-module-MGTJTVKU.mjs → swift-sdk-app-module-6H3G6AXD.mjs} +14 -14
  52. package/dist-lib/esm-chunks/{swift-sdk-image-JABGF3ZR.mjs → swift-sdk-image-WAC7GG2R.mjs} +14 -14
  53. package/dist-lib/esm-chunks/{swift-sdk-image-producer-RJRJ3EFU.mjs → swift-sdk-image-producer-B3L27QTG.mjs} +4 -4
  54. package/dist-lib/expo-swift-bundle.cjs +1171 -445
  55. package/dist-lib/expo-swift-metadata.cjs +1 -1
  56. package/dist-lib/expo-swift-metadata.mjs +7 -7
  57. package/dist-lib/home-paths.cjs +1 -1
  58. package/dist-lib/host/bridge-host.cjs +1200 -469
  59. package/dist-lib/host/fetch-proxy-handler.cjs +4 -4
  60. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  61. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  62. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  63. package/dist-lib/host/websocket-proxy.cjs +1 -1
  64. package/dist-lib/index.cjs +1 -1
  65. package/dist-lib/kotlin-host.cjs +1 -1
  66. package/dist-lib/menu.cjs +1 -1
  67. package/dist-lib/menu.mjs +3 -3
  68. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  69. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  70. package/dist-lib/metro-production-bundle.cjs +1 -1
  71. package/dist-lib/metro-production-bundle.mjs +4 -4
  72. package/dist-lib/native-app-identity-project.cjs +2 -2
  73. package/dist-lib/native-app-identity-project.mjs +16 -16
  74. package/dist-lib/native-app-identity.cjs +1 -1
  75. package/dist-lib/native-app-identity.mjs +6 -6
  76. package/dist-lib/native-firebase-metadata.cjs +1 -1
  77. package/dist-lib/native-firebase-metadata.mjs +3 -3
  78. package/dist-lib/pdfium-raster.cjs +1 -1
  79. package/dist-lib/pdfium-raster.mjs +2 -2
  80. package/dist-lib/plist.cjs +1 -1
  81. package/dist-lib/plist.mjs +3 -3
  82. package/dist-lib/profiles.cjs +1 -1
  83. package/dist-lib/public-brand.cjs +1 -1
  84. package/dist-lib/public-origins-lib-esm.json +81 -81
  85. package/dist-lib/public-origins-lib.json +69 -69
  86. package/dist-lib/react-native-host-modules.cjs +1 -1
  87. package/dist-lib/react-native-host-modules.mjs +2 -2
  88. package/dist-lib/reap-browser.cjs +1 -1
  89. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  90. package/dist-lib/sdk.cjs +1 -1
  91. package/dist-lib/sdk.mjs +8 -8
  92. package/dist-lib/skills.cjs +1202 -471
  93. package/dist-lib/swift-compile.cjs +1168 -442
  94. package/dist-lib/swift-compile.mjs +10 -10
  95. package/dist-lib/swift-package.cjs +1 -1
  96. package/dist-lib/swift-package.mjs +3 -3
  97. package/dist-lib/swift-submit.cjs +1 -1
  98. package/dist-lib/swift-submit.mjs +6 -6
  99. package/dist-lib/swift-svg-raster.cjs +1 -1
  100. package/dist-lib/swift-svg-raster.mjs +2 -2
  101. package/dist-lib/swift-toolchain.cjs +1 -1
  102. package/dist-lib/swift.cjs +1 -1
  103. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  104. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  105. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  106. package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
  107. package/dist-lib/vendor/acorn.cjs +1 -1
  108. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  109. package/dist-lib/vendor/ignore.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/plist.cjs +1 -1
  112. package/dist-lib/vendor/smol-toml.cjs +1 -1
  113. package/dist-lib/vendor/stream-json.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  117. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  118. package/dist-lib/vendor/sucrase.cjs +1 -1
  119. package/dist-lib/vendor/terser.cjs +1 -1
  120. package/dist-lib/vendor/valibot.cjs +1 -1
  121. package/dist-lib/vendor/ws.cjs +1 -1
  122. package/dist-lib/vendor/zod.cjs +1 -1
  123. package/dist-lib/worklet-executable.cjs +1 -1
  124. package/dist-lib/worklet-executable.mjs +3 -3
  125. package/kotlin/sdk.tar.gz +0 -0
  126. package/package.json +1 -1
  127. package/src/swift-guest-compile.ts +2 -2
  128. package/src/swift-guest-dyld-table.ts +9 -2
  129. package/src/swift-guest-image-ledger.ts +403 -208
  130. package/src/swift-guest-link.ts +255 -113
  131. package/src/swift-guest-linked-spans.ts +217 -28
  132. package/src/swift-guest-manifest.ts +24 -13
  133. package/src/swift-guest-projection-storage.ts +6 -8
  134. package/src/swift-guest-projection.ts +7 -6
  135. package/src/swift-sdk-image-map.ts +137 -35
  136. package/src/swift-wasm-prune.ts +263 -85
  137. package/src/swiftGuestImageContract.ts +1 -1
@@ -251,24 +251,56 @@ function layout(bytes: Uint8Array, readData = true, requireExports = true): Wasm
251
251
  const code = sections.get(10)
252
252
  if (code) {
253
253
  let pos = code[0]
254
- let count: number
255
- ;[count, pos] = number(bytes, pos)
254
+ const codeStart = code[0]
255
+ const codeEnd = code[1]
256
+ let count = 0
257
+ {
258
+ let shift = 0
259
+ for (;;) {
260
+ if (pos >= codeEnd || shift > 28) throw new Error('invalid wasm integer')
261
+ const byte = bytes[pos++]!
262
+ count += (byte & 127) * 2 ** shift
263
+ if (!(byte & 128)) break
264
+ shift += 7
265
+ }
266
+ }
256
267
  for (let i = 0; i < count; i++) {
257
268
  const prefix = pos
258
- let size: number
259
- ;[size, pos] = number(bytes, pos)
260
- functionsByCodeOffset.set(prefix - code[0], imports + i)
269
+ let size = 0
270
+ const b0 = bytes[pos++]!
271
+ if (b0 < 128) {
272
+ size = b0
273
+ } else {
274
+ size = b0 & 127
275
+ let shift = 7
276
+ for (;;) {
277
+ if (pos >= codeEnd || shift > 28) throw new Error('invalid wasm integer')
278
+ const byte = bytes[pos++]!
279
+ size += (byte & 127) * 2 ** shift
280
+ if (!(byte & 128)) break
281
+ shift += 7
282
+ }
283
+ }
284
+ functionsByCodeOffset.set(prefix - codeStart, imports + i)
261
285
  if (imports + i === startFunction) startup = bytes.subarray(pos, pos + size)
262
286
  pos += size
263
- if (pos > code[1]) throw new Error('invalid wasm code')
287
+ if (pos > codeEnd) throw new Error('invalid wasm code')
264
288
  }
265
- if (pos !== code[1]) throw new Error('invalid wasm code section')
289
+ if (pos !== codeEnd) throw new Error('invalid wasm code section')
266
290
  }
267
291
  const functionsByTableSlot = new Map<number, number>()
268
292
  const elements = sections.get(9)
269
293
  if (elements) {
270
294
  let pos = elements[0]
295
+ const elemEnd = elements[1]
271
296
  const read = () => {
297
+ if (pos < elemEnd) {
298
+ const b0 = bytes[pos]!
299
+ if (b0 < 128) {
300
+ pos++
301
+ return b0
302
+ }
303
+ }
272
304
  const [value, next] = number(bytes, pos)
273
305
  pos = next
274
306
  return value
@@ -299,7 +331,7 @@ function layout(bytes: Uint8Array, readData = true, requireExports = true): Wasm
299
331
  functionsByTableSlot.set(slot, read())
300
332
  }
301
333
  }
302
- if (pos !== elements[1]) throw new Error('invalid wasm element section')
334
+ if (pos !== elemEnd) throw new Error('invalid wasm element section')
303
335
  }
304
336
  const data: { address: number; bytes: Uint8Array }[] = []
305
337
  const passive = new Map<number, Uint8Array>()
@@ -380,6 +412,36 @@ export function guestWasmDataSegments(
380
412
  }))
381
413
  }
382
414
 
415
+ function isMapSpace(code: number): boolean {
416
+ return code === 32 || (code >= 9 && code <= 13)
417
+ }
418
+
419
+ function isMapHex(code: number): boolean {
420
+ return (code >= 48 && code <= 57) || (code >= 97 && code <= 102)
421
+ }
422
+
423
+ function mapHexDigit(code: number): number {
424
+ return code <= 57 ? code - 48 : code - 87
425
+ }
426
+
427
+ function* stringLines(text: string): IterableIterator<string> {
428
+ let start = 0
429
+ for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
430
+ yield text.slice(start, end)
431
+ start = end + 1
432
+ }
433
+ yield text.slice(start)
434
+ }
435
+
436
+ export interface GuestLinkedSpansExtra {
437
+ /** Also collect live symbol names from the same linker map pass. */
438
+ readonly collectSymbols?: Set<string>
439
+ /** Also record linear-memory spans for one specific object path in the same pass. */
440
+ readonly trackedObject?: string
441
+ readonly trackedObjectOwner?: number
442
+ readonly trackedLinearSpans?: GuestLinkedSpan[]
443
+ }
444
+
383
445
  /**
384
446
  * Read only ranges belonging to the explicitly owned final-link inputs. The
385
447
  * caller must retain the complete selected-input ownership separately. A map
@@ -397,36 +459,152 @@ export function guestLinkedSpans(
397
459
  owners: ReadonlyMap<string, number>,
398
460
  sectionOwners: ReadonlyMap<string, number> = new Map(),
399
461
  importsLayout = false,
462
+ extra?: GuestLinkedSpansExtra,
400
463
  ): GuestLinkedSpan[] {
401
464
  const unchanged = before === after
402
465
  const original = layout(before, !unchanged, !importsLayout)
403
466
  const optimized = unchanged ? original : layout(after, true, !importsLayout)
467
+ const collectSymbols = extra?.collectSymbols
468
+ const trackedObject = extra?.trackedObject
469
+ const trackedObjectOwner = extra?.trackedObjectOwner
470
+ const trackedLinearSpans = extra?.trackedLinearSpans
471
+ const hasSectionOwners = sectionOwners.size > 0
404
472
  let codeOffset: number | undefined
405
473
  let outputSection = ''
406
474
  const codeOwners = new Map<number, number>()
407
- const pieces: { image: number | undefined; address: number; length: number }[] = []
408
- for (const line of typeof map === 'string' ? map.split('\n') : map) {
409
- const match = /^\s*(\S+)\s+([\da-f]+)\s+([\da-f]+)( +)(\S.*)$/.exec(line)
410
- if (!match) continue
411
- const [, address, offset, size, indent, source] = match
412
- if (address === '-' && indent === ' ') {
413
- outputSection = source!
414
- if (source === 'CODE') codeOffset = parseInt(offset!, 16)
475
+ const pieces: {
476
+ image: number | undefined
477
+ address: number
478
+ length: number
479
+ tracked: boolean
480
+ }[] = []
481
+ const lines = typeof map === 'string' ? stringLines(map) : map
482
+ for (const line of lines) {
483
+ const lineLen = line.length
484
+ let pos = 0
485
+ let onlySpaces = true
486
+ while (pos < lineLen) {
487
+ const ch = line.charCodeAt(pos)
488
+ if (!isMapSpace(ch)) break
489
+ if (ch !== 32) onlySpaces = false
490
+ pos++
491
+ }
492
+ const leadingSpaces = pos
493
+ if (pos >= lineLen) continue
494
+
495
+ // col 1: \S+
496
+ const addrStart = pos
497
+ while (pos < lineLen && !isMapSpace(line.charCodeAt(pos))) pos++
498
+ const addrEnd = pos
499
+ if (pos >= lineLen) continue
500
+
501
+ // \s+
502
+ const s1 = pos
503
+ while (pos < lineLen) {
504
+ const ch = line.charCodeAt(pos)
505
+ if (!isMapSpace(ch)) break
506
+ if (ch !== 32) onlySpaces = false
507
+ pos++
508
+ }
509
+ if (pos === s1 || pos >= lineLen) continue
510
+
511
+ // col 2: [\da-f]+
512
+ const offStart = pos
513
+ let offsetVal = 0
514
+ while (pos < lineLen && isMapHex(line.charCodeAt(pos))) {
515
+ offsetVal = offsetVal * 16 + mapHexDigit(line.charCodeAt(pos++))
516
+ }
517
+ if (pos === offStart || pos >= lineLen) continue
518
+
519
+ // \s+
520
+ const s2 = pos
521
+ while (pos < lineLen) {
522
+ const ch = line.charCodeAt(pos)
523
+ if (!isMapSpace(ch)) break
524
+ if (ch !== 32) onlySpaces = false
525
+ pos++
526
+ }
527
+ if (pos === s2 || pos >= lineLen) continue
528
+
529
+ // col 3: [\da-f]+
530
+ const sizeStart = pos
531
+ let sizeVal = 0
532
+ while (pos < lineLen && isMapHex(line.charCodeAt(pos))) {
533
+ sizeVal = sizeVal * 16 + mapHexDigit(line.charCodeAt(pos++))
534
+ }
535
+ if (pos === sizeStart || pos >= lineLen) continue
536
+
537
+ // ( +)
538
+ const indentStart = pos
539
+ while (pos < lineLen && line.charCodeAt(pos) === 32) pos++
540
+ const indentLen = pos - indentStart
541
+ if (indentLen === 0 || pos >= lineLen) continue
542
+
543
+ const firstCh = line.charCodeAt(pos)
544
+ if (isMapSpace(firstCh)) continue
545
+ const sourceStart = pos
546
+
547
+ if (
548
+ collectSymbols &&
549
+ onlySpaces &&
550
+ leadingSpaces > 0 &&
551
+ indentLen >= 9 &&
552
+ firstCh !== 47 &&
553
+ firstCh !== 60
554
+ ) {
555
+ let symEnd = sourceStart + 1
556
+ while (symEnd < lineLen && !isMapSpace(line.charCodeAt(symEnd))) symEnd++
557
+ collectSymbols.add(line.slice(sourceStart, symEnd))
558
+ }
559
+
560
+ const isDash = addrEnd - addrStart === 1 && line.charCodeAt(addrStart) === 45
561
+ if (isDash && indentLen === 1) {
562
+ if (line.indexOf('\r', sourceStart) >= 0) continue
563
+ outputSection = line.slice(sourceStart)
564
+ if (outputSection === 'CODE') codeOffset = offsetVal
415
565
  continue
416
566
  }
417
- const separator = source!.indexOf(':(')
567
+ if (sizeVal === 0) continue
568
+ const separator = line.indexOf(':(', sourceStart)
418
569
  if (separator < 0) continue
419
- const image = sectionOwners.get(source!) ?? owners.get(source!.slice(0, separator))
420
- const length = parseInt(size!, 16)
421
- if (!length) continue
422
- if (address !== '-') {
423
- if (outputSection === 'DATA')
424
- pieces.push({ image, address: parseInt(address!, 16), length })
570
+ if (line.indexOf('\r', sourceStart) >= 0) continue
571
+ let hasLineSep = false
572
+ for (let i = sourceStart; i < lineLen; i++) {
573
+ const ch = line.charCodeAt(i)
574
+ if (ch === 0x2028 || ch === 0x2029) {
575
+ hasLineSep = true
576
+ break
577
+ }
578
+ }
579
+ if (hasLineSep) continue
580
+ const objectPath = line.slice(sourceStart, separator)
581
+ let image = hasSectionOwners ? sectionOwners.get(line.slice(sourceStart)) : undefined
582
+ if (image === undefined) image = owners.get(objectPath)
583
+ if (!isDash) {
584
+ if (outputSection === 'DATA') {
585
+ let addressVal = 0
586
+ let allHex = true
587
+ for (let i = addrStart; i < addrEnd; i++) {
588
+ const ch = line.charCodeAt(i)
589
+ if (isMapHex(ch)) addressVal = addressVal * 16 + mapHexDigit(ch)
590
+ else {
591
+ allHex = false
592
+ break
593
+ }
594
+ }
595
+ if (!allHex) addressVal = parseInt(line.slice(addrStart, addrEnd), 16)
596
+ pieces.push({
597
+ image,
598
+ address: addressVal,
599
+ length: sizeVal,
600
+ tracked: trackedObject !== undefined && objectPath === trackedObject,
601
+ })
602
+ }
425
603
  continue
426
604
  }
427
605
  if (image === undefined || outputSection !== 'CODE') continue
428
606
  if (codeOffset === undefined) throw new Error('link map has no code section')
429
- const index = original.functionsByCodeOffset.get(parseInt(offset!, 16) - codeOffset)
607
+ const index = original.functionsByCodeOffset.get(offsetVal - codeOffset)
430
608
  if (index === undefined) throw new Error('link map function has no wasm body')
431
609
  const existing = codeOwners.get(index)
432
610
  if (existing !== undefined && existing !== image)
@@ -435,12 +613,23 @@ export function guestLinkedSpans(
435
613
  }
436
614
  pieces.sort((a, b) => a.address - b.address)
437
615
  const spans: GuestLinkedSpan[] = []
438
- for (const [index, { image, address, length }] of pieces.entries()) {
439
- if (image === undefined) continue
616
+ for (let index = 0; index < pieces.length; index++) {
617
+ const piece = pieces[index]!
618
+ const { image, address, length, tracked } = piece
619
+ if (image === undefined && !tracked) continue
440
620
  let next = index + 1
441
621
  while (next < pieces.length && pieces[next]!.address < address + length) next++
442
622
  const end = pieces[next]?.address ?? address + length
443
- spans.push({ image, space: 'linear-memory', address, length: end - address })
623
+ const spanLength = end - address
624
+ if (image !== undefined)
625
+ spans.push({ image, space: 'linear-memory', address, length: spanLength })
626
+ if (tracked && trackedLinearSpans && trackedObjectOwner !== undefined)
627
+ trackedLinearSpans.push({
628
+ image: trackedObjectOwner,
629
+ space: 'linear-memory',
630
+ address,
631
+ length: spanLength,
632
+ })
444
633
  }
445
634
  const optimizedOwners = new Map<number, number>()
446
635
  const dataAt = (module: WasmLayout, start: number, length: number): Buffer => {
@@ -486,7 +675,7 @@ export function guestLinkedSpans(
486
675
  throw new Error(`optimization changed linked data at ${span.address}`)
487
676
  }
488
677
  let previous: GuestLinkedSpan | undefined
489
- for (const span of [...spans].sort((a, b) => a.address - b.address)) {
678
+ for (const span of spans) {
490
679
  if (
491
680
  previous &&
492
681
  span.address < previous.address + previous.length &&
@@ -35,9 +35,10 @@ export function selectedGuestManifestInputs(
35
35
  plan: GuestLinkPlan,
36
36
  selection: readonly GuestLinkSelection[],
37
37
  identities: ReadonlyMap<string, string>,
38
+ readSelected?: (item: GuestLinkSelection) => Uint8Array,
38
39
  ): Map<number, GuestManifestInput[]> {
39
40
  const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]))
40
- const archives = new Map<string, ReturnType<typeof readArMembers>>()
41
+ const archives = new Map<string, Map<string, Uint8Array[]>>()
41
42
  const images = new Map<number, GuestManifestInput[]>()
42
43
  for (const item of selection) {
43
44
  const artifact = artifacts.get(item.artifact)
@@ -46,19 +47,29 @@ export function selectedGuestManifestInputs(
46
47
  throw new Error(`selected input has no logical identity: ${item.artifact}`)
47
48
  let bytes: Uint8Array
48
49
  let memberIdentity: readonly [string, number] | null = null
49
- if (item.member === null) bytes = readFileSync(item.artifact)
50
- else {
51
- let members = archives.get(item.artifact)
52
- if (!members) {
53
- members = readArMembers(readFileSync(item.artifact))
54
- archives.set(item.artifact, members)
50
+ if (item.member === null) {
51
+ bytes = readSelected ? readSelected(item) : readFileSync(item.artifact)
52
+ } else {
53
+ if (readSelected) {
54
+ bytes = readSelected(item)
55
+ } else {
56
+ let members = archives.get(item.artifact)
57
+ if (!members) {
58
+ members = new Map()
59
+ for (const member of readArMembers(readFileSync(item.artifact))) {
60
+ let list = members.get(member.name)
61
+ if (!list) members.set(member.name, (list = []))
62
+ list.push(member.bytes)
63
+ }
64
+ archives.set(item.artifact, members)
65
+ }
66
+ const matching = members.get(item.member)
67
+ if (!matching || matching.length !== 1)
68
+ throw new Error(
69
+ `selected archive member is ambiguous: ${item.artifact}(${item.member})`,
70
+ )
71
+ bytes = matching[0]!
55
72
  }
56
- const matching = members.filter((member) => member.name === item.member)
57
- if (matching.length !== 1)
58
- throw new Error(
59
- `selected archive member is ambiguous: ${item.artifact}(${item.member})`,
60
- )
61
- bytes = matching[0]!.bytes
62
73
  const origin = artifact.memberOrigins?.get(item.member)
63
74
  if (artifact.memberOrigins && !origin)
64
75
  throw new Error(
@@ -263,6 +263,7 @@ export function finalizeGuestProjectionStorage(options: {
263
263
  }): { readonly wasm: Uint8Array; readonly images: readonly SwiftGuestImageManifest[] } {
264
264
  const owner = options.owners.get(options.projectionObject)
265
265
  if (owner === undefined) throw new Error('guest projection object has no image owner')
266
+ const ranges: GuestLinkedSpan[] = []
266
267
  const spans = guestLinkedSpans(
267
268
  options.map,
268
269
  options.linked,
@@ -270,20 +271,17 @@ export function finalizeGuestProjectionStorage(options: {
270
271
  options.owners,
271
272
  options.sectionOwners,
272
273
  options.sdkSpans !== undefined,
274
+ {
275
+ trackedObject: options.projectionObject,
276
+ trackedObjectOwner: owner,
277
+ trackedLinearSpans: ranges,
278
+ },
273
279
  )
274
280
  const images = planGuestProjectionRegions(
275
281
  options.reserved.images,
276
282
  options.reserved.capacities,
277
283
  options.sdkSpans ? [...spans, ...options.sdkSpans] : spans,
278
284
  )
279
- const ranges = guestLinkedSpans(
280
- options.map,
281
- options.linked,
282
- options.optimized,
283
- new Map([[options.projectionObject, owner]]),
284
- undefined,
285
- options.sdkSpans !== undefined,
286
- ).filter((span) => span.space === 'linear-memory')
287
285
  const result = Buffer.from(options.optimized)
288
286
  const data = guestWasmDataSegments(options.optimized, options.sdkSpans === undefined)
289
287
  const locations = new Map<number, number>()
@@ -184,19 +184,20 @@ export function finalizeLinkedGuestImages(options: {
184
184
  }): { readonly wasm: Uint8Array; readonly images: readonly SwiftGuestImageManifest[] } {
185
185
  const image = options.owners.get(options.projectionObject)
186
186
  if (image === undefined) throw new Error('guest projection object has no image owner')
187
+ const projectionData: GuestLinkedSpan[] = []
187
188
  const spans = guestLinkedSpans(
188
189
  options.map,
189
190
  options.linked,
190
191
  options.optimized,
191
192
  options.owners,
192
193
  options.sectionOwners,
194
+ false,
195
+ {
196
+ trackedObject: options.projectionObject,
197
+ trackedObjectOwner: image,
198
+ trackedLinearSpans: projectionData,
199
+ },
193
200
  )
194
- const projectionData = guestLinkedSpans(
195
- options.map,
196
- options.linked,
197
- options.optimized,
198
- new Map([[options.projectionObject, image]]),
199
- ).filter((span) => span.space === 'linear-memory')
200
201
  const images = options.manifests(spans)
201
202
  return {
202
203
  images,
@@ -53,6 +53,23 @@ export const chunkKey = (
53
53
  export const isPartitioned = (section: string) =>
54
54
  PARTITIONED.some((name) => section === name || section.startsWith(`${name}.`))
55
55
 
56
+ function isHexChar(code: number): boolean {
57
+ return (code >= 48 && code <= 57) || (code >= 97 && code <= 102)
58
+ }
59
+
60
+ function hexDigit(code: number): number {
61
+ return code <= 57 ? code - 48 : code - 87
62
+ }
63
+
64
+ function hasLineBreak(line: string, from: number): boolean {
65
+ if (line.indexOf('\r', from) >= 0) return true
66
+ for (let i = from; i < line.length; i++) {
67
+ const ch = line.charCodeAt(i)
68
+ if (ch === 0x2028 || ch === 0x2029) return true
69
+ }
70
+ return false
71
+ }
72
+
56
73
  /** reads a wasm-ld -Map file's data and code input chunks with the symbols each defines. */
57
74
  export function readWasmLinkMap(file: string, partition: boolean): WasmLinkMap {
58
75
  const segments = new Map<string, { address: number; size: number }>()
@@ -61,48 +78,133 @@ export function readWasmLinkMap(file: string, partition: boolean): WasmLinkMap {
61
78
  let kind = ''
62
79
  let segment = ''
63
80
  let previous: WasmMapChunk | undefined
64
- const hex = (value: string) => (value === '-' ? -1 : parseInt(value, 16))
65
81
  for (const line of guestLinkLines(file)) {
66
- const symbol = /^ *([0-9a-f]+|-) +[0-9a-f]+ +([0-9a-f]+) {17}(\S.*)$/.exec(line)
67
- if (symbol) {
68
- previous?.symbols.push({
69
- name: symbol[3]!,
70
- address: hex(symbol[1]!),
71
- size: parseInt(symbol[2]!, 16),
72
- })
73
- continue
82
+ const length = line.length
83
+ let pos = 0
84
+ while (pos < length && line.charCodeAt(pos) === 32) pos++
85
+ if (pos >= length) continue
86
+ const leadingSpaces = pos
87
+
88
+ // col 1: addr (lower hex or '-')
89
+ let address = -1
90
+ if (line.charCodeAt(pos) === 45) {
91
+ pos++
92
+ } else {
93
+ const start = pos
94
+ let value = 0
95
+ while (pos < length && isHexChar(line.charCodeAt(pos))) {
96
+ value = value * 16 + hexDigit(line.charCodeAt(pos++))
97
+ }
98
+ if (pos === start) continue
99
+ address = value
74
100
  }
75
- const output = /^ +- +[0-9a-f]+ +[0-9a-f]+ (\S+)$/.exec(line)
76
- if (output) {
77
- kind = output[1]!
101
+
102
+ // spaces between col 1 and col 2
103
+ const s1 = pos
104
+ while (pos < length && line.charCodeAt(pos) === 32) pos++
105
+ if (pos === s1 || pos >= length) continue
106
+
107
+ // col 2: offset (lower hex)
108
+ const offStart = pos
109
+ let offset = 0
110
+ while (pos < length && isHexChar(line.charCodeAt(pos))) {
111
+ offset = offset * 16 + hexDigit(line.charCodeAt(pos++))
112
+ }
113
+ if (pos === offStart) continue
114
+
115
+ // spaces between col 2 and col 3
116
+ const s2 = pos
117
+ while (pos < length && line.charCodeAt(pos) === 32) pos++
118
+ if (pos === s2 || pos >= length) continue
119
+
120
+ // col 3: size (lower hex)
121
+ const sizeStart = pos
122
+ let size = 0
123
+ while (pos < length && isHexChar(line.charCodeAt(pos))) {
124
+ size = size * 16 + hexDigit(line.charCodeAt(pos++))
125
+ }
126
+ if (pos === sizeStart || pos >= length) continue
127
+
128
+ // indent spaces
129
+ const indentStart = pos
130
+ while (pos < length && line.charCodeAt(pos) === 32) pos++
131
+ const indent = pos - indentStart
132
+ if (indent === 0 || pos >= length) continue
133
+
134
+ if (indent === 17) {
135
+ if (previous) {
136
+ const first = line.charCodeAt(pos)
137
+ if (first > 32 && !hasLineBreak(line, pos)) {
138
+ previous.symbols.push({
139
+ name: line.slice(pos),
140
+ address,
141
+ size,
142
+ })
143
+ }
144
+ }
78
145
  continue
79
146
  }
80
- if (kind === 'DATA') {
81
- const top = /^ *([0-9a-f]+) +[0-9a-f]+ +([0-9a-f]+) (\S+)$/.exec(line)
82
- if (top) {
83
- segment = top[3]!
84
- segments.set(segment, { address: hex(top[1]!), size: parseInt(top[2]!, 16) })
85
- continue
147
+
148
+ if (indent === 1) {
149
+ // single token with no whitespace for output / top-level DATA segment
150
+ let hasWhitespace = false
151
+ for (let i = pos; i < length; i++) {
152
+ const ch = line.charCodeAt(i)
153
+ if (ch <= 32) {
154
+ hasWhitespace = true
155
+ break
156
+ }
157
+ }
158
+ if (hasWhitespace) continue
159
+ if (address < 0 && leadingSpaces > 0) {
160
+ kind = line.slice(pos)
161
+ } else if (kind === 'DATA' && address >= 0) {
162
+ segment = line.slice(pos)
163
+ segments.set(segment, { address, size })
86
164
  }
165
+ continue
87
166
  }
88
- if (kind !== 'DATA' && kind !== 'CODE') continue
89
- const input = /^ *([0-9a-f]+|-) +([0-9a-f]+) +([0-9a-f]+) {9}([/<].*)$/.exec(line)
90
- if (!input) continue
91
- const name = input[4]!
92
- const split = /^(.*?):\((.*)\)$/s.exec(name)
93
- const path = split ? split[1]! : name
94
- const member = /\(([^()]+)\)$/.exec(path)
95
- previous = {
96
- inputFile: path,
97
- segment,
98
- address: hex(input[1]!),
99
- offset: parseInt(input[2]!, 16),
100
- size: parseInt(input[3]!, 16),
101
- object: (member ? member[1]! : basename(path)).replace(/^lib\w*?__/, ''),
102
- section: split ? split[2]! : '',
103
- symbols: [],
167
+
168
+ if (indent === 9 && (kind === 'DATA' || kind === 'CODE')) {
169
+ const first = line.charCodeAt(pos)
170
+ if (first !== 47 && first !== 60) continue
171
+ if (hasLineBreak(line, pos)) continue
172
+ const name = line.slice(pos)
173
+ let filePath = name
174
+ let section = ''
175
+ if (name.charCodeAt(name.length - 1) === 41) {
176
+ const splitAt = name.indexOf(':(')
177
+ if (splitAt >= 0) {
178
+ filePath = name.slice(0, splitAt)
179
+ section = name.slice(splitAt + 2, -1)
180
+ }
181
+ }
182
+ let objectName: string | undefined
183
+ if (filePath.charCodeAt(filePath.length - 1) === 41) {
184
+ const open = filePath.lastIndexOf('(')
185
+ if (open >= 0 && open + 1 < filePath.length - 1) {
186
+ const close = filePath.indexOf(')', open + 1)
187
+ if (close === filePath.length - 1) {
188
+ objectName = filePath.slice(open + 1, -1)
189
+ }
190
+ }
191
+ }
192
+ if (objectName === undefined) objectName = basename(filePath)
193
+ if (objectName.startsWith('lib') && objectName.includes('__')) {
194
+ objectName = objectName.replace(/^lib\w*?__/, '')
195
+ }
196
+ previous = {
197
+ inputFile: filePath,
198
+ segment,
199
+ address,
200
+ offset,
201
+ size,
202
+ object: objectName,
203
+ section,
204
+ symbols: [],
205
+ }
206
+ ;(kind === 'DATA' ? data : code).push(previous)
104
207
  }
105
- ;(kind === 'DATA' ? data : code).push(previous)
106
208
  }
107
209
  return { segments, data: partition ? data.flatMap(symbolPieces) : data, code }
108
210
  }