rbs 2.8.4 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +17 -17
  5. data/README.md +1 -0
  6. data/Rakefile +66 -0
  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 +18 -2
  12. data/ext/rbs_extension/constants.h +9 -1
  13. data/ext/rbs_extension/lexer.c +834 -777
  14. data/ext/rbs_extension/lexer.h +3 -1
  15. data/ext/rbs_extension/lexer.re +3 -1
  16. data/ext/rbs_extension/lexstate.c +4 -2
  17. data/ext/rbs_extension/parser.c +287 -57
  18. data/ext/rbs_extension/ruby_objs.c +71 -5
  19. data/ext/rbs_extension/ruby_objs.h +9 -2
  20. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  21. data/lib/rbs/ast/declarations.rb +49 -2
  22. data/lib/rbs/ast/directives.rb +39 -0
  23. data/lib/rbs/ast/members.rb +49 -15
  24. data/lib/rbs/cli.rb +38 -19
  25. data/lib/rbs/collection/config/lockfile.rb +115 -0
  26. data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
  27. data/lib/rbs/collection/config.rb +12 -40
  28. data/lib/rbs/collection/installer.rb +9 -13
  29. data/lib/rbs/collection/sources/base.rb +2 -2
  30. data/lib/rbs/collection/sources/git.rb +135 -62
  31. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  32. data/lib/rbs/collection/sources/stdlib.rb +10 -13
  33. data/lib/rbs/collection/sources.rb +7 -1
  34. data/lib/rbs/collection.rb +1 -0
  35. data/lib/rbs/definition.rb +1 -1
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  37. data/lib/rbs/definition_builder/method_builder.rb +3 -3
  38. data/lib/rbs/definition_builder.rb +456 -579
  39. data/lib/rbs/environment/use_map.rb +77 -0
  40. data/lib/rbs/environment.rb +356 -85
  41. data/lib/rbs/environment_loader.rb +20 -17
  42. data/lib/rbs/environment_walker.rb +1 -1
  43. data/lib/rbs/errors.rb +34 -37
  44. data/lib/rbs/locator.rb +3 -3
  45. data/lib/rbs/parser_aux.rb +8 -6
  46. data/lib/rbs/prototype/helpers.rb +29 -13
  47. data/lib/rbs/prototype/node_usage.rb +99 -0
  48. data/lib/rbs/prototype/rb.rb +3 -2
  49. data/lib/rbs/prototype/rbi.rb +6 -4
  50. data/lib/rbs/prototype/runtime.rb +25 -12
  51. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  52. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  53. data/lib/rbs/sorter.rb +3 -3
  54. data/lib/rbs/substitution.rb +19 -0
  55. data/lib/rbs/test/setup.rb +1 -1
  56. data/lib/rbs/type_alias_dependency.rb +1 -1
  57. data/lib/rbs/type_alias_regularity.rb +3 -3
  58. data/lib/rbs/types.rb +1 -5
  59. data/lib/rbs/validator.rb +25 -3
  60. data/lib/rbs/variance_calculator.rb +2 -2
  61. data/lib/rbs/version.rb +1 -1
  62. data/lib/rbs/writer.rb +54 -19
  63. data/lib/rbs.rb +3 -2
  64. data/lib/rdoc_plugin/parser.rb +3 -3
  65. data/schema/members.json +15 -10
  66. data/sig/ancestor_graph.rbs +22 -2
  67. data/sig/collection/config/lockfile.rbs +80 -0
  68. data/sig/collection/config/lockfile_generator.rbs +53 -0
  69. data/sig/collection/config.rbs +5 -48
  70. data/sig/collection/installer.rbs +1 -1
  71. data/sig/collection/sources.rbs +76 -33
  72. data/sig/constant.rbs +1 -1
  73. data/sig/declarations.rbs +36 -3
  74. data/sig/definition.rbs +1 -1
  75. data/sig/definition_builder.rbs +94 -82
  76. data/sig/directives.rbs +61 -0
  77. data/sig/environment.rbs +150 -28
  78. data/sig/environment_loader.rbs +2 -2
  79. data/sig/errors.rbs +42 -0
  80. data/sig/members.rbs +31 -7
  81. data/sig/parser.rbs +8 -15
  82. data/sig/prototype/node_usage.rbs +20 -0
  83. data/sig/resolver/constant_resolver.rbs +1 -2
  84. data/sig/shims/bundler.rbs +31 -0
  85. data/sig/shims/rubygems.rbs +15 -0
  86. data/sig/shims.rbs +0 -22
  87. data/sig/substitution.rbs +6 -0
  88. data/sig/use_map.rbs +35 -0
  89. data/sig/validator.rbs +12 -5
  90. data/sig/writer.rbs +6 -2
  91. metadata +16 -9
  92. data/lib/rbs/constant_table.rb +0 -167
  93. data/lib/rbs/type_name_resolver.rb +0 -67
  94. data/sig/constant_table.rbs +0 -30
  95. data/sig/type_name_resolver.rbs +0 -26
data/sig/writer.rbs CHANGED
@@ -21,7 +21,7 @@ module RBS
21
21
  # Output the array of declarations.
22
22
  # It automatically inserts empty lines between the declarations.
23
23
  #
24
- def write: (Array[AST::Declarations::t]) -> void
24
+ def write: (Array[AST::Declarations::t | AST::Directives::t]) -> void
25
25
 
26
26
  def preserve?: () -> bool
27
27
 
@@ -94,6 +94,10 @@ module RBS
94
94
 
95
95
  def write_loc_source: (_Located) { () -> void } -> void
96
96
 
97
+ def format_annotation: (AST::Annotation) -> String
98
+
99
+ def write_directive: (AST::Directives::t) -> void
100
+
97
101
  def write_annotation: (Array[AST::Annotation]) -> void
98
102
 
99
103
  def write_comment: (AST::Comment?) -> void
@@ -106,7 +110,7 @@ module RBS
106
110
 
107
111
  def name_and_args: (TypeName, Array[Types::t]) -> String?
108
112
 
109
- def write_alias: (AST::Declarations::Alias) -> void
113
+ def write_alias: (AST::Declarations::TypeAlias) -> void
110
114
 
111
115
  def method_name: (Symbol) -> String
112
116
 
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: 2.8.4
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-20 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
@@ -159,6 +160,7 @@ files:
159
160
  - lib/rbs/collection.rb
160
161
  - lib/rbs/collection/cleaner.rb
161
162
  - lib/rbs/collection/config.rb
163
+ - lib/rbs/collection/config/lockfile.rb
162
164
  - lib/rbs/collection/config/lockfile_generator.rb
163
165
  - lib/rbs/collection/installer.rb
164
166
  - lib/rbs/collection/sources.rb
@@ -167,12 +169,12 @@ files:
167
169
  - lib/rbs/collection/sources/rubygems.rb
168
170
  - lib/rbs/collection/sources/stdlib.rb
169
171
  - lib/rbs/constant.rb
170
- - lib/rbs/constant_table.rb
171
172
  - lib/rbs/definition.rb
172
173
  - lib/rbs/definition_builder.rb
173
174
  - lib/rbs/definition_builder/ancestor_builder.rb
174
175
  - lib/rbs/definition_builder/method_builder.rb
175
176
  - lib/rbs/environment.rb
177
+ - lib/rbs/environment/use_map.rb
176
178
  - lib/rbs/environment_loader.rb
177
179
  - lib/rbs/environment_walker.rb
178
180
  - lib/rbs/errors.rb
@@ -187,6 +189,7 @@ files:
187
189
  - lib/rbs/parser_compat/semantics_error.rb
188
190
  - lib/rbs/parser_compat/syntax_error.rb
189
191
  - lib/rbs/prototype/helpers.rb
192
+ - lib/rbs/prototype/node_usage.rb
190
193
  - lib/rbs/prototype/rb.rb
191
194
  - lib/rbs/prototype/rbi.rb
192
195
  - lib/rbs/prototype/runtime.rb
@@ -207,7 +210,6 @@ files:
207
210
  - lib/rbs/type_alias_dependency.rb
208
211
  - lib/rbs/type_alias_regularity.rb
209
212
  - lib/rbs/type_name.rb
210
- - lib/rbs/type_name_resolver.rb
211
213
  - lib/rbs/types.rb
212
214
  - lib/rbs/validator.rb
213
215
  - lib/rbs/variance_calculator.rb
@@ -239,14 +241,16 @@ files:
239
241
  - sig/collection.rbs
240
242
  - sig/collection/cleaner.rbs
241
243
  - sig/collection/config.rbs
244
+ - sig/collection/config/lockfile.rbs
245
+ - sig/collection/config/lockfile_generator.rbs
242
246
  - sig/collection/installer.rbs
243
247
  - sig/collection/sources.rbs
244
248
  - sig/comment.rbs
245
249
  - sig/constant.rbs
246
- - sig/constant_table.rbs
247
250
  - sig/declarations.rbs
248
251
  - sig/definition.rbs
249
252
  - sig/definition_builder.rbs
253
+ - sig/directives.rbs
250
254
  - sig/environment.rbs
251
255
  - sig/environment_loader.rbs
252
256
  - sig/environment_walker.rbs
@@ -261,6 +265,7 @@ files:
261
265
  - sig/namespace.rbs
262
266
  - sig/parser.rbs
263
267
  - sig/prototype/helpers.rbs
268
+ - sig/prototype/node_usage.rbs
264
269
  - sig/prototype/rb.rbs
265
270
  - sig/prototype/rbi.rbs
266
271
  - sig/rbs.rbs
@@ -271,17 +276,19 @@ files:
271
276
  - sig/resolver/type_name_resolver.rbs
272
277
  - sig/shims.rbs
273
278
  - sig/shims/abstract_syntax_tree.rbs
279
+ - sig/shims/bundler.rbs
274
280
  - sig/shims/enumerable.rbs
275
281
  - sig/shims/pp.rbs
276
282
  - sig/shims/ripper.rbs
283
+ - sig/shims/rubygems.rbs
277
284
  - sig/sorter.rbs
278
285
  - sig/substitution.rbs
279
286
  - sig/type_alias_dependency.rbs
280
287
  - sig/type_alias_regularity.rbs
281
- - sig/type_name_resolver.rbs
282
288
  - sig/type_param.rbs
283
289
  - sig/typename.rbs
284
290
  - sig/types.rbs
291
+ - sig/use_map.rbs
285
292
  - sig/util.rbs
286
293
  - sig/validator.rbs
287
294
  - sig/variance_calculator.rbs
@@ -435,11 +442,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
435
442
  version: '2.6'
436
443
  required_rubygems_version: !ruby/object:Gem::Requirement
437
444
  requirements:
438
- - - ">="
445
+ - - ">"
439
446
  - !ruby/object:Gem::Version
440
- version: '0'
447
+ version: 1.3.1
441
448
  requirements: []
442
- rubygems_version: 3.3.26
449
+ rubygems_version: 3.4.6
443
450
  signing_key:
444
451
  specification_version: 4
445
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