Reduce a miscompilation - Internet Explorer
Address
https://freetolearn.world/compiler-optimizer-reading-09.html
free to learn.world
← Compiler Optimizer

Static school reading · Terminal implementation

Reduce a miscompilation

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 GitHub
Setup, nine lessons and contracts

Reduce a miscompilation

A small, stable wrong-result example is easier to explain and repair than a large failing program. Implement reduce(program, input, transform) so simplification preserves the same legal miscompilation.

Prerequisite: U07. The guided fault reuses memory incorrectly; the final investigation uses a different optimization.

Define the interestingness predicate first

For each proposed source and input, regenerate the target using the supplied transform. Verify both programs, execute them from separate fresh heaps and require normal returns that differ in value or observable heap. A parser crash, a new bounds trap or an exhausted budget is not the required wrong-result witness.

Suppose irrelevant constant arithmetic is removed and the same source/target return discrepancy persists. That is useful reduction. Removing a definition used by the return and making the program invalid is not.

Commit item 08a.

Keep three internal decisions: interesting, not interesting, and unresolved. You may skip an unresolved candidate and preserve the best known witness, but you cannot use it as evidence that no smaller witness exists.

The supplied inspectWitness helper reports those three states and preserves both executions. Start with a deliberately tiny fuel budget and observe UNRESOLVED, then restore enough fuel. This is an execution-budget experiment, not a new counterexample. An exception inside the faulty transform is also unresolved; it cannot certify a clean neighborhood.

Reduce structure and input without losing identity

Try a finite family of legal changes, such as deleting unused total computations or simplifying an input value. A supplied Editor can enforce structural safety for eligible source changes; the interestingness check still has to rerun the faulty transform.

Accept only a strictly smaller candidate under a declared measure. Keep the signature, semantics and faulty pipeline fixed. Never manually edit only the target to preserve an apparent discrepancy. Recheck the final witness from fresh state.

Use the supplied lexicographic measure: block count, definitions/instructions, operand occurrences, heap objects, heap cells, then numeric-value complexity. Numeric complexity counts magnitude bits (plus a sign bit for a negative offset), not printed characters. Simplifying a witness word from 7 to 0 decreases it; shortening the program name or renaming an SSA value does not. Property order and whitespace also do not count. A smaller value cannot compensate for adding a block. Values can tie under this declared order; do not claim every possible simplification is ranked. Keep a trace of candidates, decisions and the best accepted witness. You design the candidate family and search order; the helper supplies execution and accounting.

A greedy reducer can produce a useful best-found result. Claim 1-minimality only after checking every permitted single-step reduction of the final candidate with no interesting or unresolved neighbor. That is still not a global minimum.

Pass that final candidate list to assessNeighborhood. Its NO_SMALLER_IN_LIST report establishes only the list it actually inspected. Explain why your list covers your declared family, or label the result best-found. A family containing only one convenient edit is weak evidence even when completely checked.

Commit item 08b.

Build the investigation artifact

node cli.mjs check 08 work --help-used none
node cli.mjs export work investigation.json

Return the reduced program, input and a short explanation of your reduction family and stopping condition. The checker demands a preserved normal-return discrepancy and actual simplification; it accepts different reduced forms.

The export preserves your first attempts and exact code. Use the rubric to explain the causal violation, not only the fact that two numbers differ. See llvm-reduce for the role of an explicit interestingness test in a production tool.

Return to setup and delivery limits

Course overviewInternet
Mission.txt - Notepad

Learning without paywalls.

Find what people pay to learn.
Build a great course. Give it away.

One course at a time.

Usage & privacy

Start