-
Notifications
You must be signed in to change notification settings - Fork 122
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
Use Prism to determine valid names #2060
Conversation
e62913d
to
04233fd
Compare
op == :definemethod && arg == name.to_sym | ||
rescue SyntaxError | ||
false | ||
# Special case: Prism supports parsing `def @foo; end`, but the Sorbet parser doesn't. This condition can go away |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prism supports parsing
def @foo; end
Is that a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if Prism should be rejecting this syntax or not. @kddnewton thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's definitely a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# once Sorbet is using Prism under the hood as it will no longer result in an RBI that Sorbet can't parse | ||
return false if name.start_with?("@") | ||
|
||
result = Prism.parse("def #{name}(a); end") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not test Prism.parse("def self.#{name}(a); end")
instead? I think it would address both the @foo
concern and the self.foo
one with just the parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, great idea #2062.
Motivation
While hunting for memory optimizations, I noticed that a lot of memory was being retained by
RubyVM::InstructionSequence
. The only place in Tapioca where we use this is to determine if method or parameter names are valid to avoid generating incorrect RBIs.We can ditch this internal API and rely on Prism to achieve the same, which won't retain memory and is actually faster.
Implementation
Switched to using Prism for determining if a method/parameter name is valid. I benchmarked the current approach vs the one on this branch and these were the results:
Tests
Current tests should cover it.