Aliases and effects - Internet Explorer
Address
https://freetolearn.world/compiler-optimizer-reading-06.html
free to learn.world
← Compiler Optimizer

Static school reading · Terminal implementation

Aliases and effects

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

Aliases and effects

Two parameter names can reference the same cell. Implement aliases and memory so a memory optimization depends on static evidence rather than an input that happened to work.

Prerequisites: U02–U04. The heap model, pointer arithmetic and checked memory edits are supplied.

Distinguish names, objects and cells

A pointer is an object ID plus an element offset. Different objects cannot overlap in this IR. Two offsets within one typed object name the same cell only when the offsets are equal. No byte reinterpretation or object lifetime change exists.

For static analysis, a pointer parameter is a symbolic base. A ptradd by a constant changes its symbolic offset. Two expressions with the same base and equal offsets must alias; the same base with different offsets cannot alias. Different unknown parameter bases may alias unless the frozen contract explicitly separates their objects.

A concrete run with p on object A and q on object B does not establish a static NoAlias claim for every invocation.

Commit items 05a and 05b.

Reuse a value across only safe effects

Consider a load through p, a store through q, then another load through p. If q may alias p, the store invalidates the saved value. If the contract proves distinct objects, the saved value can still serve the later load.

Scan backward from a load or maintain available memory values while scanning forward. A same-location earlier load or store supplies a value. A possibly aliasing intervening store blocks reuse. An emit does not change memory in this language, but it must remain in the event sequence.

The earlier access also matters for traps. If it fails, execution never reaches the later load. If it succeeds, fixed object size and the identical address make the later access in bounds. This is more precise than declaring every load pure.

Extend the same tool

node cli.mjs check 05 work --help-used none
node cli.mjs example memory memory.json
node cli.mjs optimize work memory.json memory --help-used none

The memory example includes an explicit object-separation contract. Your pass must also preserve the aliasing case without that contract. Unknown facts may justify refusing an optimization; always returning MayAlias misses the required provable case.

Review the whole output heap after a change. A return-only check would miss a store incorrectly discarded or reordered.

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