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

JSON prebuild export and import broken?

オープン
#599 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
compilers

調査の方向性

createKernelMap と toJSON/fromJSON エントリポイントから始め、次に map 関数と native 関数に対する FunctionNode の処理を調査します。issue に記載されたエクスポート/インポートのシーケンスを再現し、コンパイルされた fragment shader の出力を追跡します。map の戻り値とカスタム native 関数を含む kernel を、map 結果変数が欠落することなくエクスポート、インポート、コンパイルできれば完了です。

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

説明

What is wrong?

To make the loading time faster, I thought to prebuild my kernels once as JSON with toJSON(), and use this JSON to create my MapKernels. But the toJSON() is out of date (not handling native functions correct), and also the intern fromJSON(...) do not work. I tried to patch them, and now I can export, but I don't get the import working.
Additional information: I use a map function with some map return values, and custom native functions.

Where does it happen?

Not specific to a system.

How do we replicate the issue?

  • Create a kernel with createKernelMap(...)
    • Use at least one map function
    • Use at least one native function
  • Export the kernel with toJSON()
  • Try to create a new kernel with that JSON.

How important is this (1-5)?

2

Expected behavior (i.e. solution)

Should work

Other Comments

After some tests to patch fromJSON(...) I got it working, but the compiled fragment shader complains about complains about the missing map result variables.
Here are my patched functions:

toJSON = function() {
  return this.traceFunctionCalls(this.rootNode.name).reverse().map(name => {
    const nativeIndex = this.nativeFunctionNames.indexOf(name);
    if (nativeIndex > -1) {
      return {
        name,
        source: this.nativeFunctions[nativeIndex].source
      };
    } else if (this.functionMap[name]) {
      return this.functionMap[name].toJSON();
    } else {
      throw new Error(`function ${ name } not found`);
    }
  });
}
fromJSON = function(jsonFunctionNodes, FunctionNode) {
  this.functionMap = {};
    for (let i = 0; i < jsonFunctionNodes.length; i++) {
      const jsonFunctionNode = jsonFunctionNodes[i];
      if (jsonFunctionNode.settings) {
        const functionNode = new FunctionNode(jsonFunctionNode.ast, jsonFunctionNode.settings);
        functionNode.triggerImplyArgumentType = this.assignArgumentType.bind(this);
        // For some reason the FunctionNode object is missing some members, which I found in the FunctionBuilder.
        // I'm not sure, if this is correct, but it works somehow.
        for (const key of Object.keys(functionNode)) {
          if (functionNode[key] === null && this[key] && typeof this[key] === 'function') {
            functionNode[key] = this[key].bind(this);
          }
        }
        this.addFunctionNode(functionNode);
        if (functionNode.isSubKernel) {
          this.subKernelNodes.push(functionNode);
        }
        this.functionNodes.push(functionNode);
      } else {
        this.nativeFunctions.push(jsonFunctionNode);
      }
    }
    return this;
};
主要言語
JavaScript
スター
15.5k
フォーク
663
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

gpujs/gpu.js のほかの issue

gpujs/gpu.js の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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