Skip to content

refactor(stage1): remove Pass 2's production imports of Pass 1 (#1191) - #1212

Merged
milindsrivastava1997 merged 2 commits into
mainfrom
1191-stage-1-remove-pass-2s-production-imports-of-pass-1
Nov 4, 2026
Merged

milindsrivastava1997 merged 2 commits into
mainfrom
1191-stage-1-remove-pass-2s-production-imports-of-pass-1

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1191. Follows #1096.

Why

Pass 1 no longer imports Pass 2 (#1192), but Pass 2 still imported Pass 1's error type and two of its helpers, so the passes were not independent modules.

What / how

  • Errors: Pass 2's rewrite helpers (asap_aware_cse) return a new crate-private CseError with the three variants they use. No code matches its variants: callers stringify it into Pass2RuleError, drop the candidate, or call .ok().
    • PerComputationCandidateError loses TooManyCandidates, which only Pass 2 produced.
    • ErrorBuildingLogicalASAPDagsFromChosenCandidates::Recompose wraps SchemaDerivationError, the only error it ever held.
  • Shared helpers: what both passes need are IR operations, so they move to asap-types as Field::column_ref, FieldDataType::exact and Reduction::partitions_over. Field::column_ref also replaces two copies of the same logic: inline in schema/topk.rs, and Pass 1's schema_column_ref.
  • rolled_up: it builds its Sum/Min/Max exact accumulator inline (reads the value column, no item, UnknownOrSigned) and keeps Pass 1's check that the column resolves. Pass 1's exact_accumulator builds the same node for this case, but it would have pulled ~300 lines and Pass 1's error type into a shared module.
  • tests/pass_layering.rs: walks each pass's directory recursively, matches pass1:: / pass2:: in production lines, and now tests both directions.

Error enums per pass

Pass Enum Visibility Variants
1 PerComputationCandidateError public Structure, AssignedPhysicalAnnotation, ContainsAsap, InvalidAccuracy, InvalidChoice, Unsupported (this PR removes TooManyCandidates)
1 CandidatePopulationError public RootDependenciesChanged, InvalidTarget, InvalidAbsorption
1 PerComputationLogicalMemoCandidatesError public PerComputation, Population, Sizing (wraps the two above and SchemaDerivationError)
2 Pass2RuleError public MismatchedGroups, InvalidGroupReference, TooManyGroups, CyclicDependencies, AlreadyExpanded, ScanLabelWidening, StateConfiguration, ReuseRule
2 ErrorBuildingLogicalASAPDagsFromChosenCandidates public NoSuchCandidate, ChildNotInCandidate, Cycle, Recompose (this PR changes its payload to SchemaDerivationError)
2 CseError (new) crate-private Structure, Unsupported, TooManyCandidates

The rules turn a CseError into text inside Pass2RuleError (ReuseRule, StateConfiguration, ScanLabelWidening), or drop the candidate.

Before this PR

$ cargo test -p asap-logical-asap-optimization --test pass_layering
Pass 2 imports Pass 1:
src/pass2/memo/enumeration.rs:25: use crate::pass1::per_computation_candidates::PerComputationCandidateError;
src/pass2/asap_aware_cse.rs:124: use crate::pass1::per_computation_candidates::PerComputationCandidateError;
src/pass2/asap_aware_cse.rs:1839: use crate::pass1::per_computation_candidates::{exact_accumulator, partitions_over};

After this PR

Both pass1_does_not_import_pass2 and pass2_does_not_import_pass1 pass. Test modules may still use the other pass to build fixtures.

Key code interfaces added / modified

  • Public: PerComputationCandidateError::TooManyCandidates removed. ErrorBuildingLogicalASAPDagsFromChosenCandidates::Recompose now holds SchemaDerivationError. No caller in the workspace matched either.
  • Public, asap-types: Field::column_ref, FieldDataType::exact and Reduction::partitions_over are new.
  • Crate-private: CseError is new. Pass 1's schema_column_ref is removed.

Major algorithm changes

None.

Snapshot changes

None.

Testing

  • New unit test partitions_over_matches_keys_by_column in asap-types.
  • rollup_from_a_finer_exact_sum and extrema_and_integer_counts_roll_up cover the inline accumulator. Making it return None fails 5 rollup tests.
  • The tests of logical-asap-optimization, devtools (corpus snapshots included), planner, and the Stage 1 integration tests pass, as do asap-types'. Clippy is clean.

Out of scope

Splitting the passes into separate crates (#1209).

🤖 Generated with Claude Code

- Pass 2's rewrite helpers return a private CseError instead of Pass 1's
  PerComputationCandidateError, which loses TooManyCandidates (only Pass 2
  produced it). Recompose wraps SchemaDerivationError directly.
- column_ref, exact_family and partitions_over move to a crate-private
  ir_construction module both passes use.
- rolled_up builds its Sum/Min/Max exact accumulator inline instead of
  calling Pass 1's exact_accumulator.
- pass_layering walks each pass recursively and forbids pass2 -> pass1 too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol

zzylol commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

In the PR body, could you also list out the error enum per pass? so we can check the coverage. Thanks!

)

Review on #1212: the helpers both passes share are IR operations, and
column_ref was duplicated.

- Field::column_ref replaces ir_construction::column_ref and the copies in
  schema/topk.rs and pass1's schema_column_ref.
- FieldDataType::exact replaces exact_family.
- Reduction::partitions_over replaces partitions_over, with a unit test.
- ir_construction is deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milindsrivastava1997
milindsrivastava1997 merged commit 82165ae into main Nov 4, 2026
4 checks passed
@milindsrivastava1997
milindsrivastava1997 deleted the 1191-stage-1-remove-pass-2s-production-imports-of-pass-1 branch November 4, 2026 16:53
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.

Stage 1: remove Pass 2's production imports of Pass 1

2 participants