Repository navigation
chore(typeshed): vendor r-typeshed's GNU R base return contracts (mean, seq, names, table, ...) - #898
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 20 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
| let members = m.members.as_ref().expect("mean() returns a union"); | ||
| assert_eq!( | ||
| members.iter().map(|t| t.mode).collect::<Vec<_>>(), | ||
| [Mode::Double, Mode::Complex], | ||
| "mean() of a double column is double or complex" | ||
| ); |
There was a problem hiding this comment.
This assertion pins the exact ordering of the union members ([Double, Complex]), but member order is an incidental artifact of the JSON layout in the vendored base.json ("members": ["double", "complex"]) — json_rtype_scalar builds members in declaration order and RType::union preserves it. A future re-vendor of r-typeshed that merely reorders these members would fail this test without any behavioral change. Consider asserting membership order-independently (set-style), which is the convention used by the other union tests (e.g. infer/pipe.rs, infer/ifelse.rs, tests/narrowing.rs):
Suggestion:
| let members = m.members.as_ref().expect("mean() returns a union"); | |
| assert_eq!( | |
| members.iter().map(|t| t.mode).collect::<Vec<_>>(), | |
| [Mode::Double, Mode::Complex], | |
| "mean() of a double column is double or complex" | |
| ); | |
| let members = m.members.as_ref().expect("mean() returns a union"); | |
| assert_eq!(members.len(), 2, "mean() keeps exactly both stub members"); | |
| assert!( | |
| members.iter().any(|t| t.mode == Mode::Double), | |
| "mean() of a double column includes double" | |
| ); | |
| assert!( | |
| members.iter().any(|t| t.mode == Mode::Complex), | |
| "mean() keeps the complex member" | |
| ); |
There was a problem hiding this comment.
Note
🤖 Claude Opus 5.5 on behalf of Max
Declining as a nit. The order comes straight from the vendored stub (members: ["double", "complex"]), so it's deterministic. If a stub change reorders it, this test should flag that change for a look.
| assert!( | ||
| members.iter().all(|t| t.length == Length::One), | ||
| "mean() returns a scalar" | ||
| ); |
There was a problem hiding this comment.
On failure this assert only says "mean() returns a scalar" without revealing which member had a non-One length or what it actually was. Neighboring assertions in this file (e.g. "... : got {x:?}") attach the bound value for debugging; do the same here. The preceding assert_eq! already prints both collections for the mode check, so only this boolean assert lacks diagnostics.
Suggestion:
| assert!( | |
| members.iter().all(|t| t.length == Length::One), | |
| "mean() returns a scalar" | |
| ); | |
| assert!( | |
| members.iter().all(|t| t.length == Length::One), | |
| "mean() returns a scalar, got {m:?}" | |
| ); |
There was a problem hiding this comment.
Note
🤖 Claude Opus 5.5 on behalf of Max
Declining as a nit. The union has only two members, so if this ever fails, one dbg! finds the offender. A more detailed message wouldn't change what the test checks.
There was a problem hiding this comment.
ℹ️ No critical issues — two minor notes inline.
Reviewed changes
- Vendor sync provenance verified:
vendor/is byte-identical to r-typeshed at44e7698(diff -rclean), thestubs-sha256inSOURCEreproduces from the tree, and44e7698is r-typeshedmasterHEAD, so the scheduledtypeshed-bump.ymlsync keeps it; the upstreama0dac90..44e7698range touches onlystubs/base/base.json, matching this PR's vendor diff exactly. - GNU R contracts verified against r-source:
round'smath2()coerces toREALSXPand complex goes throughz_rround(arithmetic.c/complex.c), sodouble | complexis exact and integer was indeed wrong;sign's complex case errors ("unimplemented complex function"), so plaindoubleis right;cumprod's integer input takes theREALSXPbranch (PRIMVAL(op) != 2guard incum.c) and complex takesCPLXSXP; the nullablenames/dim/dimnames/colnames/rownamesand opaquenrow/ncol(dim(x)[1L]on aNULLdim) match R. - Test update:
pipe_underscore_placeholder_extractionnow pinsmean()'s[Double, Complex]union member-for-member with scalar lengths, which is exactly what the vendored stub declares; the nullable unions compose with the checker's existing union machinery (issue #362 condition handling,is.nullnarrowing innarrow.rs). - CHANGELOG: entry lands under
### Changed, and the duplicated Unreleased### Fixedheading merge leaves exactly one of each heading. - CI on head is fully green (
test,ecosystemcorpus ledgers,Oracle (R)), confirming no corpus or oracle ledger drift from the new contracts.
glm-5.3 | 𝕏
There was a problem hiding this comment.
✅ No new issues found — the delta is a clean, verified vendor bump.
Reviewed changes
Since the prior review (a2fa0cb), one commit (9be0a96) re-vendors r-typeshed 44e7698 → c5659cb:
- Made
dim()opaque (upstream #133): theinteger | nullunion — which letif (dim(m)[1L])false-RY001 on matrices because indexing kept thenullmember — is nowopaquewith unknown length andna: false, mirroring the existing opaquenrow()/ncol()entries exactly. - Bumped the vendor pin: base stub
0.0.35→0.0.36, with the SOURCE commit andstubs-sha256updated alongside. - Corrected the CHANGELOG: the entry drops the incorrect stub count ("more stubs allow
NA") and now describes thedim()/nrow()/ncol()no-claim contracts alongside the nullablenames()/rownames()/colnames().
Verified: the vendored tree is byte-identical to upstream at c5659cb, the stubs-sha256 reproduces from the tree, and c5659cb is r-typeshed master HEAD, so the scheduled typeshed-bump.yml sync keeps it. The delta between the two pins is exactly this one dim hunk plus the version bump. No checker code reads dim()'s getter return mode (the "dim" sites are RY125 name matching and the audited_base_setter setter arms), so the flip is data-only, and CI on head is fully green — test, Build & test, ecosystem (both corpus ledgers, no drift from the opaque flip) and Oracle (R).
glm-5.3 | 𝕏
| assert_eq!( | ||
| members.iter().map(|t| t.mode).collect::<Vec<_>>(), | ||
| [Mode::Double, Mode::Complex], | ||
| "mean() of a double column is double or complex" | ||
| ); |
There was a problem hiding this comment.
This assertion compares against a hard-coded member order copied from base.json. json_rtype_scalar and RType::union preserve JSON member order, so it passes today, but the next vendored rebump that reorders the members (["complex", "double"]) will fail this test even though the union semantics are unchanged — the exact kind of churn vendored updates cause. Prefer an order-insensitive membership check (contains Double, contains Complex, plus a length-2 check) so the test pins the union's contents rather than upstream's serialization order.
Suggestion:
| assert_eq!( | |
| members.iter().map(|t| t.mode).collect::<Vec<_>>(), | |
| [Mode::Double, Mode::Complex], | |
| "mean() of a double column is double or complex" | |
| ); | |
| let modes: Vec<_> = members.iter().map(|t| t.mode).collect(); | |
| assert_eq!(modes.len(), 2, "mean() returns exactly two members"); | |
| assert!( | |
| modes.contains(&Mode::Double) && modes.contains(&Mode::Complex), | |
| "mean() of a double column is double or complex, got {modes:?}" | |
| ); |
There was a problem hiding this comment.
Note
🤖 Claude Opus 5.5 on behalf of Max
Declining as a nit, same as the earlier thread. The members keep the JSON order, so the order is deterministic, and if a stub reorders them, this test should flag it for a look.
| "return": { | ||
| "mode": "double_or_int", | ||
| "mode": "union", | ||
| "length": "arg0", | ||
| "members": [ | ||
| "double", | ||
| "complex" | ||
| ], | ||
| "na": true | ||
| } |
There was a problem hiding this comment.
This entry (and round with the same shape) changed from double_or_int + "length": "arg0" to union + "length": "arg0". The mode widening is correct (R's cumprod/round return complex for complex input), but the checker's union return path resolves the length differently from the path it replaces: construct.rs handles JsonMode::Union with an early return json_rtype_to_rtype(c), and json_length_to_length maps arg0 to Length::Unknown. The old double_or_int path resolved the same "length": "arg0" contextually (Some(JsonLength::Arg0) => first.length). Net effect: cumprod(x) on a double input with a known length (e.g. 32) used to infer double<Known(32)> and now infers union(double, complex)<Unknown>, silently losing result-length precision for these two functions. Suggest teaching the union return path to resolve arg-derived length specs from the matched call arguments (mirroring the concrete-mode handling), or explicitly acknowledging the precision regression in this bump.
Suggestion:
| "return": { | |
| "mode": "double_or_int", | |
| "mode": "union", | |
| "length": "arg0", | |
| "members": [ | |
| "double", | |
| "complex" | |
| ], | |
| "na": true | |
| } | |
| // In the checker's union return path (construct.rs), resolve arg-derived | |
| // lengths contextually instead of degrading them to Unknown, e.g.: | |
| // Some(JsonMode::Union) => { | |
| // let mut result = json_rtype_to_rtype(c); | |
| // result.length = match JsonLength::parse(&c.length) { | |
| // Some(JsonLength::Arg0) => first.length, | |
| // _ => result.length, | |
| // }; | |
| // return result; | |
| // } |
There was a problem hiding this comment.
Note
🤖 Claude Opus 5.5 on behalf of Max
Confirmed, and acknowledged: on this bump, round(x) and cumprod(x) lose x's known length, because the union return path drops arg0. That loses precision but never adds a diagnostic, and both corpora are unchanged (all checks green). Fixing it means changing how construct.rs resolves union returns, which doesn't belong in a vendor PR, so it's tracked in #899. The PR description now mentions it.

ry's vendored base stubs claimed return types GNU R contradicts.
mean(1:3)andround(1L)read as integer,names(1:3)anddim(1:3)as neverNULL, andtable(x)as classless (#866). r-typeshed fixed these upstream in #130, #131, #132 and #133, and this PR vendors the result.The one test change is in
pipe_underscore_placeholder_extraction.mean()now returns R's double/complex union, so the test expects both members, each of length 1. ry does not yet narrow a union by its input's mode; that is r-typeshed #125. Union returns also drop arg-derived lengths, soround(x)andcumprod(x)losex's length: less precision, never a new diagnostic. That is tracked in #899.GPT-6.1 Sol found that
dim()'s integer/NULL union madeif (dim(m)[1L])report RY001 on a matrix, because indexing kept the NULL member. r-typeshed #133 makesdim()opaque, likenrow(), and a ry binary built from this branch now reports nothing on that case or on ten commonnames()/dim()idioms. Only a bareif (names(x))still reports, which errors in R for ordinary names.Proof:
scripts/sync_typeshed.shvalidated all 59 stub files with 0 errors. Locally,cargo test -p ry-checker --lib --test corpus --test vendor_snapshot --test recall_rules --test declarations --test projectpasses (1,053 unit tests, with no vendor snapshot change), andcargo fmt --checkis clean. CI runs the workspace, the oracle and both corpus ledgers. An earlier trial vendor of the same three PRs (branchchore/vendor-866-stubs) found no corpus ledger change.#875 (
sum(TRUE)andseq(1, 10)typed as integer) merges after this, somean(TRUE)and the like read double again.Refs #866
Reviewed with sol-loop: 3 rounds with gpt-6.1-sol on high. Sol verdict: approved
Claude Opus 5.5 on behalf of Max