-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Consider using parser gem across all Ruby versions #522
Comments
I have to admit Supporting two parsers is an unfortunate complication that was introduced in v0.39.0 for performance reasons. I continued supporting Side note: I've also considered the possibility of going |
Makes sense. I wasn't aware of the performance tradeoff that you were facing. I'll just manually call parser gem to keep the code simple, and think about transitioning to RubyVM AST code. Should I close the issue? |
Yeah, this should be okay to close for now. If you think of another approach that might allow us to maintain a single parser with minimal impact to performance, please feel free to open a new issue. |
As a note, So IMHO it's a mistake for any gem to use I do sympathize with the wish to parse faster. |
You could use https://github.com/ruby-syntax-tree/syntax_tree if you wanted for this. It's just one layer on top of ripper, so it gets the benefits of the fast parser without an experimental/unstable API. It also is supported on other Ruby runtimes like JRuby/TruffleRuby because they also ship a ripper implementation. I would be more than happy to pair on/help with any migration if you wanted to experiment with it. |
With the new parser I'm writing, I plan on building Syntax Tree nodes directly from the parser, so it should end up being the fastest and most stable option around. |
- Should improve the performance (castwide/solargraph#522 (comment)) - Reuse existing AST tree from solargraph and avoid redundant parsing - Required for making type inference work Squashed commit of the following: commit 42f0ace Author: Lekë Mula <[email protected]> Date: Sun May 19 20:59:02 2024 +0200 Remove redundant code Parsing commit 35ca92f Author: Lekë Mula <[email protected]> Date: Sun May 19 20:47:35 2024 +0200 Suppress SyntaxError from RubyVM in SpecWalker commit 99a4736 Author: Lekë Mula <[email protected]> Date: Sun May 19 19:57:25 2024 +0200 Refactor specs and add more unhappy paths commit f33e74e Author: Lekë Mula <[email protected]> Date: Sun May 19 19:39:39 2024 +0200 Refactor SpecWalker - extract sub-classes into own files commit daf2cd6 Author: Lekë Mula <[email protected]> Date: Sun May 19 19:32:04 2024 +0200 Rename RubyVMSpecWalker to SpecWalker commit 555ad9d Author: Lekë Mula <[email protected]> Date: Sun May 19 19:23:05 2024 +0200 Replace Util with PinFactory commit e55ce29 Author: Lekë Mula <[email protected]> Date: Sun May 19 18:35:29 2024 +0200 Don't pass AST nodes into correctors commit 102ac76 Author: Lekë Mula <[email protected]> Date: Sun May 19 18:13:30 2024 +0200 Remove old SpecWalker commit 3235e89 Author: Lekë Mula <[email protected]> Date: Sun May 19 18:10:04 2024 +0200 Adapt ExampleAndHookBlocksBindingCorrector with RubyVM commit e359861 Author: Lekë Mula <[email protected]> Date: Sun May 19 17:44:23 2024 +0200 Adapt SubjectMethodCorrector with RubyVM commit cddb93f Author: Lekë Mula <[email protected]> Date: Sun May 19 17:19:15 2024 +0200 Adapt LetMethodsCorrector with RubyVM commit 541f4df Author: Lekë Mula <[email protected]> Date: Sun May 19 16:43:15 2024 +0200 Adapt DescribedClassCorrector with RubyVM commit 66ff1ca Author: Lekë Mula <[email protected]> Date: Sun May 19 15:53:20 2024 +0200 Adapt ContextBlockNamespaceCorrector with RubyVM commit f5e6046 Author: Lekë Mula <[email protected]> Date: Thu May 16 17:56:02 2024 +0200 Implement RubyVMSpecWalker#on_described_class Last one for REAL! commit 982914b Author: Lekë Mula <[email protected]> Date: Thu May 16 17:38:35 2024 +0200 Implement RubyVMSpecWalker#on_blocks_in_examples Last hook! commit 080f9e6 Author: Lekë Mula <[email protected]> Date: Thu May 16 17:22:05 2024 +0200 Implement RubyVMSpecWalker#on_hook_block commit 4e8e662 Author: Lekë Mula <[email protected]> Date: Thu May 16 16:57:16 2024 +0200 Implement RubyVMSpecWalker#on_example_block commit badd097 Author: Lekë Mula <[email protected]> Date: Thu May 16 16:34:32 2024 +0200 Implement RubyVMSpecWalker#on_let_method commit 74ba354 Author: Lekë Mula <[email protected]> Date: Thu May 16 16:10:40 2024 +0200 Implement RubyVMSpecWalker#on_subject commit e264bd1 Author: Lekë Mula <[email protected]> Date: Thu May 16 15:18:40 2024 +0200 Implement RubyVMSpecWalker#on_each_context_block commit f8a4d6a Author: Lekë Mula <[email protected]> Date: Thu May 16 11:50:13 2024 +0200 Add walker specs
Problem
Solagraph uses
RubyVM::AbstractSyntaxTree
when it's available. When not, it's using the parser gem. This creates friction if a solargraph plugin wants to support different Ruby versions, because:This leads to the fact that if I have code that uses
source_map#node
, like for extracting methods fromdb/schema.rb
, I have to have 2 implementations depending on Ruby version https://github.com/alisnic/solar-rails/blob/master/lib/solar-rails/schema.rb#L66.Solution
Proposed solution is to use parser gem across all ruby versions, especially since Ruby's own AST docs stipulate that it's not stable:
https://docs.ruby-lang.org/en/master/RubyVM/AbstractSyntaxTree.html
The text was updated successfully, but these errors were encountered: