Skip to content

Add try_new variants for panicking constructors - #246

Merged
JoeyBF merged 8 commits into
SpectralSequences:masterfrom
hoodmane:try-variants
Jul 2, 2026
Merged

Add try_new variants for panicking constructors#246
JoeyBF merged 8 commits into
SpectralSequences:masterfrom
hoodmane:try-variants

Conversation

@hoodmane

@hoodmane hoodmane commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Add fallible variants for the remaining module constructors and FD builder methods that panic on bad preconditions.

  • HomModule::try_new: Err when target is not bounded above
  • QuotientModule::try_new: Err on too-low truncation / i32 overflow
  • HomPullback::try_new: Err on inconsistent source/target/map wiring

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds fallible validation wrappers for several algebra module constructors and validation helpers, while keeping the existing infallible APIs as unwrap() shims. Unit tests cover valid and invalid inputs, and one iterator lint allowance is broadened.

Changes

Fallible constructors for algebra modules

Layer / File(s) Summary
FiniteDimensionalModule degree-order guards
ext/crates/algebra/src/module/finite_dimensional_module.rs
Adds fallible wrappers for validity and action extension that reject non-increasing degree pairs, with tests for success and error cases.
HomModule::try_new constructor
ext/crates/algebra/src/module/hom_module.rs
Moves target boundedness validation into try_new, keeps new as an unwrap wrapper, and adds bounded/unbounded tests.
HomPullback::try_new constructor
ext/crates/algebra/src/module/homomorphism/hom_pullback.rs
Adds a fallible wiring check constructor, keeps new as an unwrap wrapper, and adds wiring tests.
QuotientModule::try_new constructor
ext/crates/algebra/src/module/quotient_module.rs
Adds truncation and overflow validation to a fallible constructor, keeps new as an unwrap wrapper, and adds validation tests.

BinomialIterator lint allowance

Layer / File(s) Summary
BinomialIterator allow attribute
ext/crates/fp/src/prime/iter.rs
Extends the existing allow attribute to include unknown_lints.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

🐇 I hop through degrees with a careful grin,
Result now says where the bounds begin.
Pullbacks and quotients line up just right,
No panic storms on a moonlit night.
One tiny lint got a cozy new nest,
And the rabbit approves of the algebra quest.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main addition of fallible try_new constructors for previously panicking code paths.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Add fallible variants for the remaining module constructors and FD
builder methods that panic on bad preconditions, following the existing
try_compute_homotopy_step precedent (the panicking function delegates via
.unwrap()):

- HomModule::try_new: Err when target is not bounded above
- QuotientModule::try_new: Err on too-low truncation / i32 overflow
- HomPullback::try_new: Err on inconsistent source/target/map wiring
- FiniteDimensionalModule::try_extend_actions / try_check_validity:
  Err when output_deg <= input_deg instead of asserting

Each returns anyhow::Result, matching the from_json/secondary-lift error
style. Adds valid+error path tests for all five.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ext/crates/algebra/src/module/quotient_module.rs`:
- Around line 37-47: The span validation in QuotientModule::try_new only checks
truncation + 1, but it still allows overflow when computing the allocation span
against module.min_degree(). Replace the current arithmetic with checked
operations for the actual span used to size the backing storage (or delegate the
guard to BiVec::with_capacity), and keep the existing min_degree/truncation
validation aligned with the final capacity calculation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 53573fdd-2e45-4075-b7cd-c323adbcab97

📥 Commits

Reviewing files that changed from the base of the PR and between dfd0fd5 and 84313fa.

📒 Files selected for processing (5)
  • ext/crates/algebra/src/module/finite_dimensional_module.rs
  • ext/crates/algebra/src/module/hom_module.rs
  • ext/crates/algebra/src/module/homomorphism/hom_pullback.rs
  • ext/crates/algebra/src/module/quotient_module.rs
  • ext/crates/fp/src/prime/iter.rs

Comment thread ext/crates/algebra/src/module/quotient_module.rs

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ext/crates/algebra/src/module/quotient_module.rs (1)

250-266: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a dedicated test for the span-overflow (checked_sub) branch.

The two tests cover truncation-too-low and capacity add-overflow, but not the case where capacity.checked_sub(min_degree) itself overflows (e.g., a very negative min_degree paired with truncation near i32::MAX). Not blocking, since the add-overflow test already exercises the overflow-handling error path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ext/crates/algebra/src/module/quotient_module.rs` around lines 250 - 266, Add
a dedicated test in QuotientModule::try_new that forces the checked_sub
span-overflow branch, not just the truncation-too-low and capacity add-overflow
cases. Use a module from joker() but override the degree inputs so
capacity.checked_sub(min_degree) overflows (for example a very negative
min_degree with truncation near i32::MAX), then assert that
QuotientModule::try_new returns an error containing the overflow path. Keep the
new case alongside try_new_truncation_too_low_errors and
try_new_truncation_overflow_errors so the error handling branches are covered
separately.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@ext/crates/algebra/src/module/quotient_module.rs`:
- Around line 250-266: Add a dedicated test in QuotientModule::try_new that
forces the checked_sub span-overflow branch, not just the truncation-too-low and
capacity add-overflow cases. Use a module from joker() but override the degree
inputs so capacity.checked_sub(min_degree) overflows (for example a very
negative min_degree with truncation near i32::MAX), then assert that
QuotientModule::try_new returns an error containing the overflow path. Keep the
new case alongside try_new_truncation_too_low_errors and
try_new_truncation_overflow_errors so the error handling branches are covered
separately.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 290d4754-7a17-466f-8145-52f6a5018b03

📥 Commits

Reviewing files that changed from the base of the PR and between 84313fa and 6f821bf.

📒 Files selected for processing (1)
  • ext/crates/algebra/src/module/quotient_module.rs

@hoodmane hoodmane changed the title Add try_new/try_extend_actions variants for panicking constructors Add try_new variants for panicking constructors Jul 2, 2026

@JoeyBF JoeyBF left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

@JoeyBF
JoeyBF merged commit db22f4c into SpectralSequences:master Jul 2, 2026
19 of 20 checks passed
github-actions Bot added a commit that referenced this pull request Jul 2, 2026
Add fallible variants for the remaining module constructors and FD
builder methods that panic on bad preconditions, following the existing
try_compute_homotopy_step precedent (the panicking function delegates via
.unwrap()):

- HomModule::try_new: Err when target is not bounded above
- QuotientModule::try_new: Err on too-low truncation / i32 overflow
- HomPullback::try_new: Err on inconsistent source/target/map wiring
- FiniteDimensionalModule::try_extend_actions / try_check_validity:
  Err when output_deg <= input_deg instead of asserting

Each returns anyhow::Result, matching the from_json/secondary-lift error
style. Adds valid+error path tests for all five.
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