Static school reading · Terminal implementation
What must an optimization preserve?
Read here, then implement your own optimizer in the learner project. This page does not execute code, save answers or award results. Use the terminal tools to preserve first attempts, source versions, help and revisions.
The named U08/U09 reduction defect has passed an independent focused public-interface recheck. The owner package’s broader pending-review statements describe its original scope; the complete documented terminal route has since been exercised in a source-aware owner run. Browser and human learning are not claimed.
Get the learner project on GitHubSetup, nine lessons and contracts
What must an optimization preserve?
A faster kernel is unusable if it changes the records it returns or modifies. Implement compare(sourceResult, targetResult) so the workbench can distinguish equal completed behavior from a discrepancy or an unfinished run.
Prerequisites: functions, arrays and basic compiler terminology. Read the observation shapes in API.md. The interpreter, input reader and execution limits are supplied.
Decide what can be observed
Kernel IR returns an i8, i32 or bool value. It can also store into input arrays, append typed events, or terminate with a defined trap. All of those observations matter. Instruction identifiers, elapsed work and the arrangement of blocks do not.
Consider two runs that return i8 6. The first emits i8 2 and then i8 5; the second emits i8 5 and then i8 2. The return values agree, but the ordered event sequences differ. Comparing the event set would lose information.
For a normal return, compare the return type and value, all heap object identities/types/cells, and events in order. For a trap, compare its code and the heap/events that existed before it. Object-map key order is irrelevant; cell and event order are meaningful.
Commit a decision before seeing feedback:
node cli.mjs question 01a
node cli.mjs answer 01a work YOUR_LETTER --help-used noneSeparate program behavior from an incomplete experiment
A bounds trap is part of this IR's meaning. Running out of fuel is an incomplete observation of the program. Two loops reaching the same fuel limit have not demonstrated equivalent final behavior.
A useful comparator first asks whether both results completed as return or trap. It then compares the relevant fields. It must return false for unknown or invalid results; the surrounding validator will classify those separately rather than call them counterexamples.
Do not compare every property indiscriminately: optimization is expected to change counters. Do not discard fields just because the current example does not use them.
Build and repair
Implement compare in work/optimizer.mjs. Start with a field inventory on paper, then write the code. Create a local pair whose only difference is a trap code and another whose only difference is a counter. Run:
node cli.mjs check 01 work --help-used noneThe checker snapshots your code before executing it. A failed check names the missed requirement. Keep that first attempt and repair the function rather than replacing its history.
Use item 01b to check the distinction between equal prefixes and completed outcomes. In U05 and the final investigation, the same comparator will expose bugs that a return-only comparison misses.