From 9e423b9b73e66228cb268813419db0a6287e13de Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 24 Sep 2026 17:22:09 -0700 Subject: [PATCH] Narrow constant discovery in the AASM and ActiveRecordRelations compilers Compiler#descendants_of, #all_classes, and #all_modules short-circuit to @@requested_constants when any are requested, but Pipeline#gather_constants merges every compiler's processable_constants before intersecting with the requested set. So the narrowing only applies to compilers that route through those helpers. These two did not. ActiveRecordRelations called ActiveRecord::Base.descendants directly, the only ActiveRecord::Base compiler to do so; the other three use descendants_of(::ActiveRecord::Base).reject(&:abstract_class?). AASM walked ObjectSpace.each_object(::AASM::ClassMethods) directly, where all_classes.grep(mod) is the established equivalent. grep applies mod === obj, the same test each_object(mod) applies, so the gathered set is unchanged. Restricting to classes is safe because AASM::ClassMethods is only extended into classes and Pipeline#run already drops non-modules. --- lib/tapioca/dsl/compilers/aasm.rb | 2 +- lib/tapioca/dsl/compilers/active_record_relations.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tapioca/dsl/compilers/aasm.rb b/lib/tapioca/dsl/compilers/aasm.rb index 87082a4f1..4bd65c3ef 100644 --- a/lib/tapioca/dsl/compilers/aasm.rb +++ b/lib/tapioca/dsl/compilers/aasm.rb @@ -211,7 +211,7 @@ class << self # @override #: -> Enumerable[Module[top]] def gather_constants - T.cast(ObjectSpace.each_object(::AASM::ClassMethods), T::Enumerable[T::Module[T.anything]]) + all_classes.grep(::AASM::ClassMethods) end end end diff --git a/lib/tapioca/dsl/compilers/active_record_relations.rb b/lib/tapioca/dsl/compilers/active_record_relations.rb index 1dea3adb7..da0bb8eaa 100644 --- a/lib/tapioca/dsl/compilers/active_record_relations.rb +++ b/lib/tapioca/dsl/compilers/active_record_relations.rb @@ -183,7 +183,7 @@ class << self # @override #: -> Enumerable[Module[top]] def gather_constants - ActiveRecord::Base.descendants.reject(&:abstract_class?) + descendants_of(::ActiveRecord::Base).reject(&:abstract_class?) end end