-
Notifications
You must be signed in to change notification settings - Fork 120
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
Iterate over requested_constants in DSL helpers #1989
Conversation
lib/tapioca/dsl/compiler.rb
Outdated
@@ -25,6 +25,8 @@ class Compiler | |||
sig { returns(T::Hash[String, T.untyped]) } | |||
attr_reader :options | |||
|
|||
@@requested_constants = T.let([], T::Array[Module]) |
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.
Open to suggestions on avoiding the class variable. We want this to be set on the subclasses of Compiler
which end up calling the helper methods, descendants_of
or all_classes
.
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.
This sketches me out a little, but there's a really really nice benefit to this approach: all the existing DSL Compilers will mostly just work, without needing to be updated.
What if we loosened that constraint: could we make a better API if we were willing to change the compilers?
e.g. what if the main module selection was done by something like:
sig { abstract.params(candidates: T::Enumerable[Module]).returns(T::Enumerable[Module]) }
def select_constants_to_decorate(candidates)
This would replace gather_constants
. By default, we would call it with select_constants_to_decorate(all_modules)
(which would work similar to how gather_constants works in practice today), otherwise we could do select_constants_to_decorate(requested_constants)
.
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.
Hmm, I personally don't think it's worth it just for avoiding class variables because it's a public API. I'd be happy to change default compilers inside tapioca but external ones worry me. We'd have to deprecate old usages and make everyone change their compilers eventually. Or we could have logic for both but the performance benefit would be disabled for old API which also adds maintenance complexity for us.
16c67de
to
c50d494
Compare
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.
Here's my $0.02!
lib/tapioca/dsl/compiler.rb
Outdated
@@ -25,6 +25,8 @@ class Compiler | |||
sig { returns(T::Hash[String, T.untyped]) } | |||
attr_reader :options | |||
|
|||
@@requested_constants = T.let([], T::Array[Module]) |
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.
This sketches me out a little, but there's a really really nice benefit to this approach: all the existing DSL Compilers will mostly just work, without needing to be updated.
What if we loosened that constraint: could we make a better API if we were willing to change the compilers?
e.g. what if the main module selection was done by something like:
sig { abstract.params(candidates: T::Enumerable[Module]).returns(T::Enumerable[Module]) }
def select_constants_to_decorate(candidates)
This would replace gather_constants
. By default, we would call it with select_constants_to_decorate(all_modules)
(which would work similar to how gather_constants works in practice today), otherwise we could do select_constants_to_decorate(requested_constants)
.
/shipit |
c50d494
to
547b5ac
Compare
@@ -25,6 +25,8 @@ class Compiler | |||
sig { returns(T::Hash[String, T.untyped]) } | |||
attr_reader :options | |||
|
|||
@@requested_constants = T.let([], T::Array[Module]) # rubocop:disable Style/ClassVars |
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.
Discussion: #1989 (comment)
Motivation
Speedup gather_constants performance when a constant is supplied by not iterating over the ObjectSpace. This PR shouldn't change the functionality because we intersect the constants received from the ObjectSpace iteration with the requested ones
tapioca/lib/tapioca/dsl/pipeline.rb
Line 156 in df6e272
Running
tapioca dsl Constant
before and after in the monolith:Implementation
Tests
Most of the tests in the dsl_spec supply arguments to
tapioca dsl
command.