rbs 4.1.0.pre.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.dockerignore +37 -0
- data/.github/workflows/bundle-update.yml +1 -1
- data/.github/workflows/c-check.yml +11 -6
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/jruby.yml +15 -3
- data/.github/workflows/milestone.yml +9 -1
- data/.github/workflows/ruby.yml +4 -4
- data/.github/workflows/rust.yml +10 -8
- data/.github/workflows/truffleruby.yml +1 -1
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/wasm.yml +4 -2
- data/.github/workflows/windows.yml +2 -2
- data/.gitignore +3 -2
- data/CHANGELOG.md +88 -0
- data/Dockerfile.jruby +53 -0
- data/Rakefile +16 -29
- data/Steepfile +2 -0
- data/core/array.rbs +228 -165
- data/core/float.rbs +0 -24
- data/core/match_data.rbs +1 -1
- data/core/pathname.rbs +0 -10
- data/core/ractor.rbs +0 -10
- data/core/rubygems/errors.rbs +4 -1
- data/core/rubygems/requirement.rbs +0 -10
- data/core/rubygems/rubygems.rbs +4 -1
- data/core/rubygems/specification.rbs +8 -0
- data/core/rubygems/version.rbs +0 -160
- data/core/thread.rbs +3 -8
- data/docs/CONTRIBUTING.md +1 -1
- data/docs/release.md +69 -0
- data/ext/rbs_extension/ast_translation.c +2 -2
- data/ext/rbs_extension/legacy_location.c +11 -6
- data/lib/rbs/parser_aux.rb +4 -2
- data/lib/rbs/prototype/rbi.rb +193 -25
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/runtime.rb +7 -28
- data/lib/rbs_jars.rb +39 -0
- data/lib/rdoc_plugin/parser.rb +5 -0
- data/rbs.gemspec +16 -3
- data/sig/prototype/rbi.rbs +33 -4
- data/src/lexer.c +97 -93
- data/src/lexer.re +1 -1
- data/src/lexstate.c +6 -2
- data/src/util/rbs_allocator.c +13 -4
- data/stdlib/delegate/0/delegator.rbs +2 -1
- data/stdlib/digest/0/digest.rbs +10 -4
- data/stdlib/erb/0/erb.rbs +1 -1
- data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
- data/stdlib/monitor/0/monitor.rbs +2 -2
- data/stdlib/openssl/0/openssl.rbs +39 -33
- data/stdlib/tempfile/0/manifest.yaml +3 -0
- data/stdlib/timeout/0/timeout.rbs +0 -5
- data/stdlib/uri/0/generic.rbs +0 -5
- data/stdlib/zlib/0/zstream.rbs +0 -1
- data/wasm/README.md +4 -3
- data/wasm/rbs_wasm.c +12 -0
- metadata +6 -1
data/lib/rbs/prototype/rbi.rb
CHANGED
|
@@ -9,10 +9,22 @@ module RBS
|
|
|
9
9
|
attr_reader :modules
|
|
10
10
|
attr_reader :last_sig
|
|
11
11
|
|
|
12
|
+
class Context
|
|
13
|
+
attr_accessor :singleton
|
|
14
|
+
attr_accessor :visibility
|
|
15
|
+
|
|
16
|
+
def initialize(singleton:, visibility:)
|
|
17
|
+
@singleton = singleton
|
|
18
|
+
@visibility = visibility
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
12
22
|
def initialize
|
|
13
23
|
@decls = []
|
|
14
24
|
|
|
15
25
|
@modules = []
|
|
26
|
+
@contexts = []
|
|
27
|
+
@emitted_visibility = {}
|
|
16
28
|
end
|
|
17
29
|
|
|
18
30
|
def parse(string)
|
|
@@ -20,19 +32,17 @@ module RBS
|
|
|
20
32
|
process RubyVM::AbstractSyntaxTree.parse(string), comments: comments
|
|
21
33
|
end
|
|
22
34
|
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
modules.inject(Namespace.empty) do |parent, mod|
|
|
29
|
-
parent + mod.name.to_namespace
|
|
35
|
+
def append_decl(decl)
|
|
36
|
+
if mod = current_module
|
|
37
|
+
mod.members << decl
|
|
38
|
+
else
|
|
39
|
+
decls << decl
|
|
30
40
|
end
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
def push_class(name, super_class, comment:)
|
|
34
44
|
class_decl = AST::Declarations::Class.new(
|
|
35
|
-
name:
|
|
45
|
+
name: const_to_name(name),
|
|
36
46
|
super_class: super_class && AST::Declarations::Class::Super.new(name: const_to_name(super_class), args: [], location: nil),
|
|
37
47
|
type_params: [],
|
|
38
48
|
members: [],
|
|
@@ -41,17 +51,20 @@ module RBS
|
|
|
41
51
|
comment: comment
|
|
42
52
|
)
|
|
43
53
|
|
|
54
|
+
append_decl class_decl
|
|
44
55
|
modules << class_decl
|
|
45
|
-
|
|
56
|
+
@contexts << Context.new(singleton: false, visibility: :public)
|
|
57
|
+
@emitted_visibility[class_decl.object_id] = :public
|
|
46
58
|
|
|
47
59
|
yield
|
|
48
60
|
ensure
|
|
61
|
+
@contexts.pop
|
|
49
62
|
modules.pop
|
|
50
63
|
end
|
|
51
64
|
|
|
52
65
|
def push_module(name, comment:)
|
|
53
66
|
module_decl = AST::Declarations::Module.new(
|
|
54
|
-
name:
|
|
67
|
+
name: const_to_name(name),
|
|
55
68
|
type_params: [],
|
|
56
69
|
members: [],
|
|
57
70
|
annotations: [],
|
|
@@ -60,11 +73,14 @@ module RBS
|
|
|
60
73
|
comment: comment
|
|
61
74
|
)
|
|
62
75
|
|
|
76
|
+
append_decl module_decl
|
|
63
77
|
modules << module_decl
|
|
64
|
-
|
|
78
|
+
@contexts << Context.new(singleton: false, visibility: :public)
|
|
79
|
+
@emitted_visibility[module_decl.object_id] = :public
|
|
65
80
|
|
|
66
81
|
yield
|
|
67
82
|
ensure
|
|
83
|
+
@contexts.pop
|
|
68
84
|
modules.pop
|
|
69
85
|
end
|
|
70
86
|
|
|
@@ -76,6 +92,47 @@ module RBS
|
|
|
76
92
|
current_module or raise
|
|
77
93
|
end
|
|
78
94
|
|
|
95
|
+
def current_context
|
|
96
|
+
@contexts.last
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def current_context!
|
|
100
|
+
current_context or raise
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Visibility of a member, given as `private def ...` in RBS
|
|
104
|
+
#
|
|
105
|
+
# Returns `nil` for members in a visibility _section_, which `sync_visibility` emits instead.
|
|
106
|
+
def member_visibility(context)
|
|
107
|
+
# RBS visibility sections don't apply to singleton members, so they need their own visibility.
|
|
108
|
+
if context.singleton && context.visibility != :public
|
|
109
|
+
:private
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def sync_visibility(visibility)
|
|
114
|
+
# Visibility sections don't apply to singleton members in RBS.
|
|
115
|
+
return if current_context!.singleton
|
|
116
|
+
|
|
117
|
+
# RBS has no protected visibility. Private is the conservative fallback.
|
|
118
|
+
visibility = :private if visibility == :protected
|
|
119
|
+
|
|
120
|
+
mod = current_module!
|
|
121
|
+
return if @emitted_visibility[mod.object_id] == visibility
|
|
122
|
+
|
|
123
|
+
member = case visibility
|
|
124
|
+
when :public
|
|
125
|
+
AST::Members::Public.new(location: nil)
|
|
126
|
+
when :private
|
|
127
|
+
AST::Members::Private.new(location: nil)
|
|
128
|
+
else
|
|
129
|
+
raise "Unexpected visibility: #{visibility}"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
mod.members << member
|
|
133
|
+
@emitted_visibility[mod.object_id] = visibility
|
|
134
|
+
end
|
|
135
|
+
|
|
79
136
|
def push_sig(node)
|
|
80
137
|
if last_sig = @last_sig
|
|
81
138
|
last_sig << node
|
|
@@ -107,6 +164,15 @@ module RBS
|
|
|
107
164
|
push_module node.children[0], comment: comment do
|
|
108
165
|
process node.children[1], outer: outer + [node], comments: comments
|
|
109
166
|
end
|
|
167
|
+
when :SCLASS
|
|
168
|
+
if node.children[0].type == :SELF
|
|
169
|
+
@contexts << Context.new(singleton: true, visibility: :public)
|
|
170
|
+
begin
|
|
171
|
+
process node.children[1], outer: outer + [node], comments: comments
|
|
172
|
+
ensure
|
|
173
|
+
@contexts.pop
|
|
174
|
+
end
|
|
175
|
+
end
|
|
110
176
|
when :FCALL
|
|
111
177
|
case node.children[0]
|
|
112
178
|
when :include
|
|
@@ -125,9 +191,9 @@ module RBS
|
|
|
125
191
|
end
|
|
126
192
|
when :extend
|
|
127
193
|
each_arg node.children[1] do |arg|
|
|
128
|
-
if arg.type == :CONST || arg.type == :COLON2
|
|
194
|
+
if arg.type == :CONST || arg.type == :COLON2 || arg.type == :COLON3
|
|
129
195
|
name = const_to_name(arg)
|
|
130
|
-
unless
|
|
196
|
+
unless ["T::Generic", "T::Helpers", "T::Sig"].include?(name.to_s.delete_prefix("::"))
|
|
131
197
|
member = AST::Members::Extend.new(
|
|
132
198
|
name: name,
|
|
133
199
|
args: [],
|
|
@@ -142,6 +208,10 @@ module RBS
|
|
|
142
208
|
when :sig
|
|
143
209
|
out = outer.last or raise
|
|
144
210
|
push_sig out.children.last.children.last
|
|
211
|
+
when :attr_reader, :attr_writer, :attr_accessor
|
|
212
|
+
process_attribute node, comments: comments
|
|
213
|
+
when :private, :protected, :public
|
|
214
|
+
process_visibility node, outer: outer, comments: comments
|
|
145
215
|
when :alias_method
|
|
146
216
|
new, old = each_arg(node.children[1]).map {|x| x.children[0] }
|
|
147
217
|
current_module!.members << AST::Members::Alias.new(
|
|
@@ -149,10 +219,15 @@ module RBS
|
|
|
149
219
|
old_name: old,
|
|
150
220
|
location: nil,
|
|
151
221
|
annotations: [],
|
|
152
|
-
kind: :instance,
|
|
222
|
+
kind: current_context!.singleton ? :singleton : :instance,
|
|
153
223
|
comment: nil
|
|
154
224
|
)
|
|
155
225
|
end
|
|
226
|
+
when :VCALL
|
|
227
|
+
case node.children[0]
|
|
228
|
+
when :private, :protected, :public
|
|
229
|
+
current_context!.visibility = node.children[0]
|
|
230
|
+
end
|
|
156
231
|
when :DEFS
|
|
157
232
|
sigs = pop_sig
|
|
158
233
|
|
|
@@ -178,6 +253,8 @@ module RBS
|
|
|
178
253
|
sigs = pop_sig
|
|
179
254
|
|
|
180
255
|
if sigs
|
|
256
|
+
context = current_context!
|
|
257
|
+
sync_visibility(context.visibility)
|
|
181
258
|
comment = join_comments(sigs, comments)
|
|
182
259
|
|
|
183
260
|
args = node.children[1]
|
|
@@ -188,10 +265,10 @@ module RBS
|
|
|
188
265
|
location: nil,
|
|
189
266
|
annotations: [],
|
|
190
267
|
overloads: types.map {|type| AST::Members::MethodDefinition::Overload.new(annotations: [], method_type: type) },
|
|
191
|
-
kind: :instance,
|
|
268
|
+
kind: context.singleton ? :singleton : :instance,
|
|
192
269
|
comment: comment,
|
|
193
270
|
overloading: false,
|
|
194
|
-
visibility:
|
|
271
|
+
visibility: member_visibility(context)
|
|
195
272
|
)
|
|
196
273
|
end
|
|
197
274
|
|
|
@@ -222,11 +299,7 @@ module RBS
|
|
|
222
299
|
end
|
|
223
300
|
else
|
|
224
301
|
name = node.children[0].yield_self do |n|
|
|
225
|
-
|
|
226
|
-
TypeName.new(namespace: current_namespace, name: n)
|
|
227
|
-
else
|
|
228
|
-
const_to_name(n)
|
|
229
|
-
end
|
|
302
|
+
n.is_a?(Symbol) ? TypeName.new(namespace: Namespace.empty, name: n) : const_to_name(n)
|
|
230
303
|
end
|
|
231
304
|
value_node = node.children.last
|
|
232
305
|
type = if value_node && value_node.type == :CALL && value_node.children[1] == :let
|
|
@@ -235,7 +308,7 @@ module RBS
|
|
|
235
308
|
else
|
|
236
309
|
Types::Bases::Any.new(location: nil)
|
|
237
310
|
end
|
|
238
|
-
|
|
311
|
+
append_decl AST::Declarations::Constant.new(
|
|
239
312
|
name: name,
|
|
240
313
|
type: type,
|
|
241
314
|
location: nil,
|
|
@@ -244,12 +317,13 @@ module RBS
|
|
|
244
317
|
)
|
|
245
318
|
end
|
|
246
319
|
when :ALIAS
|
|
320
|
+
sync_visibility(current_context!.visibility)
|
|
247
321
|
current_module!.members << AST::Members::Alias.new(
|
|
248
322
|
new_name: node.children[0].children[0],
|
|
249
323
|
old_name: node.children[1].children[0],
|
|
250
324
|
location: nil,
|
|
251
325
|
annotations: [],
|
|
252
|
-
kind: :instance,
|
|
326
|
+
kind: current_context!.singleton ? :singleton : :instance,
|
|
253
327
|
comment: nil
|
|
254
328
|
)
|
|
255
329
|
else
|
|
@@ -259,6 +333,93 @@ module RBS
|
|
|
259
333
|
end
|
|
260
334
|
end
|
|
261
335
|
|
|
336
|
+
def process_visibility(node, outer:, comments:)
|
|
337
|
+
visibility = node.children[0]
|
|
338
|
+
args = each_arg(node.children[1]).to_a
|
|
339
|
+
context = current_context!
|
|
340
|
+
|
|
341
|
+
if args.empty?
|
|
342
|
+
context.visibility = visibility
|
|
343
|
+
else
|
|
344
|
+
previous_visibility = context.visibility
|
|
345
|
+
context.visibility = visibility
|
|
346
|
+
|
|
347
|
+
begin
|
|
348
|
+
args.each do |arg|
|
|
349
|
+
if arg.type == :DEFN || arg.type == :DEFS
|
|
350
|
+
process arg, outer: outer + [node], comments: comments
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
ensure
|
|
354
|
+
context.visibility = previous_visibility
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
def process_attribute(node, comments:)
|
|
360
|
+
sigs = pop_sig
|
|
361
|
+
kind = node.children[0]
|
|
362
|
+
context = current_context!
|
|
363
|
+
sync_visibility(context.visibility)
|
|
364
|
+
|
|
365
|
+
type = attribute_type(kind, sigs)
|
|
366
|
+
comment = join_comments(sigs, comments) if sigs
|
|
367
|
+
member_class = case kind
|
|
368
|
+
when :attr_reader
|
|
369
|
+
AST::Members::AttrReader
|
|
370
|
+
when :attr_writer
|
|
371
|
+
AST::Members::AttrWriter
|
|
372
|
+
when :attr_accessor
|
|
373
|
+
AST::Members::AttrAccessor
|
|
374
|
+
else
|
|
375
|
+
raise "Unexpected attribute kind: #{kind}"
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
each_arg node.children[1] do |arg|
|
|
379
|
+
if name = symbol_literal_node?(arg)
|
|
380
|
+
current_module!.members << member_class.new(
|
|
381
|
+
name: name,
|
|
382
|
+
type: type,
|
|
383
|
+
ivar_name: nil,
|
|
384
|
+
kind: context.singleton ? :singleton : :instance,
|
|
385
|
+
annotations: [],
|
|
386
|
+
location: nil,
|
|
387
|
+
comment: comment,
|
|
388
|
+
visibility: member_visibility(context)
|
|
389
|
+
)
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
def attribute_type(kind, sigs)
|
|
395
|
+
any = Types::Bases::Any.new(location: nil)
|
|
396
|
+
return any unless sigs
|
|
397
|
+
|
|
398
|
+
method_types = sigs.filter_map do |sig|
|
|
399
|
+
method_type(nil, sig, variables: current_module!.type_params, overloads: sigs.size)
|
|
400
|
+
end
|
|
401
|
+
function = method_types.last&.type
|
|
402
|
+
return any unless function.is_a?(Types::Function)
|
|
403
|
+
|
|
404
|
+
parameter_type = function.required_positionals.first&.type
|
|
405
|
+
return_type = function.return_type
|
|
406
|
+
|
|
407
|
+
case kind
|
|
408
|
+
when :attr_reader
|
|
409
|
+
return_type
|
|
410
|
+
when :attr_writer
|
|
411
|
+
parameter_type || return_type
|
|
412
|
+
when :attr_accessor
|
|
413
|
+
if return_type.is_a?(Types::Bases::Any) || return_type.is_a?(Types::Bases::Void)
|
|
414
|
+
parameter_type || any
|
|
415
|
+
else
|
|
416
|
+
return_type
|
|
417
|
+
end
|
|
418
|
+
else
|
|
419
|
+
any
|
|
420
|
+
end
|
|
421
|
+
end
|
|
422
|
+
|
|
262
423
|
def method_type(args_node, type_node, variables:, overloads:)
|
|
263
424
|
if type_node
|
|
264
425
|
if type_node.type == :CALL
|
|
@@ -463,8 +624,10 @@ module RBS
|
|
|
463
624
|
case
|
|
464
625
|
when type.is_a?(Types::ClassInstance) && type.name.name == BuiltinNames::BasicObject.name.name
|
|
465
626
|
Types::Bases::Any.new(location: nil)
|
|
466
|
-
when type.is_a?(Types::ClassInstance) && type.name.to_s == "T::Boolean"
|
|
627
|
+
when type.is_a?(Types::ClassInstance) && type.name.to_s.delete_prefix("::") == "T::Boolean"
|
|
467
628
|
Types::Bases::Bool.new(location: nil)
|
|
629
|
+
when type.is_a?(Types::ClassInstance) && type.name.to_s.delete_prefix("::") == "T::Class"
|
|
630
|
+
Types::Bases::Any.new(location: nil)
|
|
468
631
|
else
|
|
469
632
|
type
|
|
470
633
|
end
|
|
@@ -482,6 +645,11 @@ module RBS
|
|
|
482
645
|
Types::ClassInstance.new(name: const_to_name(type_node), args: [], location: nil)
|
|
483
646
|
when call_node?(type_node, name: :[], receiver: -> (_) { true })
|
|
484
647
|
# The type_node represents a type application
|
|
648
|
+
receiver = type_node.children[0]
|
|
649
|
+
if [:CONST, :COLON2, :COLON3].include?(receiver.type) && const_to_name(receiver).to_s.delete_prefix("::") == "T::Class"
|
|
650
|
+
return Types::Bases::Any.new(location: nil)
|
|
651
|
+
end
|
|
652
|
+
|
|
485
653
|
type = type_of(type_node.children[0], variables: variables)
|
|
486
654
|
type.is_a?(Types::ClassInstance) or raise
|
|
487
655
|
|
|
@@ -559,7 +727,7 @@ module RBS
|
|
|
559
727
|
|
|
560
728
|
type_name = TypeName.new(name: node.children[1], namespace: namespace)
|
|
561
729
|
|
|
562
|
-
case type_name.to_s
|
|
730
|
+
case type_name.to_s.delete_prefix("::")
|
|
563
731
|
when "T::Array"
|
|
564
732
|
BuiltinNames::Array.name
|
|
565
733
|
when "T::Hash"
|
data/lib/rbs/version.rb
CHANGED
data/lib/rbs/wasm/runtime.rb
CHANGED
|
@@ -10,21 +10,12 @@ module RBS
|
|
|
10
10
|
# source string into the module's linear memory, runs the parser, and returns
|
|
11
11
|
# the serialized result for RBS::WASM::Deserializer to rebuild.
|
|
12
12
|
#
|
|
13
|
-
# Chicory is a pure-Java runtime, so there is no native dependency
|
|
14
|
-
# `.wasm`
|
|
13
|
+
# Chicory is a pure-Java runtime, so there is no native dependency. The
|
|
14
|
+
# `.wasm` ships in the gem; the Chicory jars are fetched from Maven by
|
|
15
|
+
# jar-dependencies (see lib/rbs_jars.rb and rbs.gemspec).
|
|
15
16
|
class Runtime
|
|
16
17
|
include MonitorMixin
|
|
17
18
|
|
|
18
|
-
# The Chicory jars the runtime needs at load time.
|
|
19
|
-
# Jars Chicory needs to load and run the module.
|
|
20
|
-
JARS = %w[wasm runtime log wasi].freeze
|
|
21
|
-
|
|
22
|
-
# Jars for Chicory's ahead-of-time compiler (wasm -> JVM bytecode), which
|
|
23
|
-
# runs the parser ~8x faster than the interpreter. Optional: the runtime
|
|
24
|
-
# falls back to the interpreter when they are absent. asm* are the ow2 ASM
|
|
25
|
-
# libraries the compiler depends on.
|
|
26
|
-
OPTIONAL_JARS = %w[compiler asm asm-tree asm-util asm-commons asm-analysis].freeze
|
|
27
|
-
|
|
28
19
|
class << self
|
|
29
20
|
def instance
|
|
30
21
|
@instance ||= new
|
|
@@ -33,15 +24,14 @@ module RBS
|
|
|
33
24
|
def wasm_path
|
|
34
25
|
ENV["RBS_WASM_PARSER"] || File.expand_path("rbs_parser.wasm", __dir__)
|
|
35
26
|
end
|
|
36
|
-
|
|
37
|
-
def jars_dir
|
|
38
|
-
ENV["RBS_WASM_JARS"] || File.expand_path("jars", __dir__)
|
|
39
|
-
end
|
|
40
27
|
end
|
|
41
28
|
|
|
42
29
|
def initialize
|
|
43
30
|
super()
|
|
44
|
-
|
|
31
|
+
# rbs_jars.rb require_jars the Chicory/ASM jars from the local Maven
|
|
32
|
+
# repository (~/.m2), where jar-dependencies puts them at gem install (or
|
|
33
|
+
# `rake wasm:install_jars` when running from source).
|
|
34
|
+
require "rbs_jars"
|
|
45
35
|
@wasm = build_instance
|
|
46
36
|
@memory = @wasm.memory
|
|
47
37
|
@alloc = @wasm.export("rbs_wasm_alloc")
|
|
@@ -201,17 +191,6 @@ module RBS
|
|
|
201
191
|
nil
|
|
202
192
|
end
|
|
203
193
|
|
|
204
|
-
def load_jars
|
|
205
|
-
JARS.each { |name| require jar_path(name) }
|
|
206
|
-
OPTIONAL_JARS.each do |name|
|
|
207
|
-
path = jar_path(name)
|
|
208
|
-
require path if File.exist?(path)
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def jar_path(name)
|
|
213
|
-
File.join(self.class.jars_dir, "#{name}.jar")
|
|
214
|
-
end
|
|
215
194
|
end
|
|
216
195
|
end
|
|
217
196
|
end
|
data/lib/rbs_jars.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This is the file jar-dependencies generates from the `jar` requirements in
|
|
4
|
+
# rbs.gemspec, kept with hand edits:
|
|
5
|
+
# 1. the `com.dylibso.chicory:runtime` require_jar line is corrected -- the
|
|
6
|
+
# generator mangles that artifact id to `jar` (it collides with a Maven
|
|
7
|
+
# scope keyword), which breaks loading;
|
|
8
|
+
# 2. the "# this is a generated file" marker is dropped so jar-dependencies
|
|
9
|
+
# does not regenerate (and re-break) this file at gem install;
|
|
10
|
+
# 3. a frozen_string_literal magic comment is added (rubocop).
|
|
11
|
+
# `rake wasm:install_jars` downloads the jars into ~/.m2; to refresh the list
|
|
12
|
+
# after a version bump, regenerate the file and re-apply these edits.
|
|
13
|
+
begin
|
|
14
|
+
require 'jar_dependencies'
|
|
15
|
+
rescue LoadError
|
|
16
|
+
require 'com/dylibso/chicory/compiler/1.7.5/compiler-1.7.5.jar'
|
|
17
|
+
require 'com/dylibso/chicory/runtime/1.7.5/runtime-1.7.5.jar'
|
|
18
|
+
require 'com/dylibso/chicory/wasm/1.7.5/wasm-1.7.5.jar'
|
|
19
|
+
require 'org/ow2/asm/asm/9.9.1/asm-9.9.1.jar'
|
|
20
|
+
require 'org/ow2/asm/asm-commons/9.9.1/asm-commons-9.9.1.jar'
|
|
21
|
+
require 'org/ow2/asm/asm-tree/9.9.1/asm-tree-9.9.1.jar'
|
|
22
|
+
require 'org/ow2/asm/asm-util/9.9.1/asm-util-9.9.1.jar'
|
|
23
|
+
require 'org/ow2/asm/asm-analysis/9.9.1/asm-analysis-9.9.1.jar'
|
|
24
|
+
require 'com/dylibso/chicory/wasi/1.7.5/wasi-1.7.5.jar'
|
|
25
|
+
require 'com/dylibso/chicory/log/1.7.5/log-1.7.5.jar'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if defined? Jars
|
|
29
|
+
require_jar 'com.dylibso.chicory', 'compiler', '1.7.5'
|
|
30
|
+
require_jar 'com.dylibso.chicory', 'runtime', '1.7.5'
|
|
31
|
+
require_jar 'com.dylibso.chicory', 'wasm', '1.7.5'
|
|
32
|
+
require_jar 'org.ow2.asm', 'asm', '9.9.1'
|
|
33
|
+
require_jar 'org.ow2.asm', 'asm-commons', '9.9.1'
|
|
34
|
+
require_jar 'org.ow2.asm', 'asm-tree', '9.9.1'
|
|
35
|
+
require_jar 'org.ow2.asm', 'asm-util', '9.9.1'
|
|
36
|
+
require_jar 'org.ow2.asm', 'asm-analysis', '9.9.1'
|
|
37
|
+
require_jar 'com.dylibso.chicory', 'wasi', '1.7.5'
|
|
38
|
+
require_jar 'com.dylibso.chicory', 'log', '1.7.5'
|
|
39
|
+
end
|
data/lib/rdoc_plugin/parser.rb
CHANGED
|
@@ -14,6 +14,11 @@ module RBS
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def scan
|
|
17
|
+
Kernel.warn(
|
|
18
|
+
"The RBS RDoc parser plugin is deprecated and will be removed from RBS. " \
|
|
19
|
+
"RDoc 8.0 provides RBS parsing directly."
|
|
20
|
+
)
|
|
21
|
+
|
|
17
22
|
_, _, decls = ::RBS::Parser.parse_signature(@content)
|
|
18
23
|
decls.each do |decl|
|
|
19
24
|
parse_member(decl: decl, context: @top_level)
|
data/rbs.gemspec
CHANGED
|
@@ -38,8 +38,10 @@ Gem::Specification.new do |spec|
|
|
|
38
38
|
|
|
39
39
|
# JRuby cannot load the MRI C extension. On JRuby (and in the `java` platform
|
|
40
40
|
# gem, built with RBS_PLATFORM=java) RBS runs the WebAssembly-backed parser, so
|
|
41
|
-
# ship the prebuilt parser
|
|
42
|
-
#
|
|
41
|
+
# ship the prebuilt parser (built by `rake wasm:build`) and skip the C
|
|
42
|
+
# extension. The Chicory/ASM jars the runtime needs are NOT shipped in the gem:
|
|
43
|
+
# they are declared as `jar-dependencies` requirements below and fetched from
|
|
44
|
+
# Maven Central at install time (see lib/rbs/wasm/jars.rb).
|
|
43
45
|
building_java_gem = ENV["RBS_PLATFORM"] == "java"
|
|
44
46
|
on_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
|
45
47
|
|
|
@@ -47,9 +49,20 @@ Gem::Specification.new do |spec|
|
|
|
47
49
|
# Only stamp the platform when building the release gem; leave it unset for
|
|
48
50
|
# local development on JRuby so it still matches a `ruby` platform lockfile.
|
|
49
51
|
spec.platform = "java" if building_java_gem
|
|
52
|
+
# rbs_parser.wasm is a build artifact (not tracked in git), so add it
|
|
53
|
+
# explicitly. lib/rbs_jars.rb is committed, so git ls-files already has it.
|
|
50
54
|
spec.files += Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
51
|
-
Dir.glob("lib/rbs/wasm/rbs_parser.wasm")
|
|
55
|
+
Dir.glob("lib/rbs/wasm/rbs_parser.wasm")
|
|
52
56
|
end
|
|
57
|
+
|
|
58
|
+
# jar-dependencies (bundled with JRuby) downloads these jars from Maven when
|
|
59
|
+
# the gem is installed, keeping the gem small and avoiding conflicting copies.
|
|
60
|
+
# Only the top-level artifacts are declared; Maven resolves the rest (runtime,
|
|
61
|
+
# wasm, asm, ...) transitively. lib/rbs_jars.rb require_jars the full resolved
|
|
62
|
+
# set at load time.
|
|
63
|
+
spec.add_dependency "jar-dependencies", ">= 0.1.7"
|
|
64
|
+
spec.requirements << "jar com.dylibso.chicory:compiler, 1.7.5"
|
|
65
|
+
spec.requirements << "jar com.dylibso.chicory:wasi, 1.7.5"
|
|
53
66
|
else
|
|
54
67
|
spec.extensions = %w{ext/rbs_extension/extconf.rb}
|
|
55
68
|
end
|
data/sig/prototype/rbi.rbs
CHANGED
|
@@ -2,7 +2,17 @@ module RBS
|
|
|
2
2
|
module Prototype
|
|
3
3
|
class RBI
|
|
4
4
|
include Helpers
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
type visibility = :private | :protected | :public
|
|
7
|
+
|
|
8
|
+
class Context
|
|
9
|
+
attr_accessor singleton: bool
|
|
10
|
+
|
|
11
|
+
attr_accessor visibility: visibility
|
|
12
|
+
|
|
13
|
+
def initialize: (singleton: bool, visibility: visibility) -> void
|
|
14
|
+
end
|
|
15
|
+
|
|
6
16
|
attr_reader decls: Array[AST::Declarations::t]
|
|
7
17
|
|
|
8
18
|
type module_decl = AST::Declarations::Class | AST::Declarations::Module
|
|
@@ -13,13 +23,15 @@ module RBS
|
|
|
13
23
|
# Last subsequent `sig` calls
|
|
14
24
|
attr_reader last_sig: Array[RubyVM::AbstractSyntaxTree::Node]?
|
|
15
25
|
|
|
26
|
+
@contexts: Array[Context]
|
|
27
|
+
|
|
28
|
+
@emitted_visibility: Hash[Integer, visibility]
|
|
29
|
+
|
|
16
30
|
def initialize: () -> void
|
|
17
31
|
|
|
18
32
|
def parse: (String) -> void
|
|
19
33
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
def current_namespace: () -> Namespace
|
|
34
|
+
def append_decl: (AST::Declarations::t decl) -> void
|
|
23
35
|
|
|
24
36
|
def push_class: (
|
|
25
37
|
RubyVM::AbstractSyntaxTree::Node name,
|
|
@@ -35,6 +47,17 @@ module RBS
|
|
|
35
47
|
# The inner most module/class definition, raises on toplevel
|
|
36
48
|
def current_module!: () -> module_decl
|
|
37
49
|
|
|
50
|
+
def current_context: () -> Context?
|
|
51
|
+
|
|
52
|
+
def current_context!: () -> Context
|
|
53
|
+
|
|
54
|
+
# Visibility of a member, given as `private def ...` in RBS
|
|
55
|
+
#
|
|
56
|
+
# Returns `nil` for members in a visibility _section_, which `sync_visibility` emits instead.
|
|
57
|
+
def member_visibility: (Context) -> AST::Members::visibility?
|
|
58
|
+
|
|
59
|
+
def sync_visibility: (visibility) -> void
|
|
60
|
+
|
|
38
61
|
# Put a `sig` call to current list.
|
|
39
62
|
def push_sig: (RubyVM::AbstractSyntaxTree::Node node) -> void
|
|
40
63
|
|
|
@@ -45,6 +68,12 @@ module RBS
|
|
|
45
68
|
|
|
46
69
|
def process: (RubyVM::AbstractSyntaxTree::Node node, comments: Hash[Integer, AST::Comment], ?outer: Array[RubyVM::AbstractSyntaxTree::Node]) -> void
|
|
47
70
|
|
|
71
|
+
def process_visibility: (RubyVM::AbstractSyntaxTree::Node node, outer: Array[RubyVM::AbstractSyntaxTree::Node], comments: Hash[Integer, AST::Comment]) -> void
|
|
72
|
+
|
|
73
|
+
def process_attribute: (RubyVM::AbstractSyntaxTree::Node node, comments: Hash[Integer, AST::Comment]) -> void
|
|
74
|
+
|
|
75
|
+
def attribute_type: (:attr_reader | :attr_writer | :attr_accessor kind, Array[RubyVM::AbstractSyntaxTree::Node]? sigs) -> Types::t
|
|
76
|
+
|
|
48
77
|
def method_type: (RubyVM::AbstractSyntaxTree::Node? args_node, RubyVM::AbstractSyntaxTree::Node? type_node, variables: Array[AST::TypeParam], overloads: Integer) -> MethodType?
|
|
49
78
|
|
|
50
79
|
def parse_params: (RubyVM::AbstractSyntaxTree::Node args_node, RubyVM::AbstractSyntaxTree::Node args, MethodType method_type, variables: Array[AST::TypeParam], overloads: Integer) -> MethodType
|