microts: a module constant read twice fails with "Invalid Model IR: duplicate binder" when its initializer hoists temporaries
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- compilers
Research direction
Start at loadConstant in microts/compiler/aot-model-frontend.ts (lines 229-236) and read at line 261, where the cached sequence is shallow-copied as { ...value, loc } and carries the hoisted let _argN binder ids into every use. Read bind and assertModelProgram in microts/compiler/aot-model-tasks.ts (lines 152-168) to see why the reused ids are rejected. Reproduce with the app.ts constant read twice in step, then make both compile commands succeed and add a regression test covering a hoisting initializer read twice.
Written by the indexing model from the issue text.
Description
Version
PocketJS v0.17.0 (83c6cac9, current main). macOS 27.2 arm64, Bun 1.4.2.
Repro
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 { f32 } from "@pocketjs/framework/solid/std";
const K = f32(0.5) * f32(2);
export const [value, setValue] = createSignal<f32>(f32(1));
export function step(): void {
setValue(value() * K + K);
}
// 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()}>
<Text class="text-lg text-slate-900">{value()}</Text>
</View>
);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb
Actual
Both builds stop:
PocketJS: Invalid Model IR: duplicate binder 4
error: Invalid Model IR: duplicate binder 4
at fail (microts/compiler/aot-model-tasks.ts:152:56)
at bind (microts/compiler/aot-model-tasks.ts:168:127)
at checkBlock (microts/compiler/aot-model-tasks.ts:222:39)
at checkExpr (microts/compiler/aot-model-tasks.ts:181:58)
at checkExpr (microts/compiler/aot-model-tasks.ts:184:53)
at checkBlock (microts/compiler/aot-model-tasks.ts:229:80)
at assertModelProgram (microts/compiler/aot-model-tasks.ts:272:7)
at analyzeModel (microts/compiler/aot-model-frontend.ts:1091:3)
Constant and uses in step |
Result |
|---|---|
const K = f32(0.5) * f32(2);, read twice |
duplicate binder |
const A = f32(0.5); const K = A * f32(2);, K read twice |
duplicate binder |
const K = f32(0.5) * f32(2);, read once |
compiles |
const K = f32(0.5);, read twice |
compiles |
const K: f32 = 1;, read twice |
compiles |
Expected
The model compiles, and step multiplies by 1 and adds 1, as in TypeScript.
Cause
loadConstant (microts/compiler/aot-model-frontend.ts:229–236) caches the result of isolated(initializer). When lowering the initializer hoists operands into temporaries (the two f32() calls become let _argN statements), the cached value is a sequence expression that owns those let binders. read (aot-model-frontend.ts:261) inlines the constant at each use as { ...value, loc }, a shallow copy that keeps the binder ids. The second use in one function declares the same binders again, and assertModelProgram rejects them (aot-model-tasks.ts:168).
Workaround
Write the folded value with a type annotation (const K: f32 = 1;), or keep the initializer to one conversion call (const K = f32(1);).
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pocket-stack/pocketjs
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
pocket-stack/pocketjs#729 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pocket-stack/pocketjs#725 ·
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 85/100
pocket-stack/pocketjs#724 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 62/100
pocket-stack/pocketjs#728 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
pocket-stack/pocketjs#727 ·
All issues in pocket-stack/pocketjs
Similar issues
-
dream report: normalizeMutation discards ok/status, consumers can only string-match the summaryOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
thecodacus/understory#61 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Termix-SSH/Plugin-Hosts-Config#14 · 1 comment ·
Maintainers usually reply within 4 days
-
ai-generated priority: p2 size: s type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JonathanTSilva/jts-website#92 ·
Maintainers usually reply within 1 day
-
Toast announcer reads a doubled period when a toast's title ends in punctuationPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel-labs/ui#999 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ehmpathy/rhachet-roles-ehmpathy#1443 ·
Maintainers usually reply within 1 day