rbs 3.0.0.dev.1 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Gemfile.lock +2 -2
  5. data/README.md +1 -0
  6. data/Rakefile +75 -1
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +16 -2
  12. data/ext/rbs_extension/constants.h +8 -1
  13. data/ext/rbs_extension/extconf.rb +1 -1
  14. data/ext/rbs_extension/lexer.c +834 -777
  15. data/ext/rbs_extension/lexer.h +3 -1
  16. data/ext/rbs_extension/lexer.re +3 -1
  17. data/ext/rbs_extension/lexstate.c +4 -2
  18. data/ext/rbs_extension/parser.c +264 -44
  19. data/ext/rbs_extension/ruby_objs.c +56 -2
  20. data/ext/rbs_extension/ruby_objs.h +7 -1
  21. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  22. data/lib/rbs/ast/declarations.rb +49 -2
  23. data/lib/rbs/ast/directives.rb +39 -0
  24. data/lib/rbs/cli.rb +32 -18
  25. data/lib/rbs/collection/config/lockfile_generator.rb +25 -20
  26. data/lib/rbs/collection/config.rb +2 -2
  27. data/lib/rbs/collection/sources/git.rb +1 -1
  28. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  29. data/lib/rbs/definition_builder.rb +8 -8
  30. data/lib/rbs/environment/use_map.rb +77 -0
  31. data/lib/rbs/environment.rb +352 -83
  32. data/lib/rbs/environment_loader.rb +9 -7
  33. data/lib/rbs/environment_walker.rb +1 -1
  34. data/lib/rbs/errors.rb +34 -37
  35. data/lib/rbs/locator.rb +1 -1
  36. data/lib/rbs/parser_aux.rb +8 -6
  37. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  38. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  39. data/lib/rbs/sorter.rb +3 -3
  40. data/lib/rbs/test/setup.rb +1 -1
  41. data/lib/rbs/type_alias_dependency.rb +1 -1
  42. data/lib/rbs/type_alias_regularity.rb +3 -3
  43. data/lib/rbs/validator.rb +23 -2
  44. data/lib/rbs/variance_calculator.rb +2 -2
  45. data/lib/rbs/version.rb +1 -1
  46. data/lib/rbs/writer.rb +28 -2
  47. data/lib/rbs.rb +2 -2
  48. data/lib/rdoc_plugin/parser.rb +2 -2
  49. data/rbs.gemspec +1 -1
  50. data/sig/ancestor_graph.rbs +22 -2
  51. data/sig/collection/config/lockfile_generator.rbs +8 -10
  52. data/sig/collection/config.rbs +1 -1
  53. data/sig/collection/sources.rbs +12 -6
  54. data/sig/constant.rbs +1 -1
  55. data/sig/declarations.rbs +36 -3
  56. data/sig/definition.rbs +1 -1
  57. data/sig/definition_builder.rbs +0 -1
  58. data/sig/directives.rbs +61 -0
  59. data/sig/environment.rbs +150 -28
  60. data/sig/environment_loader.rbs +1 -1
  61. data/sig/errors.rbs +22 -1
  62. data/sig/parser.rbs +8 -15
  63. data/sig/resolver/constant_resolver.rbs +1 -2
  64. data/sig/shims/bundler.rbs +18 -0
  65. data/sig/shims/rubygems.rbs +6 -0
  66. data/sig/use_map.rbs +35 -0
  67. data/sig/validator.rbs +12 -5
  68. data/sig/writer.rbs +4 -2
  69. metadata +7 -9
  70. data/lib/rbs/constant_table.rb +0 -167
  71. data/lib/rbs/type_name_resolver.rb +0 -67
  72. data/sig/constant_table.rbs +0 -30
  73. data/sig/type_name_resolver.rbs +0 -26
  74. data/steep/Gemfile +0 -3
  75. data/steep/Gemfile.lock +0 -61
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.dev.1
4
+ version: 3.0.0.dev.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -151,6 +151,7 @@ files:
151
151
  - lib/rbs/ast/annotation.rb
152
152
  - lib/rbs/ast/comment.rb
153
153
  - lib/rbs/ast/declarations.rb
154
+ - lib/rbs/ast/directives.rb
154
155
  - lib/rbs/ast/members.rb
155
156
  - lib/rbs/ast/type_param.rb
156
157
  - lib/rbs/buffer.rb
@@ -168,12 +169,12 @@ files:
168
169
  - lib/rbs/collection/sources/rubygems.rb
169
170
  - lib/rbs/collection/sources/stdlib.rb
170
171
  - lib/rbs/constant.rb
171
- - lib/rbs/constant_table.rb
172
172
  - lib/rbs/definition.rb
173
173
  - lib/rbs/definition_builder.rb
174
174
  - lib/rbs/definition_builder/ancestor_builder.rb
175
175
  - lib/rbs/definition_builder/method_builder.rb
176
176
  - lib/rbs/environment.rb
177
+ - lib/rbs/environment/use_map.rb
177
178
  - lib/rbs/environment_loader.rb
178
179
  - lib/rbs/environment_walker.rb
179
180
  - lib/rbs/errors.rb
@@ -209,7 +210,6 @@ files:
209
210
  - lib/rbs/type_alias_dependency.rb
210
211
  - lib/rbs/type_alias_regularity.rb
211
212
  - lib/rbs/type_name.rb
212
- - lib/rbs/type_name_resolver.rb
213
213
  - lib/rbs/types.rb
214
214
  - lib/rbs/validator.rb
215
215
  - lib/rbs/variance_calculator.rb
@@ -247,10 +247,10 @@ files:
247
247
  - sig/collection/sources.rbs
248
248
  - sig/comment.rbs
249
249
  - sig/constant.rbs
250
- - sig/constant_table.rbs
251
250
  - sig/declarations.rbs
252
251
  - sig/definition.rbs
253
252
  - sig/definition_builder.rbs
253
+ - sig/directives.rbs
254
254
  - sig/environment.rbs
255
255
  - sig/environment_loader.rbs
256
256
  - sig/environment_walker.rbs
@@ -285,10 +285,10 @@ files:
285
285
  - sig/substitution.rbs
286
286
  - sig/type_alias_dependency.rbs
287
287
  - sig/type_alias_regularity.rbs
288
- - sig/type_name_resolver.rbs
289
288
  - sig/type_param.rbs
290
289
  - sig/typename.rbs
291
290
  - sig/types.rbs
291
+ - sig/use_map.rbs
292
292
  - sig/util.rbs
293
293
  - sig/validator.rbs
294
294
  - sig/variance_calculator.rbs
@@ -423,8 +423,6 @@ files:
423
423
  - stdlib/yaml/0/store.rbs
424
424
  - stdlib/yaml/0/yaml.rbs
425
425
  - stdlib/zlib/0/zlib.rbs
426
- - steep/Gemfile
427
- - steep/Gemfile.lock
428
426
  homepage: https://github.com/ruby/rbs
429
427
  licenses:
430
428
  - BSD-2-Clause
@@ -448,7 +446,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
448
446
  - !ruby/object:Gem::Version
449
447
  version: 1.3.1
450
448
  requirements: []
451
- rubygems_version: 3.3.26
449
+ rubygems_version: 3.4.6
452
450
  signing_key:
453
451
  specification_version: 4
454
452
  summary: Type signature for Ruby.
@@ -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
@@ -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
@@ -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
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "steep"
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