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 $.compilation_unit, optimize grammar #269

Merged
merged 1 commit into from
May 30, 2023

Conversation

susliko
Copy link
Collaborator

@susliko susliko commented May 29, 2023

Summary

$.compilation_unit is now a sequence of top-level statements separated by $.semicolon

This change has two effects:

@susliko
Copy link
Collaborator Author

susliko commented May 29, 2023

I've tested the hypothesis: this change makes it straightforward to allow top-level expressions (while still passing all test suites)

@susliko susliko force-pushed the refactor-compilation-unit branch from cfc5fe7 to 4b2cbc2 Compare May 29, 2023 22:20
Summary
-------
`$.compilation_unit` is now a sequence of top-level stats separated by
`$.semicolon`

This change has two effects:
- Grammar optimization:
  - ~10% faster generation time
  - lower number of parser states ([before](https://gist.github.com/susliko/f950b997a98c54bbfd88969a949346fd), [after](https://gist.github.com/susliko/236a85dce46219c5868c494d7f5cf629))
  - parser size reduction from 43M to 36M
- It seems to me, that handling `$._automatic_semicolon` on the top level is a
  prerequisite to support top-level expressions (tree-sitter#198) and leading infix operators (tree-sitter#141)
@@ -3,9 +3,9 @@
# This is an integration test to generally check the quality of parsing.

SCALA_SCALA_LIBRARY_EXPECTED=95
SCALA_SCALA_COMPILER_EXPECTED=87
SCALA_SCALA_COMPILER_EXPECTED=86
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a degradation in a single file:

StdAttachments.scala#L214 5 ms (ERROR [213, 13] - [214, 5]), which is minimized to

package x

trait A {
  self: A =>
  import a._
}

trait B {
  self: B =>

  class A() 
  val x = 1
}

It seams feasible to me to investigate the issue individually after this PR gets merged

@susliko
Copy link
Collaborator Author

susliko commented May 29, 2023

PR is ready for review!

cc @eed3si9n @ckipp01 @keynmol

Copy link
Collaborator

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see reduction in complexity. Looking forward to the further changes enabled by this.

Copy link
Collaborator

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @susliko, thanks!

@ckipp01 ckipp01 merged commit fad8ec3 into tree-sitter:master May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants