Repository navigation
perf(diagnostics): loosen lifetime bound on OxcDiagnostic::with_source_code - #29849
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will improve performance by 5.08%
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Merge activity
|
…ce_code` (#29849) `with_source_code` required `T: SourceCode + 'static`, because it returned `Error` (`Box<dyn Diagnostic + Send + Sync>`, which is implicitly `'static`). So callers which only render a diagnostic on the spot had to copy the source text into an owned `String` or `Arc<String>` first. Return `Box<dyn Diagnostic + Send + Sync + 's>` instead, bounded by the lifetime of the source. When the source is `'static`, that is still the `Error` type, so callers which need one (e.g. `DiagnosticService`, which sends diagnostics across threads) are unaffected. Remove the copies this made unnecessary - in the linter's rule `Tester` (which copied the whole source text for every diagnostic), the coverage runner, and various tests and examples. This also allows `with_source_code` to integrate with the new `Source` API (#29763) where source text is always a borrowed `&str` in the arena, not an owned `String`.
653dc26 to
27777a9
Compare
…th_source_code` callers (#29850) `render_with_source_code` has never required `'static` source, but many callers still copied the source text before rendering (`.to_string()`, `.clone()`, `Arc<String>`), a leftover from `with_source_code`'s old `'static` bound (removed in #29849). Pass `&str` instead to avoid cloning and copying source text strings, and having to create `Arc<String>`s. This benfits NAPI error paths in `oxc_napi` and `oxc_parser_napi`, which copied the whole source text on every call that produced errors. Most of the other reductions in allocations are in examples and tests. `OxcError::from_diagnostic` is made generic over the source type rather than changing its parameter type, so existing callers still compile.
### 💥 BREAKING CHANGES - f573c93 syntax: [**BREAKING**] Remove `NumberBase` and `BigintBase` types (#29920) (overlookmotel) - b90b3aa ast: [**BREAKING**] Remove `base` field from `NumericLiteral` and `BigIntLiteral` (#29919) (overlookmotel) - 8c2abc4 diagnostics: [**BREAKING**] Implement `SourceCode` for `&T` (#29852) (overlookmotel) - 2bc8e89 diagnostics: [**BREAKING**] `NamedSource` support `&str` as name (#29851) (overlookmotel) ### 🚀 Features - 2384875 minifier: Remove redundant `| 0` under bitwise operators (#29991) (Cameron) - abf889f minifier: Flatten nested string concatenations (#30015) (Cameron) - 5f51bd3 minifier: Fold division with short numeric results (#29994) (Cameron) - 1102f24 minifier: Flatten nested untagged template literals (#29993) (Cameron) - 12897a0 minifier: Fold switch with one case and default into if-else (#29990) (Cameron) - f9e90de minifier: Fold numeric identities like `x - 0` and `x * 1` (#29926) (Dunqing) - c265eda minifier,ecmascript: Fold additive zero and safe offsets on int32/uint32 expressions (#29865) (Andre_Ramirez) - 37ec2e2 compat: Add standard decorators compatibility data (#29448) (Dunqing) - 22e4d0b runtime: Add standard decorator helpers (#29447) (Dunqing) - a67ac1f data_structures: Add brand types (#29756) (overlookmotel) ### 🐛 Bug Fixes - 38cd470 transformer: Share auto-accessor lowering and fix its private storage names (#29449) (Dunqing) - 6838760 packages/codegen: Parenthesize for-of targets that start with `let` (#30071) (Cameron) - 13dd5ac packages/codegen: Parenthesize comma expressions in enum initializers (#30070) (Cameron) - c4e4fcc packages/codegen: Parenthesize private `in` checks in for initializers (#30073) (Cameron) - 32882ef packages/codegen: Parenthesize comma expressions in export assignments (#30072) (Cameron) - 7d8998d packages/codegen: Parenthesize comma expressions in JSX containers (#30074) (Cameron) - c98b8b1 packages/codegen: Parenthesize TypeScript instantiation operands (#30068) (Cameron) - d615de4 codegen: Parenthesize TypeScript instantiation expressions used as operands (#30065) (Cameron) - 90b5af9 codegen: Keep `()` on minified `new` expressions with type arguments (#30062) (Cameron) - 4b1efd3 transformer/legacy-decorator: Move class self-references to alias symbol (#30056) (Dunqing) - adf284e mangler: Use debug names for private members (#30061) (Cameron) - bbe2fba transformer/legacy-decorator: Avoid class name shadowing in static setters (#30058) (Dunqing) - 7fa5d50 codegen: Keep comments from ending a line after code (#29814) (Yuji Sugiura) - 41dbc08 mangler: Keep names set by redeclarations with keepNames (#30055) (Dunqing) - 8921865 transformer/legacy-decorator: Keep static private brand checks on the original class (#30054) (Dunqing) - abb3593 transformer/legacy-decorator: Share anonymous default class bindings (#29753) (Dunqing) - bbc6772 lexer: Read << as a shift where TypeScript opens no type arguments (#30051) (Shanon Jackson) - 52b5506 transformer/class-properties: Preserve names of anonymous classes (#29931) (Dunqing) - 8488767 codegen: Parenthesize private `in` tests in `for` initializers (#30037) (Cameron) - 395913e parser: Parse `<=` after `as` and `satisfies` (#30028) (Cameron) - 9570bc8 parser: Require `class` keyword for decorated class export (#30027) (Cameron) - e9e80b1 codegen: Parenthesize for-of heads that print a leading `let` or `async` (#30025) (Cameron) - a54befb codegen: Avoid double parentheses around `as`/`satisfies` for-of heads (#30024) (Cameron) - 157673a codegen: Parenthesize comma expressions in export assignments (#30022) (Cameron) - bedf3f5 codegen: Parenthesize comma expressions in enum initializers (#30021) (Cameron) - 11bafb6 codegen: Parenthesize comma expressions in JSX containers (#30020) (Cameron) - 967a97c codegen: Print a computed key for renamed `__proto__` shorthand (#30019) (Cameron) - 64b7176 minifier: Preserve throwing `String.fromCodePoint` calls (#30014) (Cameron) - f17a216 ecmascript: Evaluate unary expressions in `ToNumber` (#30009) (Cameron) - 181dd40 ecmascript: Canonicalize RegExp flags in string conversion (#30008) (Cameron) - cf35a2e ecmascript: Respect shadowed `NaN` in strict equality (#30005) (Cameron) - 2d9246e minifier: Don't inline block-level vars visible to an outer direct eval (#29992) (Cameron) - 08023ad transformer: Keep TypeScript assign semantics for preserved classes (#29930) (Dunqing) - 32798b3 minifier: Don't treat reassigned `@__NO_SIDE_EFFECTS__` functions as pure (#29974) (oxc-captain[bot]) - 0167451 parser: Treat `import x = require()` as module syntax (#29908) (camc314) - e27f727 semantic: Align JSDoc nullable type suggestions with TypeScript (#29947) (camc314) - 831fbca transformer: Don't fold computed key assignments into non-computed method keys (#29912) (Dunqing) - 6db561f transformer: Keep correct keys on leftover fields with setPublicClassFields (#29911) (Dunqing) - e4e2ac4 parser,semantic: Reject invalid types in type arguments (#29945) (camc314) - bdbed9e transformer/async-to-generator: Avoid invalid and shadowing inferred function names (#29815) (YT) - a0f67fa parser: Parse TSX `<T extends U` as start of generic arrow function (#29910) (overlookmotel) - 8c84c5f parser: Never parse `<` as start of generic arrow function in JSX files (#29909) (overlookmotel) - f5022f2 lexer: Read yield and await by enclosing function in modules (#29890) (Shanon Jackson) - 168daf3 lexer: Keep async and generator scope across class members and generic async arrows (#29889) (Shanon Jackson) - 777d2d1 parser: Report import/export in unambiguous code resolved to script (#29902) (camc314) - e385fe8 parser: Don't treat `await` in function parameters and class fields as top-level await (#29901) (camc314) - 5442f8a parser: Report misplaced import/export before checking parse goal (#29898) (camc314) - c589002 minifier: Drop redeclarations of removed declarations (#29415) (Dunqing) - 24a1aaf parser: Discard comments from rewound speculative parses (#29847) (camc314) - 1aadbe7 isolated-declarations: Preserve const literal initializers through parentheses (#29041) (camc314) - a7ea78b transformer: Keep classes whose decorators are preserved (#29748) (Dunqing) - 5ece804 transformer/async-to-generator: Remove leading digits from inferred function names (#29816) (YT) - 15bdce3 parser: `parse_expression` produce correct error for overlong source (#29761) (overlookmotel) - b6ff506 react-compiler: Do not treat the receiver of a JSX ref property load as a ref (#29754) (Boshen) - 2f6a11f semantic: Keep catch parameters in the catch clause scope (#29635) (Dunqing) - 60718a1 minifier: Keep unused classes with a static computed `prototype` key (#27966) (baltasarblanco) - d59aa8e transformer/legacy-decorator: Apply static member decorators last (#27744) (Yunus Ozen) - 97307e3 transformer/legacy-decorator: Emit `String`/`Number` metadata for enums declared after the class (#29724) (Max Schwenk) - 3586c66 transformer: Preserve object rest assignment evaluation (#29645) (Boshen) - 4fb4887 allocator: Require Sync allocator for Drain Send (#26152) (Cameron) - f860f1b semantic: Resolve a private name to the enclosing class that declares it (#29714) (Nadir Ali) - 7b2b207 parser: Parse contextual keywords after relational expressions (#25097) (camc314) - b7e2beb minifier: Preserve indirect calls when inlining eval aliases (#29725) (Yunfei He) - 279185a react-compiler: Ignore ESLint suppressions when hooks and memo validations are enabled (#29655) (Boshen) - d69ba66 napi/parser: Walk skipped ESTree fields in lazy visitor (#29381) (Ryan Tsao) - f22757c transformer/class-properties: Preserve receivers in TS-wrapped private calls (#29684) (camc314) - 0e1ef65 transformer/exponentiation-operator: Scope default parameter temporaries (#29685) (camc314) ### ⚡ Performance - 209f078 mangler: Include digits in trailing character frequency order (#29437) (camc314) - 5e7abd1 parser: Remove unnecessary conversion when parsing BigInts (#29913) (overlookmotel) - 5ac3942 parser: Mark missing-digit lexer errors cold (#29806) (Boshen) - 892f086 various: Avoid copying source text in `OxcDiagnostic::render_with_source_code` callers (#29850) (overlookmotel) - 27777a9 diagnostics: Loosen lifetime bound on `OxcDiagnostic::with_source_code` (#29849) (overlookmotel) - a2eed1b parser: Read each comment once (#29794) (Boshen) - ec4090d semantic: Size the `Scoping` arena from symbol, reference and scope counts (#29809) (Boshen) - 7c39be0 minifier: Avoid rebuilding variable declarations when keeping all declarators (#29767) (camc314) - 0537b09 parser: Take the name of a JSX identifier from its token (#29746) (Boshen) - 1c2cd7c parser: Take the value of a string literal without escapes from its source text (#29745) (Boshen) - 1d84d3f parser: Take the value of JSX text from its source text (#29744) (Boshen) - 41e3075 parser: Check for the `<` of type arguments without a call (#29743) (Boshen) - 6e783b1 parser: Keep the token read after `import` (#29742) (Boshen) - eb9c7a4 parser: Parse `(<div />)` as a parenthesized expression directly (#29741) (Boshen) - 7acf20a parser: Parse JSX at the start of an expression without speculation (#29740) (Boshen) - aea847b estree: Merge compact `serialize_field` writes (#28399) (codspeed[bot]) - 414532b parser: Cache failed type argument speculation (#29518) (Boshen) - d91c961 parser: Take comments from the lexer without copying inline storage (#29623) (Boshen) - dda1781 parser: Finish plain strings and integers in their token handler (#29622) (Boshen) - 6f5d371 parser: Choose how to scan a block comment from its first bytes (#29621) (Boshen) - d80d731 parser: Do less work to record each comment (#29620) (Boshen) - ce2b7aa parser: Lex the token after a line break in its token handler (#29619) (Boshen) - 7833ea0 parser: Finish identifier and keyword tokens in their token handler (#29618) (Boshen) - bb08acb parser: Dispatch tokens through handlers which finish the token (#29617) (Boshen) - a1ed5af parser: Parse `(…)` once with a cover grammar for arrow functions (#29603) (Boshen) ### 📚 Documentation - 158fcf5 minifier: Fix duplicated word in comment (#30059) (Dunqing) - 3ff249b skills: Share PR title guidance with triagebot (#29980) (Cameron) - 983ebc7 ast: Clarify which keys `PropertyKey::static_name` supports (#29905) (camc314) - 1da6ea8 skills: Merge PR guidance into pr-guide skill (#29866) (Dunqing) - 9740083 minifier: Clarify when variable declarations are merged (#29768) (camc314) --------- Co-authored-by: Cameron <cameron.clark@hey.com>
# Oxlint ### 💥 BREAKING CHANGES - 8c2abc4 diagnostics: [**BREAKING**] Implement `SourceCode` for `&T` (#29852) (overlookmotel) ### 🚀 Features - a96e2bd linter/typescript/no-unsafe-class-instance-assignment: Add rule (#29982) (Cameron) ### 🐛 Bug Fixes - 11d16bd linter/eslint/prefer-object-spread: Prefix semicolon when the fix could merge with the previous statement (#30080) (oxc-captain[bot]) - 106d301 linter/unicorn/prefer-math-trunc: Report `parseInt(String(...), 10)` (#30067) (Lê Văn Xuân Hoàn) - 226ba04 linter/unicorn/prefer-import-meta-properties: Stop flagging `fileURLToPath(new URL('.', import.meta.url))` (#30041) (oxc-captain[bot]) - 04cdaec linter/unicorn/no-useless-spread: Replace holes with `undefined` in spread array literals (#30042) (oxc-captain[bot]) - 7141c26 linter/eslint/no-implicit-coercion: Skip autofix when coercion constructor is shadowed (#30043) (oxc-captain[bot]) - f22709d linter/eslint/no-unused-vars: Fixes remove a whole CRLF after an unused import (#30047) (Nicholas Rayburn) - 6998259 linter/eslint/max-lines: Report diagnostic at the start of the last character (#30046) (Nicholas Rayburn) - 48ed7f7 linter: Find tsgolint in case-sensitive directories on Windows (#26234) (Nicolas Stepien) - f92aeab linter/vitest/valid-expect: Validate `expectTypeOf` matcher chains (#30023) (Cameron) - 0f774dc linter/react/exhaustive-deps: Report setters accessed through member expressions (#30017) (Cameron) - 8726fca linter/react/exhaustive-deps: Report setters from parenthesized or `as`-cast `useState` calls (#30016) (Cameron) - 1a19370 linter/eslint/no-extra-boolean-cast: Parenthesize the replacement when needed (#30012) (Thejesh) - 4452bb6 linter/eslint/operator-assignment: Parenthesize a conditional right operand in the "never" fix (#30013) (Thejesh) - ad91ec9 linter/react/exhaustive-deps: Don't report `useReducer` dispatches as `setState` calls (#29986) (oxc-captain[bot]) - 589d281 linter/oxc/branches-sharing-code: Skip move suggestions for branch-local references (#30006) (Cameron) - 27440dc linter/react/jsx-curly-brace-presence: Don't report or fix props with escape sequences and preserve raw text (#29976) (oxc-captain[bot]) - 18d6e27 linter: Escape file and rule names in checkstyle and junit reporters (#28962) (Zain Qureshi) - 9882eab linter/unicorn/prefer-bigint-literals: Provide fix for hex literals containing `e` or `E` (#29915) (overlookmotel) - 9c39045 linter/eslint/no-unneeded-ternary: Don't drop side-effecting tests in equal-literal fix (#29880) (oxc-captain[bot]) - 7261f5b linter/unicorn/prefer-logical-operator-over-ternary: Parenthesize operands that bind looser than `||` in fixer (#29882) (oxc-captain[bot]) - d4c3cbe linter/typescript/array-type: Report and fix `Readonly<T[]>` (#29841) (camc314) - 35694db linter/typescript/explicit-function-return-type: Check block-bodied arrows in returned objects (#29843) (camc314) - cf124c8 linter/typescript/prefer-as-const: Report angle-bracket literal assertions (#29839) (camc314) - 86cdc9d linter: Do not flag one export { a, b } from as duplicate (#26992) (Bartok) - 4263221 agent: Implement all_rules for --rules support (#27585) (Bartok) - 2f6a11f semantic: Keep catch parameters in the catch clause scope (#29635) (Dunqing) - f84e6b2 linter/import/extensions: Read options next to `pattern` (#29442) (Nadir Ali) - a527e7b linter: Preserve code in Jest and Vitest padding fixes (#29496) (oxc-captain[bot]) - 536e240 linter/unicorn/catch-error-name: Keep the key of a shorthand property (#28727) (YT) - f860f1b semantic: Resolve a private name to the enclosing class that declares it (#29714) (Nadir Ali) - 279185a react-compiler: Ignore ESLint suppressions when hooks and memo validations are enabled (#29655) (Boshen) - ddedec8 linter/eslint/new-cap: Allow `UTC()` only on the global `Date` (#29711) (Nadir Ali) - 709d89d linter/eslint/no-async-promise-executor: Ignore shadowed Promise (#29706) (Nadir Ali) - 90196a5 linter/eslint/radix: Only report literal and `undefined` radixes, skip spreads (#29708) (Nadir Ali) - 0fb527b linter/eslint/no-invalid-regexp: Ignore a shadowed `RegExp` (#29715) (Nadir Ali) - 60fedf9 linter/eslint/no-loss-of-precision: Ignore a `.` with no fraction digits (#29713) (Nadir Ali) - 4069cb3 linter/eslint/use-isnan: Ignore a shadowed `NaN` or `Number` (#29707) (Nadir Ali) - dd9683c linter/eslint/prefer-promise-reject-errors: Ignore a shadowed `Promise` (#29710) (Nadir Ali) - d7e12de linter/eslint/no-extra-boolean-cast: Ignore a shadowed `Boolean` (#29709) (Nadir Ali) - 1ac8a63 linter/eslint/no-obj-calls: Respect shadowed globalThis (#29705) (周星星同学) - 3464a0d linter/eslint/prefer-numeric-literals: Avoid invalid fixes for signed strings (#29703) (周星星同学) - d3af621 linter/typescript/class-literal-property-style: Only suggest readonly fields in TypeScript files (#29704) (Chung-il) - 49b935a linter/eslint/no-unneeded-ternary: Preserve boolean binary results (#29702) (周星星同学) - 3f05c06 linter/react/require-render-return: Check non-JSX render methods (#29701) (oxc-captain) - 78b6494 linter/vitest/prefer-called-times: Preserve expect head in fixes (#29699) (camc314) - f2cd3c7 linter/jest/prefer-to-contain,linter/vitest/prefer-to-contain: Offer rewrites as suggestions (#29698) (camc314) - 3398425 linter/typescript/ban-tslint-comment: Preserve line breaks in fixes (#29695) (camc314) - a0214ae linter/eslint/no-unsafe-negation: Offer rewrite as a suggestion (#29694) (camc314) - 658762e linter/eslint/no-unexpected-multiline: Recognize all line terminators (#29682) (周星星同学) - 89ad201 linter/eslint/no-compare-neg-zero: Exclude BigInt zero (#29683) (周星星同学) - 5629d00 linter/eslint/no-unsafe-finally: Report labeled continues escaping finally (#29681) (周星星同学) - 7ab52dd linter/jest/no-restricted-jest-methods,linter/vitest/no-restricted-vi-methods: Report restricted methods in call chains (#29660) (oxc-captain[bot]) - 5d2129c oxlint: Write --init errors to stderr (#29654) (oxc-captain[bot]) - a53df45 linter/eslint/no-fallthrough: Recognize all line terminators (#29676) (周星星同学) - 8270346 linter/typescript/consistent-type-definitions: Add a semicolon when code follows on the same line (#29634) (Jingbo Chai) - 132793f linter/eslint: Preserve statement boundaries in autofixes (#29633) (Jingbo Chai) ### ⚡ Performance - 2c4240a oxlint: Convert diagnostic offsets to positions with a line index (#29987) (Nicholas Rayburn) - 892f086 various: Avoid copying source text in `OxcDiagnostic::render_with_source_code` callers (#29850) (overlookmotel) - 27777a9 diagnostics: Loosen lifetime bound on `OxcDiagnostic::with_source_code` (#29849) (overlookmotel) - f43a92f linter/plugins: Match selectors without allocating ancestor arrays (#29652) (Shanon Jackson) # Oxfmt ### 💥 BREAKING CHANGES - b90b3aa ast: [**BREAKING**] Remove `base` field from `NumericLiteral` and `BigIntLiteral` (#29919) (overlookmotel) ### 🚀 Features - 42f62d6 formatter/sort_imports: Break ties for the same source by subgroup (#29817) (leaysgur) - d3af78a formatter_htmlish/angular: Support Tailwind class sorting (#29737) (leaysgur) - 0fe3d0c formatter_htmlish/angular: Format template JS expressions (#29726) (leaysgur) - ae32aed formatter_htmlish/angular: Implement printer w/o JS expressions (#29657) (leaysgur) ### 🐛 Bug Fixes - b373412 formatter_css: Preserve glued numbers (#29941) (leaysgur) - f1816d8 formatter_htmlish: Count a blank line after unclosed element (#29881) (leaysgur) - 5952610 formatter_htmlish/angular: Do not break a parent for ICU (#29874) (leaysgur) - 596c70d formatter_htmlish/angular: Break as-written block parameters (#29873) (leaysgur) - 1fb897f formatter_htmlish: Keep blank lines before borrowed `}}` when preserved (#29872) (leaysgur) - 488a9fa formatter: Break an assigned class's heritage as a class anywhere else (#29869) (leaysgur) - 7053128 formatter_markdown: Handle empty footnote (#29735) (leaysgur) - 7caf3be oxfmt: Run `WalkRunner` in `block_in_place()` to avoid hang with 1 Tokio worker (#29728) (Yuji Sugiura) ### ⚡ Performance - 892f086 various: Avoid copying source text in `OxcDiagnostic::render_with_source_code` callers (#29850) (overlookmotel) ### 📚 Documentation - c5790e2 formatter_css: Record multi-line value comment expanding its group as a divergence (#29950) (leaysgur) - a5b1405 formatter: Move open debts out of comments and add heritage items (#29870) (leaysgur) --------- Co-authored-by: Cameron <cameron.clark@hey.com>

with_source_coderequiredT: SourceCode + 'static, because it returnedError(Box<dyn Diagnostic + Send + Sync>, which is implicitly'static). So callers which only render a diagnostic on the spot had to copy the source text into an ownedStringorArc<String>first.Return
Box<dyn Diagnostic + Send + Sync + 's>instead, bounded by the lifetime of the source. When the source is'static, that is still theErrortype, so callers which need one (e.g.DiagnosticService, which sends diagnostics across threads) are unaffected.Remove the copies this made unnecessary - in the linter's rule
Tester(which copied the whole source text for every diagnostic), the coverage runner, and various tests and examples.This also allows
with_source_codeto integrate with the newSourceAPI (#29763) where source text is always a borrowed&strin the arena, not an ownedString.