Skip to content

fix(checker): honest NSE name lists with a stub-overlap guard - #149

Merged
sims1253 merged 8 commits into
mainfrom
fix/infer-name-list-honesty
Sep 1, 2026
Merged

sims1253 merged 8 commits into
mainfrom
fix/infer-name-list-honesty

Conversation

@sims1253

Copy link
Copy Markdown
Owner

Summary

is_nse_symbol_fn is the hardcoded half of the NSE knowledge. The typeshed eval metadata is the other half. This PR deletes the entries the stubs already cover, keeps the ones they do not, and adds a guard so the two halves cannot overlap silently. It also wires generic_argument_may_dispatch to the same s3_generics list the dispatch path reads. Stacked on #145 (which stacks on #137); merges after both.

Changes

  • Removed eight entries from is_nse_symbol_fn:
    • tidyselect is a package name, not a function. A call spelled tidyselect(...) now evaluates its arguments.
    • alist is covered by the base stub's quoted_expression dots. The stub path also keeps the list return type.
    • enexpr, ensym, enquo, enquos, ensyms, and quos are covered by rlang's captures_promise metadata. Loaded or qualified calls resolve the stub. Unqualified calls without library(rlang) now evaluate their arguments.
  • Kept every member without stub coverage. quote, substitute, bquote, and delayedAssign have base stubs without eval fields. makeActiveBinding, the ggplot2 and data.table names, the remaining rlang names, and all_vars/peek_vars have no coverage. Blocked on r-typeshed.
  • The list is now the NSE_SYMBOL_FNS const so tests can enumerate it.
  • generic_argument_may_dispatch now consults typeshed.globals.s3_generics, the same list the S3 dispatch path reads. The stub list omits round, mean, log, sqrt, and exp, so a five-name fallback stays and a comment says why.
  • assertion_call_target and the stub-assertion path in infer_call now carry cross-reference comments. Both sites encode the same knowledge. The fold-in is blocked on r-typeshed (Consolidate three independent NSE/defusing function encodings #41).
  • CHANGELOG gains a ### Fixed entry: RY010 now fires where bogus or redundant entries suppressed it.

Verification

  • New guard nse_symbol_fallback_does_not_overlap_stub_promise_capture fails when a member is stub-covered and lists the overlap. Verified by temporarily re-adding enquo.
  • New tests pin the stub-driven paths for alist and the six rlang helpers. They pass before and after the removals.
  • New tests pin the two observable changes: a literal tidyselect(...) call and an unloaded unqualified defusing call now report RY010.
  • cargo fmt -p ry-checker
  • cargo clippy -p ry-checker --all-targets -- -D warnings
  • cargo test -p ry-checker — full suite green, corpus snapshots included.

Implements the in-repo part of #41 and #49

…helpers

Mechanical prefix of #130. Semantics are unchanged; the full crate
suite passes untouched.

- apply_narrowing loses its unused _has_else parameter and returns
  early for Narrowing::None, so a no-narrowing if skips the match-arm
  work while still returning owned scopes.
- merge_branch_bindings takes the branch scopes by reference; the
  caller no longer clones both just to keep reading them.
- infer_if_expr no longer clones the branch scopes it consumes last.
- One is_comparison predicate replaces the six-operator list written
  out at six sites.
- One concrete_json_mode mapping replaces the JsonMode-to-Mode table
  written out three times.
- extract_builtin_type_narrowing shares its inherits target lookup and
  first-argument identifier extraction; apply_narrowing shares the
  narrow-away-from-null sequence repeated across four arms.
- try_s3_binop_dispatch and try_s3_unary_dispatch share the class
  vector walk.
- equality_list_leaf_type loses its dead op parameter; unused span and
  name parameters are underscore-named at the signature instead of
  silenced in the body; a mid-file use moves to the top of misc.rs.
… emitter

Second half of #130. Semantics are unchanged; the full crate suite passes
untouched.

- enter_function_body unifies the two ~55-line function-body walks in
  walk_stmt. The Assign arm passes its binding name plus a flag for the S3
  dispatch context, the only line that differed.
- emit_condition_diagnostics replaces the RY001/RY003/RY002 block written
  three times across walk_stmt's If and While arms and infer_if_expr. A
  ConditionContext selects the message noun and carries the While arm's
  missing RY002 case unchanged: the rule table scopes RY002 to `if`
  conditions, and that arm has never had it.
- trusted_defusers is cached on the Checker instead of being rebuilt from
  DEFUSING_CALLS plus the whole fn table on every function per fixpoint
  iteration. collect_fns clears it, matching the only pass that writes
  fn_table.fns.
- infer_call builds one ArgumentMatch per call. eval_mode_for_arg and
  bound_argument_index_matched consume it, so the argument loop is no
  longer O(n^2) and the assertion path matches once instead of three
  times. argument_eval_mode stays for the schema-call site outside infer/.
- infer_data_frame calls longest_arg_length instead of repeating its
  ladder. infer_rep resolves times and each through rep_count.
- list_binding_origin is inlined into its single caller.
- The structure(x, class=...) doc comment moves from infer_injected_call,
  which handles typeshed injection, to infer_structure_call, which it
  describes.
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 632c2143-5f2c-4a56-8f94-ba9a4f1fa427

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

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

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

Important

The removals themselves check out — every deleted entry was verified against all 32 vendored package stubs, and the suite is green. But the anti-drift guard only sees one of the eval modes that create fallback overlap (mutation-proven below), and one kept member already violates the "no stub declares its evaluation mode" membership rule. Details inline.

Reviewed changes

  • NSE fallback list pruned to stub-uncovered names — is_nse_symbol_fn is now backed by the NSE_SYMBOL_FNS const (26 entries); removed tidyselect (a package name), alist (base stub dots are quoted_expression), and the six rlang defusing helpers whose stubs declare captures_promise. The alist list-return special case in infer_call went with it, replaced by the stub's own list return.
  • Overlap guard test — nse_symbol_fallback_does_not_overlap_stub_promise_capture enumerates the const against the stub promise-capture index, which required promoting promise_capture_index to pub(crate).
  • RY092 dispatch alignment — generic_argument_may_dispatch now consults typeshed.globals.s3_generics, the same list the dispatch path reads, plus a five-name fallback. Verified inert against every vendored stub today (none of those names has a typed param), so this is forward alignment, not a behavior change.
  • Behavior pins and CHANGELOG — new tests pin the stub-driven rlang/alist paths and the two observable changes (a literal tidyselect(...) call and unloaded unqualified defusing calls now report RY010). Full cargo test -p ry-checker green locally; the ### Fixed entry matches the section's sibling style.

ℹ️ Nitpicks

  • The five-name fallback in generic_argument_may_dispatch keeps round, log, sqrt, and exp hardcoded, but those four are already Math-group members in s3_group_generic (crates/ry-checker/src/higher_order.rs:673) — the dispatch path's other source. Deriving them from s3_group_generic(&function_name).is_some() (keeping only mean, which is in neither source) would mirror dispatch exactly and drop the list to one name. Inert today either way, so purely optional.

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

Comment thread crates/ry-checker/src/infer/index.rs Resolved
…on-walks

# Conflicts:
#	CHANGELOG.md
#	crates/ry-checker/src/infer/binop.rs
The cache was built during fixpoint iteration 1 (nested function literals
fire check_lazy_default_reachability in pass 2) and survived the quoting
propagators, so the pass-3 RY098 walk could read a pre-propagation
snapshot. Both propagators and signature seeding now clear it whenever
they write quoting/defused flags. Regression test pins that a cached set
matches the post-propagation table.
…nto fix/infer-name-list-honesty

# Conflicts:
#	CHANGELOG.md
… NSE fallback

The guard now scans every stub eval mode, not just captures_promise, so
a member quoted or data-masked by any stub must leave the fallback list.
all_vars leaves: dplyr declares expr: data_mask for it, and the fallback
intercepted even dplyr::all_vars() before signature resolution. Pin the
new paths: qualified and loaded calls data-mask their expression, an
unloaded unqualified call evaluates its argument (RY010).
generic_argument_may_dispatch derives the Math-group names from
s3_group_generic, keeping only mean hardcoded.
@sims1253

Copy link
Copy Markdown
Owner Author

Addressed all three findings in c6dc2b1 (on top of a merge from the moved base).

Guard widened. nse_symbol_fallback_does_not_overlap_stub_eval_modes now walks the same stubs the old index builder walked (load_base_cached() plus every known_packages() entry) and records each function's non-Normal eval modes. A member fails when it carries quoted_expression, captures_promise, or quoted_symbol, and also when it carries data_mask or tidy_select unless it sits in data_mask_exemptions with a reason. The exemption list is empty. Mutation check: re-adding both alist and all_vars fails the guard with ["alist (QuotedExpression)", "all_vars (DataMask)"]; the old guard saw neither. promise_capture_index went back to private since the guard no longer reads it.

all_vars removed. dplyr — the package it is called through — declares expr: data_mask for it, and the fallback intercepted even dplyr::all_vars(...) before signature resolution. Same trade as the rlang helpers. Pins: dplyr::all_vars(x) and library(dplyr) + all_vars(x) data-mask the expression (no RY010 on unknown columns, and a literal RY040 inside the masked expression still fires, which the old fallback skipped), and an unloaded unqualified all_vars(x) evaluates its argument (RY010 on unbound names). Re-adding all_vars fails both pins. The membership-rule comment and the CHANGELOG ### Fixed bullet now cover it. peek_vars stays: no vendored stub mentions it at all.

Dispatch fallback aligned. generic_argument_may_dispatch derives round/log/sqrt/exp from s3_group_generic(&name).is_some() and keeps only mean hardcoded. Inert today, as noted.

cargo fmt, cargo clippy -p ry-checker --all-targets -- -D warnings, and full cargo test -p ry-checker (468 lib tests) are green.

@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. Both findings from the prior review are fully addressed — I re-ran the mutation checks that exposed them, and the widened guard now catches both shapes.

Reviewed changes

  • Overlap guard widened to every eval mode — nse_symbol_fallback_does_not_overlap_stub_eval_modes now scans base plus every known_packages() entry (all 32 vendored packages) for any non-Normal EvalMode keyed under a member name, with an empty, documented data_mask/tidy_select exemption fixture; promise_capture_index went back to private. Mutation-verified: re-adding both alist and all_vars fails the guard with ["all_vars (DataMask)", "alist (QuotedExpression)"] — exactly the two blind spots the old guard missed.
  • all_vars left the fallback list — dplyr's stub declares expr: data_mask for it, so qualified and library(dplyr) calls now reach that metadata (no RY010, and RY040 still fires inside the mask), while unloaded unqualified calls report RY010. The const's doc comment and the CHANGELOG entry both state the dplyr rationale.
  • RY092 dispatch fallback collapsed to mean — generic_argument_may_dispatch now derives round/log/sqrt/exp from s3_group_generic (the dispatch path's other source) and consults globals.s3_generics, matching dispatch exactly; the doc comment names both sources. Confirmed mean is in neither, so the single hardcoded name is correct.

Verification this run: a fresh scan of all 32 vendored stubs shows zero eval-metadata overlap for the 25 remaining members; cargo test -p ry-checker --lib green (468 tests); cargo fmt --check and clippy -D warnings clean.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

@sims1253
sims1253 changed the base branch from refactor/infer-function-walks to main September 1, 2026 15:44

@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 — one minor suggestion inline (a one-word CHANGELOG revert the merge silently carries).

Reviewed changes

Since the last review the PR was retargeted from refactor/infer-function-walks to main (its stack landed as #137/#145) and origin/main was merged in. The PR's own code is unchanged from the approved state; the delta is integration.

  • Retargeted to main and merged origin/main — brings in #143–#148 (typeshed FunctionSig deserialization, the CLI/LSP refactors, and the collect.rs walker collapse). Verified the merge is lossless: the stack's content — the single function-entry path, the condition-diagnostics emitter, the trusted_defusers cache with its pin test — now lives on main via #145, and origin/main...HEAD is exactly the six fix files.
  • PR delta vs main is byte-identical to the previously approved diff — a range-diff against the last-reviewed head (c6dc2b1) shows only stack hunks leaving the diff; no fix-commit hunk changed.
  • Re-validated against the merged tree — cargo test -p ry-checker --lib green (469 tests, including the widened overlap guard and all six pin tests), so #143's typeshed refactor and #148's walker collapse did not disturb the stub-eval paths this PR depends on. The only blemish found is the inline CHANGELOG nit.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

Comment thread CHANGELOG.md
- The test harness's async JSON-RPC decoder now applies the same 16 MiB
message cap as the blocking decoder, rejecting oversized headers instead
of buffering them without limit.
of buffering without limit.

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.

The merge kept the branch's pre-#139 wording here, so the PR diff now silently reverts a one-word fix from main: #139 (8577b2d) authored "of buffering them without limit." for the async-decoder entry, and merging this PR as-is drops "them" again. Restoring main's wording makes this line leave the diff entirely.

@sims1253
sims1253 merged commit fb8c267 into main Sep 1, 2026
15 checks passed
@sims1253
sims1253 deleted the fix/infer-name-list-honesty branch September 1, 2026 16:06
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