microts: generated Rust raises unused_assignments and unused_variables warnings

Open Beginner friendly
#725 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, typescript
Domain
compilers

Research direction

Start at microts/compiler/aot-model-codegen.ts around lines 251-252, where let mut result_N = Default::default() is emitted before the pop/removeAt arms assign it, and the module-level allow list around line 1211. Then look at tools/aot-compile.ts:161, which writes load_images/load_fonts with an unread ui parameter. Reproduce with the given bun tools/pocket.ts compile --aot command followed by cargo check; done means that crate compiles clean under -D warnings without blanket allows.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
1.6k
Forks
88
PR merge metrics
No merged PRs in 30d

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pocket-stack/pocketjs

All issues in pocket-stack/pocketjs

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.