Skip to content

Apply automatic clippy fixes in codegen#5425

Merged
proggeramlug merged 4 commits into
mainfrom
feat/clippy-codegen-auto-fixes
Jun 19, 2026
Merged

Apply automatic clippy fixes in codegen#5425
proggeramlug merged 4 commits into
mainfrom
feat/clippy-codegen-auto-fixes

Conversation

@TheHypnoo

@TheHypnoo TheHypnoo commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

  • Applies mechanical cargo clippy --fix suggestions across the codegen crates.
  • Covers perry-codegen, perry-codegen-arkts, perry-codegen-js, and perry-codegen-wasm without changing generated-code intent.

Validation

  • cargo fmt --all -- --check
  • cargo clippy -p perry-codegen -p perry-codegen-arkts -p perry-codegen-js -p perry-codegen-wasm -- -A clippy::not_unsafe_ptr_arg_deref
  • Follow-up cargo clippy --fix --lib -p perry-codegen --allow-dirty --allow-staged -- -A clippy::not_unsafe_ptr_arg_deref for one remaining automatic suggestion, then cargo fmt --all -- --check

Remaining clippy output is pre-existing warning debt not covered by automatic fixes in this branch.

Summary by CodeRabbit

  • Refactor
    • Simplified conditional logic throughout the code generation pipeline (using more concise pattern matching and guards).
    • Updated iterator and string construction patterns for consistent output formatting.
    • Cleaned up module wiring (imports/re-exports) and simplified internal data handling.
  • Bug Fixes
    • Improved the formatting/whitespace of fallback placeholder text in generated widget/tree-view output.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 85669e9b-fb56-498b-bab6-56b673ff0afb

📥 Commits

Reviewing files that changed from the base of the PR and between d66a82c and 7dbbc1b.

📒 Files selected for processing (4)
  • crates/perry-codegen/src/codegen/string_pool.rs
  • crates/perry-codegen/src/collectors/pointer_locals.rs
  • crates/perry-codegen/src/native_value/mod.rs
  • crates/perry-codegen/src/type_analysis.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/perry-codegen/src/codegen/string_pool.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/perry-codegen/src/collectors/pointer_locals.rs
  • crates/perry-codegen/src/type_analysis.rs

📝 Walkthrough

Walkthrough

This PR applies broad code-quality cleanup across perry-codegen and sibling crates. It removes unused imports (anyhow, bail, perry_hir bulk imports, super::*) from ~40 files, narrows the collectors/mod.rs and expr/mod.rs internal re-export hubs, simplifies match-arm control flow with guards, and applies idiomatic Rust micro-patterns (repeat_n, entry().or_insert_with, derived Default, is_some_and/is_none_or, .clone() removal).

Changes

Codegen cleanup and idiomatic Rust refactors

Layer / File(s) Summary
Module surfaces and core codegen defaults
crates/perry-codegen/src/codegen/opts.rs, collectors/mod.rs, expr/mod.rs, codegen/mod.rs, codegen/entry.rs, codegen/string_pool.rs, native_value/mod.rs
FpContractMode gains derived Default with #[default] on Off, removing the hand-written impl. The collectors/mod.rs and expr/mod.rs internal re-export hubs are narrowed to remove previously exposed internal helpers. codegen/mod.rs adopts HashMap::entry().or_insert_with for static-field-globals registration. Struct-field shorthand is used in FnCtx init. string_pool.rs uses sort_by_key instead of explicit comparator. BufferViewRep re-export is gated as test-only.
Collector import cleanup and consolidation
collectors/clamp_detect.rs, collectors/closures.rs, collectors/escape_arrays.rs, collectors/escape_objects.rs, collectors/i32_locals.rs, collectors/i64_emit.rs, collectors/index_uses.rs, collectors/refs.rs, collectors/shadow_slots.rs, collectors/mutation.rs
All affected collector files remove now-redundant top-level bulk imports for perry_hir, HashSet, and super::*, relying instead on local and fully-qualified references.
Collector control-flow simplification with match guards
collectors/clamp_detect.rs, collectors/escape_arrays.rs, collectors/escape_check.rs, collectors/integer_locals.rs, collectors/mutation.rs, collectors/pointer_locals.rs, lower_call/closure_analysis.rs
Nested if-inside-match-arm patterns in has_any_mutation, find_array_candidates, find_new_candidates, int32_producing_deps, collect_extra_integer_let_ids, returns_int_stmts, walk, and find_outer_writes_expr are rewritten as match guards, preserving identical insertion and early-return behavior.
Expr submodule anyhow import pruning
expr/array_methods.rs, expr/arrays_finds.rs, expr/bigint_set.rs, expr/binary.rs, expr/call_spread.rs, expr/calls.rs, expr/child_proc.rs, expr/closure.rs, expr/compare.rs, expr/conditional.rs, expr/env_clones.rs, expr/fs_await.rs, expr/index_get.rs, expr/index_set.rs, expr/instance_misc1.rs, expr/js_runtime.rs, expr/literals_vars.rs, expr/logical_collections.rs, expr/math_simple.rs, expr/misc_methods.rs, expr/new_dynamic.rs, expr/objects_arrays_lit.rs, expr/os_uri_dates.rs, expr/property_get.rs, expr/property_set.rs, expr/proxy_reflect.rs, expr/static_field_meta.rs, expr/static_method.rs, expr/string_regex_proc.rs, expr/super_method.rs, expr/this_super_call.rs, expr/unary.rs, expr/url_main.rs
All ~30 expr submodule files trim their anyhow import lists to only the symbols actually used, removing unused anyhow and bail identifiers.
Expr and lower-call behavior-preserving logic edits
expr/arrays_finds.rs, expr/calls.rs, expr/dyn_extern_i18n.rs, expr/buffer_access.rs, expr/property_get.rs, expr/this_super_call.rs, expr/static_method.rs, expr/v8_interop.rs, lower_call/extern_func.rs, lower_call/namespace_call.rs, lower_call/property_get.rs, lower_call/builtin.rs, stmt/let_stmt.rs
Six access_mode.clone() calls are removed in buffer_access. .as_bytes().len() is simplified to .len() in v8_interop. repeat().take() is replaced with repeat_n for iterator construction. Promise .then/.catch/.finally arms use match guards. Tail Ok(...) replaces explicit return Ok(...). Literals are used directly instead of .to_string() conversions. is_some_and replaces map_or(false, ...) patterns. Borrow passing is adjusted from &ctx.class_ids to ctx.class_ids.
Type analysis Option-helper and guard modernization
type_analysis.rs
Type analysis predicates modernize their conditional patterns using is_none_or and is_some_and for string type detection and array element type refinement, with explicit Undefined matching for encoding-argument presence.
ArkTS, JS, and Wasm emitter micro-cleanups
crates/perry-codegen-arkts/src/emit_widget.rs, crates/perry-codegen-arkts/src/widgets/tree.rs, crates/perry-codegen-js/src/emit/exprs_more.rs, crates/perry-codegen-wasm/src/emit/locals.rs
emit_widget.rs and tree.rs replace format! placeholder construction with static string literals via .to_string(). exprs_more.rs switches push_str("(") to push('('). Wasm collect_locals uses a match guard on Stmt::Let to skip duplicate-key registration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PerryTS/perry#5291: Both PRs modify crates/perry-codegen/src/codegen/entry.rs within compile_module_entry's FnCtx struct initialization (this PR changes closure_rest_params field wiring, related PR adds native_facts to the same FnCtx construction).

Poem

🐇 Hop, hop, I trimmed the weeds,
bail! and clone — no one needs!
Match guards bloom where nested ifs grew,
repeat_n skips the .take() queue.
The re-export hub is lean and bright,
This bunny tidied things up right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description clearly explains the summary, validation steps, and scope. However, the provided checklist items (cargo build/test, test plan, docs updates) required by the template are not explicitly checked/completed. Complete the template checklist items by either checking the boxes for completed steps or explicitly stating test results and validation outcomes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: applying automatic clippy fixes to the codegen crates. It is clear, concise, and directly reflects the PR's primary objective.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/clippy-codegen-auto-fixes

Comment @coderabbitai help to get the list of available commands and usage tips.

TheHypnoo and others added 3 commits June 19, 2026 00:27
clippy --fix dropped the `BufferViewRep` re-export from
native_value/mod.rs because its only remaining user is the `verify`
test module (non-test code reaches the type via super::buffer
directly). Restore it gated behind #[cfg(test)] so the test build
resolves `crate::native_value::BufferViewRep` without reintroducing
an unused-import warning in release builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@proggeramlug proggeramlug merged commit 503cf16 into main Jun 19, 2026
15 checks passed
@proggeramlug proggeramlug deleted the feat/clippy-codegen-auto-fixes branch June 19, 2026 09:34
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