peachsim 0.1.2589 → 0.1.2591

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 +1490 -534
  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-EMX4WZ72.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-33SCXU3Y.mjs → chunk-4QHHRGO4.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-Y4PV4HZB.mjs → chunk-7627LKJK.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-M4KUWGU3.mjs → chunk-AKKHSVJ4.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-MKSOJCRT.mjs → chunk-EGKH2L6J.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-5EFD2VBY.mjs → chunk-ILWFGZWW.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-57FFWABF.mjs → chunk-J676B57D.mjs} +5 -5
  33. package/dist-lib/esm-chunks/{chunk-JLOJZF2Y.mjs → chunk-JHXDM3YU.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-464CBA5U.mjs → chunk-MC6NMYWY.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-CRIYVOMB.mjs → chunk-NX23AMX4.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-EAIFG4MQ.mjs → chunk-Q4NA6PUR.mjs} +3 -3
  37. package/dist-lib/esm-chunks/{chunk-47K4QPVA.mjs → chunk-QBMFX3J2.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-FQQ2DMXS.mjs → chunk-RKQZGWX2.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-5QWQDXXD.mjs → chunk-SOAYP72T.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-XTKKROVU.mjs → chunk-TFG4LZ5T.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-KFHCRS5K.mjs → chunk-UIVXVMS5.mjs} +2 -2
  42. package/dist-lib/esm-chunks/{chunk-BSAAJR25.mjs → chunk-UYJXLDCG.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-FMWEI6OI.mjs → chunk-VD27WNCT.mjs} +4 -4
  44. package/dist-lib/esm-chunks/{chunk-3VNUC4DT.mjs → chunk-VF5WVB3D.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-WQ73RKJY.mjs → chunk-VRVXRZI4.mjs} +5 -5
  46. package/dist-lib/esm-chunks/{chunk-L3OSVIGA.mjs → chunk-VYZ5DC3M.mjs} +1359 -487
  47. package/dist-lib/esm-chunks/{chunk-I22LAVD5.mjs → chunk-YR6DNV76.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-PUBH3EXI.mjs → chunk-ZL5N6ENT.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{metro-layout-parser-T5QIJTEV.mjs → metro-layout-parser-ANKZARNW.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{swift-package-prebuilt-AWTZHPDM.mjs → swift-package-prebuilt-4N5CXBOZ.mjs} +10 -10
  51. package/dist-lib/esm-chunks/{swift-sdk-app-module-MGTJTVKU.mjs → swift-sdk-app-module-5IUSRXYA.mjs} +151 -67
  52. package/dist-lib/esm-chunks/{swift-sdk-image-JABGF3ZR.mjs → swift-sdk-image-7T2LMQS5.mjs} +14 -14
  53. package/dist-lib/esm-chunks/{swift-sdk-image-producer-RJRJ3EFU.mjs → swift-sdk-image-producer-7QJ3BF6E.mjs} +4 -4
  54. package/dist-lib/expo-swift-bundle.cjs +1489 -533
  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 +1518 -557
  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 +1520 -559
  93. package/dist-lib/swift-compile.cjs +1486 -530
  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 +43 -10
  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 +258 -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-guest-source-inputs.ts +158 -30
  136. package/src/swift-sdk-app-module.ts +146 -59
  137. package/src/swift-sdk-image-map.ts +137 -35
  138. package/src/swift-wasm-prune.ts +263 -85
  139. 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,