Skip to content

refactor(runtime): evaluate lowered payloads by expression id - #2249

Merged
HuiJun merged 13 commits into
developfrom
feat/ir-expr-payload-ids
Nov 15, 2026
Merged

HuiJun merged 13 commits into
developfrom
feat/ir-expr-payload-ids

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What and why

No tracking issue.

Third part of the execution-owned expression migration in docs/internals/execution-ir-design.md, after #2218 and #2225. Lowered payloads now name the expressions they state by program.ExprID, and the runtime evaluates the id rather than the syntax tree.

  • Every lowered graph (action, state, calculation, nested action and block flows) owns a lower.ExprTable. ExprTable.Intern records an expression once per (tree, scope).
  • Statement, binding, transition, guard, probability, accept-trigger and zero-crossing payloads carry an id beside each tree field (ValueID, ConditionID, GuardID, TriggerExprID, BindingEnd.ExprID/IndexID, ZeroCrossing.GuardID/TerminalID, ...).
  • The four runtime-owned payloads carry ids into the model's own table: Condition.ExprID, Objective.ValueID, EffectiveFeature.DefaultValueID, SatisfyAssertion.SubjectChainID.
  • EvalContext carries the table of the flow it evaluates; an id that is not in that table is an error (expression 0 is not in the table of its flow), never a fallback read of the tree. An expression evaluated in a scope other than the one it was interned in is lowered again in that scope through the model's memoized path.

The change is additive: the tree fields stay beside the ids until the last readers move, so lazy and memoized evaluation, scopes, cleanup and error timing are unchanged.

Not in this PR:

  • Accept.SubsetsEvent, Channel.Message and SubjectDecl.Value get no id; the runtime does not evaluate them as payload expressions.
  • Context.UnitOf and the other semantic questions the runtime still asks of a tree move in the follow-up PR stacked on this branch.
  • Removing the tree fields and forbidding exec/runtime from importing syntax/ast is the final step.

Baselines

EffectiveFeature gains a field, so examples/self-model/execution.sysml states fieldCount = 12 and its comment is one line shorter. Any edit under examples/ changes the provenance digest of the two differentials, which were re-recorded by tool under JDK 21 on develop dd08d75454:

  • Pilot differential: only the examples digest moves; no count moves.
  • API-JSON differential: the examples digest, and examples/self-model/execution.sysml.json ours-only 186 → 185 (index totals 19152 → 19151, examples 5590 → 5589). One ours-only sysx:Note is lost because notes are keyed by ordinal: /self-model/execution.sysml/sysx:Note#35. Matched and pilot-only are unchanged, with no match lost or gained.

develop with #2242 and #2245 is merged in and the baselines are re-recorded on top of it. This branch still overlaps #2235 in examples/self-model/execution.sysml, where both state fieldCount = 12 for a different twelfth field; whichever lands second states 13 and re-records.

WebAssembly size budget

coreGzipBudget goes from 7,450,000 to 7,500,000 bytes. The gzipped js sysml-core.wasm measures 7,441,184 on develop dd08d75454 and 7,454,466 here; the 13,282 bytes are the expression ids the payloads carry and the code that reads them.

How it was verified

On the pushed head, merged with develop 97e7eedb29:

  • go build ./..., go vet ./..., gofmt -l ., make lint
  • go test -count=1 ./... with the training and pilot corpora required, and go test -C tools -count=1 ./...
  • go test ./tests/hygiene, scripts/check-doc-ids.py, scripts/changelog.py check
  • make docs-counts, make spec-compliance-check, make wasm-check
  • pilot-diff -check and pilot-apijson-diff -check (JDK 21), pilot-exec-diff, pilot-xpect -check

New tests in internal/exec/runtime/expr_payload_ids_test.go cover graph and model table ownership, ids reaching each payload, invalid ids, evaluation in another scope, and nested table switching.

Checklist

  • make test and make lint pass locally (the suite was run without -race)
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (docs/internals/execution-ir-design.md)
  • Changelog entry: none, an internal refactor with no user-visible change
  • baselines regenerated and make docs-counts run
  • No internal work-item labels in the body, docs, or changelog

🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

devin-ai-integration Bot and others added 7 commits November 14, 2026 06:26
Each lowered graph carries an expression table, and each expression a
lowered payload states has its id beside the tree. Conditions, objectives,
feature defaults and satisfy subjects carry theirs in the model's table.
The runtime evaluates the id; an id that is not in its table is an error,
never a read of the tree. The tree fields stay until step 8.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…the self-model field count

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration Bot and others added 2 commits November 14, 2026 20:01
The attributes of a region's owner and the machine's own run-to-completion
value are recorded under keys that are not states of the graph, so walking
its states left their expression ids unset.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
A default stated between the steps of a case runs as a node of the flow lowered
for those steps, which read it in a table of its own rather than the one the
default was interned in.

Co-Authored-By: jason.han <hanhuijun@gmail.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Missing IDs for machine and region expressions — Reproduced: a region owner's attribute and the machine's own run-to-completion value had id 0. The machine now interns every recorded owner, not only its states.
  • Case defaults use the wrong expression table — Reproduced: the flow lowered for a case's steps had its own table while the default run as its node was interned in the body's. The flow now shares the body's table.

View findings in Devin Review · Follow Devin's work

Devin Review

devin-ai-integration Bot and others added 4 commits November 15, 2026 00:37
…ad-ids

Co-Authored-By: jason.han <hanhuijun@gmail.com>

# Conflicts:
#	docs/project/api-json-differential/index.json
The examples provenance digest moves with the self-model file, and one
ours-only element goes with it: /self-model/execution.sysml/sysx:Note#35.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…velop

The merged develop measures 7,441,184 bytes gzipped against the 7,450,000
budget; the expression ids the lowered payloads carry add 13,282.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@HuiJun
HuiJun added this pull request to the merge queue Nov 15, 2026
Merged via the queue into develop with commit e46f8f1 Nov 15, 2026
30 checks passed
@HuiJun
HuiJun deleted the feat/ir-expr-payload-ids branch November 15, 2026 12:12
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