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

Delete meta data from MethodType and Types::* #1201

Merged
merged 5 commits into from
Aug 9, 2024
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
19 changes: 19 additions & 0 deletions bin/stackprof_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env ruby

require "stackprof"

mode = (ENV["STEEP_STACKPROF_MODE"] || :cpu).to_sym
out = ENV["STEEP_STACKPROF_OUT"] || "tmp/stackprof-#{mode}-test.dump"
interval = ENV["STEEP_STACKPROF_INTERVAL"]&.to_i || 1000

STDERR.puts "Running profiler: mode => #{mode}, out => #{out}"
StackProf.run(mode: mode, out: out, raw: true, interval: interval) do
# 10.times do
# 1_000.times do
# Array.new(1_000_000)
# end
# sleep 0.1
# end

sleep 5
end
14 changes: 14 additions & 0 deletions bin/steep-check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,22 @@ def type_check_files(command_line_args, env)
end

when :none

pp rbs_method_types: ObjectSpace.each_object(RBS::MethodType).count
GC.start(immediate_sweep: true, immediate_mark: true, full_mark: true)

pp defs: ObjectSpace.each_object(RBS::AST::Members::MethodDefinition).count
pp aliases: ObjectSpace.each_object(RBS::AST::Members::Alias).count
pp attr_reader: ObjectSpace.each_object(RBS::AST::Members::AttrReader).count
pp attr_writer: ObjectSpace.each_object(RBS::AST::Members::AttrWriter).count
pp attr_accessor: ObjectSpace.each_object(RBS::AST::Members::AttrAccessor).count

Steep.measure("type check", level: :fatal) do
GC.disable
typings = command.type_check_files(command_line_args, env)

pp steep_method_types: ObjectSpace.each_object(Steep::Interface::MethodType).count, rbs_method_types: ObjectSpace.each_object(RBS::MethodType).count
pp any: ObjectSpace.each_object(Steep::AST::Types::Any).count, void: ObjectSpace.each_object(Steep::AST::Types::Void).count, self: ObjectSpace.each_object(Steep::AST::Types::Self).count
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/steep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
require "rbs"

require "steep/path_helper"

require "steep/located_value"
require "steep/thread_waiter"
require "steep/equatable"
require "steep/method_name"
require "steep/node_helper"
require "steep/ast/types/shared_instance"
require "steep/ast/types/helper"
require "steep/ast/types/any"
require "steep/ast/types/instance"
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/annotation_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def parse(src, location:)
name = match[:name] or raise
type = match[:type] or raise

method_type = factory.method_type(RBS::Parser.parse_method_type(type) || raise, method_decls: Set[])
method_type = factory.method_type(RBS::Parser.parse_method_type(type) || raise)

AST::Annotation::MethodType.new(name: name.to_sym,
type: method_type,
Expand Down
10 changes: 5 additions & 5 deletions lib/steep/ast/builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ def module_type?(type)
Proc = Type.new("::Proc")

def self.nil_type
AST::Types::Nil.new
AST::Types::Nil.instance
end

def self.any_type
AST::Types::Any.new
AST::Types::Any.instance
end

def self.bool_type
AST::Types::Boolean.new
AST::Types::Boolean.instance
end

def self.bottom_type
AST::Types::Bot.new
AST::Types::Bot.instance
end

def self.top_type
AST::Types::Top.new
AST::Types::Top.instance
end

def self.optional(type)
Expand Down
13 changes: 7 additions & 6 deletions lib/steep/ast/node/type_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ def source
def types(context, subtyping, type_vars)
resolver = RBS::Resolver::TypeNameResolver.new(subtyping.factory.env)

# @type var types: Array[Types::t]
# @type var types: Array[LocatedValue[Types::t]]
types = []

loc = type_location

while true
ty = RBS::Parser.parse_type(loc.buffer, range: loc.range, variables: type_vars) or break
ty = ty.map_type_name {|name| resolver.resolve(name, context: context) || name.absolute! }
rbs_ty = RBS::Parser.parse_type(loc.buffer, range: loc.range, variables: type_vars) or break
rbs_loc = rbs_ty.location or raise
ty = rbs_ty.map_type_name {|name| resolver.resolve(name, context: context) || name.absolute! }

validator = Signature::Validator.new(checker: subtyping)
validator.rescue_validation_errors do
Expand All @@ -46,11 +47,11 @@ def types(context, subtyping, type_vars)
end

ty = subtyping.factory.type(ty)
types << ty
types << LocatedValue.new(value: ty, location: rbs_loc)

match = RBS::Location.new(loc.buffer, ty.location.end_pos, type_location.end_pos).source.match(/\A\s*,\s*/) or break
match = RBS::Location.new(loc.buffer, rbs_loc.end_pos, type_location.end_pos).source.match(/\A\s*,\s*/) or break
offset = match.length
loc = RBS::Location.new(loc.buffer, ty.location.end_pos + offset, type_location.end_pos)
loc = RBS::Location.new(loc.buffer, rbs_loc.end_pos + offset, type_location.end_pos)
end

types
Expand Down
10 changes: 1 addition & 9 deletions lib/steep/ast/types/any.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ module Steep
module AST
module Types
class Any
attr_reader :location

def initialize(location: nil)
@location = location
end
extend SharedInstance

def ==(other)
other.is_a?(Any)
Expand All @@ -33,10 +29,6 @@ def to_s
def level
[1]
end

def with_location(new_location)
self.class.new(location: new_location)
end
end
end
end
Expand Down
24 changes: 8 additions & 16 deletions lib/steep/ast/types/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ module Steep
module AST
module Types
class Boolean
attr_reader :location

def initialize(location: nil)
@location = location
end

extend SharedInstance

def ==(other)
other.is_a?(Boolean)
end
Expand All @@ -34,17 +30,13 @@ def level
[0]
end

def with_location(new_location)
self.class.new(location: new_location)
end

def back_type
Union.build(types:
[
Builtin::TrueClass.instance_type,
Builtin::FalseClass.instance_type
],
location: location)
Union.build(
types: [
Builtin::TrueClass.instance_type,
Builtin::FalseClass.instance_type
]
)
end
end
end
Expand Down
12 changes: 2 additions & 10 deletions lib/steep/ast/types/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ module Steep
module AST
module Types
class Bot
attr_reader :location

def initialize(location: nil)
@location = location
end

extend SharedInstance

def ==(other)
other.is_a?(Bot)
end
Expand All @@ -33,10 +29,6 @@ def to_s
def level
[2]
end

def with_location(new_location)
self.class.new(location: new_location)
end
end
end
end
Expand Down
14 changes: 1 addition & 13 deletions lib/steep/ast/types/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ module Steep
module AST
module Types
class Class
attr_reader :location

def initialize(location: nil)
@location = location
end

def self.instance
@instance ||= new()
end
extend SharedInstance

def to_s
"class"
Expand Down Expand Up @@ -45,10 +37,6 @@ def free_variables
def level
[0]
end

def with_location(new_location)
self.class.new(location: new_location)
end
end
end
end
Expand Down
Loading