Skip to content

refactor: narrow physical, cost, accuracy and types visibility (#1054 step 8b) - #1094

Merged
zzylol merged 1 commit into
mainfrom
refactor/1054-8b-visibility
Oct 30, 2026
Merged

zzylol merged 1 commit into
mainfrom
refactor/1054-8b-visibility

Conversation

@zzylol

@zzylol zzylol commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Part of #1054 (step 8b, visibility): asap-physical-asap-optimization, asap-cost, asap-accuracy and asap-types. Logical and plan-selection follow after their #1047 reshapes.

Why

#1054's rule: an item is pub only if another crate's non-test code uses it. Test-only access goes behind a test-support feature that only dev-dependencies enable. Many items in these four crates were pub with no production user outside their own crate, so the crate boundaries did not show what each stage actually uses.

What

Visibility, import paths and deletions only. Behavior is unchanged.

Narrowed:

  • physical: optimize_physical_asap_assigned, materializes_any, optimize_physical_asap_chosen, implement_candidate_operators and the summary_window module are now reached through test_support. summary_materialization_eligibility and its types are pub(crate).
  • accuracy: satisfies, local_guarantee, the sketch size helpers, PropagationStats and its constants are now pub(crate), with test_support wrappers. The budget, function_rules and estimators::{cms,kll} modules are private. There is one path to per_input_target.
  • cost: the measured and resources modules are private. lookup, aggregate_lookup and StateFamily are re-exported at the crate root, because plan-selection uses them. Internal statistics types and fields are pub(crate).
  • types: the single-stage and test-only helpers that [Refactor] Crate organization by stage: per-crate functionality, cross-stage code into asap-accuracy / asap-cost / asap-types, enforced crate boundaries, public vs private #1054's table lists, plus about 30 more items used only inside the crate. Test-only items sit behind the new asap-types/test-support feature.

Deleted (no non-test reader):

  • PhysicalWorkloadPlan::assignment
  • SummaryMaterializationEligibility::may_materialize_at_query, with two test asserts that read only it
  • OperatorStatistics::input_count and promql_input
  • AggIntent::requires and the DataModel enum it alone used
  • ParsedWorkload::planning_workload

How

  1. For each pub item, git grep found its users across the workspace.
  2. Each item went to the narrowest visibility its users allow:
    • production use in another crate (including devtools binaries): stays pub;
    • test use only: #[cfg(any(test, feature = "test-support"))] or a thin test_support wrapper;
    • otherwise: pub(crate).
  3. asap-types gains a test-support feature. The planner's test-support feature enables it.

Key code interfaces added / modified

New test-only modules:

Each is a one-line forward or a re-export, compiled only with test-support.

Usage: a test that needs a crate-internal helper enables the feature in dev-dependencies and calls it through test_support:

[dev-dependencies]
asap-types = { path = "../types", features = ["test-support"] }
let layout = asap_physical_asap_optimization::test_support::summary_window::plan_pane_phase(/* … */);

Production code is unaffected: stage_pipeline and the planner build without any test-support feature.

Major algorithm changes

None.

Before / After

  • Before: about 90 items in these crates were pub with no production user outside their crate.
  • After: pub means used by another crate's production code.

Not done here: about 50 test-only asap-types fields and methods that the crate also uses itself (for example SummaryCoverage.selection and PhysicalASAPDAGEdge fields). Hiding them needs accessors and many test edits, so that is a follow-up.

Verification

At 7f575d51f (on main 2109b346d):

  • Lint: fmt clean. clippy --workspace --all-targets -D warnings clean, also per package.

  • Normal builds: cargo build --workspace, cargo build -p asap-devtools --bins and cargo build -p asap-planner pass with 0 warnings.

  • Feature leakage: cargo tree -e features,normal on planner, devtools, executor, frontends, plan-selection and integration-tests shows no test-support feature on a normal edge, apart from the test-only crate integration-tests, as before.

  • Test builds: cargo test -p <crate> --no-run for each of the 14 crates compiles with 0 warnings.

  • Tests:

    Crate Passed
    types 145 + 97 + 8
    accuracy 77
    cost 35
    physical 25
    logical 178 + 35
    frontends 229 / 177 / 15 / 54
    plan-selection --lib 336
    planner 86
    devtools 106
    integration-tests 374

    The 2 known parallel-load flakes pass alone.

  • Docs: cargo doc --no-deps warnings are the same as base, or one fewer for accuracy.

  • Independent review: no blocking findings. It confirmed:

    • each deleted item had no non-test reader;
    • the wrappers are pass-throughs;
    • the diff has no logic changes.

External impact: none outside this repo.

🤖 Generated with Claude Code

…step 8b)

Each item is pub only when another crate's non-test code uses it; items
only tests use sit behind a `test-support` feature enabled in
dev-dependencies, and items nothing reads are deleted.

- physical: `optimize_physical_asap_assigned` and `materializes_any` are
  test-support only; `optimize_physical_asap_chosen`,
  `implement_candidate_operators` and the pane-coverage check move behind
  `test_support`; summary eligibility, `IngestionPruneReason` and
  `summary_window` become crate-private. Deleted the write-only
  `PhysicalWorkloadPlan::assignment` and
  `SummaryMaterializationEligibility::may_materialize_at_query`.
- accuracy: estimator, sizing and composition helpers only tests call move
  behind `test_support`; `budget` and `function_rules` become private (one
  path to `per_input_target`).
- cost: `measured` and `resources` become private (one path to the cost
  table types); unused `OperatorStatistics::{input_count, promql_input}`
  deleted.
- types: new `test-support` feature; single-stage helpers named in #1054
  are crate-private with test wrappers; test-only methods are gated;
  unused `AggIntent::requires`, `DataModel` and
  `ParsedWorkload::planning_workload` deleted.

No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant