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

refactor(parser): wrapper type for parser #2339

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Feb 7, 2024

Split parser into public interface Parser and internal implementation ParserImpl.

This involves no changes to public API.

This change is a bit annoying, but justification is that it's required for #2341, which I believe to be very worthwhile.

The ParserOptions type also makes it a bit clearer what the defaults for allow_return_outside_function and preserve_parens are. It came as a surprise to me that preserve_parens defaults to true, and this refactor makes that a bit more obvious when reading the code.

All the real changes are in oxc_parser/src/lib.rs. The rest of the diff is basically replacing Parser with ParserImpl everywhere else.

@overlookmotel
Copy link
Contributor Author

overlookmotel commented Feb 7, 2024

Copy link

codspeed-hq bot commented Feb 7, 2024

CodSpeed Performance Report

Merging #2339 will not alter performance

Comparing 02-07-refactor_parser_wrapper_type_for_parser (72cf7e2) with main (3268d7d)

Summary

✅ 27 untouched benchmarks

@Boshen Boshen merged commit 0bdecb5 into main Feb 7, 2024
22 checks passed
@Boshen Boshen deleted the 02-07-refactor_parser_wrapper_type_for_parser branch February 7, 2024 15:22
Boshen pushed a commit that referenced this pull request Feb 8, 2024
Make `Source::set_position` a safe function.

This addresses a shortcoming of #2288.

Instead of requiring caller of `Source::set_position` to guarantee that the `SourcePosition` is created from this `Source`, the preceding PRs enforce this guarantee at the type level.

`Source::set_position` is going to be a central API for transitioning the lexer to processing the source as bytes, rather than `char`s (and the anticipated speed-ups that will produce). So making this method safe will remove the need for a *lot* of unsafe code blocks, and boilerplate comments promising "SAFETY: There's only one `Source`", when to the developer, this is blindingly obvious anyway.

So, while splitting the parser into `Parser` and `ParserImpl` (#2339) is an annoying change to have to make, I believe the benefit of this PR justifies it.
IWANABETHATGUY pushed a commit to IWANABETHATGUY/oxc that referenced this pull request May 29, 2024
Split parser into public interface `Parser` and internal implementation `ParserImpl`.

This involves no changes to public API.

This change is a bit annoying, but justification is that it's required for oxc-project#2341, which I believe to be very worthwhile.

The `ParserOptions` type also makes it a bit clearer what the defaults for `allow_return_outside_function` and `preserve_parens` are. It came as a surprise to me that `preserve_parens` defaults to `true`, and this refactor makes that a bit more obvious when reading the code.

All the real changes are in [oxc_parser/src/lib.rs](https://github.com/oxc-project/oxc/pull/2339/files#diff-8e59dfd35fc50b6ac9a9ccd991e25c8b5d30826e006d565a2e01f3d15dc5f7cb). The rest of the diff is basically replacing `Parser` with `ParserImpl` everywhere else.
IWANABETHATGUY pushed a commit to IWANABETHATGUY/oxc that referenced this pull request May 29, 2024
Make `Source::set_position` a safe function.

This addresses a shortcoming of oxc-project#2288.

Instead of requiring caller of `Source::set_position` to guarantee that the `SourcePosition` is created from this `Source`, the preceding PRs enforce this guarantee at the type level.

`Source::set_position` is going to be a central API for transitioning the lexer to processing the source as bytes, rather than `char`s (and the anticipated speed-ups that will produce). So making this method safe will remove the need for a *lot* of unsafe code blocks, and boilerplate comments promising "SAFETY: There's only one `Source`", when to the developer, this is blindingly obvious anyway.

So, while splitting the parser into `Parser` and `ParserImpl` (oxc-project#2339) is an annoying change to have to make, I believe the benefit of this PR justifies it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area - Parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants