microts: a model local that every branch assigns raises unused_assignments in the generated Rust
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust, typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu tại microts/compiler/aot-model-codegen.ts:1225 và đọc danh sách #![allow(...)] của module model; so sánh nó với microts/compiler/aot-model-frontend.ts:728, tệp yêu cầu mọi local phải có initializer. Tái hiện bằng lệnh biên dịch từ issue và cargo check trong crate harness, sau đó quyết định xem nên thêm unused_assignments vào allow list hay hạ các local được gán chắc chắn mà không có initializer. Hoàn tất nghĩa là gen/app_model.rs được tạo biên dịch dưới -D warnings và các bài kiểm thử AOT model hiện có vẫn chạy qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 1.6k
- Fork
- 88
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pocket-stack/pocketjs
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pocket-stack/pocketjs#746 ·
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
pocket-stack/pocketjs#745 ·
-
cli: the type check of pocket compile resolves "./app" to the view when the model is app.d.tsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
pocket-stack/pocketjs#743 ·
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
pocket-stack/pocketjs#757 ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
pocket-stack/pocketjs#744 ·
Tất cả issue của pocket-stack/pocketjs
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
security: set top-level least-privilege permissions in five workflowsCó thể đã có người làm @JonathanTSilva đã nhận hôm nay. Đang mởpriority: p2 size: xs type: security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
JonathanTSilva/jts-website#150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] SETUP.md is out of dateĐang mởbug Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
scottbenton/Iron-Link#437 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
speakeasy-api/speakeasy#2159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vercel-labs/ui#1066 ·
Maintainer thường phản hồi trong vòng 1 ngày