Repository navigation
sourcemap: count an ill-formed UTF-8 lead byte as one byte so the line break after it is not skipped #38593
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
Closed
Closed
sourcemap: count an ill-formed UTF-8 lead byte as one byte so the line break after it is not skipped #38593
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7351fdc
sourcemap: do not skip the bytes after an ill-formed UTF-8 lead byte
robobun 34634fc
test: drain stdout of the bun build child as well
robobun 92d29b1
sourcemap: shorten the decoder comments
robobun a492bab
sourcemap: one-line decoder comments
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,27 +186,23 @@ impl LineOffsetTable { | |
| // Hoist the base pointer so per-iteration offset math is a single sub + truncate. | ||
| let base = contents.as_ptr() as usize; | ||
|
|
||
| // `CodepointIterator` is also what `LineColumnOffset::advance` and the | ||
| // generated-side walk in `Chunk.rs` use, so all three agree on what a byte | ||
| // sequence is: a lead byte whose continuation bytes are missing (Latin-1 text) | ||
| // is one U+FFFD, one byte wide, and the bytes after it (a line terminator, say) | ||
| // are looked at on their own rather than skipped as part of the width the lead | ||
| // byte declared. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| let iter = strings::CodepointIterator::init(contents); | ||
| let mut remaining = contents; | ||
| while !remaining.is_empty() { | ||
| let b0 = remaining[0]; | ||
| let len_ = strings::wtf8_byte_sequence_length_with_invalid(b0); | ||
| // After the SIMD skip below lands, the loop head | ||
| // is overwhelmingly an ASCII '\r'/'\n' or a non-ASCII lead byte, so keep the | ||
| // 1-byte path branch-only and confine the zero+copy pad to the cold | ||
| // multibyte arm. | ||
| // `len_` is the lead byte's *declared* width; a source whose final bytes are | ||
| // a truncated multibyte sequence declares more bytes than remain, so every | ||
| // slice below (decode, SIMD-skip offset, advance) must use the clamped width. | ||
| let cp_len = (len_ as usize).min(remaining.len()); | ||
| let c: i32 = if len_ == 1 { | ||
| b0 as i32 | ||
| } else { | ||
| let mut cp_bytes = [0u8; 4]; | ||
| cp_bytes[..cp_len].copy_from_slice(&remaining[..cp_len]); | ||
| strings::decode_wtf8_rune_t::<i32>(cp_bytes, len_, 0) | ||
| }; | ||
|
|
||
| let offset = (remaining.as_ptr() as usize - base) as u32; | ||
| let mut cursor = strings::Cursor { | ||
| i: offset, | ||
| ..Default::default() | ||
| }; | ||
| let _ = iter.next(&mut cursor); | ||
| let c: i32 = cursor.c; | ||
| let cp_len = cursor.width as usize; | ||
|
|
||
| if column == 0 { | ||
| line_byte_offset = offset; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code