Skip to content

format: state the postcondition convention for instruction contexts - #281

Merged
gnidan merged 2 commits into
mainfrom
architect-postcondition-convention
Aug 5, 2026
Merged

format: state the postcondition convention for instruction contexts#281
gnidan merged 2 commits into
mainfrom
architect-postcondition-convention

Conversation

@gnidan

@gnidan gnidan commented Aug 5, 2026

Copy link
Copy Markdown
Member

Instruction contexts use postcondition semantics, pointers included. The description of program/instruction's context carried a single sentence framing pointers as resolving against the pre-execution "trace step" state — an outlier that contradicted the rest of that same description ("the context known to exist following the execution"), the program-example walkthrough on the spec site, and existing compiler emission. This PR states the convention plainly and fixes the one example that was wrong under it.

  • program/instruction — a context holds following the instruction's execution; both its semantic facts and its pointers resolve against the post-execution state. Contexts form a chain: the program-level context is the precondition before the first instruction, each instruction's context is its postcondition (and the next instruction's precondition), and a debugger paused about to execute instruction i reads instruction i − 1's context.

  • program — the program-level context description now names its role as the base case of that chain (the precondition to the first instruction).

  • program example — under the postcondition convention the Incrementer example was already correct except at the ADD and the PUSH0 after it, which wrongly kept localValue listed on the stack; this PR removes it from those two contexts, and nothing else in the example changes. In this example localValue is the loaded storedValue (let localValue = storedValue; storedValue += 1;), so ADD consumes it, leaving storedValue + 1. Post-execution stack per instruction:

    offset op post-exec stack (top → bottom) localValue
    0 PUSH0 [0x00] not yet loaded
    1 SLOAD [localValue] slot 0
    2 PUSH1 0x01 [localValue, 0x01] slot 1
    4 ADD [storedValue+1] consumed
    5 PUSH0 [storedValue+1, 0x00] consumed
    6 SSTORE [] gone

    localValue is now dropped from the ADD and following PUSH0 contexts, matching how the spec-site walkthrough omits a local once it is consumed. The offset-1 and offset-2 stack pointers were already correct post-execution and are unchanged. A stale value = tmp; line is also removed from the pseudo-code.

This supersedes #278, which had reworked the same example toward the pre-execution reading.

The instruction context description carried one sentence framing pointers
as resolving against the pre-execution ("trace step") state, contradicting
the rest of the same description ("following the execution"), the
program-example walkthrough, and compiler emission — all of which treat a
context as a postcondition. This states the intended convention plainly.

- program/instruction: a context holds following the instruction's
  execution; both its semantic facts and its pointers resolve against the
  post-execution state. Contexts form a chain — the program-level context
  is the precondition before the first instruction, each instruction's
  context is its postcondition (and the next instruction's precondition),
  and a debugger paused about to execute instruction i reads instruction
  i-1's context.
- program: the program-level context description now names its role as the
  base case of that chain (the precondition to the first instruction).
- program example: under the postcondition reading the Incrementer example
  was correct except at the ADD and the following PUSH0, where it still
  listed localValue on the stack after ADD had consumed it (leaving only
  storedValue + 1). localValue is now dropped from those two contexts.
  Also removes a stale 'value = tmp;' line from the pseudo-code.
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-05 22:42 UTC

Adds the equivalent trace-position framing to the instruction context
description: prepending the program-level context to the sequence of
instruction contexts gives one sequence indexed by trace position, so
the context in effect before executing the instruction at position i is
element i — no special case for the first instruction.
@gnidan
gnidan merged commit 1c2617f into main Aug 5, 2026
5 checks passed
@gnidan
gnidan deleted the architect-postcondition-convention branch August 5, 2026 22:37
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