Skip to content

bundler: spell elided Graph<'_> in signatures (mismatched_lifetime_syntaxes)#31033

Open
Jarred-Sumner wants to merge 1 commit into
mainfrom
claude/bundler-perfile-followup
Open

bundler: spell elided Graph<'_> in signatures (mismatched_lifetime_syntaxes)#31033
Jarred-Sumner wants to merge 1 commit into
mainfrom
claude/bundler-perfile-followup

Conversation

@Jarred-Sumner
Copy link
Copy Markdown
Collaborator

@Jarred-Sumner Jarred-Sumner commented May 19, 2026

Spell the elided lifetime as &Graph<'_> / -> &Graph<'a> in the four signatures where #30971 made Graph lifetime-generic and updated the adjacent &LinkerGraph<'_> parameter but left &Graph bare — which triggers rustc's mismatched_lifetime_syntaxes lint (surfaced by robobun on the build job).

Sites: LinkerContext::parse_graph (→ &Graph<'a>, matching parse_graph_mut), Chunk.rs (×3), HTMLImportManifest.rs (×2), ungate_support.rs — all &Graph&Graph<'_>.

cargo check -p bun_bin clean.

Note: this PR previously also carried a Zig-defer comment cleanup, which went through several rounds of orphaned-comment churn. Dropped it — the cosmetic comment removal wasn't worth the review overhead. Reduced to just the lint fix.

@robobun
Copy link
Copy Markdown
Collaborator

robobun commented May 19, 2026

Updated 7:17 PM PT - May 19th, 2026

@Jarred-Sumner, your commit 0a4d711 has 4 failures in Build #56276 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31033

That installs a local version of the PR into your bun-31033 executable, so you can run:

bun-31033 --bun

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR modernizes Rust port semantics and documentation across the codebase: parameterizing Graph lifetime annotations in bundler APIs, adding explicit RAII guards for resource cleanup, refactoring pending-item accounting logic, and systematically replacing Zig-style defer port-notes with accurate Rust ownership and control-flow patterns.

Changes

Rust Port Cleanup and RAII Modernization

Layer / File(s) Summary
Graph lifetime parameterization in bundler APIs
src/bundler/Chunk.rs, src/bundler/HTMLImportManifest.rs, src/bundler/LinkerContext.rs, src/bundler/ungate_support.rs
Public and internal code-generation methods update Graph parameter types from &Graph to &Graph<'_>, binding the borrow lifetime to caller context and matching the parameterized Graph type signature. LinkerContext::parse_graph() return type updates to &Graph<'a> to tie the borrow to its lifetime parameter.
RAII guards for worker and visitor lifecycle
src/bundler/linker_context/doStep5.rs, src/bundler/linker_context/findImportedFilesInCSSOrder.rs
Thread-local worker retrieved via ThreadPool::Worker::get is wrapped with scopeguard::guard(..., |w| w.unget()) so unget() runs automatically on scope exit. CSS visitor visited stack cleanup switches from defer-registered pop to explicit end-of-function pop, with comments documenting the early-return bypass.
Bundler port-note cleanup: allocation ownership and deinit comments
src/bundler/LinkerContext.rs, src/bundler/linker_context/MetafileBuilder.rs, src/bundler/linker_context/computeCrossChunkDependencies.rs, src/bundler/linker_context/scanImportsAndExports.rs, src/bundler/linker_context/generateCodeForLazyExport.rs
Remove or reword Zig-style defer comments describing cleanup for temporary collections and state (seen_sources, parsed JSON, bytes_in_output, imported_by, chunk_metas, cross-chunk exports/imports); deallocation is handled via Rust Drop and move semantics.
Parse and compilation task logic and lifecycle updates
src/bundler/ParseTask.rs, src/bundler/ServerComponentParseTask.rs, src/bundler/bundle_v2.rs, src/runtime/api/js_bundle_completion_task.rs
ParseTask expands deallocation comments to clarify struct-only destroy semantics; ServerComponentParseTask adds explicit worker.unget() call after event loop dispatch instead of relying on deferred cleanup; bundle_v2 refactors pending-items accounting from defer-based comment to explicit tail logic with scoped logging and conditional callback; JSBundleCompletionTask removes Zig-port comment patterns.
Parser and printer port-note cleanup
src/js_parser/parse/parse_entry.rs, src/js_printer/lib.rs
parse_entry reorders imports and removes commented-out defer block for allocated_names_pool cleanup; js_printer updates print_stmt comments to explain prev_stmt_tag assignment at each return point (vs. deferred) and removes obsolete cleanup comments for minify_identifiers, source_maps_chunk, and temporary_bindings.
Resolver debug indentation and cleanup documentation
src/resolver/resolver.rs
Remove outdated commented-out notes about deferred debug indentation decrements in resolve_and_auto_install, load_from_main_field, and load_as_file_or_directory; note about top_parent defer is removed. Mutex unlock and error-flush handling comments are cleaned up.
JSC RuntimeTranspilerStore port-note cleanup
src/jsc/RuntimeTranspilerStore.rs
Remove Zig-style defer comments in dump_source_string_failiable and TranspilerJob::run describing cleanup of mappings Arc::drop, arena allocator, log clone/recycle, and input_file_fd close behavior; scopeguard implementations remain unchanged.
Runtime API JSTranspiler documentation cleanup
src/runtime/api/JSTranspiler.rs
Remove defer-style comments across Config::from_js, TransformTask::run, and JSTranspiler methods (scan, transform, transform_sync, scan_imports) describing cleanup of iterators, arguments, code holders, logs, and buffer state; actual parsing logic and RAII guard behavior unchanged.
Exception handling and bundler completion task documentation
src/runtime/jsc_hooks.rs
Update print_exception comments to clarify buffered error-writer flush occurs at function tail instead of via defer; remove redundant comment about formatter.deinit drop behavior in non-exception path.
Snapshot test documentation updates
src/runtime/test_runner/snapshot.rs
Update inline comments in get_or_put, parse_file, and write_inline_snapshots to clarify snapshot ownership via buntest_strong, AST cleanup timing on early return, value cloning/insertion semantics, and scopeguard lifecycle across all loop-body exits including error-return paths; success Cell mutation behavior is explicit.
AST printer buffer cleanup comment
src/ast/nodes.rs
Remove in-function comment in printmem that described prior Output.flush() defer ordering emulation; call sequence (init_test, print, flush) remains unchanged.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and specifically describes the main change: spelling elided lifetimes in Graph signatures and referencing the specific lint issue (#30971, mismatched_lifetime_syntaxes).
Description check ✅ Passed The description provides detailed explanation of what the PR does (spells elided lifetimes in four signatures), how to verify (cargo check clean), and context about dropping porting comments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

LGTM — comment-only cleanup + lint fix; the two orphaned comment fragments flagged inline are cosmetic and can be tidied before merge or in a follow-up.

Extended reasoning...

Overview

Two commits, both mechanical:

  • 10f75af spells &Graph<'_> (or &Graph<'a> in LinkerContext::parse_graph) in 7 signatures where #30971 already wrote &LinkerGraph<'_> alongside a bare &Graph. Pure type-annotation change to silence mismatched_lifetime_syntaxes; semantically identical (or, in the 'a case, a strict relaxation the compiler verifies).
  • c7d4bf0 deletes/rewords ~50 // Zig: \defer ...`/// defer X → Drop` porting comments across 35 files. Net −144 lines. I walked the full diff: every hunk in this commit touches only comment lines or rewraps existing comment prose — no executable code is added, removed, or reordered.

Security risks

None. No logic, control flow, I/O, or data handling is changed. The lifetime annotations are compiler-checked no-ops.

Level of scrutiny

Low. Despite the 38-file footprint, this is a comment sweep plus a lint fix. The compiler is the ground truth for the Graph<'_> half, and the comment half cannot affect behavior.

Other factors

The bug-hunting pass found one nit: two spots (resolver/lib.rs:1245, runtime/jsc_hooks.rs:4001) where only the first line of a two-line comment was removed, leaving a lowercase sentence fragment. The same PR handles the identical pattern correctly at resolver/lib.rs:1485, so these are clearly oversights. Cosmetic only — flagged inline, not a blocker.

No prior reviews on the timeline; build #56039 is in flight.

Comment thread src/resolver/lib.rs
Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

LGTM — thanks for addressing the earlier orphaned-fragment nits in 757317a; the two remaining ones flagged inline are cosmetic and fine to fold in or leave for a follow-up.

Extended reasoning...

Overview

Two-commit follow-up to #30971: (1) 10f75af adds <'_> to 7 &Graph parameters where the adjacent &LinkerGraph<'_> was already updated, silencing the mismatched_lifetime_syntaxes lint; (2) c7d4bf0 deletes/rewords ~50 // Zig: \defer ...`porting comments across 35 files (net −144 lines). A third commit757317acapitalizes two orphaned comment fragments I flagged in the previous run. Every hunk in the diff is either a comment edit or aGraphGraph<'_>` signature tweak — no executable logic changes.

Security risks

None. Comment-only edits plus elided-lifetime syntax that the compiler already inferred; no control-flow, allocation, FFI, or auth surface touched.

Level of scrutiny

Low. The Graph<'_> changes are pure lint conformance (lifetime elision was already in effect). The comment sweep removes Zig-port scaffolding; the only failure mode is leaving prose fragments that read awkwardly, which is exactly what the two new nit reports cover (a dangling "those" at bundle_v2.rs:4898 and a now-inaccurate "Captured by reference" at js_bundle_completion_task.rs:277). Both are zero-runtime-impact wording issues.

Other factors

The author already responded to my prior round of the same defect class (757317a fixed resolver/lib.rs:1245 and jsc_hooks.rs:4001), and the prior inline thread is resolved. CodeRabbit found nothing actionable. Build #56236 is running on the latest commit. The remaining nits are filed inline and don't warrant blocking a comment-cleanup PR.

Comment thread src/bundler/bundle_v2.rs
Comment thread src/runtime/api/js_bundle_completion_task.rs Outdated
@Jarred-Sumner Jarred-Sumner force-pushed the claude/bundler-perfile-followup branch from 3fe1741 to 18afdd8 Compare May 19, 2026 21:30
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/js_printer/lib.rs (1)

8126-8147: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't unconditionally drop line_offset_tables here.

get_source_map_builder() bitwise-copies either a freshly-built table or opts.line_offset_tables into this ManuallyDrop. This guard always calls ManuallyDrop::drop(tables), so print_ast() will free caller-owned storage if it is ever invoked with a borrowed table. Please track whether opts.line_offset_tables was Some(_) before building the SourceMap::chunk::Builder, and only run this cleanup when the table was allocated on this path. Apply the same gate to the identical block in print_common_js.

Suggested shape
-    let source_map_builder = get_source_map_builder::<ASCII_ONLY>(
+    let borrowed_line_offset_tables = opts.line_offset_tables.is_some();
+    let source_map_builder = get_source_map_builder::<ASCII_ONLY>(
         GenerateSourceMap::lazy_if(GENERATE_SOURCE_MAP),
         &mut opts,
         source,
         tree,
     );
...
-            if GENERATE_SOURCE_MAP {
+            if GENERATE_SOURCE_MAP && !borrowed_line_offset_tables {
                 let tables = unsafe { &mut *p };
                 for v in tables.items_mut::<"columns_for_non_ascii", Box<[i32]>>() {
                     core::mem::take(v);
                 }
                 unsafe { core::mem::ManuallyDrop::drop(tables) };
             }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/js_printer/lib.rs` around lines 8126 - 8147, The guard unconditionally
drops Builder.line_offset_tables even when it contains a borrowed table from
opts.line_offset_tables; modify the logic so you record whether
get_source_map_builder allocated a new line_offset_tables (e.g. a boolean like
created_line_offset_tables) by checking opts.line_offset_tables before building,
and only install/run the scopeguard/ManuallyDrop::drop branch when that flag is
true; apply the same gated check to the identical block in print_common_js,
referencing get_source_map_builder, Builder.line_offset_tables, print_ast,
print_common_js, opts.line_offset_tables and the existing
scopeguard/ManuallyDrop usage to locate and conditionally execute the cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/js_printer/lib.rs`:
- Around line 8126-8147: The guard unconditionally drops
Builder.line_offset_tables even when it contains a borrowed table from
opts.line_offset_tables; modify the logic so you record whether
get_source_map_builder allocated a new line_offset_tables (e.g. a boolean like
created_line_offset_tables) by checking opts.line_offset_tables before building,
and only install/run the scopeguard/ManuallyDrop::drop branch when that flag is
true; apply the same gated check to the identical block in print_common_js,
referencing get_source_map_builder, Builder.line_offset_tables, print_ast,
print_common_js, opts.line_offset_tables and the existing
scopeguard/ManuallyDrop usage to locate and conditionally execute the cleanup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6afbd4d7-1c87-41e4-8cc4-9914e8de81f3

📥 Commits

Reviewing files that changed from the base of the PR and between 757317a and 18afdd8.

📒 Files selected for processing (38)
  • src/ast/nodes.rs
  • src/bun_alloc/lib.rs
  • src/bun_core/util.rs
  • src/bundler/Chunk.rs
  • src/bundler/HTMLImportManifest.rs
  • src/bundler/LinkerContext.rs
  • src/bundler/ParseTask.rs
  • src/bundler/ServerComponentParseTask.rs
  • src/bundler/bundle_v2.rs
  • src/bundler/cache.rs
  • src/bundler/linker_context/MetafileBuilder.rs
  • src/bundler/linker_context/computeCrossChunkDependencies.rs
  • src/bundler/linker_context/doStep5.rs
  • src/bundler/linker_context/findAllImportedPartsInJSOrder.rs
  • src/bundler/linker_context/findImportedFilesInCSSOrder.rs
  • src/bundler/linker_context/generateCodeForLazyExport.rs
  • src/bundler/linker_context/postProcessJSChunk.rs
  • src/bundler/linker_context/scanImportsAndExports.rs
  • src/bundler/transpiler.rs
  • src/bundler/ungate_support.rs
  • src/css/css_parser.rs
  • src/js_parser/lexer.rs
  • src/js_parser/p.rs
  • src/js_parser/parse/parse_entry.rs
  • src/js_parser/parser.rs
  • src/js_printer/lib.rs
  • src/jsc/AsyncModule.rs
  • src/jsc/RuntimeTranspilerStore.rs
  • src/jsc/lib.rs
  • src/resolver/lib.rs
  • src/resolver/package_json.rs
  • src/resolver/resolver.rs
  • src/runtime/api/JSTranspiler.rs
  • src/runtime/api/js_bundle_completion_task.rs
  • src/runtime/bake/DevServer.rs
  • src/runtime/cli/create/SourceFileProjectGenerator.rs
  • src/runtime/jsc_hooks.rs
  • src/runtime/test_runner/snapshot.rs
💤 Files with no reviewable changes (10)
  • src/bundler/linker_context/generateCodeForLazyExport.rs
  • src/bundler/linker_context/findAllImportedPartsInJSOrder.rs
  • src/bundler/linker_context/doStep5.rs
  • src/jsc/lib.rs
  • src/css/css_parser.rs
  • src/runtime/cli/create/SourceFileProjectGenerator.rs
  • src/bundler/ServerComponentParseTask.rs
  • src/ast/nodes.rs
  • src/bundler/linker_context/MetafileBuilder.rs
  • src/bundler/linker_context/computeCrossChunkDependencies.rs

Comment thread src/bundler/linker_context/scanImportsAndExports.rs Outdated
Comment thread src/bundler/bundle_v2.rs Outdated
Silences mismatched_lifetime_syntaxes lint introduced when Graph became
Graph<'a> in 303cd28 but a few sibling signatures kept bare `&Graph`.
@Jarred-Sumner Jarred-Sumner force-pushed the claude/bundler-perfile-followup branch from b141fba to ea74518 Compare May 19, 2026 22:28
@Jarred-Sumner
Copy link
Copy Markdown
Collaborator Author

Regenerated the defer-cleanup commit from scratch (force-pushed ea745180) to end the orphaned-fragment whack-a-mole. The new commit does whole-comment-block deletions only and never edits a comment's interior, so no sentence fragments can be stranded. Verified: diff vs main is deletions-only (zero added or modified comment lines). PR is now 2 clean commits — the Graph<'_> lint fix and this cleanup.

Comment thread src/js_parser/parse/parse_entry.rs Outdated
Comment thread src/resolver/resolver.rs
@Jarred-Sumner Jarred-Sumner force-pushed the claude/bundler-perfile-followup branch from 876b09b to 0a4d711 Compare May 19, 2026 23:51
@Jarred-Sumner Jarred-Sumner changed the title bundler: post-#30971 cleanup — Graph<'_> lint + drop Zig-defer comments bundler: spell elided Graph<'_> in signatures (mismatched_lifetime_syntaxes) May 19, 2026
Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

LGTM — mechanical mismatched_lifetime_syntaxes fix now that the defer-comment cleanup has been dropped.

Extended reasoning...

Overview

The PR now touches exactly 4 files with 7 one-line signature edits: &Graph&Graph<'_> in Chunk.rs (×3), HTMLImportManifest.rs (×2), ungate_support.rs (×1), and -> &Graph-> &Graph<'a> on LinkerContext::parse_graph. These spell out the lifetime that was already being elided, to silence rustc's mismatched_lifetime_syntaxes lint after #30971 made Graph lifetime-generic. No bodies, comments, or call sites change; the adjacent &LinkerGraph<'_> parameters already used this style, and parse_graph_mut already returns &mut Graph<'a>, so this is pure consistency.

Security risks

None. Type-signature-only edits with no behavioral effect — the elided and explicit forms compile to identical borrow regions.

Level of scrutiny

Low. This is a mechanical lint fix equivalent to a typo correction. The previously-contentious portion of this PR (the Zig-defer comment sweep that generated six rounds of orphaned-fragment review) has been dropped entirely per the updated PR description, and the changed-files list confirms only the four bundler files remain. All my prior inline comments targeted files that are no longer in the diff and are now moot.

Other factors

No CODEOWNERS match for these paths. No bugs found by the bug-hunting system on the current revision. The robobun comment references a single 03830.test.ts asan failure, but that status is pinned to commit 876b09ba (the old state including the dropped cleanup + autofix churn); a pure <'_> spelling change cannot affect that regression test, so it's unrelated/flaky. cargo check -p bun_bin is reported clean.

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.

2 participants