Skip to content

fix(semantic): do not rely on spans for node comparison in Function::bind#18296

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_
Jan 21, 2026
Merged

fix(semantic): do not rely on spans for node comparison in Function::bind#18296
graphite-app[bot] merged 1 commit intomainfrom
om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jan 20, 2026

Binder for Function was using spans to check for node equality.

This is fine when the AST has come directly from the parser as spans are guaranteed to be unique, but it is not reliable when the AST has gone through transformation. If the code has been generated, it might have zeroed spans (SPAN), in which case span equality does not guarantee uniqueness.

e.g. if this code is generated:

const obj = {
  [function f() {}]: function g() {},
};

f and g both have the same span (0, 0).

Switch to using Address for comparison, which doesn't have this problem.

Copy link
Member Author

overlookmotel commented Jan 20, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 20, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ (95c9636) with main (7018888)1

Summary

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks2

Footnotes

  1. No successful run was found on main (22b4d39) during the generation of this report, so 7018888 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel marked this pull request as ready for review January 20, 2026 13:06
Copilot AI review requested due to automatic review settings January 20, 2026 13:06
@overlookmotel overlookmotel force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from 6c841fa to 463fab0 Compare January 20, 2026 13:08
@overlookmotel overlookmotel force-pushed the om/01-20-perf_semantic_single_call_to_function_bind_for_functions branch from 2f58b37 to d0f8dc7 Compare January 20, 2026 13:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug in the semantic binder where node identity comparison was using spans instead of memory addresses. The issue arises when transformed or generated AST nodes have zeroed spans (0, 0), making span-based comparison unreliable for determining node uniqueness.

Changes:

  • Replaced span-based node comparison with address-based comparison in Function::bind
  • Removed unused GetSpan import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel changed the base branch from om/01-20-perf_semantic_single_call_to_function_bind_for_functions to graphite-base/18296 January 20, 2026 13:42
@overlookmotel overlookmotel force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from 463fab0 to a4d92d3 Compare January 20, 2026 13:42
@overlookmotel overlookmotel changed the base branch from graphite-base/18296 to om/01-20-refactor_semantic_move_code_into_if_block January 20, 2026 13:42
@graphite-app graphite-app bot changed the base branch from om/01-20-refactor_semantic_move_code_into_if_block to graphite-base/18296 January 20, 2026 14:12
@graphite-app graphite-app bot force-pushed the graphite-base/18296 branch from 7853545 to 22b4d39 Compare January 20, 2026 14:15
@graphite-app graphite-app bot force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from a4d92d3 to 01e8de9 Compare January 20, 2026 14:15
@graphite-app graphite-app bot changed the base branch from graphite-base/18296 to main January 20, 2026 14:16
@graphite-app graphite-app bot force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from 01e8de9 to 95c9636 Compare January 20, 2026 14:16
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
Copy link
Member

Dunqing commented Jan 21, 2026

Merge activity

  • Jan 21, 1:10 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jan 21, 1:10 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Jan 21, 1:18 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #18292.
  • Jan 21, 1:18 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #18292.
  • Jan 21, 1:57 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jan 21, 2:05 AM UTC: Graphite rebased this pull request, because this pull request is set to merge when ready.
  • Jan 21, 2:19 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Jan 21, 2:29 AM UTC: Merged by the Graphite merge queue.

@Dunqing
Copy link
Member

Dunqing commented Jan 21, 2026

