Skip to content

Lower branch-yield result joins into Core - #194

Open
flyingrobots wants to merge 12 commits into
feature/bounded-control-pure-helpersfrom
feature/core-branch-result-joins
Open

Lower branch-yield result joins into Core#194
flyingrobots wants to merge 12 commits into
feature/bounded-control-pure-helpersfrom
feature/core-branch-result-joins

Conversation

@flyingrobots

@flyingrobots flyingrobots commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • give Core branches an optional result binding;
  • lower effectful branch-yield let expressions into isolated Core blocks with one joined result;
  • reject incompatible branch results before Core exists;
  • enforce recursive effect-profile admission before branch-yield lowering;
  • preserve enclosing loop-budget state across yield branches and infer bare integer widths symmetrically;
  • reject structurally incompatible anonymous-record branch results before Core;
  • reject any semantic-effect coordinate that would otherwise masquerade as a pure helper call;
  • regenerate the provider contract pack from the owning Core CDDL change.

This PR is stacked on #193 and is another bounded part of #192. It does not close #192 or claim Target IR/runtime execution.

Plain-English Walkthrough

TL;DR

Edict can now preserve the meaning of let x = if predicate { ... yield a; } else { ... yield b; }; in Core without evaluating either branch in the compiler and without adding a host callback. [claim:branch-yield-core, confidence:1.00] Each branch remains an isolated Core block; exactly the selected block runs; its result becomes one explicit outer local; and incompatible yielded types fail during type checking.

Walkthrough

The preceding PR introduced target-neutral Core branch blocks, but those blocks had no way to name the selected result. That was sufficient for statement-only if, whose blocks return Null, but insufficient for the language's branch-yield form.

This change makes the distinction explicit:

Source shape Core branch binding Block result
statement if absent Null
branch-yield let one typed local each branch's yielded expression

[claim:optional-branch-binding, confidence:1.00] The optional binding is part of the normative Core CDDL, Rust model, canonical encoder, CLI review projection, and generated provider contract pack.

The compiler dataflow is:

flowchart TD
    A[Branch-yield let] --> P[Type-check pure predicate]
    P --> T[Lower then block in isolated scope]
    P --> E[Lower else block in isolated scope]
    T --> J{Yielded types compatible?}
    E --> J
    J -->|No| R[Structured TypeMismatch]
    J -->|Yes| B[Allocate one outer result local]
    B --> C[Emit bound Core branch]
Loading
Caption: Explicit branch-result join
  1. The predicate is checked as a Core predicate; it is not executed by the compiler.
  2. Each yield block gets a cloned environment and its own local/effect node list.
  3. Both yielded expressions must share one compatible bounded type.
  4. The selected block's result becomes the branch binding, which the enclosing body may reference.

The join is semantic structure, not runtime policy. The current Target IR lowerer continues to reject Core branch nodes, so this PR gives downstream work honest compiler-produced input without claiming that Echo can execute it yet.

Branch-local effects use only the already-supported typed effect-call path and obstruction mapping. [claim:branch-scope, confidence:1.00] Branch locals do not leak into the enclosing environment; only the explicit result binding does. Bare effect statements, new intrinsics, application-specific operations, and host callbacks remain unsupported.

Branch-yield profile admission now runs before its specialized lowering path. [claim:branch-effect-profile-gate, confidence:1.00] A coordinate that appears in both pure-helper and write-effect facts cannot bypass its operation-profile write-class gate; a disallowed write class returns ProfileEffectMismatch before Core.

Canonical identity covers the new meaning. [claim:branch-binding-identity, confidence:1.00] Tests show that swapping compatible yielded values changes the Core digest, and removing only the result binding also changes the Core digest.

Verification

The authority-gate RED command was:

cargo test -p edict-syntax --test compiler_spine branch_yield_rejects_pure_helper_that_is_a_disallowed_write_effect -- --nocapture

Before the fix, that source incorrectly produced Core. It now returns exactly ProfileEffectMismatch.

The original focused RED command was:

cargo test -p edict-syntax --test compiler_spine effectful_branch_yield -- --nocapture

Before implementation, it failed because CoreNode::Branch had no binding field. After implementation, all three focused branch-yield cases passed.

The first full gate correctly found two contract-boundary obligations: an invalid topic-source registry reference and provider contract-pack drift after the Core CDDL change. The registry reference was removed, and the generated pack was refreshed through its owner:

cargo xtask provider-contract-pack --write

The parallel fixture calibration and final complete gates passed:

cargo test -p edict-syntax --test compiler_spine -- --test-threads 32
cargo deny check
cargo xtask verify
cargo xtask provider-component-fixtures --check

[claim:full-verification, confidence:1.00] This includes formatting, clippy, all workspace tests, Core schema checks, provider contract-pack reproduction, doctests, and golden checks.

Compatibility, dependencies, and documentation

No dependency was added. Adding a field to the public Rust CoreNode::Branch variant requires downstream exhaustive destructuring to account for binding; in-repository consumers were updated. The CDDL field is optional, preserving the existing representation for statement-only branches. Compiler-spine and Core IR shelves now document the distinction and the remaining Target IR boundary.

Appendix: Citations
Claim Evidence Confidence Notes
claim:branch-yield-core crates/edict-syntax/src/compiler.rs#1725@244a6645e61308b616b8675706fe3c16be0ccba1; effectful_branch_yield_lowers_to_bound_core_branch in crates/edict-syntax/tests/compiler_spine.rs 1.00 Source branch-yield reaches an explicit Core branch result.
claim:optional-branch-binding docs/abi/edict-core.cddl#308@244a6645e61308b616b8675706fe3c16be0ccba1; crates/edict-syntax/src/core_ir.rs#315@244a6645e61308b616b8675706fe3c16be0ccba1; crates/edict-syntax/src/canonical.rs#1098@244a6645e61308b616b8675706fe3c16be0ccba1 1.00 Schema, model, and encoder agree.
claim:branch-scope crates/edict-syntax/src/compiler.rs#1785@244a6645e61308b616b8675706fe3c16be0ccba1; effectful_branch_yield_lowers_to_bound_core_branch in crates/edict-syntax/tests/compiler_spine.rs 1.00 Each branch uses its own environment, locals, and nodes.
claim:branch-binding-identity effectful_branch_yield_mutation_moves_core_digest in crates/edict-syntax/tests/compiler_spine.rs#992@244a6645e61308b616b8675706fe3c16be0ccba1 1.00 Yielded meaning and binding presence are digest-sensitive.
claim:branch-effect-profile-gate crates/edict-syntax/src/compiler.rs#1653; branch_yield_rejects_pure_helper_that_is_a_disallowed_write_effect in crates/edict-syntax/tests/compiler_spine.rs#969 1.00 Recursive profile admission precedes specialized branch-yield lowering.
claim:full-verification cargo xtask verify at 244a6645e61308b616b8675706fe3c16be0ccba1 (passed locally) 1.00 Full repository gate passed after owned golden regeneration.

Part of #192

@flyingrobots flyingrobots self-assigned this Aug 18, 2026
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f2acc317-27da-4b5a-9a3c-980be7f86ac6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ab765f9ac9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/edict-syntax/src/compiler.rs
@flyingrobots

Copy link
Copy Markdown
Owner Author

@codex review please

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bae3229e52

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/edict-syntax/src/compiler.rs
Comment thread crates/edict-syntax/src/compiler.rs Outdated
@flyingrobots

Copy link
Copy Markdown
Owner Author

@codex review please

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4eff0c0fb6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/edict-syntax/src/compiler.rs
@flyingrobots

Copy link
Copy Markdown
Owner Author

@codex review please

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3aeab2603

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/edict-syntax/src/compiler.rs
@flyingrobots

Copy link
Copy Markdown
Owner Author

@codex review please

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: ce811c3068

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@flyingrobots

Copy link
Copy Markdown
Owner Author

@codex review please

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 244a6645e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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