-
-
Notifications
You must be signed in to change notification settings - Fork 454
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): make Source::set_position
safe
#2341
Merged
Boshen
merged 1 commit into
main
from
02-07-refactor_parser_make_Source_set_position_safe
Feb 8, 2024
Merged
refactor(parser): make Source::set_position
safe
#2341
Boshen
merged 1 commit into
main
from
02-07-refactor_parser_make_Source_set_position_safe
Feb 8, 2024
Conversation
This file contains 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 was referenced Feb 7, 2024
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
CodSpeed Performance ReportMerging #2341 will not alter performanceComparing Summary
|
My first foray into Graphite. Is this roughly how you like it to be used? Did I split the change into too many PRs? Or too few? |
Boshen
pushed a commit
that referenced
this pull request
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](https://github.com/oxc-project/oxc/pull/2339/files#diff-8e59dfd35fc50b6ac9a9ccd991e25c8b5d30826e006d565a2e01f3d15dc5f7cb). The rest of the diff is basically replacing `Parser` with `ParserImpl` everywhere else.
Boshen
approved these changes
Feb 7, 2024
overlookmotel
force-pushed
the
02-07-parser_refactor_promise_only_one_on_a_thread_at_a_time
branch
from
February 7, 2024 15:35
0769a03
to
5dcc001
Compare
overlookmotel
force-pushed
the
02-07-refactor_parser_make_Source_set_position_safe
branch
from
February 7, 2024 17:44
fee4da9
to
9789eac
Compare
Base automatically changed from
02-07-parser_refactor_promise_only_one_on_a_thread_at_a_time
to
main
February 8, 2024 06:51
Boshen
pushed a commit
that referenced
this pull request
Feb 8, 2024
) Introduce invariant that only a single `lexer::Source` can exist on a thread at one time. This is a preparatory step for #2341. 2 notes: Restriction is only 1 x `ParserImpl` / `Lexer` / `Source` on 1 *thread* at a time, not globally. So this does not prevent parsing multiple files simultaneously on different threads. Restriction does not apply to public type `Parser`, only `ParserImpl`. `ParserImpl`s are not created in created in `Parser::new`, but instead in `Parser::parse`, where they're created and then immediately consumed. So the end user is also free to create multiple `Parser` instances (if they want to for some reason) on the same thread.
Boshen
force-pushed
the
02-07-refactor_parser_make_Source_set_position_safe
branch
from
February 8, 2024 06:51
9789eac
to
66c6e8e
Compare
Boshen
deleted the
02-07-refactor_parser_make_Source_set_position_safe
branch
February 8, 2024 06:56
Thanks Boshen! |
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
…c-project#2340) Introduce invariant that only a single `lexer::Source` can exist on a thread at one time. This is a preparatory step for oxc-project#2341. 2 notes: Restriction is only 1 x `ParserImpl` / `Lexer` / `Source` on 1 *thread* at a time, not globally. So this does not prevent parsing multiple files simultaneously on different threads. Restriction does not apply to public type `Parser`, only `ParserImpl`. `ParserImpl`s are not created in created in `Parser::new`, but instead in `Parser::parse`, where they're created and then immediately consumed. So the end user is also free to create multiple `Parser` instances (if they want to for some reason) on the same thread.
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
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.
Make
Source::set_position
a safe function.This addresses a shortcoming of #2288.
Instead of requiring caller of
Source::set_position
to guarantee that theSourcePosition
is created from thisSource
, 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 thanchar
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 oneSource
", when to the developer, this is blindingly obvious anyway.So, while splitting the parser into
Parser
andParserImpl
(#2339) is an annoying change to have to make, I believe the benefit of this PR justifies it.