All are nice improvements! And it's not easy to find them if you don't dig into it!

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
@graphite-app graphite-app bot changed the base branch from main to graphite-base/18296 January 21, 2026 02:03
@Dunqing Dunqing force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from 95c9636 to 2b813a5 Compare January 21, 2026 02:04
@graphite-app graphite-app bot changed the base branch from graphite-base/18296 to main January 21, 2026 02:05
@graphite-app graphite-app bot force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from 2b813a5 to cd3530d Compare January 21, 2026 02:10
graphite-app bot pushed a commit that referenced this pull request Jan 21, 2026
…:bind` (#18296)

Binder for `Function` was using spans to check for node equality.

This is fine when the AST has come directly from the parser as spans are guaranteed to be unique, but it is not reliable when the AST has gone through transformation. If the code has been generated, it might have zeroed spans (`SPAN`), in which case span equality does not guarantee uniqueness.

e.g. if this code is generated:

```js
const obj = {
  [function f() {}]: function g() {},
};
```

`f` and `g` both have the same span (0, 0).

Switch to using `Address` for comparison, which doesn't have this problem.
@graphite-app graphite-app bot force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from cd3530d to 324dd7a Compare January 21, 2026 02:19
…:bind` (#18296)

Binder for `Function` was using spans to check for node equality.

This is fine when the AST has come directly from the parser as spans are guaranteed to be unique, but it is not reliable when the AST has gone through transformation. If the code has been generated, it might have zeroed spans (`SPAN`), in which case span equality does not guarantee uniqueness.

e.g. if this code is generated:

```js
const obj = {
  [function f() {}]: function g() {},
};
```

`f` and `g` both have the same span (0, 0).

Switch to using `Address` for comparison, which doesn't have this problem.
@graphite-app graphite-app bot force-pushed the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch from 324dd7a to 9a15c6a Compare January 21, 2026 02:22
@graphite-app graphite-app bot merged commit 9a15c6a into main Jan 21, 2026
21 checks passed
@graphite-app graphite-app bot deleted the om/01-20-fix_semantic_do_not_rely_on_spans_for_node_comparison_in_function_bind_ branch January 21, 2026 02:29
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
overlookmotel pushed a commit that referenced this pull request Jan 26, 2026
### 💥 BREAKING CHANGES

- 22dec6a semantic: [**BREAKING**] Remove
`Scoping::scope_build_child_ids` and all related APIs (#18362) (Dunqing)
- 30a4899 oxc: [**BREAKING**] Remove
`CompilerInterface::semantic_child_scope_ids` (#18361) (Dunqing)
- 777fc40 ast: [**BREAKING**] Add `Ident` type (#18354) (Boshen)
- af0ca46 span: [**BREAKING**] Use `ModuleKind::CommonJS` for
`SourceType::cjs()` (#18276) (sapphi-red)

### 🚀 Features

- 0a02026 semantic: Add TS1499 code to diagnostic (#18557) (camc314)
- 8b4618f parser: Add TS1500 code to diagnostic (#18547) (camc314)
- 866b6b3 parser: Add TS1048 code to diagnostic (#18546) (camc314)
- 1117c44 parser: Add TS1054 code to diagnostic (#18541) (camc314)
- e4fcdde semantic: Add TS1053 code to diagnostic (#18539) (camc314)
- bcbf396 semantic: Add TS1052 code to diagnostic (#18538) (camc314)
- 8155edf semantic: Add TS1049 code to diagnostic (#18535) (camc314)
- 51d3b3f parser: Add TS1502 code to diagnostic (#18534) (camc314)
- 00854e8 semantic: Add TS2337 error code to super call diagnostic
(#18531) (camc314)
- 993fd2b parser: Parse unambiguous await with better error messages
(#18480) (Boshen)
- 8db0e78 linter/plugins: Handle BOMs (#18376) (overlookmotel)
- 6ac09e2 linter/plugins: Support source text not being at start of
buffer (#18375) (overlookmotel)
- 2ef5647 ast: Add escape_raw parameter to template_element builders
(#18121) (Boshen)

### 🐛 Bug Fixes

- 74d0998 semantic: Update error msg for multiple `default` cases in
switch stmt (#18526) (camc314)
- c205b0d ast: Remove `ThisExpression` from `TSModuleReference` (#18489)
(Boshen)
- aed3669 parser: Parse HTML-like comments in unambiguous mode (#18442)
(Boshen)
- c4132fb parser: Validate accessor parameters in interface method
signatures (#18391) (Boshen)
- b0cd74d semantic: Allow `var` and `function` with same name in static
blocks (#18358) (Boshen)
- 6037995 semantic: Allow `new.target` in class field initializers
(#18349) (Boshen)
- 9a15c6a semantic: Do not rely on spans for node comparison in
`Function::bind` (#18296) (overlookmotel)

### ⚡ Performance

- 6b600c4 semantic: Skip parent lookup for function declarations in
`Function::bind` (#18293) (overlookmotel)
- c27ad2d semantic: Move check for function declaration out of
`is_function_part_of_if_statement` (#18292) (overlookmotel)
- 63eb89e semantic: Skip checking redeclarations for function
expressions (#18291) (overlookmotel)
- 7c12743 semantic: Skip checking unresolved exports in CommonJS files
(#18250) (overlookmotel)
- 2349031 allocator: Increase initial chunk size from 512B to 16KB
(#18234) (Boshen)

### 📚 Documentation

- 8ccd853 npm: Update package homepage URLs and add keywords (#18509)
(Boshen)
- 9b3165f napi/parser: Clarify when to use `parseAsync` vs `parseSync`
(#18486) (Boshen)
- 1b59f63 napi/parser: Correct typo in README (#18251) (overlookmotel)
- 00ff75f mangler: Fix `top_level` option in example (#18233)
(overlookmotel)
- 2ddc073 semantic: Fix typo in comment (#18238) (overlookmotel)

Co-authored-by: Boshen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments