Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure greatest_lower_bound returns lowest match index #60

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

jridgewell
Copy link
Contributor

When we switched to Rust's binary_search_by_key, we accidentally changed the behavior when a token matches exactly. Before, we were guaranteed to always return the lowest index because we didn't stop iterating when we found a match. Now, we exit as soon as we find a match, which can be any matching based on the size of the slice.

Fixes swc-project/swc#6973

When we switched to Rust's `binary_search_by_key`, we accidentally changed the behavior when a token matches exactly. Before, we were guaranteed to always return the lowest index because we didn't stop iterating when we found a match. Now, we exit as soon as we find a match, which can be any matching based on the size of the slice.

Fixes swc-project/swc#6973
Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

Ah, the tests make the behavior very clear, thanks.
The rust std says the following:

If there are multiple matches, then any one of the matches could be returned. The index is chosen deterministically, but is subject to change in future versions of Rust.

What we want is, we always want the lowest element if multiple matches exist.

src/utils.rs Outdated Show resolved Hide resolved
Co-authored-by: Arpad Borsos <swatinem@swatinem.de>
@kamilogorek
Copy link
Contributor

Shall we merge and cut 6.2.2 to unblock swc-project/swc#6973 merge?

@Swatinem Swatinem merged commit b8c94ce into getsentry:master Feb 24, 2023
@jridgewell jridgewell deleted the glb branch February 24, 2023 17:15
kwonoj added a commit to vercel/turborepo that referenced this pull request Mar 24, 2024
### Description

While debugging
https://vercel.slack.com/archives/C03EWR7LGEN/p1711146825831219?thread_ts=1711143217.892349&cid=C03EWR7LGEN,
found out sourcemap lookup fails on certain source and always returns
synthetictoken only.

Weirdly, the guards in this PR
https://github.com/vercel/turbo/pull/7823/files#diff-2ce67e28c5b3144ec6f7a89167f3c96da9f9e268abf3fd685ce881d75a4cd8a5L319
is preventing those lookup - removing it makes correct sourcemap lookup
occurs. I updated pkg to the version what swc uses and removed + ran
next.js tests, seems like most of tests are running just fine

(vercel/next.js#63624)

Still not 100% sure if this'll be ok or not, if not open to change for
the correct fixes. Some related fixes
getsentry/rust-sourcemap#60 might be the reason
we don't see any regressions in the test.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
### Description

While debugging
https://vercel.slack.com/archives/C03EWR7LGEN/p1711146825831219?thread_ts=1711143217.892349&cid=C03EWR7LGEN,
found out sourcemap lookup fails on certain source and always returns
synthetictoken only.

Weirdly, the guards in this PR
https://github.com/vercel/turbo/pull/7823/files#diff-2ce67e28c5b3144ec6f7a89167f3c96da9f9e268abf3fd685ce881d75a4cd8a5L319
is preventing those lookup - removing it makes correct sourcemap lookup
occurs. I updated pkg to the version what swc uses and removed + ran
next.js tests, seems like most of tests are running just fine

(#63624)

Still not 100% sure if this'll be ok or not, if not open to change for
the correct fixes. Some related fixes
getsentry/rust-sourcemap#60 might be the reason
we don't see any regressions in the test.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

While debugging
https://vercel.slack.com/archives/C03EWR7LGEN/p1711146825831219?thread_ts=1711143217.892349&cid=C03EWR7LGEN,
found out sourcemap lookup fails on certain source and always returns
synthetictoken only.

Weirdly, the guards in this PR
https://github.com/vercel/turbo/pull/7823/files#diff-2ce67e28c5b3144ec6f7a89167f3c96da9f9e268abf3fd685ce881d75a4cd8a5L319
is preventing those lookup - removing it makes correct sourcemap lookup
occurs. I updated pkg to the version what swc uses and removed + ran
next.js tests, seems like most of tests are running just fine

(#63624)

Still not 100% sure if this'll be ok or not, if not open to change for
the correct fixes. Some related fixes
getsentry/rust-sourcemap#60 might be the reason
we don't see any regressions in the test.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

While debugging
https://vercel.slack.com/archives/C03EWR7LGEN/p1711146825831219?thread_ts=1711143217.892349&cid=C03EWR7LGEN,
found out sourcemap lookup fails on certain source and always returns
synthetictoken only.

Weirdly, the guards in this PR
https://github.com/vercel/turbo/pull/7823/files#diff-2ce67e28c5b3144ec6f7a89167f3c96da9f9e268abf3fd685ce881d75a4cd8a5L319
is preventing those lookup - removing it makes correct sourcemap lookup
occurs. I updated pkg to the version what swc uses and removed + ran
next.js tests, seems like most of tests are running just fine

(#63624)

Still not 100% sure if this'll be ok or not, if not open to change for
the correct fixes. Some related fixes
getsentry/rust-sourcemap#60 might be the reason
we don't see any regressions in the test.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

While debugging
https://vercel.slack.com/archives/C03EWR7LGEN/p1711146825831219?thread_ts=1711143217.892349&cid=C03EWR7LGEN,
found out sourcemap lookup fails on certain source and always returns
synthetictoken only.

Weirdly, the guards in this PR
https://github.com/vercel/turbo/pull/7823/files#diff-2ce67e28c5b3144ec6f7a89167f3c96da9f9e268abf3fd685ce881d75a4cd8a5L319
is preventing those lookup - removing it makes correct sourcemap lookup
occurs. I updated pkg to the version what swc uses and removed + ran
next.js tests, seems like most of tests are running just fine

(#63624)

Still not 100% sure if this'll be ok or not, if not open to change for
the correct fixes. Some related fixes
getsentry/rust-sourcemap#60 might be the reason
we don't see any regressions in the test.
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.

3 participants