Skip to content

chore(typeshed): vendor r-typeshed's GNU R base return contracts (mean, seq, names, table, ...) - #898

Merged
sims1253 merged 2 commits into
mainfrom
chore/vendor-base-stubs-866
Nov 7, 2026
Merged

sims1253 merged 2 commits into
mainfrom
chore/vendor-base-stubs-866

Conversation

@sims1253

@sims1253 sims1253 commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

ry's vendored base stubs claimed return types GNU R contradicts. mean(1:3) and round(1L) read as integer, names(1:3) and dim(1:3) as never NULL, and table(x) as classless (#866). r-typeshed fixed these upstream in #130, #131, #132 and #133, and this PR vendors the result.

 crates/ry-typeshed/vendor/SOURCE      commit a0dac90 -> c5659cb
 crates/ry-typeshed/vendor/base/base.json
-  mean, prod, round, cumprod: double_or_int     sign: double_or_int
+  mean, prod, round, cumprod: double | complex  sign: double
+  seq, seq.int: integer | double     sample, ave, median: opaque
+  names, rownames, colnames: may be NULL   dim, nrow, ncol: opaque
+  table, proc.time, ordered, interaction, dist: classes   factor, as.factor, ts: opaque
+  19 stubs: na allowed
 crates/ry-checker/src/tests/type_inference.rs
~  mean(<double column>) is now the double | complex union
 CHANGELOG.md
+  one line; also merges a duplicated Unreleased "### Fixed" heading

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, so round(x) and cumprod(x) lose x's length: less precision, never a new diagnostic. That is tracked in #899.

GPT-6.1 Sol found that dim()'s integer/NULL union made if (dim(m)[1L]) report RY001 on a matrix, because indexing kept the NULL member. r-typeshed #133 makes dim() opaque, like nrow(), and a ry binary built from this branch now reports nothing on that case or on ten common names()/dim() idioms. Only a bare if (names(x)) still reports, which errors in R for ordinary names.

Proof: scripts/sync_typeshed.sh validated 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 project passes (1,053 unit tests, with no vendor snapshot change), and cargo fmt --check is clean. CI runs the workspace, the oracle and both corpus ledgers. An earlier trial vendor of the same three PRs (branch chore/vendor-866-stubs) found no corpus ledger change.

#875 (sum(TRUE) and seq(1, 10) typed as integer) merges after this, so mean(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

…n contracts

r-typeshed #130, #131 and #132 correct base stubs that disagreed with
GNU R (sims1253/r-typeshed#124, #126 to #129). mean() now returns the
double/complex union, so one inference test expects both members.

Also merge the duplicated Unreleased 'Fixed' heading in CHANGELOG.

Refs #866
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: bbc1f0e5-75f7-48dc-8f40-839fe043ec7d
Commits

Reviewing files that changed from the base of the PR and between 3d20408 and 9be0a96.

Files selected for processing: 4

  • CHANGELOG.md
  • crates/ry-checker/src/tests/type_inference.rs
  • crates/ry-typeshed/vendor/SOURCE
  • crates/ry-typeshed/vendor/base/base.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)

⚠️ 1 warning(s) occurred during review.


⚠️ Warnings:

  • crates/ry-checker/src/tests/type_inference.rs,crates/ry-typeshed/vendor/SOURCE,crates/ry-typeshed/vendor/base/base.json (review_round_failed): round 2: LLM completion error: POST "https://api.z.ai/api/coding/paas/v4/chat/completions": 429 Too Many Requests {"code":"1302","message":"Rate limit reached for requests"}

Comment on lines +330 to +335
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"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test · low
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:

Suggested change
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"
);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +336 to +339
assert!(
members.iter().all(|t| t.length == Length::One),
"mean() returns a scalar"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test · low
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:

Suggested change
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:?}"
);

@sims1253 sims1253 Nov 7, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — two minor notes inline.

Reviewed changes

  • Vendor sync provenance verified: vendor/ is byte-identical to r-typeshed at 44e7698 (diff -r clean), the stubs-sha256 in SOURCE reproduces from the tree, and 44e7698 is r-typeshed master HEAD, so the scheduled typeshed-bump.yml sync keeps it; the upstream a0dac90..44e7698 range touches only stubs/base/base.json, matching this PR's vendor diff exactly.
  • GNU R contracts verified against r-source: round's math2() coerces to REALSXP and complex goes through z_rround (arithmetic.c/complex.c), so double | complex is exact and integer was indeed wrong; sign's complex case errors ("unimplemented complex function"), so plain double is right; cumprod's integer input takes the REALSXP branch (PRIMVAL(op) != 2 guard in cum.c) and complex takes CPLXSXP; the nullable names/dim/dimnames/colnames/rownames and opaque nrow/ncol (dim(x)[1L] on a NULL dim) match R.
  • Test update: pipe_underscore_placeholder_extraction now pins mean()'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.null narrowing in narrow.rs).
  • CHANGELOG: entry lands under ### Changed, and the duplicated Unreleased ### Fixed heading merge leaves exactly one of each heading.
  • CI on head is fully green (test, ecosystem corpus ledgers, Oracle (R)), confirming no corpus or oracle ledger drift from the new contracts.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using glm-5.3 | 𝕏

Comment thread CHANGELOG.md Resolved
r-typeshed #133 makes dim() opaque, like nrow() and ncol(): its
integer/NULL union made if (dim(m)[1L]) report RY001 on a matrix.

Refs #866

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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): the integer | null union — which let if (dim(m)[1L]) false-RY001 on matrices because indexing kept the null member — is now opaque with unknown length and na: false, mirroring the existing opaque nrow()/ncol() entries exactly.
  • Bumped the vendor pin: base stub 0.0.35 → 0.0.36, with the SOURCE commit and stubs-sha256 updated alongside.
  • Corrected the CHANGELOG: the entry drops the incorrect stub count ("more stubs allow NA") and now describes the dim()/nrow()/ncol() no-claim contracts alongside the nullable names()/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).

Pullfrog  | View workflow run | Using glm-5.3 | 𝕏

Comment on lines +331 to +335
assert_eq!(
members.iter().map(|t| t.mode).collect::<Vec<_>>(),
[Mode::Double, Mode::Complex],
"mean() of a double column is double or complex"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test · low
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:

Suggested change
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:?}"
);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 3453 to 3461
"return": {
"mode": "double_or_int",
"mode": "union",
"length": "arg0",
"members": [
"double",
"complex"
],
"na": true
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · medium
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:

Suggested change
"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;
// }

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sims1253
sims1253 merged commit 83d9017 into main Nov 7, 2026
17 checks passed
@sims1253
sims1253 deleted the chore/vendor-base-stubs-866 branch November 7, 2026 02:29
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.

1 participant