rbs 3.0.0.dev.1 → 3.0.0.dev.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -3
- data/CHANGELOG.md +28 -0
- data/Gemfile.lock +12 -12
- data/README.md +1 -0
- data/Rakefile +77 -3
- data/Steepfile +1 -1
- data/core/array.rbs +574 -424
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +9 -1
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +114 -176
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +111 -18
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/constants.c +16 -2
- data/ext/rbs_extension/constants.h +8 -1
- data/ext/rbs_extension/extconf.rb +1 -1
- data/ext/rbs_extension/lexer.c +834 -777
- data/ext/rbs_extension/lexer.h +3 -1
- data/ext/rbs_extension/lexer.re +3 -1
- data/ext/rbs_extension/lexstate.c +4 -2
- data/ext/rbs_extension/parser.c +262 -43
- data/ext/rbs_extension/ruby_objs.c +56 -2
- data/ext/rbs_extension/ruby_objs.h +7 -1
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/ast/declarations.rb +49 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +37 -30
- data/lib/rbs/collection/config.rb +3 -3
- data/lib/rbs/collection/sources/git.rb +10 -3
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder.rb +8 -8
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +358 -88
- data/lib/rbs/environment_loader.rb +12 -9
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +52 -37
- data/lib/rbs/locator.rb +27 -8
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +5 -5
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/type_alias_dependency.rb +1 -1
- data/lib/rbs/type_alias_regularity.rb +3 -3
- data/lib/rbs/validator.rb +23 -2
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +28 -2
- data/lib/rbs.rb +2 -2
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +1 -1
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile_generator.rbs +8 -10
- data/sig/collection/config.rbs +1 -1
- data/sig/collection/sources.rbs +44 -9
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +0 -1
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -29
- data/sig/environment_loader.rbs +1 -1
- data/sig/errors.rbs +22 -1
- data/sig/locator.rbs +14 -2
- data/sig/parser.rbs +8 -15
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/sig/shims/bundler.rbs +18 -0
- data/sig/shims/rubygems.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +4 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +13 -13
- data/core/deprecated.rbs +0 -9
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- data/sig/shims/ripper.rbs +0 -8
- data/sig/type_name_resolver.rbs +0 -26
- data/steep/Gemfile +0 -3
- data/steep/Gemfile.lock +0 -61
data/lib/rbs/constant_table.rb
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
class ConstantTable
|
5
|
-
attr_reader :definition_builder
|
6
|
-
attr_reader :constant_scopes_cache
|
7
|
-
|
8
|
-
def env
|
9
|
-
definition_builder.env
|
10
|
-
end
|
11
|
-
|
12
|
-
def resolver
|
13
|
-
@resolver ||= TypeNameResolver.from_env(env)
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(builder:)
|
17
|
-
@definition_builder = builder
|
18
|
-
@constant_scopes_cache = {}
|
19
|
-
end
|
20
|
-
|
21
|
-
def absolute_type(type, context:)
|
22
|
-
type.map_type_name do |type_name, location|
|
23
|
-
absolute_type_name(type_name, context: context, location: location)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def absolute_type_name(type_name, context:, location:)
|
28
|
-
resolver.resolve(type_name, context: context) or
|
29
|
-
raise NoTypeFoundError.new(type_name: type_name, location: location)
|
30
|
-
end
|
31
|
-
|
32
|
-
def name_to_constant(name)
|
33
|
-
case
|
34
|
-
when entry = env.constant_decls[name]
|
35
|
-
type = absolute_type(entry.decl.type, context: entry.context)
|
36
|
-
Constant.new(name: name, type: type, entry: entry)
|
37
|
-
when entry = env.class_decls[name]
|
38
|
-
type = Types::ClassSingleton.new(name: name, location: nil)
|
39
|
-
Constant.new(name: name, type: type, entry: entry)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def split_name(name)
|
44
|
-
name.namespace.path + [name.name]
|
45
|
-
end
|
46
|
-
|
47
|
-
def resolve_constant_reference(name, context:)
|
48
|
-
raise "Context cannot be empty: Specify `[Namespace.root]`" if context.empty?
|
49
|
-
|
50
|
-
head, *tail = split_name(name)
|
51
|
-
|
52
|
-
raise unless head
|
53
|
-
|
54
|
-
head_constant = case
|
55
|
-
when name.absolute?
|
56
|
-
name_to_constant(TypeName.new(name: head, namespace: Namespace.root))
|
57
|
-
when context == [Namespace.root]
|
58
|
-
name_to_constant(TypeName.new(name: head, namespace: Namespace.root))
|
59
|
-
else
|
60
|
-
resolve_constant_reference_context(head, context: context) ||
|
61
|
-
context.first.yield_self do |first_context|
|
62
|
-
raise unless first_context
|
63
|
-
resolve_constant_reference_inherit(head, scopes: constant_scopes(first_context.to_type_name))
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
tail.inject(head_constant) do |constant, name|
|
68
|
-
if constant
|
69
|
-
resolve_constant_reference_inherit(
|
70
|
-
name,
|
71
|
-
scopes: constant_scopes(constant.name),
|
72
|
-
no_object: constant.name != BuiltinNames::Object.name
|
73
|
-
)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def resolve_constant_reference_context(name, context:)
|
79
|
-
head, *tail = context
|
80
|
-
|
81
|
-
if head
|
82
|
-
if head.path.last == name
|
83
|
-
name_to_constant(head.to_type_name)
|
84
|
-
else
|
85
|
-
name_to_constant(TypeName.new(name: name, namespace: head)) ||
|
86
|
-
resolve_constant_reference_context(name, context: tail)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def resolve_constant_reference_inherit(name, scopes:, no_object: false)
|
92
|
-
scopes.each do |context|
|
93
|
-
if context.path == [:Object]
|
94
|
-
unless no_object
|
95
|
-
constant = name_to_constant(TypeName.new(name: name, namespace: context)) ||
|
96
|
-
name_to_constant(TypeName.new(name: name, namespace: Namespace.root))
|
97
|
-
end
|
98
|
-
else
|
99
|
-
constant = name_to_constant(TypeName.new(name: name, namespace: context))
|
100
|
-
end
|
101
|
-
|
102
|
-
return constant if constant
|
103
|
-
end
|
104
|
-
|
105
|
-
nil
|
106
|
-
end
|
107
|
-
|
108
|
-
def constant_scopes(name)
|
109
|
-
constant_scopes_cache[name] ||= constant_scopes0(name, scopes: [])
|
110
|
-
end
|
111
|
-
|
112
|
-
def constant_scopes_module(name, scopes:)
|
113
|
-
entry = env.class_decls[name]
|
114
|
-
namespace = name.to_namespace
|
115
|
-
|
116
|
-
entry.decls.each do |d|
|
117
|
-
d.decl.members.each do |member|
|
118
|
-
case member
|
119
|
-
when AST::Members::Include
|
120
|
-
if member.name.class?
|
121
|
-
constant_scopes_module absolute_type_name(member.name, context: d.context, location: member.location),
|
122
|
-
scopes: scopes
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
scopes.unshift namespace
|
129
|
-
end
|
130
|
-
|
131
|
-
def constant_scopes0(name, scopes: [])
|
132
|
-
entry = env.class_decls[name]
|
133
|
-
namespace = name.to_namespace
|
134
|
-
|
135
|
-
case entry
|
136
|
-
when Environment::ClassEntry
|
137
|
-
unless name == BuiltinNames::BasicObject.name
|
138
|
-
super_name = entry.primary.decl.super_class&.yield_self do |super_class|
|
139
|
-
absolute_type_name(super_class.name, context: entry.primary.context, location: entry.primary.decl.location)
|
140
|
-
end || BuiltinNames::Object.name
|
141
|
-
|
142
|
-
constant_scopes0 super_name, scopes: scopes
|
143
|
-
end
|
144
|
-
|
145
|
-
entry.decls.each do |d|
|
146
|
-
d.decl.members.each do |member|
|
147
|
-
case member
|
148
|
-
when AST::Members::Include
|
149
|
-
if member.name.class?
|
150
|
-
constant_scopes_module absolute_type_name(member.name, context: d.context, location: member.location),
|
151
|
-
scopes: scopes
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
scopes.unshift namespace
|
158
|
-
|
159
|
-
when Environment::ModuleEntry
|
160
|
-
constant_scopes0 BuiltinNames::Module.name, scopes: scopes
|
161
|
-
constant_scopes_module name, scopes: scopes
|
162
|
-
end
|
163
|
-
|
164
|
-
scopes
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RBS
|
4
|
-
class TypeNameResolver
|
5
|
-
Query = _ = Struct.new(:type_name, :context, keyword_init: true)
|
6
|
-
|
7
|
-
attr_reader :all_names
|
8
|
-
attr_reader :cache
|
9
|
-
|
10
|
-
def initialize()
|
11
|
-
@all_names = Set[]
|
12
|
-
@cache = {}
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.from_env(env)
|
16
|
-
new.add_names(env.class_decls.keys)
|
17
|
-
.add_names(env.interface_decls.keys)
|
18
|
-
.add_names(env.alias_decls.keys)
|
19
|
-
end
|
20
|
-
|
21
|
-
def add_names(names)
|
22
|
-
all_names.merge(names)
|
23
|
-
self
|
24
|
-
end
|
25
|
-
|
26
|
-
def try_cache(query)
|
27
|
-
cache.fetch(query) do
|
28
|
-
result = yield
|
29
|
-
cache[query] = result
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def resolve(type_name, context:)
|
34
|
-
if type_name.absolute?
|
35
|
-
return type_name
|
36
|
-
end
|
37
|
-
|
38
|
-
query = Query.new(type_name: type_name, context: context)
|
39
|
-
try_cache(query) do
|
40
|
-
path_head, *path_tail = type_name.split
|
41
|
-
raise unless path_head
|
42
|
-
|
43
|
-
name_head = TypeName.new(name: path_head, namespace: Namespace.empty)
|
44
|
-
|
45
|
-
absolute_head = context.find do |namespace|
|
46
|
-
# @type break: TypeName
|
47
|
-
full_name = name_head.with_prefix(namespace)
|
48
|
-
has_name?(full_name) and break full_name
|
49
|
-
end
|
50
|
-
|
51
|
-
case absolute_head
|
52
|
-
when TypeName
|
53
|
-
has_name?(Namespace.new(path: absolute_head.to_namespace.path.push(*path_tail), absolute: true).to_type_name)
|
54
|
-
when Namespace
|
55
|
-
# This cannot happen because the `context.find` doesn't return a Namespace.
|
56
|
-
raise
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def has_name?(full_name)
|
62
|
-
if all_names.include?(full_name)
|
63
|
-
full_name
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/sig/constant_table.rbs
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class ConstantTable
|
3
|
-
attr_reader definition_builder: DefinitionBuilder
|
4
|
-
attr_reader constant_scopes_cache: Hash[TypeName, Array[Namespace]]
|
5
|
-
attr_reader resolver: TypeNameResolver
|
6
|
-
attr_reader env(): Environment
|
7
|
-
|
8
|
-
def initialize: (builder: DefinitionBuilder) -> void
|
9
|
-
|
10
|
-
def absolute_type: (Types::t, context: Array[Namespace]) -> Types::t
|
11
|
-
|
12
|
-
def absolute_type_name: (TypeName, context: Array[Namespace], location: Location[untyped, untyped]?) -> TypeName
|
13
|
-
|
14
|
-
def name_to_constant: (TypeName) -> Constant?
|
15
|
-
|
16
|
-
def split_name: (TypeName) -> Array[Symbol]
|
17
|
-
|
18
|
-
def resolve_constant_reference: (TypeName name, context: Array[Namespace]) -> Constant?
|
19
|
-
|
20
|
-
def resolve_constant_reference_context: (Symbol, context: Array[Namespace]) -> Constant?
|
21
|
-
|
22
|
-
def resolve_constant_reference_inherit: (Symbol, scopes: Array[Namespace], ?no_object: boolish) -> Constant?
|
23
|
-
|
24
|
-
def constant_scopes: (TypeName) -> Array[Namespace]
|
25
|
-
|
26
|
-
def constant_scopes_module: (TypeName, scopes: Array[Namespace]) -> Array[Namespace]
|
27
|
-
|
28
|
-
def constant_scopes0: (TypeName, ?scopes: Array[Namespace]) -> Array[Namespace]
|
29
|
-
end
|
30
|
-
end
|
data/sig/shims/ripper.rbs
DELETED
data/sig/type_name_resolver.rbs
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class TypeNameResolver
|
3
|
-
type context = Array[Namespace]
|
4
|
-
|
5
|
-
class Query
|
6
|
-
attr_reader type_name: TypeName
|
7
|
-
attr_reader context: Array[Namespace]
|
8
|
-
|
9
|
-
def initialize: (type_name: TypeName, context: context) -> void
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader all_names: Set[TypeName]
|
13
|
-
|
14
|
-
attr_reader cache: Hash[Query, TypeName?]
|
15
|
-
|
16
|
-
def self.from_env: (Environment) -> TypeNameResolver
|
17
|
-
|
18
|
-
def add_names: (Array[TypeName]) -> self
|
19
|
-
|
20
|
-
def resolve: (TypeName, context: context) -> TypeName?
|
21
|
-
|
22
|
-
def has_name?: (TypeName) -> TypeName?
|
23
|
-
|
24
|
-
def try_cache: (Query) { () -> TypeName? } -> TypeName?
|
25
|
-
end
|
26
|
-
end
|
data/steep/Gemfile
DELETED
data/steep/Gemfile.lock
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (7.0.4)
|
5
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
-
i18n (>= 1.6, < 2)
|
7
|
-
minitest (>= 5.1)
|
8
|
-
tzinfo (~> 2.0)
|
9
|
-
ast (2.4.2)
|
10
|
-
concurrent-ruby (1.1.10)
|
11
|
-
csv (3.2.5)
|
12
|
-
ffi (1.15.5)
|
13
|
-
fileutils (1.6.0)
|
14
|
-
i18n (1.12.0)
|
15
|
-
concurrent-ruby (~> 1.0)
|
16
|
-
json (2.6.2)
|
17
|
-
language_server-protocol (3.17.0.1)
|
18
|
-
listen (3.7.1)
|
19
|
-
rb-fsevent (~> 0.10, >= 0.10.3)
|
20
|
-
rb-inotify (~> 0.9, >= 0.9.10)
|
21
|
-
logger (1.5.1)
|
22
|
-
minitest (5.16.3)
|
23
|
-
parallel (1.22.1)
|
24
|
-
parser (3.1.2.1)
|
25
|
-
ast (~> 2.4.1)
|
26
|
-
rainbow (3.1.1)
|
27
|
-
rb-fsevent (0.11.2)
|
28
|
-
rb-inotify (0.10.1)
|
29
|
-
ffi (~> 1.0)
|
30
|
-
rbs (2.8.0)
|
31
|
-
securerandom (0.2.0)
|
32
|
-
steep (1.3.0)
|
33
|
-
activesupport (>= 5.1)
|
34
|
-
csv (>= 3.0.9)
|
35
|
-
fileutils (>= 1.1.0)
|
36
|
-
json (>= 2.1.0)
|
37
|
-
language_server-protocol (>= 3.15, < 4.0)
|
38
|
-
listen (~> 3.0)
|
39
|
-
logger (>= 1.3.0)
|
40
|
-
parallel (>= 1.0.0)
|
41
|
-
parser (>= 3.1)
|
42
|
-
rainbow (>= 2.2.2, < 4.0)
|
43
|
-
rbs (>= 2.8.0)
|
44
|
-
securerandom (>= 0.1)
|
45
|
-
strscan (>= 1.0.0)
|
46
|
-
terminal-table (>= 2, < 4)
|
47
|
-
strscan (3.0.4)
|
48
|
-
terminal-table (3.0.2)
|
49
|
-
unicode-display_width (>= 1.1.1, < 3)
|
50
|
-
tzinfo (2.0.5)
|
51
|
-
concurrent-ruby (~> 1.0)
|
52
|
-
unicode-display_width (2.3.0)
|
53
|
-
|
54
|
-
PLATFORMS
|
55
|
-
ruby
|
56
|
-
|
57
|
-
DEPENDENCIES
|
58
|
-
steep
|
59
|
-
|
60
|
-
BUNDLED WITH
|
61
|
-
2.3.14
|