Rust codegen: Function::new lacks Send + Sync bounds for closures invoked and dropped across Valdi threads

オープン 初心者向け
#239 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
73/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend

調査の方向性

valdi_core/src/valdi_core/rust/function.rsから始め、Function::newとそのinvokeトランポリンを読みます。次に、関数の構築またはスレッド安全性の境界に関する近くのテストを確認します。説明に従ってクロージャの境界を更新し、関連するRustテストを実行します。両方のエントリポイントでクロージャがSend + Syncを満たす必要があり、テストが通れば完了です。

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

説明

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

Function::new lacks Send + Sync bounds for closures invoked and dropped across Valdi threads

File: valdi_core/src/valdi_core/rust/function.rs

When a closure capturing !Send or !Sync state (such as Rc or RefCell) is passed to Function::new and exposed to the Valdi JS runtime, invoking or dropping it from the JS or GC thread causes a data race and undefined behavior. Function::new only constrains F: Fn(ValdiCall) -> Result<(), String> + 'static, omitting Send + Sync.

valdi_rust_value_new_function wraps the closure in a ref-counted RustValueFunction (Valdi::ValueFunction) that Valdi can invoke from the JS thread and destroy from whichever thread drops the last reference. Without Send + Sync bounds on F, Rust's type system cannot prevent non-thread-safe captures from crossing threads through C++.

Require F: Fn(ValdiCall) -> Result<(), String> + Send + Sync + 'static on Function::new and its invoke trampoline.

主要言語
C++
スター
16.4k
フォーク
539
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

Snapchat/Valdi のほかの issue

Snapchat/Valdi の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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