@ai-ecoverse/slicc-kernel 1.165.1 → 1.165.3

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.
@@ -630,6 +630,9 @@ var init_access = __esm({
630
630
  function renameWait(view) {
631
631
  return view.foreign() ? RENAME_WAIT_SHARED_MS : RENAME_WAIT_MS;
632
632
  }
633
+ function heldSlot(path) {
634
+ return HELD + (changeHash(normal(path)) & HELD_SLOTS - 1);
635
+ }
633
636
  function changeHash(path) {
634
637
  let h = 2166136261;
635
638
  for (let i = 0; i < path.length; i++) {
@@ -647,7 +650,7 @@ function normal(path) {
647
650
  }
648
651
  return `/${parts.join("/")}`;
649
652
  }
650
- var GEN, RING, RING_SIZE, SLOT, SHARED_TTL_MS, RENAME_WAIT_MS, RENAME_WAIT_SHARED_MS, DIRTY, FOREIGN, RENAMES, CHANGES_BYTES, ChangeView;
653
+ var GEN, RING, RING_SIZE, SLOT, SHARED_TTL_MS, RENAME_WAIT_MS, RENAME_WAIT_SHARED_MS, DIRTY, FOREIGN, RENAMES, HELD, HELD_SLOTS, CHANGES_BYTES, ChangeView;
651
654
  var init_changes = __esm({
652
655
  "src/fs/changes.ts"() {
653
656
  "use strict";
@@ -662,7 +665,9 @@ var init_changes = __esm({
662
665
  DIRTY = RING + RING_SIZE * SLOT;
663
666
  FOREIGN = DIRTY + 1;
664
667
  RENAMES = FOREIGN + 1;
665
- CHANGES_BYTES = (RENAMES + 1) * 4;
668
+ HELD = RENAMES + 1;
669
+ HELD_SLOTS = 1024;
670
+ CHANGES_BYTES = (HELD + HELD_SLOTS) * 4;
666
671
  ChangeView = class {
667
672
  view;
668
673
  constructor(sab) {
@@ -677,6 +682,9 @@ var init_changes = __esm({
677
682
  foreign() {
678
683
  return this.view.length > FOREIGN && capturedAtomics.load(this.view, FOREIGN) === 1;
679
684
  }
685
+ peerHeld(path) {
686
+ return this.view.length > HELD && capturedAtomics.load(this.view, heldSlot(path)) === 1;
687
+ }
680
688
  renames() {
681
689
  return this.view.length > RENAMES ? capturedAtomics.load(this.view, RENAMES) : 0;
682
690
  }
@@ -854,6 +862,14 @@ var init_pages = __esm({
854
862
  pin() {
855
863
  this.pinned = true;
856
864
  }
865
+ landed(at, length) {
866
+ const end = at + length;
867
+ for (let page = capturedMath.floor(at / PAGE); page * PAGE < end; page++) {
868
+ if (this.pages.has(page) && !this.dirty.has(page)) this.drop(page);
869
+ }
870
+ this.length = capturedMath.max(this.length, end);
871
+ this.stored = capturedMath.max(this.stored, end);
872
+ }
857
873
  reset(size) {
858
874
  if (this.pinned) return;
859
875
  for (const page of [...this.pages.keys()]) if (!this.dirty.has(page)) this.drop(page);
@@ -975,6 +991,11 @@ var init_ranged = __esm({
975
991
  get changed() {
976
992
  return this.pages.changed;
977
993
  }
994
+ wrote(at, length) {
995
+ this.pages.landed(at, length);
996
+ this.version = void 0;
997
+ this.fresh();
998
+ }
978
999
  get pinnedVersion() {
979
1000
  return this.version;
980
1001
  }
@@ -3062,7 +3083,7 @@ var init_version = __esm({
3062
3083
  "src/version.ts"() {
3063
3084
  "use strict";
3064
3085
  init_captured_globals();
3065
- KERNEL_VERSION = true ? "1.165.1" : "0.0.0-dev";
3086
+ KERNEL_VERSION = true ? "1.165.3" : "0.0.0-dev";
3066
3087
  OS_RELEASE = "6.0.0-slicc";
3067
3088
  }
3068
3089
  });
@@ -7597,8 +7618,43 @@ var init_wasi_files = __esm({
7597
7618
  live() {
7598
7619
  if (this.spoiled) throw new WasiError("ESTALE");
7599
7620
  }
7621
+ crowded() {
7622
+ return this.watch?.view.peerHeld(this.where) === true;
7623
+ }
7624
+ exact() {
7625
+ this.flush();
7626
+ const watch = this.watch;
7627
+ const size = this.retried(() => watch.stat(this.where)).size;
7628
+ if (this.ranged) {
7629
+ if (size !== this.ranged.size()) this.ranged.reread();
7630
+ return void 0;
7631
+ }
7632
+ if (this.data && size !== this.length) this.data = void 0;
7633
+ return this.data ? void 0 : size;
7634
+ }
7635
+ wrote(at, bytes) {
7636
+ if (this.ranged) {
7637
+ this.ranged.wrote(at, bytes.length);
7638
+ return;
7639
+ }
7640
+ const view = this.watch.view;
7641
+ const { now, changed: changed2 } = view.changedSince(this.seen, this.where);
7642
+ this.seen = now;
7643
+ if (changed2) this.data = void 0;
7644
+ if (!this.data) return;
7645
+ const end = at + bytes.length;
7646
+ this.ensure(end);
7647
+ const buf = this.data;
7648
+ if (at > this.length) buf.fill(0, this.length, at);
7649
+ buf.set(bytes, at);
7650
+ this.length = capturedMath.max(this.length, end);
7651
+ }
7600
7652
  size() {
7601
7653
  this.live();
7654
+ if (this.crowded()) {
7655
+ const known = this.exact();
7656
+ if (known !== void 0) return known;
7657
+ }
7602
7658
  if (this.ranged) return this.ranged.size();
7603
7659
  this.load();
7604
7660
  return this.length;
@@ -7618,6 +7674,13 @@ var init_wasi_files = __esm({
7618
7674
  if (bytes.length === 0) return 0;
7619
7675
  const end = at + bytes.length;
7620
7676
  this.fits(end);
7677
+ const { pwrite } = this.fs;
7678
+ if (pwrite && this.crowded() && end > this.size()) {
7679
+ const copy2 = bytes.slice();
7680
+ this.retried(() => pwrite.call(this.fs, this.where, at, copy2, true));
7681
+ this.wrote(at, bytes);
7682
+ return bytes.length;
7683
+ }
7621
7684
  this.dirty = true;
7622
7685
  if (this.ranged) {
7623
7686
  this.ranged.write(at, bytes);