Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 18, 2025

to_bytes converts a char to a series of N bytes. Add an assertion to make sure that the character is actually N bytes long.

Also, const assert the value of LOSSY_REPLACEMENT_CHAR_FIRST_BYTE, rather than just a comment stating what we expect it to be.

Copy link
Member Author


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.

@github-actions github-actions bot added A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Aug 18, 2025
@overlookmotel overlookmotel marked this pull request as ready for review August 18, 2025 14:59
Copilot AI review requested due to automatic review settings August 18, 2025 14:59
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 18, 2025

CodSpeed Instrumentation Performance Report

Merging #13193 will not alter performance

Comparing 08-18-refactor_parser_improve_safety_of_char_to_bytes_conversions (6c5f7e5) with main (7fcc51e)1

Summary

✅ 34 untouched benchmarks

Footnotes

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

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 PR enhances the safety of character-to-bytes conversions by adding compile-time assertions. The changes ensure that the to_bytes function correctly handles UTF-8 encoding and validates expected byte values for replacement characters.

  • Adds assertions to verify that characters have the expected UTF-8 byte length in to_bytes function
  • Replaces a comment with a const assertion to validate the first byte of the lossy replacement character

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_parser/src/lexer/template.rs Added assertion to verify character byte length in to_bytes function
crates/oxc_parser/src/lexer/string.rs Added assertion to to_bytes function and replaced comment with const assertion for replacement character byte value

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@overlookmotel
Copy link
Member Author

I don't think much to argue on this one (despite Copilot's best attempts). So merging without further review.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Aug 18, 2025
Copy link
Member Author

overlookmotel commented Aug 18, 2025

Merge activity

  • Aug 18, 3:14 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Aug 18, 5:44 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Aug 18, 5:49 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.

@overlookmotel overlookmotel force-pushed the 08-18-refactor_parser_improve_safety_of_char_to_bytes_conversions branch from 8cbac03 to 6c5f7e5 Compare August 18, 2025 17:22
@overlookmotel
Copy link
Member Author

Why aren't you merging this, Graphite?

@overlookmotel overlookmotel added 0-merge Merge with Graphite Merge Queue and removed 0-merge Merge with Graphite Merge Queue labels Aug 18, 2025
@overlookmotel overlookmotel merged commit b2d59a2 into main Aug 18, 2025
25 checks passed
@overlookmotel overlookmotel deleted the 08-18-refactor_parser_improve_safety_of_char_to_bytes_conversions branch August 18, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants