Skip to content
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

Cache interfaces #230

Merged
merged 2 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bin/steep-prof
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def exit(*)

end


STDERR.puts "Running profiler: mode=#{mode}, out=#{out}"
StackProf.run(mode: mode, out: out) do
StackProf.run(mode: mode, out: out, raw: true) do
load File.join(__dir__, "../exe/steep")
end
15 changes: 14 additions & 1 deletion lib/steep/ast/types/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ class Factory
attr_reader :type_name_cache
attr_reader :type_cache

attr_reader :type_interface_cache

def initialize(builder:)
@definition_builder = builder

@type_name_cache = {}
@type_cache = {}
@type_interface_cache = {}
end

def type_name_resolver
Expand Down Expand Up @@ -390,15 +393,23 @@ def setup_primitives(method_name, method_type)

def interface(type, private:, self_type: type)
Steep.logger.debug { "Factory#interface: #{type}, private=#{private}, self_type=#{self_type}" }
type = expand_alias(type)

cache_key = [type, self_type, private]
if type_interface_cache.key?(cache_key)
return type_interface_cache[cache_key]
end

case type
when Name::Alias
interface(expand_alias(type), private: private, self_type: self_type)

when Self
if self_type != type
interface self_type, private: private, self_type: Self.new
else
raise "Unexpected `self` type interface"
end

when Name::Instance
Interface::Interface.new(type: self_type, private: private).tap do |interface|
definition = definition_builder.build_instance(type.name)
Expand Down Expand Up @@ -689,6 +700,8 @@ def interface(type, private:, self_type: type)

else
raise "Unexpected type for interface: #{type}"
end.tap do |interface|
type_interface_cache[cache_key] = interface
end
end

Expand Down