Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

feat: Granular tracking of stale references

オープン
#2,753 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
静か
技術スタック
typescript
領域
compilers

調査の方向性

issueではファイルもテストも特定されていません。まず、提案で言及されているTypeScript-to-WGSL参照の生成と、既存の消費検証作業を追跡してください。元の値が変更された可能性がある場合に参照へアクセスできなくなり、不変の引数の使用は引き続き有効であれば完了です。

索引モデルが issue の本文から書いたものです。

説明

There has been TypeScript behavior that we have overlooked up until now that has to do with references:

const Boid = d.struct({
  pos: d.vec3f,
  vel: d.vec3f,
});

function main() {
  'use gpu';
  const boid = Boid();
  // getting a reference to the boid's position
  const boidPos = boid.pos;
  // replacing the `pos` property of the boid with a new vector
  boid.pos = d.vec3f(1, 2, 3);
  // returning the `x` coordinate of the vector that was once
  // the boid's position
  return boidPos.x;
}

We'd expect the result of main() to be 0, since we haven't actually updated the x coordinate of the existing boid.pos, rather we replaced that vector with an entirely new one, making boidPos no longer point to the actual value of boid.pos (they drifted out of sync).
We generate the following WGSL:

struct Boid {
  pos: vec3f,
  vel: vec3f,
}

fn main() -> f32 {
  var boid = Boid();
  let boidPos = (&boid.pos);
  boid.pos = vec3f(1, 2, 3);
  return (*boidPos).x;
}

In the generated WGSL, boidPos is a pointer to boid.pos, meaning it always reflects the up-to-date value of boid.pos, making the result of calling main() be 1.

Stale reference tracking

@cieplypolar's insight is that we can use a sort of borrow checker (like we were planning to do for consumption verification) to invalidate stale references. Essentially, as soon as it's determined that boid (the original value) could have been mutated by an instruction, boidPos would become invalidated and unaccessible.

struct Boid {
  pos: vec3f,
  vel: vec3f,
}

fn main() -> f32 {
  var boid = Boid();
  let boidPos = (&boid.pos);
  boid.pos = vec3f(1, 2, 3); // <- accessing the original invalidates the aliases
  return (*boidPos).x; // 🚫 `boidPos` is a stale reference
}

I believe there is a way to do this statically without introducing too much complexity to the system.

[!NOTE]
To be continued...

function main() {
  'use gpu';
  const boid = Boid();
  // boid
  //

  const boidPos = boid.pos;
  // boid
  // |
  // | (.pos)
  // |
  // boidPos

  randomFunction(boid) // <- arguments are immutable, so this is okay

  blackBox(d.ref(boid)); // <- could mutate `boid`
  // boid
  // |
  // | (.pos)
  // |
  // ☠️ boidPos

  return boidPos.x; // 🚫 `boidPos` is a stale reference
}
function main() {
  'use gpu';
  const boid = Boid();
  // boid
  //

  const boidPos = boid.pos;
  // boid
  // |
  // | (.pos)
  // |
  // boidPos

  const boidVel = boid.vel;
  // boid
  // |         \
  // | (.pos)   \ (.vel)
  // |           \
  // boidPos      boidVel

  blackBox(d.ref(boid)); // <- could mutate `boid`
  // boid
  // |         \
  // | (.pos)   \ (.vel)
  // |           \
  // ☠️ boidPos   ☠️ boidVel

  return boidPos.x; // 🚫 `boidPos` is a stale reference
}
主要言語
TypeScript
スター
3.3k
フォーク
141
平均マージ
3日 8時間
マージ済み PR(30日)
72

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/TypeGPU のほかの issue

software-mansion/TypeGPU の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。