-
-
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
parser(refactor): promise only one Source
on a thread at a time
#2340
parser(refactor): promise only one Source
on a thread at a time
#2340
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
CodSpeed Performance ReportMerging #2340 will not alter performanceComparing Summary
|
PS: I initially wanted to use the type system to enforce this invariant, rather than making This would be possible using a "uniqueness token" type which only However, this would (by design) make it impossible to create a Or is there some way to conditionally expose an extra type/method only when running tests? Something like |
Actually, yes, this is possible. Am going to refactor to use types to enforce the invariant, rather than Changed to draft until I've done that. |
Yeah the Besides, how do we even create a test case for this one? |
0769a03
to
5dcc001
Compare
I've now refactored to enforce this invariant through the type system instead of unsafe. But have to stop for today now. I'm neglecting my day job! |
My new type system-based approach removes the unsafe. I don't think with this new approach it's possible to write tests for it, as there's just no API to do what is meant to be illegal. But that's good, right? |
I've changed this PR quite a lot since you first signed off on it @Boshen. Would you mind taking another look now? Very slight regression on the From my side at least, I'm happy with this now. Please merge it if you like it, or tell me if you don't! |
…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.
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
, onlyParserImpl
.ParserImpl
s are not created in created inParser::new
, but instead inParser::parse
, where they're created and then immediately consumed. So the end user is also free to create multipleParser
instances (if they want to for some reason) on the same thread.