microts: generated Rust raises unused_assignments and unused_variables warnings

未关闭 适合新手
#725 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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 在 -D warnings 下干净编译,且没有 blanket allows。

由索引模型根据 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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pocket-stack/pocketjs 的其他 Issue

查看 pocket-stack/pocketjs 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。