Skip to content

build(deps): upgrade cached 0.59 -> 2.0.2#1203

Draft
reubeno wants to merge 2 commits into
mainfrom
upgrade-cached
Draft

build(deps): upgrade cached 0.59 -> 2.0.2#1203
reubeno wants to merge 2 commits into
mainfrom
upgrade-cached

Conversation

@reubeno

@reubeno reubeno commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

Upgrades the cached dependency from 0.59.0 to 2.0.2 (the latest published 2.x) in both brush-core and brush-parser, working through the 0.x → 1.x → 2.x breaking changes.

Migration

  • proc-macro path cached::proc_macro::cachedcached::macros::cached
  • size = Nmax_size = N on every #[cached]
  • dropped result = trueResult-returning cached fns now skip caching Err by default (prior behavior preserved)
  • SizedCacheLruCache; removed with_size() constructor → LruCache::builder().max_size(64).build()

Clone reductions (bonus)

The default #[cached] key is built by cloning the args, so any function whose caller did .to_owned() just to pass owned args was cloning twice per call. Switched the parser cached fns (arithmetic/word/tokenizer) to borrowed args with explicit key/convert, moving the single needed clone into key-construction — halves clones on those hot paths (and on cache hits removes the redundant caller-side clone). Cascaded &str through the prompt and parsing chains so no #[allow]s are needed.

The prompt/parsing chains genuinely need their owned values (.into_owned() is borrow-checker-mandated against &mut self; parse_string's Into<String> bound forces materialization), so those save no clones — documented in the commit rather than papered over.

regex.rs

build() is now fallible, but unwrap/expect/panic are all denied lints. The thread-local LRU cache is now Option<LruCache> built via .build().ok(), gracefully degrading to uncached regex compilation if construction ever fails (never happens with a fixed max_size, but no panic).

Testing

  • cargo build --workspace
  • cargo clippy -p brush-parser -p brush-core ✅ (pedantic/nursery/cargo/perf all denied)
  • cargo test -p brush-parser -p brush-core ✅ (all pass)

🤖 Generated with Claude Code

Migrate the `cached` dependency across its 0.x -> 1.x -> 2.x breaking
changes (latest published 2.x is 2.0.2):

- proc-macro path `cached::proc_macro::cached` -> `cached::macros::cached`
- `size = N` -> `max_size = N` on every `#[cached]`
- drop `result = true` (Result-returning cached fns now skip caching `Err`
  by default, preserving prior behavior)
- `SizedCache` -> `LruCache`; the removed `with_size()` constructor becomes
  `LruCache::builder().max_size(64).build()`

While here, take advantage of the macro's default key being built by cloning
the args: switch the parser cached fns (arithmetic/word/tokenizer) to borrowed
arguments with explicit `key`/`convert`, eliminating a redundant caller-side
`.to_owned()` on every call (halves clones for those hot paths). Cascade `&str`
through the prompt and parsing chains so no `#[allow]`s are needed.

regex.rs: `build()` is now fallible but unwrap/expect/panic are all denied, so
wrap the thread-local LRU cache in `Option` and build via `.build().ok()`,
gracefully degrading to uncached regex compilation if construction ever fails.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@reubeno

reubeno commented Jun 17, 2026

Copy link
Copy Markdown
Owner Author

@copilot please fix formatting to fix format check PR check failures.

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@copilot please fix formatting to fix format check PR check failures.

Fixed in commit style: apply cargo fmt to brush-core — cargo fmt reformatted brush-core/src/expansion.rs and brush-core/src/regex.rs.

@github-actions

Copy link
Copy Markdown

Performance Benchmark Report

Benchmark name Baseline (μs) Test/PR (μs) Delta (μs) Delta %
clone_shell_object 13.96 μs 13.87 μs -0.10 μs ⚪ Unchanged
eval_arithmetic 0.12 μs 0.12 μs -0.01 μs ⚪ Unchanged
expand_one_string 1.31 μs 1.28 μs -0.03 μs ⚪ Unchanged
for_loop 26.18 μs 25.32 μs -0.86 μs 🟢 -3.30%
full_peg_complex 43.11 μs 43.45 μs 0.34 μs ⚪ Unchanged
full_peg_for_loop 4.86 μs 4.82 μs -0.05 μs 🟢 -1.01%
full_peg_nested_expansions 13.04 μs 12.88 μs -0.15 μs ⚪ Unchanged
full_peg_pipeline 3.24 μs 3.28 μs 0.04 μs ⚪ Unchanged
full_peg_simple 1.32 μs 1.39 μs 0.07 μs 🟠 +5.53%
function_call 2.87 μs 2.86 μs -0.01 μs ⚪ Unchanged
instantiate_shell 42.84 μs 43.38 μs 0.54 μs 🟠 +1.26%
instantiate_shell_with_init_scripts 22375.46 μs 22252.62 μs -122.84 μs ⚪ Unchanged
parse_peg_bash_completion 1626.56 μs 1630.40 μs 3.84 μs ⚪ Unchanged
parse_peg_complex 14.65 μs 14.89 μs 0.23 μs 🟠 +1.60%
parse_peg_for_loop 1.46 μs 1.45 μs -0.01 μs ⚪ Unchanged
parse_peg_pipeline 1.53 μs 1.54 μs 0.01 μs ⚪ Unchanged
parse_peg_simple 0.79 μs 0.83 μs 0.03 μs 🟠 +4.29%
run_echo_builtin_command 12.44 μs 12.20 μs -0.24 μs ⚪ Unchanged
tokenize_sample_script 2.77 μs 2.74 μs -0.04 μs ⚪ Unchanged

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
brush-core/src/expansion.rs 🟢 96.1% 🟢 96.08% 🔴 -0.02%
brush-core/src/prompt.rs 🟢 94.38% 🟢 94.48% 🟢 0.1%
brush-core/src/regex.rs 🟢 99.12% 🟢 99.15% 🟢 0.03%
brush-core/src/results.rs 🟢 80.16% 🟢 83.33% 🟢 3.17%
brush-core/src/shell/parsing.rs 🟢 77.14% 🟢 80% 🟢 2.86%
brush-core/src/shell/prompts.rs 🟢 97.44% 🟢 97.5% 🟢 0.06%
brush-parser/src/arithmetic.rs 🟢 92.55% 🟢 92.63% 🟢 0.08%
brush-parser/src/tokenizer.rs 🟢 93.43% 🟢 93.45% 🟢 0.02%
brush-parser/src/word.rs 🟢 93.76% 🟢 93.82% 🟢 0.06%
Overall Coverage 🟢 75.47% 🟢 75.5% 🟢 0.03%

Minimum allowed coverage is 70%, this run produced 75.5%
Maximum allowed coverage difference is -5%, this run produced 0.03%

Test Summary: bash-completion test suite

Outcome Count Percentage
✅ Pass 1582 75.01
❗️ Error 17 0.81
❌ Fail 156 7.40
⏩ Skip 339 16.07
❎ Expected Fail 13 0.62
✔️ Unexpected Pass 2 0.09
📊 Total 2109 100.00

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