microts: a model local that every branch assigns raises unused_assignments in the generated Rust
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 80/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust, typescript
- 領域
- compilers
調査の方向性
microts/compiler/aot-model-codegen.ts:1225 から始めて、model モジュールの #![allow(...)] リストを読む。それを microts/compiler/aot-model-frontend.ts:728 と比較する。このファイルはすべてのローカルに初期化子を要求している。issue のコンパイルコマンドと harness crate 内の cargo check で再現し、その後 unused_assignments を allow リストに追加するか、初期化子のない definitely assigned なローカルを lower するかを決める。完了とは、生成された gen/app_model.rs が -D warnings の下でコンパイルされ、既存の AOT model テストが引き続き通ることを意味する。
索引モデルが issue の本文から書いたものです。
説明
Version
PocketJS main (2c9fcf30), after #736. macOS 27.2 arm64, Bun 1.4.2, Rust 1.98.1.
Repro
pocket.host.json, pocket.host.config.ts (aot: true, model: "compiled") and main.tsx as in #720.
// app.ts
import { createSignal } from "solid-js";
import type { i32 } from "@pocketjs/framework/solid/std";
export const [value, setValue] = createSignal<i32>(0);
export function step(dir: i32): void {
const cell = value();
let next = cell;
if (dir === 0) {
next = cell - 1;
} else {
next = cell + 1;
}
setValue(next);
}
// app.tsx
import { Text, View } from "@pocketjs/framework/solid/components";
import { step, value } from "./app";
export default function App() {
return (
<View class="w-full h-full p-4 bg-slate-100" focusable onPress={() => step(1)}>
<Text class="text-lg text-slate-900">{value()}</Text>
</View>
);
}
The harness crate of #725 (include!("../../gen/include.rs") in a no_std lib depending on microts):
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
(cd harness && cargo check)
Actual
warning: value assigned to `v_5` is never read
--> src/../../gen/app_model.rs:64:32
|
64 | let mut v_5: i32 = v_4;
| ^^^ this value is reassigned later and never used
...
76 | / v_5 = {
77 | | let left_2 = v_4;
78 | | let right_2 = 1i32;
79 | | left_2.wrapping_add(right_2)
80 | | };
| |_________________- `v_5` is overwritten here before the previous value is read
A crate built with -D warnings fails on it.
step body |
Warnings |
|---|---|
let next = cell; and an if/else that assigns next in both branches |
1 |
the same with an if and no else (the initial value is read on one path) |
0 |
let next: i32; and the same if/else |
rejected: locals require a simple binder and initializer |
An if/else if/else chain that assigns the local in every branch gives the same warning.
Expected
The generated model compiles without warnings, as #736 established for the other cases.
Cause
The frontend requires every model local to have an initializer (microts/compiler/aot-model-frontend.ts:728), so a local that every branch assigns carries an initial value that no path reads, and the generator emits it as let mut v_N: T = <initializer>;. rustc's liveness analysis reports the dead store. The model module's #![allow(...)] list (microts/compiler/aot-model-codegen.ts:1225) holds unused_mut and unused_variables but not unused_assignments.
Either change removes the warning:
- add
unused_assignmentsto the model module's allow list: the dead store is the source program's, asunused_mutandunused_variablesalready cover source-level patterns; - or admit
let x: T;when every path assigns it before a read (TypeScript's definite assignment) and lower it without an initializer.
Workaround
#![allow(unused_assignments)] in the crate that includes include.rs; it also hides the lint for the crate's own code. In the source, a conditional expression in the initializer avoids the dead store where the branches have no other statements.
Related
#725 (closed by #736): the pop/removeAt result declared with a default the assignment overwrote.
- 主要言語
- TypeScript
- スター
- 1.6k
- フォーク
- 88
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pocket-stack/pocketjs のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pocket-stack/pocketjs#746 ·
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
pocket-stack/pocketjs#745 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
pocket-stack/pocketjs#743 ·
-
bug
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
pocket-stack/pocketjs#757 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
pocket-stack/pocketjs#744 ·
pocket-stack/pocketjs の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 1 日以内に返信
-
security: set top-level least-privilege permissions in five workflows対応中かも @JonathanTSilva が今日担当しました。 オープンpriority: p2 size: xs type: security
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
JonathanTSilva/jts-website#150 ·
メンテナーはふだん 1 日以内に返信
-
bug Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
scottbenton/Iron-Link#437 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
speakeasy-api/speakeasy#2159 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
vercel-labs/ui#1066 ·
メンテナーはふだん 1 日以内に返信