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 ContextArray #1199

Merged
merged 6 commits into from
Aug 6, 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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ DEPENDENCIES
vernier (~> 1.0)

BUNDLED WITH
2.3.8
2.5.17
4 changes: 2 additions & 2 deletions bin/steep-check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def type_check_files(command_line_args, env)
variable_context: TypeInference::Context::TypeVariableContext.empty
)

typing = Typing.new(source: source, root_context: context)
typing = Typing.new(source: source, root_context: context, cursor: nil)
construction = TypeConstruction.new(checker: subtyping, source: source, annotations: annotations, context: context, typing: typing)

construction.synthesize(source.node)
Expand Down Expand Up @@ -201,7 +201,7 @@ def type_check_files(command_line_args, env)
require "stackprof"
out = Pathname.pwd + "tmp/typecheck-#{Process.pid}.stackprof"
puts ">> Profiling with stackprof: #{out}"
StackProf.run(mode: :cpu, out: out, raw: true, interval: 1000) do
StackProf.run(out: out, raw: true, interval: 1000) do
typings = command.type_check_files(command_line_args, env)
end

Expand Down
2 changes: 1 addition & 1 deletion gemfile_steep/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ DEPENDENCIES
steep (~> 1.7.0.dev)

BUNDLED WITH
2.3.15
2.5.17
1 change: 0 additions & 1 deletion lib/steep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
require "steep/typing"
require "steep/type_construction"
require "steep/type_inference/context"
require "steep/type_inference/context_array"
require "steep/type_inference/send_args"
require "steep/type_inference/block_params"
require "steep/type_inference/method_params"
Expand Down
21 changes: 11 additions & 10 deletions lib/steep/services/completion_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ def type_check!(text, line:, column:)
end

Steep.measure "typechecking" do
location = source.buffer.loc_to_pos([line, column])
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
@typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver)
@typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: location)
end
end

Expand Down Expand Up @@ -348,7 +349,7 @@ def items_for_trigger(position:)

items = [] #: Array[item]

context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise

case
when node.type == :send && node.children[0] == nil && at_end?(position, of: (_ = node.loc).selector)
Expand Down Expand Up @@ -469,7 +470,7 @@ def items_for_dot(position:)

if at_end?(shift_pos, of: node.loc)
begin
context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
receiver_type =
case (type = typing.type_of(node: node))
when AST::Types::Self
Expand Down Expand Up @@ -499,7 +500,7 @@ def items_for_qcall(position:)

if at_end?(shift_pos, of: node.loc)
begin
context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
receiver_type =
case (type = typing.type_of(node: node))
when AST::Types::Self
Expand Down Expand Up @@ -529,11 +530,11 @@ def items_for_colon2(position:)
case node&.type
when :const
# Constant:: ←
context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
constant_items_for_context(context, parent: node, position: position, items: items, prefix: "")
when nil
# :: ←
context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
constant_items_for_context(context, parent: nil, position: position, items: items, prefix: "")
end

Expand All @@ -552,7 +553,7 @@ def items_for_atmark(position:)

return [] unless node

context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
items = [] #: Array[item]
instance_variable_items_for_context(context, prefix: "@", position: position, items: items)
items
Expand All @@ -561,7 +562,7 @@ def items_for_atmark(position:)
def items_for_rbs(position:, buffer:)
items = [] #: Array[item]

context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
completion = TypeNameCompletion.new(env: context.env, context: context.module_context.nesting, dirs: [])
prefix = TypeNameCompletion::Prefix.parse(buffer, line: position.line, column: position.column)

Expand Down Expand Up @@ -609,7 +610,7 @@ def items_for_following_keyword_arguments(text, index:, line:, column:, items:)

def method_items_for_receiver_type(type, include_private:, prefix:, position:, items:)
range = range_for(position, prefix: prefix)
context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise

config =
if (module_type = context.module_context&.module_type) && (instance_type = context.module_context&.instance_type)
Expand Down Expand Up @@ -731,7 +732,7 @@ def keyword_argument_items_for_method(call_node:, send_node:, position:, prefix:

case call
when TypeInference::MethodCall::Typed, TypeInference::MethodCall::Error
context = typing.context_at(line: position.line, column: position.column)
context = typing.cursor_context.context or raise
type = call.receiver_type
type = type.subst(Interface::Substitution.build([], self_type: context.self_type, module_type: context.module_context&.module_type, instance_type: context.module_context&.instance_type))

Expand Down
5 changes: 3 additions & 2 deletions lib/steep/services/goto_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def query_at(path:, line:, column:)
when :def, :defs
named_location = (_ = node.location) #: Parser::AST::_NamedLocation
if test_ast_location(named_location.name, line: line, column: column)
if method_context = typing.context_at(line: line, column: column).method_context
if method_context = typing.cursor_context.context&.method_context
if method = method_context.method
method.defs.each do |defn|
singleton_method =
Expand Down Expand Up @@ -285,8 +285,9 @@ def type_check_path(target:, path:, content:, line:, column:)
source = Source.parse(content, path: path, factory: subtyping.factory)
source = source.without_unrelated_defs(line: line, column: column)
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
loc = source.buffer.loc_to_pos([line, column])
[
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver),
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: loc),
signature_service
]
rescue
Expand Down
11 changes: 6 additions & 5 deletions lib/steep/services/hover_provider/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def typecheck(target, path:, content:, line:, column:)
source = Source.parse(content, path: path, factory: subtyping.factory)
source = source.without_unrelated_defs(line: line, column: column)
resolver = ::RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver)
pos = source.buffer.loc_to_pos([line, column])
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: pos)
rescue
nil
end
Expand Down Expand Up @@ -118,7 +119,7 @@ def content_for(target:, path:, line:, column:)
case node.type
when :lvar
var_name = node.children[0]
context = typing.context_at(line: line, column: column)
context = typing.cursor_context.context or raise
var_type = context.type_env[var_name] || AST::Types::Any.new(location: nil)

return VariableContent.new(
Expand All @@ -130,7 +131,7 @@ def content_for(target:, path:, line:, column:)

when :lvasgn
var_name, rhs = node.children
context = typing.context_at(line: line, column: column)
context = typing.cursor_context.context or raise
type = context.type_env[var_name] || typing.type_of(node: node)

return VariableContent.new(
Expand Down Expand Up @@ -165,7 +166,7 @@ def content_for(target:, path:, line:, column:)
end

when :def, :defs
context = typing.context_at(line: line, column: column)
context = typing.cursor_context.context or raise
method_context = context.method_context

if method_context && method_context.method
Expand All @@ -181,7 +182,7 @@ def content_for(target:, path:, line:, column:)
end

when :const, :casgn
context = typing.context_at(line: line, column: column)
context = typing.cursor_context.context or raise

type = typing.type_of(node: node)
const_name = typing.source_index.reference(constant_node: node)
Expand Down
5 changes: 3 additions & 2 deletions lib/steep/services/signature_help_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def run(line:, column:)
def type_check!(line:, column:)
source = self.source.without_unrelated_defs(line: line, column: column)
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver)
pos = self.source.buffer.loc_to_pos([line, column])
TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: pos)
end

def last_argument_nodes_for(argument_nodes:, line:, column:)
Expand All @@ -99,7 +100,7 @@ def last_argument_nodes_for(argument_nodes:, line:, column:)

def signature_help_for(node, argument, last_argument, typing)
call = typing.call_of(node: node)
context = typing.context_at(line: node.loc.expression.line, column: node.loc.expression.column)
context = typing.cursor_context.context or raise

items = [] #: Array[Item]
index = nil #: Integer?
Expand Down
1 change: 1 addition & 0 deletions lib/steep/services/signature_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def apply_changes(files, changes)
old_text = files[path]&.content
content = cs.inject(old_text || "") {|text, change| change.apply_to(text) }

content ||= "" # It was not clear why `content` can be `nil`, but it happens with `master_test`.
buffer = RBS::Buffer.new(name: path, content: content)

update[path] =
Expand Down
6 changes: 3 additions & 3 deletions lib/steep/services/type_check_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def update_sources(changes:, requests:)
def type_check_file(target:, subtyping:, path:, text:)
Steep.logger.tagged "#type_check_file(#{path}@#{target.name})" do
source = Source.parse(text, path: path, factory: subtyping.factory)
typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: yield)
typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: yield, cursor: nil)
ignores = Source::IgnoreRanges.new(ignores: source.ignores)
SourceFile.with_typing(path: path, content: text, node: source.node, typing: typing, ignores: ignores)
end
Expand All @@ -380,7 +380,7 @@ def type_check_file(target:, subtyping:, path:, text:)
SourceFile.no_data(path: path, content: text)
end

def self.type_check(source:, subtyping:, constant_resolver:)
def self.type_check(source:, subtyping:, constant_resolver:, cursor:)
annotations = source.annotations(block: source.node, factory: subtyping.factory, context: nil)

definition = subtyping.factory.definition_builder.build_instance(AST::Builtin::Object.module_name)
Expand Down Expand Up @@ -418,7 +418,7 @@ def self.type_check(source:, subtyping:, constant_resolver:)
variable_context: TypeInference::Context::TypeVariableContext.empty
)

typing = Typing.new(source: source, root_context: context)
typing = Typing.new(source: source, root_context: context, cursor: cursor)

construction = TypeConstruction.new(
checker: subtyping,
Expand Down
Loading