Skip to content

Deduplicate repeated compiler and language-server code - #1637

Merged
sbillig merged 6 commits into
masterfrom
simplify-roi
Sep 30, 2026
Merged

sbillig merged 6 commits into
masterfrom
simplify-roi

Conversation

@sbillig

@sbillig sbillig commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1636; review that first. Net -756 lines.

Two line-count plays:

  • hir: single-label diagnostics through primary_diag.
    diagnostics.rs spelled out a full CompleteDiagnostic literal for
    every variant, including the 71 whose only label is a primary one
    with no notes. primary_diag now takes impl Into<String> so a
    format! result can be passed without a detour through &str.
  • hir: inline the visitor walk closures. Every walk_* wrapped
    its child visit in a braced closure holding one statement, often
    with a let binding used once. 97 collapse to expression closures,
    so the walk functions read as a list of child spans.

Four drift-hazard removals, where the duplication meant a change had to
be made in two or more places to be correct:

  • reachable_input and reachable_region held byte-identical
    capability loops; the only real difference is that one projects
    through a RegionPath first.
  • setup_service and setup_ws_service repeated the same 43-entry LSP
    handler chain, differing only in the Initialize handler and whether
    they observe FileChange.
  • convert_dependency spelled out the same remote-checkout descriptor
    block six times. It goes from ~200 lines and five levels of nesting
    to 95 and three.
  • The document-symbol and workspace-symbol handlers each carried their
    own copy of the item-to-SymbolKind match, so a new item kind had to
    be added twice.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T02:56:00.493771Z 1a3709c New commits
🔒 Security Review ✅ Completed 2026-09-30T03:15:23.810305Z 1a3709c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sbillig
sbillig added this pull request to stack #1639 September 29, 2026 18:11
Base automatically changed from simplify-lints to master September 29, 2026 19:53
`diagnostics.rs` spelled out a full `CompleteDiagnostic` literal for
every variant, including the 71 whose only label is a primary one with
no notes. Those now call the existing `primary_diag` helper, which
takes `impl Into<String>` so a `format!` result can be passed without a
detour through `&str`.
Every `walk_*` function wrapped its child visit in a braced closure
holding one statement, often with a `let` binding used exactly once.
Both collapse to an expression closure, so the walk functions now read
as a list of child spans rather than a wall of blocks.
`reachable_input` and `reachable_region` carried byte-identical copies
of the capability loop: freshen, retarget abstract contract roots, union
the region, collect loan parents. The only real difference is that the
input path projects through a `RegionPath` first, so that becomes an
`Option` argument on a shared `fold_reachable`.
`setup_service` and `setup_ws_service` repeated the same 43-entry
handler chain, differing only in which `Initialize` handler they use and
whether they observe `FileChange`. The common chain moves into
`register_shared_handlers` and the fallback-router wiring into
`with_streaming_fallback`, so the two connection kinds can no longer
drift apart.
`convert_dependency` spelled out the same "resolve the path inside the
checkout, rebuild the git description, report on failure" block three
times, once per dependency location, and each of those was duplicated
again for the named and unnamed cases. That work moves into
`checkout_description`, which reports and yields `None` so callers can
use `?`, and `remote_descriptor`, which picks between `RemoteByName`
and `Remote`.

Each arm now computes a descriptor and shares one recording tail, which
takes the function from roughly 200 lines and five levels of nesting to
95 lines and three.
`document_symbols` and `workspace_symbols` each carried their own copy
of the item-to-`(SymbolKind, String)` match, so a new item kind had to
be added in two places. The named kinds move to `util::named_item_symbol`,
which folds the eight near-identical arms into one by pulling the
keyword out of the `format!`. `document_symbols` keeps its own arms for
`impl` and `impl trait`, the two kinds that have no name of their own
and that the workspace handler deliberately skips.
@sbillig
sbillig merged commit 2ffb7a0 into master Sep 30, 2026
9 checks passed
@sbillig
sbillig deleted the simplify-roi branch September 30, 2026 13:24
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