ast: name BabyString::r#in's parameters for what they are - #39137
Conversation
r#in(parent, text) locates `text` inside `parent`, so every caller passes its message text as `parent`, which mordant's arg_named_like_other_param flags as a possibly transposed call. The calls are in the right order; only the parameter names were misleading. Rename them to `container` and `substring`, matching BabyString::slice. No behavior change. Regenerate mordant-baseline.toml. Besides the entry this fixes, it drops two that were already stale: the PackageInstall.rs Option removed in #38271 and the node_crypto_binding.rs narrowing removed in #37648, both of which landed after the baseline was recorded.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
There was a problem hiding this comment.
LGTM — pure parameter rename, no behavior change.
What was reviewed:
BabyString::r#inbody is byte-identical after the rename;index_of(container, substring)preserves the (haystack, needle) order andsubstring.len()replacestext.len().- All three callers (
src/ast/lib.rs:1653,src/jsc/VirtualMachine.rs:4698,src/runtime/jsc_hooks.rs:5496) already pass (haystack, needle) — no call sites need updating, and the newcontainername matchesBabyString::slice's existing parameter. mordant-baseline.tomlonly drops entries (one fixed here, two stale from #38271/#37648); the ratchet tightens, never loosens.
Extended reasoning...
Overview
This PR renames the two parameters of BabyString::r#in in src/ast/lib.rs from (parent, text) to (container, substring) and adds a one-line doc comment. The function body is unchanged apart from the substituted identifiers: index_of(parent, text) → index_of(container, substring), text.is_empty() → substring.is_empty(), text.len() → substring.len(). The second file, mordant-baseline.toml, is the regenerated lint ratchet: it drops the arg_named_like_other_param:src/ast/lib.rs entry this rename resolves plus two entries the PR description identifies as already stale on main.
Security risks
None. This is a local identifier rename inside a 9-line helper with no change to control flow, argument order, types, or return value. No user input handling, no FFI, no allocation, no auth/crypto surface is touched.
Level of scrutiny
Low. The change is mechanical and self-evidently behavior-preserving — the function body diffs to the same AST modulo local names. I confirmed via grep that all three call sites pass the haystack first and the needle second, matching both the old and new parameter order, and that BabyString::slice (the paired reader) already names its parameter container, so the rename improves internal consistency rather than introducing a new convention. The baseline file is tool-generated; dropping entries can only make the CI lint gate stricter, not laxer, so even if one of the two "stale" removals were wrong the mordant job would catch it (and the PR description reports a clean bun run rust:mordant against both baselines).
Other factors
No CODEOWNERS cover these paths. No prior human review comments to address. The PR correctly ships no new test because nothing observable changes — existing coverage (resolve-error.test.ts, import-meta-resolve.test.mjs, the dev-error-page tests) exercises the value r#in computes and was reported passing. The bug hunting system found nothing.
| /// Locates `substring` inside `container` (the string later passed to | ||
| /// [`BabyString::slice`]) and records its offset and length. |
There was a problem hiding this comment.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code
| // needle, but an empty `substring` reaches this path via resolve errors | ||
| // for `import ""`, so short-circuit it here to offset 0. |
There was a problem hiding this comment.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code
There was a problem hiding this comment.
LGTM — pure parameter rename (parent/text → container/substring) with no behavior change, plus the corresponding one-line mordant baseline drop.
What was reviewed:
- Confirmed the function body is byte-identical modulo the renamed identifiers;
index_of(container, substring)argument order matches the oldindex_of(parent, text). containermatches the existing name inBabyString::slice, so the two methods now agree on vocabulary.- The comment-cop flags on lines 1081/1085 are false positives: 1081 is a two-line rustdoc (not a workaround justification), and 1085 is a pre-existing comment that was only reworded (
text→substring) and rewrapped. - The baseline diff removes only
arg_named_like_other_param:src/ast/lib.rs; the two stale entries mentioned in the description were already gone after the merge with main.
Extended reasoning...
Overview
This PR renames the two parameters of BabyString::r#in in src/ast/lib.rs from parent/text to container/substring, adds a two-line rustdoc, and drops one line from mordant-baseline.toml. The rename resolves a mordant arg_named_like_other_param finding: callers pass a local named text as the first (haystack) argument, which read as if swapped against a second parameter also named text. Callers are unchanged. I diffed against bf1437a1 and confirmed the function body is identical except for identifier substitution and a rewrapped pre-existing comment.
Security risks
None. Parameter names are not part of the compiled artifact; no control flow, allocation, or boundary handling changes.
Level of scrutiny
Low. This is a mechanical clarity rename in the class of the other mordant-cleanup PRs already on main (#39130, #39129, #39119, #39125). The only executable-adjacent change is the identifier substitution inside the function body, which preserves argument order to bun_core::strings::index_of and to BabyString::new. The baseline hunk is a single deletion of the entry this rename fixes.
Other factors
The PR description mentions two additional stale baseline entries being dropped, but the actual diff between base and head only removes one line — the merge commit b8863156 from main appears to have already reconciled those. The two comment-cop bot comments are canned heuristic messages ("paragraph-long comment to justify a workaround") that misfire here: line 1081 is a two-line rustdoc cross-referencing BabyString::slice, and line 1085 is a pre-existing three-line comment whose only change is text → substring plus rewrap. Neither is a workaround justification, so I don't consider them blocking. The bug-hunting pass found nothing.
Problem
arg_named_like_other_paramreportssrc/ast/lib.rs:1651, inLog::add_resolve_error_with_level: the localtextis passed asBabyString::r#in'sparentparameter, andr#inalso has a parameter namedtextof the same type (&[u8]), so the call reads as if its arguments were swapped.BabyString::r#in(parent, text)(src/ast/lib.rs:1080) searches fortextinsideparentand records the offset and length it found there; the caller wants the specifier located inside the formatted message, which is whatr#in(&text, specifier_arg)does. The other two callers (src/jsc/VirtualMachine.rs:4698,src/runtime/jsc_hooks.rs:5496) pass the same order. Onlyr#in's parameter names are misleading: itstextis the needle, while every caller'stextis the haystack.Fix
r#in's parameters tocontainerandsubstring.containeris the nameBabyString::slicealready uses for the same string (aBabyStringonly means something against the string it was built from), andsubstringsays what the second argument is. Callers are unchanged. No behavior change: the body is the same code with the names substituted.mordant-baseline.tomlregenerated withbun run rust:mordant:baseline. It drops thearg_named_like_other_param:src/ast/lib.rsentry this change fixes, plus two entries that were already stale on main because the findings were removed by changes that landed after the baseline was recorded in ci: bump the mordant pin (sixteen new lints) and record their baseline #38846:always_unwrapped_option:src/install/PackageInstall.rs(theOption<Walker>removed in install: let the walker own the cache dir it walks and build InstallDirState in one go #38271) andnarrowed_two_ways:src/runtime/node/node_crypto_binding.rs(the key length madeusizein crypto: store PBKDF2's key length as usize #37648). Happy to drop those two hunks if you would rather keep this to the one line.bun run rust:mordant(cargo-dylint 6.0.3, the mordant revision pinned inCargo.toml) over the whole workspace: no findings and notarget/mordant/over-baseline.txt(the CI gate), both against the baseline on main and against the regenerated one.bun bd test test/js/bun/resolve/resolve-error.test.ts test/js/node/missing-module.test.js test/js/bun/resolve/import-meta.test.js test/js/bun/resolve/import-meta-resolve.test.mjs test/regression/issue/29264.test.ts: 71 pass.resolve-error.test.tsreads.specifieroff runtimeResolveMessages and offBun.buildlogs, which is the valuer#incomputes;import-meta-resolve.test.mjscovers the empty-specifier branch.bun bd test test/js/bun/http/serve.test.ts -t "dev error page": 2 pass (the dev error page is the other reader of the stored offset).mordantjob in the Rust lints workflow, which runs against the regenerated baseline.Background
BabyString(src/ast/lib.rs) packs a 16-bit offset and a 16-bit length into au32. A resolve error stores its specifier this way, as a position inside the message's own text, instead of keeping a second copy of the string;BabyString::r#inbuilds it andBabyString::slicereads it back (src/jsc/ResolveMessage.rs,src/runtime/server/DevErrorPage.rs). The method is spelledr#inbecauseinis a keyword; the name is carried over from the logger this was ported from.bun run rust:mordantruns in the Rust lints workflow.mordant-baseline.tomlis a ratchet: per (lint, file) counts of the findings that predate the job, so a PR fails only when it adds one. Fixing a finding means regenerating the file so its entry disappears, which is the second hunk here.