Skip to content

refactor!: replace Result with panic in stable-structures API#351

Merged
maksymar merged 28 commits intomainfrom
maksym/rm-grow-failed
Jun 27, 2025
Merged

refactor!: replace Result with panic in stable-structures API#351
maksymar merged 28 commits intomainfrom
maksym/rm-grow-failed

Conversation

@maksymar
Copy link
Copy Markdown
Contributor

@maksymar maksymar commented Jun 23, 2025

[Breaking change] This PR refactors the public API of stable-structures to remove Result return types and instead panic internally on failure.

The change applies to Vec, MinHeap, Cell, and Log, affecting methods like new, init, push, etc.

These operations are expected to succeed under normal conditions. Returning Result forces callers to handle errors that are either:

  • unrecoverable (e.g., memory allocation failure, memory corruption such as bad magic)
  • highly unlikely edge cases (e.g., writing a Cell with a value larger than u32::MAX)

By switching to panics:

  • the API becomes simpler and more ergonomic
  • client code is cleaner, with no need for .unwrap() or ?

This is a breaking change and requires updates to any downstream code that previously handled these errors.

Fixes #221

@maksymar maksymar requested a review from Copilot June 25, 2025 14:47

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 25, 2025

canbench 🏋 (dir: ./benchmarks/memory_manager) 559f26d 2025-06-26 14:46:45 UTC

./benchmarks/memory_manager/canbench_results.yml is up to date
📦 canbench_results_memory-manager.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 3 | regressed 0 | improved 0 | new 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 3 | regressed 0 | improved 0 | new 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 3 | regressed 0 | improved 0 | new 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 25, 2025

canbench 🏋 (dir: ./benchmarks/btreeset) 559f26d 2025-06-26 14:47:06 UTC

./benchmarks/btreeset/canbench_results.yml is up to date
📦 canbench_results_btreeset.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 100 | regressed 0 | improved 0 | new 0 | unchanged 100]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 100 | regressed 0 | improved 0 | new 0 | unchanged 100]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 100 | regressed 0 | improved 0 | new 0 | unchanged 100]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 25, 2025

canbench 🏋 (dir: ./benchmarks/vec) 559f26d 2025-06-26 14:46:50 UTC

./benchmarks/vec/canbench_results.yml is up to date
📦 canbench_results_vec.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max +20.00K | p75 +20.00K | median 0 | p25 0 | min 0]
    change %: [max +0.62% | p75 +0.55% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 25, 2025

canbench 🏋 (dir: ./benchmarks/compare) 559f26d 2025-06-26 14:47:38 UTC

./benchmarks/compare/canbench_results.yml is up to date
📦 canbench_results_compare.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 18 | regressed 0 | improved 0 | new 0 | unchanged 18]
    change:   [max +22.00M | p75 +21.53K | median +3 | p25 0 | min -56]
    change %: [max +0.05% | p75 0.00% | median 0.00% | p25 0.00% | min -0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 18 | regressed 0 | improved 0 | new 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 18 | regressed 0 | improved 0 | new 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 25, 2025

canbench 🏋 (dir: ./benchmarks/btreemap) 559f26d 2025-06-26 14:48:36 UTC

./benchmarks/btreemap/canbench_results.yml is up to date
📦 canbench_results_btreemap.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 285 | regressed 0 | improved 0 | new 0 | unchanged 285]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 285 | regressed 0 | improved 0 | new 0 | unchanged 285]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 285 | regressed 0 | improved 0 | new 0 | unchanged 285]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@maksymar maksymar changed the title refactor: remove GrowFailed error from API refactor: remove Err from API Jun 25, 2025
@maksymar maksymar requested a review from Copilot June 26, 2025 09:01
@maksymar maksymar marked this pull request as ready for review June 26, 2025 09:01
@maksymar maksymar requested a review from a team as a code owner June 26, 2025 09:01

This comment was marked as outdated.

@maksymar maksymar marked this pull request as draft June 26, 2025 09:56
@maksymar maksymar requested a review from Copilot June 26, 2025 10:56

This comment was marked as outdated.

@maksymar maksymar changed the title refactor: remove Err from API refactor: remove Result-returns in stable-structures public API and switch to panic Jun 26, 2025
@maksymar maksymar requested a review from Copilot June 26, 2025 13:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the public API of stable-structures by removing Result return types and switching to panics on failure. The changes simplify the code by eliminating error handling through Result and updating tests to expect panics for failure cases.

  • Public API methods (new, init, push, set, etc.) now panic internally on failure.
  • Test cases have been updated to expect panics and no longer unwrap Results.
  • Minor import reorderings and cleanup have been applied across affected modules.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/api_confomrance.rs Updated to remove unwrap handling; also note a filename typo
src/vec.rs Refactored methods to panic on failure instead of returning Result
src/min_heap.rs Similar refactoring applied to heap methods
src/log.rs Refactored initialization to panic on incompatible memory states
src/cell.rs Updated cell creation and update methods to use panic internally
Other test files and benchmarks Updated tests and benchmarks to remove error handling
Comments suppressed due to low confidence (1)

tests/api_confomrance.rs:1

  • The filename 'api_confomrance.rs' appears to contain a typo. Consider renaming it to 'api_conformance.rs' for clarity.
use std::cell::RefCell;

@maksymar maksymar changed the title refactor: remove Result-returns in stable-structures public API and switch to panic refactor: replace Result with panic in stable-structures API Jun 26, 2025
@maksymar maksymar marked this pull request as ready for review June 26, 2025 13:17
@maksymar maksymar changed the title refactor: replace Result with panic in stable-structures API refactor!: replace Result with panic in stable-structures API Jun 26, 2025
Copy link
Copy Markdown
Contributor

@berestovskyy berestovskyy left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@maksymar maksymar merged commit 6e31d42 into main Jun 27, 2025
15 checks passed
@maksymar maksymar deleted the maksym/rm-grow-failed branch June 27, 2025 07:54
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.

The inconsistency of init APIs

3 participants