-
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 our internal RBI backend for DSL generators #388
Conversation
def decorate(root, constant) | ||
return if constant.state_machines.empty? | ||
|
||
root.path(constant) do |klass| | ||
root.create_path(T.unsafe(constant)) do |klass| |
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.
Tree#create_path
expects a Module
but we get a StateMachines::ClassMethods
for argument constant
which doesn't seem to be a module.
One notable problem here is that the redefinition of decorate
does not follow Liskov substitution principle. We do some shady thing (https://github.com/Shopify/tapioca/blob/master/lib/tapioca/compilers/dsl/base.rb#L28-L36) to avoid detection but this is weird design.
We should refactor this part to offer a correct/safe interface.
|
||
sig { params(node: Node).returns(Node) } | ||
def create_node(node) | ||
cached = nodes_cache[node.to_s] |
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.
To avoid recreating the scopes between two generators, if we already created it in a previous generator we return it and append to it.
spec/tapioca/cli_spec.rb
Outdated
@@ -451,47 +452,50 @@ def title=(title); end | |||
assert_path_exists("#{outdir}/namespace/comment.rbi") | |||
refute_path_exists("#{outdir}/user.rbi") | |||
|
|||
assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/baz/role.rbi")) | |||
assert_equal(<<~CONTENTS, File.read("#{outdir}/baz/role.rbi")) |
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.
No need to chomp
since this PR fixes #346.
class Conversation | ||
include EnumMethodsModule | ||
|
||
sig { returns(T::Hash[T.any(String, Symbol), Integer]) } |
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.
Like for gem RBIs, all methods are sorted before the subconstants
class Cart | ||
sig { params(customer_id: Integer, shop_id: Integer).void } |
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.
Like in gems RBIs, initialize
methods are always sorted first.
@@ -268,10 +268,10 @@ def to_bar; end | |||
|
|||
class String | |||
include ::Comparable | |||
include ::JSON::Ext::Generator::GeneratorMethods::String |
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 order changes because we removed Parlour has a dependency.
include ::ActionDispatch::Routing::UrlFor | ||
include ::ActionDispatch::Routing::PolymorphicRoutes |
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.
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.
Nice! Thankfully, the order didn't matter here.
|
||
class ActionDispatch::IntegrationTest | ||
include GeneratedUrlHelpersModule | ||
include GeneratedPathHelpersModule |
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.
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.
Great speedup 🏃
class Conversation | ||
include EnumMethodsModule | ||
|
||
sig { returns(T::Hash[T.any(String, Symbol), Integer]) } | ||
def self.statuses; 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.
Usage of both class << self
and def self.
in the RBIs is inconsistent. Do we prefer it over sticking with def self.
everywhere?
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 planning to make this configurable in a follow up.
My thinking is to always create them as def self.foo
then let the use decide if they should be printed as such or inside a class << self
.
For now I aimed at the smaller possible diff in generated files.
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.
Looks great! I just have one question.
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
…elf block Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Pushed a few changed:
|
Motivation
Use our RBI generation framework instead of
Parlour
.Implementation
Added a
RBI::Builder
to make an interface compatible with our current generators and minimize the diffs.Tests
See automated tests.
This was also tested by regenerating all Core DSL RBIs with success. Typecheking is passing and diff is minimal.
One interesting side effect is the time required to generate all the RBIs:
Fixes #346.