Skip to content

Fit input values to the current bit width of their pin - #76

Merged
Rn86222 merged 3 commits into
mainfrom
fix-stale-input-values
Nov 14, 2026
Merged

Rn86222 merged 3 commits into
mainfrom
fix-stale-input-values

Conversation

@Rn86222

@Rn86222 Rn86222 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

An input value is kept as it was set, so it goes stale when the bit width of its pin changes afterwards. For example, a value set while the width of an input was not fixed yet is a single bit, and stays one after the input is connected to a pin of 8 bits. Every later time step inherits the stale value, so every attempt to play fails and falls back to edit mode, and the value cannot be fixed in play mode either, since the editor of an input value takes the width from the value itself.

  • Fit the value to the current bit width of the pin when it is read in getInputValue: keep it if it fits, padding or dropping leading zeros with fitSimulationValue, and start over from zero otherwise. The stored values are left as they are, so nothing is written to the store during simulation.
  • The editor of an input value takes its width from the returned value, so it follows the current width as well.
  • The width the simulation assumes for an open pin, which the fitting has to agree with, is shared as DEFAULT_SIMULATION_BIT_WIDTH instead of being hard-coded as 1 on both sides.

Testing

  • Added src/pages/edit/Editor/store/slices/core/index.test.ts, which fails without the change: a value set before the width was fixed is fitted (and inherited by later time steps), a value that does not fit starts over from zero, and a circuit ANDing such an input with an 8-bit constant simulates without the "Input lengths must match" error it used to fail with.
  • createEditorStore is exported for the test, and ResizeObserver, which the perspective slice constructs, is stubbed there and restored afterwards.

🤖 Generated with Claude Code

An input value is kept as it was set, so it went stale when the bit
width of its pin changed afterwards, e.g. a value set while the width
was not fixed (a single bit) and the pin later connected to one of 8
bits. Every time step from then on inherited the stale value, so the
simulation failed in every attempt to play, and the value could not be
fixed either, since the editor of an input value takes the width from
the value itself.

Fit the value to the current bit width of the pin when it is read: keep
it if it fits, padding or dropping leading zeros, and start over from
zero otherwise.

`createEditorStore` is exported so that the editor store can be tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Deploying create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee with  Cloudflare Pages  Cloudflare Pages

Latest commit: ffec66a
Status: ✅  Deploy successful!
Preview URL: https://f18f1ac7.create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee.pages.dev
Branch Preview URL: https://fix-stale-input-values.create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee.pages.dev

View logs

Rn86222 and others added 2 commits November 14, 2026 11:35
The editor fits the values it feeds to the input pins of the simulated
component to the width the simulation assumes for a pin the circuit
leaves open. Both hard-coded it as 1, so changing one of them would have
brought back the mismatch fixed in the previous commit. Define it once
as `DEFAULT_SIMULATION_BIT_WIDTH`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test of simulating a circuit whose input got wider fixed the width
with a display, which does not check the width of its input, so the
simulation succeeded even with the stale value. Fix the width with an
And of the input and a constant instead, which fails on operands of
different widths as the reported circuits did.

Also restore the stubbed `ResizeObserver` after the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rn86222
Rn86222 merged commit 48007f3 into main Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant