Skip to content

Apply automatic clippy fixes in runtime and FFI - #5426

Merged
proggeramlug merged 5 commits into
mainfrom
feat/clippy-runtime-ffi-auto-fixes
Jun 19, 2026
Merged

Apply automatic clippy fixes in runtime and FFI#5426
proggeramlug merged 5 commits into
mainfrom
feat/clippy-runtime-ffi-auto-fixes

Conversation

@TheHypnoo

@TheHypnoo TheHypnoo commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

  • Applies mechanical cargo clippy --fix suggestions in crates/perry-runtime and crates/perry-ffi.
  • Keeps the change scoped to runtime/FFI idiom fixes and preserves explicit raw-pointer slice borrowing in arena/walk.rs to avoid reintroducing dangerous_implicit_autorefs warnings after rustfix.

Validation

  • cargo fmt --all -- --check
  • cargo check -p perry-runtime -p perry-ffi

Note: cargo clippy -p perry-runtime -p perry-ffi -- -A clippy::not_unsafe_ptr_arg_deref currently stops on pre-existing denied lints in untouched files (array/sort.rs and dgram.rs), so this PR uses cargo check for compile validation.

Summary by CodeRabbit

  • Refactor
    • Modernized internal pointer comparisons and simplified numeric/range validation using Rust range checks and is_multiple_of to keep logic more consistent.
    • Streamlined option handling and iterator/dispatch flow with modern idioms, with no end-user behavior changes expected.
  • Bug Fixes
    • Improved animated spinner defaults when no frames are provided.
    • Fixed console text formatting for the prefix-empty path.
  • Documentation
    • Added clarifying documentation for ECMA-262 ToIntegerOrInfinity behavior and error propagation timing.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0aa3aaac-1d2f-4759-8b70-89d5c2c58fd9

📥 Commits

Reviewing files that changed from the base of the PR and between f79d4c5 and d33ce01.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/json/replacer.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/object/class_registry.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/object_ops.rs
  • crates/perry-runtime/src/proxy.rs
✅ Files skipped from review due to trivial changes (2)
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/json/replacer.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • crates/perry-runtime/src/proxy.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/class_registry.rs

📝 Walkthrough

Walkthrough

Broad mechanical refactoring across perry-ffi and perry-runtime converts explicit range comparisons to contains(), modulo alignment checks to is_multiple_of(), option-chain patterns to ?/is_none_or/is_some(), pointer casts to std::ptr::eq, manual Default impls to #[derive(Default)]/#[default], thread-local initializers to const { } blocks, and collection operations to vector contains/map entry defaults. No public APIs, signatures, or runtime behaviors are changed.

Changes

Runtime and FFI idiom modernization

Layer / File(s) Summary
Numeric range containment checks
crates/perry-ffi/src/jsvalue.rs, crates/perry-runtime/src/array/indexing.rs, crates/perry-runtime/src/atomics.rs, crates/perry-runtime/src/buffer/dataview.rs, crates/perry-runtime/src/buffer/from.rs, crates/perry-runtime/src/buffer/header.rs, crates/perry-runtime/src/buffer/query.rs, crates/perry-runtime/src/buffer/transcode.rs, crates/perry-runtime/src/buffer/validate.rs, crates/perry-runtime/src/dgram.rs, crates/perry-runtime/src/json/parse_api.rs, crates/perry-runtime/src/native_abi.rs, crates/perry-runtime/src/native_arena.rs, crates/perry-runtime/src/node_submodules/zlib.rs, crates/perry-runtime/src/node_vm.rs, crates/perry-runtime/src/node_stream_constructors.rs, crates/perry-runtime/src/object/global_this.rs, crates/perry-runtime/src/string/format.rs, crates/perry-runtime/src/typedarray_view.rs
Explicit >= / <= and < / > numeric bound pairs are replaced with (range).contains(&val) or !(range).contains(&val) across NaN-box tag checks, buffer/typed-array length guards, atomic index validation, TTL range checks, and numeric precision validation.
Alignment checks and GC rounding
crates/perry-runtime/src/box.rs, crates/perry-runtime/src/buffer/u8_codec.rs, crates/perry-runtime/src/closure/dynamic_props.rs, crates/perry-runtime/src/gc/barrier.rs, crates/perry-runtime/src/native_arena.rs, crates/perry-runtime/src/object/alloc.rs, crates/perry-runtime/src/object/class_registry.rs
addr % align != 0 alignment predicates are replaced with !addr.is_multiple_of(align). GC barrier rounding switches from (x + 7) / 8 to div_ceil(8).
Option-flow idioms and control-flow refactoring
crates/perry-runtime/src/arena/walk.rs, crates/perry-runtime/src/array/from_concat.rs, crates/perry-runtime/src/array/generic.rs, crates/perry-runtime/src/array/splice_slice.rs, crates/perry-runtime/src/child_process/..., crates/perry-runtime/src/cluster_sched.rs, crates/perry-runtime/src/gc/oldgen.rs, crates/perry-runtime/src/json/reviver.rs, crates/perry-runtime/src/node_stream_readwrite.rs, crates/perry-runtime/src/node_submodules/diagnostics.rs, crates/perry-runtime/src/object/exotic_expando.rs, crates/perry-runtime/src/object/instanceof.rs, crates/perry-runtime/src/object/mod.rs, crates/perry-runtime/src/object/native_call_method.rs, crates/perry-runtime/src/promise/combinators.rs, crates/perry-runtime/src/typedarray_props.rs
is_none() + explicit return replaced by ?; map_or(true, ...)/then_some().unwrap_or() replaced by is_none_or() and conditional expressions; if let Some(_) replaced by .is_some(); tail-position expressions used instead of explicit return.
GC state defaults and root tracking
crates/perry-runtime/src/builtins/globals.rs, crates/perry-runtime/src/gc/oldgen.rs, crates/perry-runtime/src/gc/roots.rs, crates/perry-runtime/src/gc/telemetry.rs, crates/perry-runtime/src/gc/trace.rs, crates/perry-runtime/src/node_submodules/trace_events.rs, crates/perry-runtime/src/process.rs
ConservativeStackScanDecision and CopiedMinorFallbackReason derive Default with #[default] variant annotations, removing manual impl Default blocks. Thread-local statics adopt const { } initializer blocks. Root slot address recording switches from then_some().unwrap_or(0) to conditional expressions.
JSON, string, regex, and path utilities
crates/perry-runtime/src/json/parse_api.rs, crates/perry-runtime/src/json/raw_json.rs, crates/perry-runtime/src/json/reviver.rs, crates/perry-runtime/src/json_tape.rs, crates/perry-runtime/src/map.rs, crates/perry-runtime/src/path.rs, crates/perry-runtime/src/regex.rs, crates/perry-runtime/src/regex/replace_expand.rs, crates/perry-runtime/src/set.rs, crates/perry-runtime/src/string/compare.rs, crates/perry-runtime/src/util_parse_env.rs
Function signatures remove explicit lifetime generics via Rust lifetime elision. Regex replacement expansion moves has_named_groups check to pattern guard. Path helpers adopt is_some_and(), rfind(), and direct collection methods. String/environment trimming switches to slice-based predicates.
Pointer identity and shape contracts
crates/perry-runtime/src/array/concat_reverse.rs, crates/perry-runtime/src/closure/dispatch.rs, crates/perry-runtime/src/object/native_module.rs, crates/perry-runtime/src/typed_feedback/guards.rs
Pointer comparisons via as usize casts replaced with std::ptr::eq() for direct pointer identity testing in bound-function dispatch, native-module method binding detection, and typed-array shape-guard contracts.
Collection and initialization idioms
crates/perry-runtime/src/lib.rs, crates/perry-runtime/src/object/class_registry.rs, crates/perry-runtime/src/os/signal.rs, crates/perry-runtime/src/ui_text_registry.rs
`iter().any(
Object dispatch, allocation, and prototype paths
crates/perry-runtime/src/object/alloc.rs, crates/perry-runtime/src/object/array_object_ops.rs, crates/perry-runtime/src/object/buffer_dispatch.rs, crates/perry-runtime/src/object/class_registry.rs, crates/perry-runtime/src/object/field_get_set.rs, crates/perry-runtime/src/object/field_set_by_name.rs, crates/perry-runtime/src/object/native_module.rs, crates/perry-runtime/src/object/native_module_dispatch.rs, crates/perry-runtime/src/object/object_ops.rs, crates/perry-runtime/src/object/prototype_helpers.rs, crates/perry-runtime/src/proxy.rs
Object assignment and native-module dispatch consolidate pointer validity checks, adopt is_multiple_of() for closure alignment, simplify class method storage to or_default(), refactor prototype-resolution thresholds into combined conditions, and streamline property and symbol lookups with early-return and .is_some() guards.
Typed-array and UI utilities
crates/perry-runtime/src/typedarray/mod.rs, crates/perry-runtime/src/typedarray_props.rs, crates/perry-runtime/src/typedarray_view.rs, crates/perry-runtime/src/ui_text_registry.rs
Typed-array length validation and view offset conversion adopt range containment checks; ownership-kind checking simplifies via ? operator; UI registry entry allocation uses or_default() for per-ID vector initialization.
Type-cast removal and syntax cleanup
crates/perry-runtime/src/bigint.rs, crates/perry-runtime/src/builtins/console.rs, crates/perry-runtime/src/closure/mod.rs, crates/perry-runtime/src/collection_iter.rs, crates/perry-runtime/src/date.rs, crates/perry-runtime/src/fs/..., crates/perry-runtime/src/gc/heap_snapshot.rs, crates/perry-runtime/src/i18n.rs, crates/perry-runtime/src/json/replacer.rs, crates/perry-runtime/src/node_stream.rs, crates/perry-runtime/src/node_submodules/stream_promises.rs, crates/perry-runtime/src/process/credentials.rs, crates/perry-runtime/src/punycode.rs, crates/perry-runtime/src/readline_helpers.rs, crates/perry-runtime/src/symbol.rs, crates/perry-runtime/src/temporal/zoned_date_time.rs, crates/perry-runtime/src/timer.rs, crates/perry-runtime/src/tui/ffi.rs, crates/perry-runtime/src/url/node_compat.rs, crates/perry-runtime/src/web_storage.rs, crates/perry-runtime/src/yoga.rs
Unnecessary type casts removed where types already align. Closure bindings simplified from mut to immutable where permitted. Unused variable bindings marked with underscore. Direct variable returns replace intermediate assignments. Helper function parameters adjusted to remove extra references.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐇 A hundred small tidies, a sweep through the code,
contains replaces the comparison load,
is_multiple_of hops where % once stood,
? shortens the path through the Option-wood,
No behaviors changed — just the rabbit's clean trail,
Idiomatic Rust from the head to the tail! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Apply automatic clippy fixes in runtime and FFI' accurately and concisely describes the main change in this PR.
Description check ✅ Passed The PR description provides a clear summary of changes, validation steps, and a note about limitations encountered, though it lacks some template sections like test plan details.
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-runtime-ffi-auto-fixes

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

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

🧹 Nitpick comments (2)
crates/perry-runtime/src/dgram.rs (1)

1550-1576: ⚡ Quick win

Inconsistent finiteness validation between set_ttl_impl and set_multicast_ttl_impl.

Line 1552 in set_ttl_impl retains the explicit !ttl.is_finite() check, while line 1566 in set_multicast_ttl_impl relies on implicit rejection via range containment. Although both will correctly reject NaN/Infinity (since they fail the range check), the inconsistency makes the code harder to maintain.

Recommend explicitly checking is_finite() in set_multicast_ttl_impl for symmetry and clarity:

fn set_multicast_ttl_impl(socket: f64, args: &[f64]) -> f64 {
    let ttl = validate_number_arg(args.first().copied().unwrap_or_else(undefined_value), "ttl");
-   if !(0.0..=255.0).contains(&ttl) {
+   if !ttl.is_finite() || !(0.0..=255.0).contains(&ttl) {
        throw_socket_errno("setMulticastTTL", "EINVAL");
    }
🤖 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 `@crates/perry-runtime/src/dgram.rs` around lines 1550 - 1576, The set_ttl_impl
function explicitly checks is_finite() before the range validation, but
set_multicast_ttl_impl relies only on implicit rejection via range containment.
Add an explicit is_finite() check to set_multicast_ttl_impl before the range
check to match the validation pattern in set_ttl_impl. This will make the
validation logic consistent and more maintainable across both functions.
crates/perry-runtime/src/web_storage.rs (1)

375-389: 💤 Low value

Consider removing the no-op rebinding on line 381.

Line 381 (let ptr = ptr;) is a no-op rebinding that was left after the as i64 cast was removed. While functionally correct (the subsequent pointer comparisons work as-is), this line serves no purpose and can be deleted entirely.

  fn storage_kind_from_value(value: f64) -> Option<StorageKind> {
      let this = value;
      let ptr = crate::value::js_nanbox_get_pointer(this);
      if ptr == 0 {
          return None;
      }
-     let ptr = ptr;
      if ptr == crate::object::LOCAL_STORAGE_PTR.load(Ordering::Acquire) {
🤖 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 `@crates/perry-runtime/src/web_storage.rs` around lines 375 - 389, In the
storage_kind_from_value function, remove the unnecessary rebinding statement
`let ptr = ptr;` that appears after the null pointer check. This line is a no-op
leftover from a previous refactoring and does not affect the subsequent pointer
comparisons, so it can be safely deleted to clean up the code.
🤖 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.

Nitpick comments:
In `@crates/perry-runtime/src/dgram.rs`:
- Around line 1550-1576: The set_ttl_impl function explicitly checks is_finite()
before the range validation, but set_multicast_ttl_impl relies only on implicit
rejection via range containment. Add an explicit is_finite() check to
set_multicast_ttl_impl before the range check to match the validation pattern in
set_ttl_impl. This will make the validation logic consistent and more
maintainable across both functions.

In `@crates/perry-runtime/src/web_storage.rs`:
- Around line 375-389: In the storage_kind_from_value function, remove the
unnecessary rebinding statement `let ptr = ptr;` that appears after the null
pointer check. This line is a no-op leftover from a previous refactoring and
does not affect the subsequent pointer comparisons, so it can be safely deleted
to clean up the code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 31494789-edb7-4b3f-abaf-9ae5aa59ba17

📥 Commits

Reviewing files that changed from the base of the PR and between c84bba3 and 316df29.

📒 Files selected for processing (101)
  • crates/perry-ffi/src/jsvalue.rs
  • crates/perry-runtime/src/arena/walk.rs
  • crates/perry-runtime/src/array/concat_reverse.rs
  • crates/perry-runtime/src/array/from_concat.rs
  • crates/perry-runtime/src/array/generic.rs
  • crates/perry-runtime/src/array/indexing.rs
  • crates/perry-runtime/src/array/iter_object.rs
  • crates/perry-runtime/src/array/splice_slice.rs
  • crates/perry-runtime/src/atomics.rs
  • crates/perry-runtime/src/bigint.rs
  • crates/perry-runtime/src/box.rs
  • crates/perry-runtime/src/buffer/access.rs
  • crates/perry-runtime/src/buffer/dataview.rs
  • crates/perry-runtime/src/buffer/from.rs
  • crates/perry-runtime/src/buffer/header.rs
  • crates/perry-runtime/src/buffer/query.rs
  • crates/perry-runtime/src/buffer/transcode.rs
  • crates/perry-runtime/src/buffer/u8_codec.rs
  • crates/perry-runtime/src/buffer/validate.rs
  • crates/perry-runtime/src/builtins/console.rs
  • crates/perry-runtime/src/builtins/globals.rs
  • crates/perry-runtime/src/builtins/numbers.rs
  • crates/perry-runtime/src/child_process/mod.rs
  • crates/perry-runtime/src/child_process/sync_run.rs
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/closure/mod.rs
  • crates/perry-runtime/src/cluster_sched.rs
  • crates/perry-runtime/src/collection_iter.rs
  • crates/perry-runtime/src/date.rs
  • crates/perry-runtime/src/dgram.rs
  • crates/perry-runtime/src/fs/dir_glob_watch.rs
  • crates/perry-runtime/src/fs/dirent.rs
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/gc/barrier.rs
  • crates/perry-runtime/src/gc/heap_snapshot.rs
  • crates/perry-runtime/src/gc/oldgen.rs
  • crates/perry-runtime/src/gc/roots.rs
  • crates/perry-runtime/src/gc/telemetry.rs
  • crates/perry-runtime/src/gc/trace.rs
  • crates/perry-runtime/src/gc/types.rs
  • crates/perry-runtime/src/i18n.rs
  • crates/perry-runtime/src/json/parse_api.rs
  • crates/perry-runtime/src/json/raw_json.rs
  • crates/perry-runtime/src/json/replacer.rs
  • crates/perry-runtime/src/json/reviver.rs
  • crates/perry-runtime/src/json_tape.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/map.rs
  • crates/perry-runtime/src/native_abi.rs
  • crates/perry-runtime/src/native_arena.rs
  • crates/perry-runtime/src/node_stream.rs
  • crates/perry-runtime/src/node_stream_constructors.rs
  • crates/perry-runtime/src/node_stream_readwrite.rs
  • crates/perry-runtime/src/node_submodules/diagnostics.rs
  • crates/perry-runtime/src/node_submodules/stream_promises.rs
  • crates/perry-runtime/src/node_submodules/trace_events.rs
  • crates/perry-runtime/src/node_submodules/zlib.rs
  • crates/perry-runtime/src/node_vm.rs
  • crates/perry-runtime/src/object/alloc.rs
  • crates/perry-runtime/src/object/array_object_ops.rs
  • crates/perry-runtime/src/object/buffer_dispatch.rs
  • crates/perry-runtime/src/object/class_registry.rs
  • crates/perry-runtime/src/object/exotic_expando.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/object/global_this.rs
  • crates/perry-runtime/src/object/instanceof.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/native_module.rs
  • crates/perry-runtime/src/object/native_module_dispatch.rs
  • crates/perry-runtime/src/object/object_ops.rs
  • crates/perry-runtime/src/object/prototype_helpers.rs
  • crates/perry-runtime/src/os/signal.rs
  • crates/perry-runtime/src/path.rs
  • crates/perry-runtime/src/process.rs
  • crates/perry-runtime/src/process/credentials.rs
  • crates/perry-runtime/src/promise/combinators.rs
  • crates/perry-runtime/src/proxy.rs
  • crates/perry-runtime/src/punycode.rs
  • crates/perry-runtime/src/readline_helpers.rs
  • crates/perry-runtime/src/regex.rs
  • crates/perry-runtime/src/regex/replace_expand.rs
  • crates/perry-runtime/src/set.rs
  • crates/perry-runtime/src/string/compare.rs
  • crates/perry-runtime/src/string/format.rs
  • crates/perry-runtime/src/string/split.rs
  • crates/perry-runtime/src/symbol.rs
  • crates/perry-runtime/src/temporal/zoned_date_time.rs
  • crates/perry-runtime/src/timer.rs
  • crates/perry-runtime/src/tui/ffi.rs
  • crates/perry-runtime/src/typed_feedback/guards.rs
  • crates/perry-runtime/src/typedarray/mod.rs
  • crates/perry-runtime/src/typedarray_props.rs
  • crates/perry-runtime/src/typedarray_view.rs
  • crates/perry-runtime/src/ui_text_registry.rs
  • crates/perry-runtime/src/url/node_compat.rs
  • crates/perry-runtime/src/util_parse_env.rs
  • crates/perry-runtime/src/web_storage.rs
  • crates/perry-runtime/src/yoga.rs
💤 Files with no reviewable changes (3)
  • crates/perry-runtime/src/array/iter_object.rs
  • crates/perry-runtime/src/object/native_module_dispatch.rs
  • crates/perry-runtime/src/builtins/numbers.rs

Ralph and others added 3 commits June 18, 2026 21:42
clippy --fix dropped `ObjectHeader` and `js_object_get_field_by_name_f64`
from the `use crate::object::{...}` in node_stream.rs because they are only
referenced by `#[cfg(test)]` code (node_stream_state_tests.rs et al. via
`use super::*`). That broke `cargo test -p perry-runtime` with E0425. Restore
them under a `#[cfg(test)]` import so the non-test build stays clippy-clean.

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

# Conflicts:
#	crates/perry-runtime/src/closure/dynamic_props.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.

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 `@crates/perry-runtime/src/object/object_ops.rs`:
- Around line 2811-2828: The native-module prototype handling logic is
duplicated across two branches in the object_ops.rs file (the `top16 == 0x7FFD`
branch and the `top16 == 0 && bits >= threshold` branch). This 18-line block
that checks if `(*obj).class_id == super::native_module::NATIVE_MODULE_CLASS_ID`
and returns either `Object.prototype` or `TAG_NULL` should be extracted into a
separate helper function. Create a helper function that encapsulates this check
and returns the appropriate prototype value, then replace both instances of the
duplicate block by calling this helper function instead. This eliminates code
duplication while maintaining the same behavior at both call sites.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0aa3aaac-1d2f-4759-8b70-89d5c2c58fd9

📥 Commits

Reviewing files that changed from the base of the PR and between f79d4c5 and d33ce01.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/json/replacer.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/object/class_registry.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/object_ops.rs
  • crates/perry-runtime/src/proxy.rs
✅ Files skipped from review due to trivial changes (2)
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/json/replacer.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • crates/perry-runtime/src/proxy.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/class_registry.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

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

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 `@crates/perry-runtime/src/object/object_ops.rs`:
- Around line 2811-2828: The native-module prototype handling logic is
duplicated across two branches in the object_ops.rs file (the `top16 == 0x7FFD`
branch and the `top16 == 0 && bits >= threshold` branch). This 18-line block
that checks if `(*obj).class_id == super::native_module::NATIVE_MODULE_CLASS_ID`
and returns either `Object.prototype` or `TAG_NULL` should be extracted into a
separate helper function. Create a helper function that encapsulates this check
and returns the appropriate prototype value, then replace both instances of the
duplicate block by calling this helper function instead. This eliminates code
duplication while maintaining the same behavior at both call sites.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0aa3aaac-1d2f-4759-8b70-89d5c2c58fd9

📥 Commits

Reviewing files that changed from the base of the PR and between f79d4c5 and d33ce01.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/json/replacer.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/object/class_registry.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/object_ops.rs
  • crates/perry-runtime/src/proxy.rs
✅ Files skipped from review due to trivial changes (2)
  • crates/perry-runtime/src/fs/mod.rs
  • crates/perry-runtime/src/json/replacer.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • crates/perry-runtime/src/proxy.rs
  • crates/perry-runtime/src/object/mod.rs
  • crates/perry-runtime/src/closure/dynamic_props.rs
  • crates/perry-runtime/src/object/field_set_by_name.rs
  • crates/perry-runtime/src/closure/dispatch.rs
  • crates/perry-runtime/src/object/field_get_set.rs
  • crates/perry-runtime/src/lib.rs
  • crates/perry-runtime/src/object/native_call_method.rs
  • crates/perry-runtime/src/object/class_registry.rs
🛑 Comments failed to post (1)
crates/perry-runtime/src/object/object_ops.rs (1)

2811-2828: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Extract duplicate native-module prototype logic.

This identical 18-line block (including comments) appears in both the top16 == 0x7FFD branch (lines 2811-2828) and the top16 == 0 && bits >= threshold branch (lines 2931-2948). The logic that checks class_id == NATIVE_MODULE_CLASS_ID and returns Object.prototype (or TAG_NULL) should be extracted into a helper function to eliminate the duplication.

♻️ Suggested refactor

Extract a helper function:

fn native_module_prototype_or_none(obj: *const ObjectHeader) -> Option<f64> {
    unsafe {
        if (*obj).class_id == super::native_module::NATIVE_MODULE_CLASS_ID {
            let proto = crate::object::builtin_prototype_value("Object");
            if proto.to_bits() != crate::value::TAG_UNDEFINED {
                return Some(proto);
            }
            return Some(f64::from_bits(TAG_NULL));
        }
    }
    None
}

Then replace both blocks with:

+                if let Some(proto) = native_module_prototype_or_none(obj) {
+                    return proto;
+                }
-                // A native-module namespace object (`require("path")` etc.,
-                // class_id NATIVE_MODULE_CLASS_ID, the `__module__`-tagged
-                // object) is an ordinary object whose [[Prototype]] is
-                // %Object.prototype% — NOT itself. The `return obj_value` self-
-                // prototype fallback below makes turbopack's `interopEsm`
-                // proto-chain walk (`for(cur=raw; !LEAF.includes(cur);
-                // cur=getProto(cur))`) never terminate — getProto keeps
-                // returning the same object, so it creates export getters
-                // forever (the Next.js standalone startup runaway: unbounded
-                // memory growth, no `✓ Ready`). Return Object.prototype so the
-                // walk reaches a LEAF_PROTOTYPE and stops.
-                if (*obj).class_id == super::native_module::NATIVE_MODULE_CLASS_ID {
-                    let proto = crate::object::builtin_prototype_value("Object");
-                    if proto.to_bits() != crate::value::TAG_UNDEFINED {
-                        return proto;
-                    }
-                    return f64::from_bits(TAG_NULL);
-                }

Apply the same replacement at both locations (lines 2811-2828 and 2931-2948).

Also applies to: 2931-2948

🤖 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 `@crates/perry-runtime/src/object/object_ops.rs` around lines 2811 - 2828, The
native-module prototype handling logic is duplicated across two branches in the
object_ops.rs file (the `top16 == 0x7FFD` branch and the `top16 == 0 && bits >=
threshold` branch). This 18-line block that checks if `(*obj).class_id ==
super::native_module::NATIVE_MODULE_CLASS_ID` and returns either
`Object.prototype` or `TAG_NULL` should be extracted into a separate helper
function. Create a helper function that encapsulates this check and returns the
appropriate prototype value, then replace both instances of the duplicate block
by calling this helper function instead. This eliminates code duplication while
maintaining the same behavior at both call sites.

@proggeramlug
proggeramlug merged commit dea1fb2 into main Jun 19, 2026
15 checks passed
@proggeramlug
proggeramlug deleted the feat/clippy-runtime-ffi-auto-fixes branch June 19, 2026 09:46
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