microts: generated Rust raises unused_assignments and unused_variables warnings

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

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

評価

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

調査の方向性

microts/compiler/aot-model-codegen.ts の 251-252 行目付近から始めてください。ここでは let mut result_N = Default::default() が、pop/removeAt の各アームがそれを代入する前に出力され、また 1211 行目付近にモジュールレベルの allow list があります。次に tools/aot-compile.ts:161 を見てください。これは読まれていない ui パラメータ付きで load_images/load_fonts を書き込みます。指定された bun tools/pocket.ts compile --aot コマンドに続けて cargo check を実行して再現してください。完了とは、その crate が包括的な allow なしで -D warnings の下でクリーンにコンパイルされることです。

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

説明

bug

Version

PocketJS v0.17.0 (83c6cac9, current main). macOS 27.2 arm64, Bun 1.4.2, Rust 1.98.1.

Repro

A compiled model that calls pop, and an application without images.

pocket.host.json, pocket.host.config.ts, main.tsx
{
  "format": "pocket-host/2",
  "id": "repro-esp32s3",
  "platform": "esp-idf",
  "form": "takeover",
  "cadences": [30],
  "display": {
    "logicalViewports": [[240, 240]],
    "presentations": ["native"],
    "rasterDensity": 1,
    "animation": "repaint"
  },
  "panel": { "primary": [240, 240] },
  "capabilities": ["input.buttons", "text.glyphs.baked"]
}
// pocket.host.config.ts
import { defineHostConfig } from "@pocketjs/framework/host-config";

export default defineHostConfig({
  host: "./pocket.host.json",
  app: {
    id: "dev.example.repro",
    title: "Repro",
    version: "0.1.0",
    entry: "main.tsx",
    output: "repro",
    framework: "solid",
    viewport: { logical: [240, 240], presentation: "native" },
    features: ["input.buttons", "text.glyphs.baked"],
    aot: true,
    model: "compiled",
  },
});
// main.tsx
import { mount } from "@pocketjs/framework/solid";
import App from "./app.tsx";
mount(() => <App />);
// app.ts
import { createSignal } from "solid-js";
import { len, pop, push, type i32 } from "@pocketjs/framework/solid/std";

export const [size, setSize] = createSignal<i32>(0);

let stack: i32[] = [1, 2, 3];

export function press(): void {
  const top = pop(stack);
  push(stack, top);
  setSize(len(stack));
}
// app.tsx
import { Text, View } from "@pocketjs/framework/solid/components";
import { press, size } from "./app";

export default function App() {
  return (
    <View class="w-full h-full p-4 bg-slate-100" focusable onPress={() => press()}>
      <Text class="text-lg text-slate-900">{size()}</Text>
    </View>
  );
}
# harness/Cargo.toml
[package]
name = "aot-warnings"
version = "0.0.0"
edition = "2021"

[dependencies]
microts = { path = "<pocketjs>/engine/microts-runtime" }

[workspace]
// harness/src/lib.rs
#![no_std]
extern crate alloc;
include!("../../gen/include.rs");
pub use generated::*;
pub fn mount(ui: &mut microts::Ui) {
    load_fonts(ui);
    load_images(ui);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
(cd harness && cargo check)

Actual

warning: value assigned to `result_0` is never read
  --> src/../../gen/app_model.rs:65:41
   |
65 |                 let mut result_0: i32 = Default::default();
   |                                         ^^^^^^^^^^^^^^^^^^ this value is reassigned later and never used
66 |                 result_0 = self.v_2.pop().unwrap_or_else(|| Default::default());
   |                 --------------------------------------------------------------- `result_0` is overwritten here before the previous value is read

warning: unused variable: `ui`
  --> src/../../gen/include.rs:12:16
   |
12 | fn load_images(ui: &mut microts::Ui) {
   |                ^^ help: if this is intentional, prefix it with an underscore: `_ui`

A crate built with -D warnings fails on them.

Expected

Generated code compiles without warnings.

Cause

  • microts/compiler/aot-model-codegen.ts:251–252 declares let mut result_N = Default::default() before the pop and removeAt arms assign it. The model module's #![allow(…)] list (aot-model-codegen.ts:1211) does not include unused_assignments.
  • tools/aot-compile.ts:161 writes load_images (and load_fonts) with a ui parameter that an application without images (or fonts) never reads; the functions carry #[allow(dead_code)] only.

Workaround

#![allow(unused_assignments, unused_variables)] in the crate that includes include.rs. It also hides these warnings in the crate's own code.

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

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

pocket-stack/pocketjs のほかの issue

pocket-stack/pocketjs の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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