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

Draft: Quick and dirty node counting in the parser #6083

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DavidHancu
Copy link

This is a quick and dirty implementation for counting nodes in the parser instead of a separate oxc_semantic pass. Currently, this draft PR is not in a production-ready state, introducing printing statements in the AST builder to debug the node incrementing and reconciliation.

The debugging statements have this form:

<function>: nodes<++|~~>

  • The <function> tag represents the function name in the builder.
  • If the node count is being incremented, nodes will be followed by ++.
  • If the node count is not being incremented (being synced due to the parser rewinding or throwing tokens away), nodes will be followed by ~~ indicating a reconciliation.

Copy link

graphite-app bot commented Sep 26, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added A-parser Area - Parser A-semantic Area - Semantic A-ast Area - AST A-codegen Area - Code Generation A-isolated-declarations Isolated Declarations A-ast-tools Area - AST tools labels Sep 26, 2024
@overlookmotel
Copy link
Collaborator

overlookmotel commented Oct 1, 2024

I've had a look. It's quite hard to see what's going on in this PR as there seem to be a bunch of unrelated changes (related to comments in codegen, and stuff to do with isolated declarations). Has something gone wrong while updating the PR to sit on top of latest main?

But a few comments based on what I can see:

  1. I don't think Stats should need to be passed in to Parser::new. Instead, parser can generate a Stats object internally, and return it as a property of ParserReturn.
  2. I don't think it's necessary for Stats's fields to be Cells. In parser, it can be owned by AstBuilder. AstBuilder is owned by ParserImpl, which parser methods receive as &mut self. So AstBuilder's methods can require a &mut self and then mutate Stats's fields without using Cell.
  3. AstBuilder will have to cease to be Clone and Copy, as it's now stateful.
  4. Stats can be Copy. It's only 16 bytes.

We have made some improvements to the transformer since you submitted this PR. The transformer now only holds a single instance of AstBuilder (#6209). This should enable AstBuilder being stateful (without Cells) in the transformer too now.

I know you're busy, so if you don't have time for this, please feel free to say so and I can take this over when I have time. But if you would have time to at least clean up (what I assume is) extraneous changes which have got in via some git accident, that'd be a big help - you know better than me what changes were intentional, and which accidental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area - AST A-ast-tools Area - AST tools A-codegen Area - Code Generation A-isolated-declarations Isolated Declarations A-parser Area - Parser A-semantic Area - Semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants