Skip to content

Scalarize POD values carried by while loops - #735

Merged
shankarapailoor merged 13 commits into
mainfrom
shankara/r1cs-scalar-lowering
Sep 22, 2026
Merged

shankarapailoor merged 13 commits into
mainfrom
shankara/r1cs-scalar-lowering

Conversation

@shankarapailoor

@shankarapailoor shankarapailoor commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This is PR 1 of 3 in the R1CS lowering stack.

Stack:

  1. This PR
  2. Promote straight-line arrays before SROA #736
  3. Cache access analysis during scalar lowering #737

Extend POD-to-scalar lowering to handle POD values carried by supported scf.while loops. The rewrite expands carried PODs into scalar leaves while conservatively declining asymmetric or unsupported loop shapes. It also prevents negative felt constants from being incorrectly folded to index constants.

Related issues

No linked issue.

Changes

  • Scalarize supported POD-typed scf.while iteration values.
  • Preserve loop semantics by validating forwarded values, aliases, and init/result shapes before rewriting.
  • Refresh POD access facts when conversion rounds mutate the IR.
  • Keep negative felt constants from being reinterpreted by cast.toindex canonicalization.
  • Add focused rejection, crash-regression, and differential Witgen coverage.
  • Add a changelog entry.

Testing

  • nix develop --command bash -c "cmake --build build --target check-lit"
    • 423 discovered: 416 passed, 3 expected failures, 4 unsupported.
  • nix build -L
    • Full release build, lit suite, and unit tests passed.
  • Differential Witgen test runs the source and scalarized loop with both interpreter backends.

Submission checklist

  • Internal contribution; the external-contributor issue requirement does not apply.
  • I added or updated tests for all relevant behavior.
  • I updated relevant documentation and implementation comments.
  • I added a changelog entry describing user-visible changes.
  • This branch is hosted in the upstream repository; maintainer-edit permission is not applicable.

AI assistance

  • No AI tools contributed to this PR.
  • AI tools contributed to this PR.

Tools used: OpenAI Codex and Anthropic Claude.

How the tools contributed: Codex assisted with implementation, test construction, review fixes, and validation. Claude performed independent code-review passes and developed additional adversarial reproducers.

How I verified the contribution: I reviewed the resulting diffs, reproduced the reported failure modes, ran focused semantic and crash-regression tests, ran the complete lit suite, and completed a full Nix release build with unit tests.

@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex review please

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T18:23:02.042649Z 619e583 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

  2 files  ± 0    2 suites  ±0   2m 21s ⏱️ +22s
440 tests +10  436 ✅ +10  4 💤 ±0  0 ❌ ±0 
880 runs  +20  872 ✅ +20  8 💤 ±0  0 ❌ ±0 

Results for commit 4d0848c. ± Comparison against base commit a1400a8.

♻️ This comment has been updated with latest results.

@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: 6ebfb0201a

ℹ️ 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 lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex please review the latest changes, including the fix for aliased POD while initializers.

@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: 31d6e66be4

ℹ️ 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 lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 134d3fefe2

ℹ️ 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 lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex review

Comment thread test/Transforms/FullR1CSLowering/circom_is_negative.llzk Outdated
Comment thread test/Transforms/FullR1CSLowering/circom_is_negative.llzk Outdated
Comment thread lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
Comment thread test/Transforms/PodToScalar/while_carried_pod_reject.llzk Outdated

@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: 3c0cbc64c9

ℹ️ 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 lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
Comment thread lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 7016fcd241

ℹ️ 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 test/Transforms/PodToScalar/while_carried_pod_reject.llzk Outdated
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@tim-hoffman @codex please review the latest fix, 38cb8ce. Carried-POD scalarization now conservatively rejects unsupported mutable copies and snapshot initialization shapes while retaining read-only nested-copy support. Added four regressions; the release build and full lit suite pass. The redundant-read/write pass is unchanged.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 38cb8ce7eb

ℹ️ 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 changelogs/unreleased/shankara__r1cs-scalar-lowering.yaml Outdated
@shankarapailoor
shankarapailoor force-pushed the shankara/r1cs-scalar-lowering branch 2 times, most recently from af0dd35 to 9f884e4 Compare September 21, 2026 21:19
@shankarapailoor
shankarapailoor force-pushed the shankara/r1cs-scalar-lowering branch from 9f884e4 to 7c400eb Compare September 22, 2026 13:44
Comment thread lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
Comment thread test/Transforms/PodToScalar/while_carried_pod_distinct_children.llzk Outdated
Comment thread test/Transforms/PodToScalar/while_carried_pod_distinct_children.llzk Outdated
Comment thread test/Transforms/FullR1CSLowering/circom_is_negative.llzk Outdated
Comment thread test/Transforms/FullR1CSLowering/circom_is_positive.llzk Outdated
Comment thread test/Transforms/PodToScalar/while_carried_pod_copy_reject.llzk

@tim-hoffman tim-hoffman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LG, just a few more minor things

Comment thread test/Transforms/PodToScalar/while_carried_pod_success.llzk Outdated
Comment thread test/Transforms/FullR1CSLowering/circom_is_positive.llzk
Comment thread lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
Comment thread lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
Comment thread lib/Dialect/POD/Transforms/PodToScalarPass.cpp Outdated
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex review

@tim-hoffman tim-hoffman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@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: de6452cbe1

ℹ️ 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 lib/Dialect/POD/Transforms/PodToScalarPass.cpp
@shankarapailoor
shankarapailoor force-pushed the shankara/r1cs-scalar-lowering branch from de6452c to c522f23 Compare September 22, 2026 17:18
@shankarapailoor
shankarapailoor disabled stacked auto-merge September 22, 2026 18:06
@shankarapailoor

Copy link
Copy Markdown
Contributor Author

@codex review

@tim-hoffman tim-hoffman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 619e583d34

ℹ️ 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".

@shankarapailoor
shankarapailoor force-pushed the shankara/r1cs-scalar-lowering branch from 619e583 to 4d0848c Compare September 22, 2026 18:23
@shankarapailoor
shankarapailoor merged commit bdca647 into main Sep 22, 2026
10 checks passed
@shankarapailoor
shankarapailoor deleted the shankara/r1cs-scalar-lowering branch September 22, 2026 18:42
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.

2 participants