Skip to content

Stateful POD and aggregate storage - #649

Open
iangneal wants to merge 2 commits into
mainfrom
codex/circom-analysis-2-aggregate-storage
Open

Stateful POD and aggregate storage#649
iangneal wants to merge 2 commits into
mainfrom
codex/circom-analysis-2-aggregate-storage

Conversation

@iangneal

@iangneal iangneal commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Separates physical SourceRef identity from logical dependency resolution on top of #648. Raw lattices continue to identify POD and aggregate storage, while an explicit dependency view resolves stored values for clients that need logical dependencies. This is PR 2 of 6 in the stacked series.

Related issues

No standalone issue; depends on #648.

Changes

  • Keep SourceRefAnalysis::getValueState() address-oriented for POD/array reads and aggregate allocation roots.
  • Add public SourceRefAnalysis::getDependencyState(DataFlowSolver &, Value), backed by aggregate aliases and definite/possible storage-write summaries.
  • Resolve dependencies transitively at query time, preserving unwritten addresses, aggregate shape, possible values, and conservative cycle termination.
  • Keep interval analysis address-based and remove the prior POD-read workaround.
  • Use resolved states for emitted CDG constraints and conditional markers, while retaining raw states for storage targets, direct aliases, and interprocedural translation.
  • Index CDG values by both raw and resolved references where they differ without treating stateful writes as symmetric equality.
  • Add raw-versus-resolved tests for initialized fields, later and transitive writes, aggregate rebasing, conditional writes, unwritten fields, cycles, and address-keyed interval precision.

Testing

  • git diff --check
  • Focused SourceRef, aggregate-storage, interval, and CDG regressions
  • nix build -L on this exact stacked commit: 371 lit tests and 1,311 unit/CAPI tests passed

Submission checklist

  • If I am an external contributor, this PR has a linked issue marked approved; otherwise, this does not apply.
  • I added or updated tests for all relevant behavior, or explained above why tests are not needed.
  • I updated the relevant TableGen or other documentation, or explained above why documentation is not needed.
  • I added a changelog entry describing user-visible changes. (create-changelog in the Nix development shell creates a template.)
  • I enabled Allow edits from maintainers if this PR comes from a fork.

AI assistance

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

Tools used: OpenAI Codex.

How the tools contributed: Codex helped partition the original working-tree change, implement the raw-versus-resolved SourceRef architecture, add focused regressions, and prepare this draft PR.

How I verified the contribution: Reviewed the isolated diff and ran git diff --check, the focused analysis regressions through the project test suite, and nix build -L on this exact commit.

@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from 305ed85 to 7cef052 Compare July 28, 2026 20:07
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Test Results

  2 files  ±0    2 suites  ±0   10m 38s ⏱️ + 1m 11s
372 tests ±0  368 ✅ ±0  4 💤 ±0  0 ❌ ±0 
744 runs  ±0  736 ✅ ±0  8 💤 ±0  0 ❌ ±0 

Results for commit 8c54a02. ± Comparison against base commit 5db6f8f.

♻️ This comment has been updated with latest results.

@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from 7cef052 to 8c1fbaa Compare July 28, 2026 22:08
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch 2 times, most recently from 10496f8 to 447bd82 Compare July 28, 2026 22:46
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from 447bd82 to 7f5319e Compare July 29, 2026 02:20
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from 7f5319e to b927c8f Compare July 29, 2026 15:06
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from b927c8f to c9ce071 Compare July 29, 2026 15:30
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch 2 times, most recently from c965086 to e845f58 Compare July 29, 2026 17:05
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from e845f58 to 232e94f Compare July 29, 2026 20:38
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch 3 times, most recently from 969d4e2 to a3cb1e6 Compare July 30, 2026 05:05
Base automatically changed from codex/circom-analysis-1-primitives to main July 30, 2026 17:28
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch 3 times, most recently from 010c330 to f841b5d Compare July 30, 2026 18:57
@iangneal
iangneal marked this pull request as ready for review July 30, 2026 23:54
@iangneal
iangneal requested a review from a team as a code owner July 30, 2026 23:54
@iangneal

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: f841b5d819

ℹ️ 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/Analysis/ConstraintDependencyGraph.cpp Outdated
Comment thread lib/Analysis/ConstraintDependencyGraph.cpp Outdated
Comment thread lib/Analysis/ConstraintDependencyGraph.cpp Outdated
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from f841b5d to 7c0b886 Compare July 31, 2026 00:23
@iangneal

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: 7c0b8864b6

ℹ️ 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/Analysis/ConstraintDependencyGraph.cpp Outdated
Comment thread lib/Analysis/ConstraintDependencyGraph.cpp
Comment thread lib/Analysis/ConstraintDependencyGraph.cpp Outdated
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from 7c0b886 to 31f6931 Compare July 31, 2026 02:55
@iangneal
iangneal force-pushed the codex/circom-analysis-2-aggregate-storage branch from 31f6931 to 1e92ace Compare July 31, 2026 03:03
@iangneal

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: 1e92ace677

ℹ️ 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 on lines +180 to +181
const llvm::DenseMap<SourceRef, SourceRefLatticeValue> storedValues =
materializeStoredValues(before, aliases);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Record array mutations in dependency storage

When an array is created uninitialized, or an initialized element is overwritten, and a later array.read feeds a constraint, materializeStoredValues() has no entry for the array.write/array.insert: the array-access branch in visitOperation() returns without calling recordStorageWrite. Consequently the new dependency view leaves the read as its allocation address or stale initializer instead of the written operand, so the CDG can omit the actual witness dependency; record the rvalue against getWriteTargetState() with the same conditional-write semantics used for POD writes.

Useful? React with 👍 / 👎.

Comment on lines +314 to +317
void SourceRefAnalysis::StorageState::recordAggregateAlias(
Operation *op, size_t aliasIndex, const SourceRefLatticeValue &source,
const SourceRefLatticeValue &target
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Treat aliases created in skipped regions as conditional

When an aggregate assignment occurs inside an scf.if branch or zero-trip loop, this alias event has no mayBeSkipped state and is therefore materialized unconditionally. For example, if a POD record initially contains aggregate A and is conditionally overwritten with aggregate B, B's alias—and its initializer write, which is also recorded as definite—canonicalizes B's fields onto the target even when the branch does not execute, causing the initial dependency to be dropped. Preserve both alias alternatives for potentially skipped regions and mark nested initializer events optional as well.

Useful? React with 👍 / 👎.

Comment on lines +382 to +384
Operation *defOp = sourceRoot->getDefiningOp();
if (defOp == nullptr || !llvm::isa<CallOp, NewPodOp, CreateArrayOp, NonDetOp>(defOp)) {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve child paths for aggregate arguments

Fresh evidence beyond the earlier aggregate-initializer report is that this new filter explicitly rejects block-argument roots (getDefiningOp() == nullptr) and aggregate member values rooted at struct.new. When such an aggregate initializes a POD record and a nested child is later read, no alias rebases the requested suffix; resolution matches the root write and returns the source aggregate root, potentially including sibling dependencies, rather than the requested child. Support these source forms or transfer the queried suffix onto the stored aggregate value during resolution.

Useful? React with 👍 / 👎.

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