microts: a module constant read twice fails with "Invalid Model IR: duplicate binder" when its initializer hoists temporaries

Abierto
#720 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

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);).

Lenguaje dominante
TypeScript
Estrellas
1.6k
Forks
88
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pocket-stack/pocketjs

Todos los issues de pocket-stack/pocketjs

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.