From d368c8c12d4c0d0f556cefd65e368c6756b206e3 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Fri, 23 Jan 2026 15:09:43 -0500 Subject: [PATCH 1/2] Bootstrap gem symbols from Rubydex graph Signed-off-by: Alexandre Terrasa --- lib/tapioca/gem/pipeline.rb | 14 ++++---------- lib/tapioca/static/symbol_loader.rb | 8 ++------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/tapioca/gem/pipeline.rb b/lib/tapioca/gem/pipeline.rb index ccf22fe5c..db1d3a076 100644 --- a/lib/tapioca/gem/pipeline.rb +++ b/lib/tapioca/gem/pipeline.rb @@ -31,8 +31,10 @@ def initialize( @events = [] #: Array[Gem::Event] @payload_symbols = Static::SymbolLoader.payload_symbols #: Set[String] - @bootstrap_symbols = load_bootstrap_symbols(@gem) #: Set[String] - gem_graph = Static::SymbolLoader.graph_from_paths(@gem.files) if include_doc + gem_graph = Static::SymbolLoader.graph_from_paths(@gem.files) #: Rubydex::Graph + gem_symbols = gem_graph.declarations.map(&:name).to_set + engine_symbols = Static::SymbolLoader.engine_symbols(@gem) + @bootstrap_symbols = gem_symbols.union(engine_symbols) #: Set[String] @bootstrap_symbols.each { |symbol| push_symbol(symbol) } @@ -191,14 +193,6 @@ def name_of(constant) private - #: (Gemfile::GemSpec gem) -> Set[String] - def load_bootstrap_symbols(gem) - engine_symbols = Static::SymbolLoader.engine_symbols(gem) - gem_symbols = Static::SymbolLoader.gem_symbols(gem) - - gem_symbols.union(engine_symbols) - end - # Events handling #: -> Gem::Event diff --git a/lib/tapioca/static/symbol_loader.rb b/lib/tapioca/static/symbol_loader.rb index 7f0c08b09..c52cdfd45 100644 --- a/lib/tapioca/static/symbol_loader.rb +++ b/lib/tapioca/static/symbol_loader.rb @@ -26,11 +26,6 @@ def graph_from_paths(paths) graph end - #: (Gemfile::GemSpec gem) -> Set[String] - def gem_symbols(gem) - symbols_from_paths(gem.files) - end - #: (Gemfile::GemSpec gem) -> Set[String] def engine_symbols(gem) gem_engine = engines.find do |engine| @@ -51,7 +46,8 @@ def engine_symbols(gem) Pathname.glob("#{load_path}/**/*.rb") end - symbols_from_paths(paths) + engine_graph = graph_from_paths(paths) + engine_graph.declarations.map(&:name).to_set rescue Set.new end From 3649e0b0710f12e0f18165e572d96c7256b38db9 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 23 Apr 2026 16:44:48 +0900 Subject: [PATCH 2/2] Filter Rubydex declarations to namespaces, constants, and aliases --- lib/tapioca/gem/pipeline.rb | 2 +- lib/tapioca/static/symbol_loader.rb | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/tapioca/gem/pipeline.rb b/lib/tapioca/gem/pipeline.rb index db1d3a076..f7d3cf74a 100644 --- a/lib/tapioca/gem/pipeline.rb +++ b/lib/tapioca/gem/pipeline.rb @@ -32,7 +32,7 @@ def initialize( @payload_symbols = Static::SymbolLoader.payload_symbols #: Set[String] gem_graph = Static::SymbolLoader.graph_from_paths(@gem.files) #: Rubydex::Graph - gem_symbols = gem_graph.declarations.map(&:name).to_set + gem_symbols = Static::SymbolLoader.symbols_from_graph(gem_graph) engine_symbols = Static::SymbolLoader.engine_symbols(@gem) @bootstrap_symbols = gem_symbols.union(engine_symbols) #: Set[String] diff --git a/lib/tapioca/static/symbol_loader.rb b/lib/tapioca/static/symbol_loader.rb index c52cdfd45..a070f9a29 100644 --- a/lib/tapioca/static/symbol_loader.rb +++ b/lib/tapioca/static/symbol_loader.rb @@ -26,6 +26,28 @@ def graph_from_paths(paths) graph end + #: (Rubydex::Graph graph) -> Set[String] + def symbols_from_graph(graph) + graph.declarations.filter_map do |decl| + next unless decl.is_a?(Rubydex::Namespace) || + decl.is_a?(Rubydex::Constant) || + decl.is_a?(Rubydex::ConstantAlias) || + decl.is_a?(Rubydex::Todo) + + # Declarations added by `graph.resolve` only have `rubydex:built-in` definitions. + # We exclude those unless the namespace has method or constant members defined in + # source files, which indicates a class reopening (e.g. `class Object; def Nokogiri(); end`). + if decl.definitions.any? && decl.definitions.all? { |defn| defn.location.uri == "rubydex:built-in" } + next unless decl.is_a?(Rubydex::Namespace) && decl.members.any? do |m| + (m.is_a?(Rubydex::Method) || m.is_a?(Rubydex::Constant) || m.is_a?(Rubydex::ConstantAlias)) && + m.definitions.any? + end + end + + decl.name + end.to_set + end + #: (Gemfile::GemSpec gem) -> Set[String] def engine_symbols(gem) gem_engine = engines.find do |engine| @@ -47,7 +69,7 @@ def engine_symbols(gem) end engine_graph = graph_from_paths(paths) - engine_graph.declarations.map(&:name).to_set + symbols_from_graph(engine_graph) rescue Set.new end