rbs 4.0.0.dev.5 → 4.0.1.dev.1
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/.clang-format +1 -0
- data/.github/workflows/c-check.yml +8 -4
- data/.github/workflows/comments.yml +3 -1
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +10 -0
- data/.github/workflows/rust.yml +95 -0
- data/CHANGELOG.md +323 -0
- data/Rakefile +12 -29
- data/Steepfile +1 -0
- data/config.yml +393 -37
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +52 -40
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +5 -5
- data/core/enumerable.rbs +96 -91
- data/core/enumerator.rbs +4 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +36 -36
- data/core/file.rbs +186 -113
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +41 -32
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -28
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +120 -135
- data/core/kernel.rbs +189 -139
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -6
- data/core/module.rbs +146 -85
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +35 -32
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -33
- data/core/process.rbs +219 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +4 -3
- data/core/range.rbs +52 -47
- data/core/rational.rbs +5 -5
- data/core/rbs/unnamed/argf.rbs +58 -51
- data/core/rbs/unnamed/env_class.rbs +18 -13
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +7 -5
- data/core/regexp.rbs +236 -197
- data/core/ruby.rbs +1 -1
- data/core/ruby_vm.rbs +32 -30
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +1 -1
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +5 -3
- data/core/set.rbs +17 -16
- data/core/signal.rbs +2 -2
- data/core/string.rbs +311 -292
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -34
- data/core/time.rbs +47 -42
- data/core/trace_point.rbs +34 -31
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +10 -10
- data/core/warning.rbs +7 -7
- data/docs/collection.md +1 -1
- data/docs/config.md +171 -0
- data/docs/inline.md +110 -4
- data/docs/syntax.md +13 -12
- data/ext/rbs_extension/ast_translation.c +489 -135
- data/ext/rbs_extension/class_constants.c +8 -0
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/legacy_location.c +28 -51
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +12 -20
- data/include/rbs/ast.h +423 -195
- data/include/rbs/lexer.h +2 -2
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +2 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/ruby/annotations.rb +157 -4
- data/lib/rbs/ast/ruby/members.rb +374 -22
- data/lib/rbs/cli/validate.rb +5 -60
- data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
- data/lib/rbs/definition_builder.rb +60 -27
- data/lib/rbs/errors.rb +0 -11
- data/lib/rbs/inline_parser.rb +1 -1
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +1 -26
- data/lib/rbs/prototype/rbi.rb +1 -20
- data/lib/rbs/test/type_check.rb +3 -0
- data/lib/rbs/types.rb +62 -52
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +0 -1
- data/rbs.gemspec +1 -1
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/sig/ast/ruby/annotations.rbs +191 -4
- data/sig/ast/ruby/members.rbs +21 -1
- data/sig/cli/validate.rbs +1 -6
- data/sig/definition_builder.rbs +2 -0
- data/sig/errors.rbs +0 -8
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +17 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/types.rbs +10 -11
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +339 -161
- data/src/lexstate.c +1 -1
- data/src/location.c +7 -47
- data/src/parser.c +674 -480
- data/src/util/rbs_constant_pool.c +0 -4
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
- data/stdlib/cgi-escape/0/escape.rbs +4 -4
- data/stdlib/coverage/0/coverage.rbs +4 -3
- data/stdlib/date/0/date.rbs +33 -28
- data/stdlib/date/0/date_time.rbs +24 -23
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +138 -125
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +135 -108
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +159 -134
- data/stdlib/objspace/0/objspace.rbs +8 -7
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +36 -35
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +18 -14
- data/stdlib/pathname/0/pathname.rbs +2 -2
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +61 -8
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +2 -2
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/securerandom.rbs +1 -1
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +10 -9
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +1 -1
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +55 -54
- data/stdlib/strscan/0/string_scanner.rbs +46 -44
- data/stdlib/tempfile/0/tempfile.rbs +24 -20
- data/stdlib/time/0/time.rbs +7 -5
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +26 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +4 -4
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- metadata +23 -5
- data/.github/workflows/valgrind.yml +0 -42
data/core/errors.rbs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#
|
|
7
7
|
# [1, 2, 3].first(4, 5)
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# <em>raises the exception:</em>
|
|
10
10
|
#
|
|
11
11
|
# ArgumentError: wrong number of arguments (given 2, expected 1)
|
|
12
12
|
#
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
#
|
|
15
15
|
# [1, 2, 3].first(-4)
|
|
16
16
|
#
|
|
17
|
-
#
|
|
17
|
+
# <em>raises the exception:</em>
|
|
18
18
|
#
|
|
19
19
|
# ArgumentError: negative array size
|
|
20
20
|
#
|
|
@@ -66,7 +66,7 @@ end
|
|
|
66
66
|
#
|
|
67
67
|
# [1, 2, 3].freeze << 4
|
|
68
68
|
#
|
|
69
|
-
#
|
|
69
|
+
# <em>raises the exception:</em>
|
|
70
70
|
#
|
|
71
71
|
# FrozenError: can't modify frozen Array
|
|
72
72
|
#
|
|
@@ -115,11 +115,11 @@ end
|
|
|
115
115
|
# puts "Note: You will typically use Signal.trap instead."
|
|
116
116
|
# end
|
|
117
117
|
#
|
|
118
|
-
#
|
|
118
|
+
# <em>produces:</em>
|
|
119
119
|
#
|
|
120
120
|
# Press ctrl-C when you get bored
|
|
121
121
|
#
|
|
122
|
-
#
|
|
122
|
+
# <em>then waits until it is interrupted with Control-C and then prints:</em>
|
|
123
123
|
#
|
|
124
124
|
# Note: You will typically use Signal.trap instead.
|
|
125
125
|
#
|
|
@@ -184,7 +184,7 @@ end
|
|
|
184
184
|
#
|
|
185
185
|
# require 'this/file/does/not/exist'
|
|
186
186
|
#
|
|
187
|
-
#
|
|
187
|
+
# <em>raises the exception:</em>
|
|
188
188
|
#
|
|
189
189
|
# LoadError: no such file to load -- this/file/does/not/exist
|
|
190
190
|
#
|
|
@@ -209,7 +209,7 @@ end
|
|
|
209
209
|
# end
|
|
210
210
|
# call_block
|
|
211
211
|
#
|
|
212
|
-
#
|
|
212
|
+
# <em>raises the exception:</em>
|
|
213
213
|
#
|
|
214
214
|
# LocalJumpError: no block given (yield)
|
|
215
215
|
#
|
|
@@ -220,7 +220,7 @@ end
|
|
|
220
220
|
# end
|
|
221
221
|
# get_me_a_return.call
|
|
222
222
|
#
|
|
223
|
-
#
|
|
223
|
+
# <em>raises the exception:</em>
|
|
224
224
|
#
|
|
225
225
|
# LocalJumpError: unexpected return
|
|
226
226
|
#
|
|
@@ -248,7 +248,7 @@ end
|
|
|
248
248
|
#
|
|
249
249
|
# puts foo
|
|
250
250
|
#
|
|
251
|
-
#
|
|
251
|
+
# <em>raises the exception:</em>
|
|
252
252
|
#
|
|
253
253
|
# NameError: undefined local variable or method `foo' for main:Object
|
|
254
254
|
#
|
|
@@ -256,7 +256,7 @@ end
|
|
|
256
256
|
#
|
|
257
257
|
# Integer.const_set :answer, 42
|
|
258
258
|
#
|
|
259
|
-
#
|
|
259
|
+
# <em>raises the exception:</em>
|
|
260
260
|
#
|
|
261
261
|
# NameError: wrong constant name answer
|
|
262
262
|
#
|
|
@@ -350,7 +350,7 @@ end
|
|
|
350
350
|
#
|
|
351
351
|
# "hello".to_ary
|
|
352
352
|
#
|
|
353
|
-
#
|
|
353
|
+
# <em>raises the exception:</em>
|
|
354
354
|
#
|
|
355
355
|
# NoMethodError: undefined method `to_ary' for an instance of String
|
|
356
356
|
#
|
|
@@ -360,11 +360,13 @@ class NoMethodError[T] < NameError[T]
|
|
|
360
360
|
# - NoMethodError.new(msg=nil, name=nil, args=nil, private=false, receiver: nil) -> no_method_error
|
|
361
361
|
# -->
|
|
362
362
|
# Construct a NoMethodError exception for a method of the given name called with
|
|
363
|
-
# the given arguments. The name may be accessed using the
|
|
364
|
-
# resulting object, and the arguments using the
|
|
363
|
+
# the given arguments. The name may be accessed using the <code>#name</code>
|
|
364
|
+
# method on the resulting object, and the arguments using the <code>#args</code>
|
|
365
|
+
# method.
|
|
365
366
|
#
|
|
366
367
|
# If *private* argument were passed, it designates method was attempted to call
|
|
367
|
-
# in private context, and can be accessed with
|
|
368
|
+
# in private context, and can be accessed with <code>#private_call?</code>
|
|
369
|
+
# method.
|
|
368
370
|
#
|
|
369
371
|
# *receiver* argument stores an object whose method was called.
|
|
370
372
|
#
|
|
@@ -393,8 +395,8 @@ end
|
|
|
393
395
|
# exception if the underlying operating system or Ruby runtime does not support
|
|
394
396
|
# them.
|
|
395
397
|
#
|
|
396
|
-
# Note that if `fork` raises a `NotImplementedError`, then
|
|
397
|
-
# returns `false`.
|
|
398
|
+
# Note that if `fork` raises a `NotImplementedError`, then
|
|
399
|
+
# <code>respond_to?(:fork)</code> returns `false`.
|
|
398
400
|
#
|
|
399
401
|
class NotImplementedError < ScriptError
|
|
400
402
|
end
|
|
@@ -404,7 +406,7 @@ end
|
|
|
404
406
|
#
|
|
405
407
|
# [1, 2, 3].drop(1 << 100)
|
|
406
408
|
#
|
|
407
|
-
#
|
|
409
|
+
# <em>raises the exception:</em>
|
|
408
410
|
#
|
|
409
411
|
# RangeError: bignum too big to convert into `long'
|
|
410
412
|
#
|
|
@@ -416,7 +418,7 @@ end
|
|
|
416
418
|
#
|
|
417
419
|
# Regexp.new("?")
|
|
418
420
|
#
|
|
419
|
-
#
|
|
421
|
+
# <em>raises the exception:</em>
|
|
420
422
|
#
|
|
421
423
|
# RegexpError: target of repeat operator is not specified: /?/
|
|
422
424
|
#
|
|
@@ -429,7 +431,7 @@ end
|
|
|
429
431
|
#
|
|
430
432
|
# raise "ouch"
|
|
431
433
|
#
|
|
432
|
-
#
|
|
434
|
+
# <em>raises the exception:</em>
|
|
433
435
|
#
|
|
434
436
|
# RuntimeError: ouch
|
|
435
437
|
#
|
|
@@ -461,7 +463,7 @@ end
|
|
|
461
463
|
# puts "received Exception #{e}"
|
|
462
464
|
# end
|
|
463
465
|
#
|
|
464
|
-
#
|
|
466
|
+
# <em>produces:</em>
|
|
465
467
|
#
|
|
466
468
|
# received Exception SIGHUP
|
|
467
469
|
#
|
|
@@ -502,7 +504,7 @@ end
|
|
|
502
504
|
#
|
|
503
505
|
# require 'does/not/exist' rescue "Hi"
|
|
504
506
|
#
|
|
505
|
-
#
|
|
507
|
+
# <em>raises the exception:</em>
|
|
506
508
|
#
|
|
507
509
|
# LoadError: no such file to load -- does/not/exist
|
|
508
510
|
#
|
|
@@ -520,7 +522,7 @@ end
|
|
|
520
522
|
# end
|
|
521
523
|
# puts "Done!"
|
|
522
524
|
#
|
|
523
|
-
#
|
|
525
|
+
# <em>produces:</em>
|
|
524
526
|
#
|
|
525
527
|
# Hello
|
|
526
528
|
# Done!
|
|
@@ -560,7 +562,7 @@ end
|
|
|
560
562
|
#
|
|
561
563
|
# eval("1+1=2")
|
|
562
564
|
#
|
|
563
|
-
#
|
|
565
|
+
# <em>raises the exception:</em>
|
|
564
566
|
#
|
|
565
567
|
# SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
|
|
566
568
|
#
|
|
@@ -587,7 +589,7 @@ end
|
|
|
587
589
|
#
|
|
588
590
|
# File.open("does/not/exist")
|
|
589
591
|
#
|
|
590
|
-
#
|
|
592
|
+
# <em>raises the exception:</em>
|
|
591
593
|
#
|
|
592
594
|
# Errno::ENOENT: No such file or directory - does/not/exist
|
|
593
595
|
#
|
|
@@ -614,7 +616,7 @@ class SystemCallError < StandardError
|
|
|
614
616
|
# SystemCallError.new("foo", Errno::EPIPE::Errno)
|
|
615
617
|
# #=> #<Errno::EPIPE: Broken pipe - foo>
|
|
616
618
|
#
|
|
617
|
-
# If *func* is not `nil`, it is appended to the message with "
|
|
619
|
+
# If *func* is not `nil`, it is appended to the message with "<code> @ </code>".
|
|
618
620
|
#
|
|
619
621
|
# SystemCallError.new("foo", Errno::EPIPE::Errno, "here")
|
|
620
622
|
# #=> #<Errno::EPIPE: Broken pipe @ here - foo>
|
|
@@ -685,7 +687,7 @@ end
|
|
|
685
687
|
# end
|
|
686
688
|
# me_myself_and_i
|
|
687
689
|
#
|
|
688
|
-
#
|
|
690
|
+
# <em>raises the exception:</em>
|
|
689
691
|
#
|
|
690
692
|
# SystemStackError: stack level too deep
|
|
691
693
|
#
|
|
@@ -712,7 +714,7 @@ end
|
|
|
712
714
|
#
|
|
713
715
|
# [1, 2, 3].first("two")
|
|
714
716
|
#
|
|
715
|
-
#
|
|
717
|
+
# <em>raises the exception:</em>
|
|
716
718
|
#
|
|
717
719
|
# TypeError: no implicit conversion of String into Integer
|
|
718
720
|
#
|
|
@@ -725,7 +727,7 @@ end
|
|
|
725
727
|
#
|
|
726
728
|
# throw "foo", "bar"
|
|
727
729
|
#
|
|
728
|
-
#
|
|
730
|
+
# <em>raises the exception:</em>
|
|
729
731
|
#
|
|
730
732
|
# UncaughtThrowError: uncaught throw "foo"
|
|
731
733
|
#
|
|
@@ -741,7 +743,7 @@ class UncaughtThrowError < ArgumentError
|
|
|
741
743
|
#
|
|
742
744
|
# throw "foo", "bar"
|
|
743
745
|
#
|
|
744
|
-
#
|
|
746
|
+
# <em>raises the exception:</em>
|
|
745
747
|
#
|
|
746
748
|
# UncaughtThrowError: uncaught throw "foo"
|
|
747
749
|
#
|
data/core/exception.rbs
CHANGED
|
@@ -102,7 +102,7 @@ class Exception
|
|
|
102
102
|
# Returns the backtrace (the list of code locations that led to the exception),
|
|
103
103
|
# as an array of strings.
|
|
104
104
|
#
|
|
105
|
-
# Example (assuming the code is stored in the file named
|
|
105
|
+
# Example (assuming the code is stored in the file named <code>t.rb</code>):
|
|
106
106
|
#
|
|
107
107
|
# def division(numerator, denominator)
|
|
108
108
|
# numerator / denominator
|
|
@@ -136,7 +136,7 @@ class Exception
|
|
|
136
136
|
# Returns the backtrace (the list of code locations that led to the exception),
|
|
137
137
|
# as an array of Thread::Backtrace::Location instances.
|
|
138
138
|
#
|
|
139
|
-
# Example (assuming the code is stored in the file named
|
|
139
|
+
# Example (assuming the code is stored in the file named <code>t.rb</code>):
|
|
140
140
|
#
|
|
141
141
|
# def division(numerator, denominator)
|
|
142
142
|
# numerator / denominator
|
|
@@ -173,8 +173,8 @@ class Exception
|
|
|
173
173
|
# rdoc-file=error.c
|
|
174
174
|
# - cause -> exception or nil
|
|
175
175
|
# -->
|
|
176
|
-
# Returns the previous value of global variable
|
|
177
|
-
# [Global Variables](rdoc-ref:exceptions.md@Global+Variables)):
|
|
176
|
+
# Returns the previous value of global variable <code>$!</code>, which may be
|
|
177
|
+
# `nil` (see [Global Variables](rdoc-ref:exceptions.md@Global+Variables)):
|
|
178
178
|
#
|
|
179
179
|
# begin
|
|
180
180
|
# raise('Boom 0')
|
|
@@ -237,10 +237,10 @@ class Exception
|
|
|
237
237
|
# An overriding method must be tolerant of passed keyword arguments, which may
|
|
238
238
|
# include (but may not be limited to):
|
|
239
239
|
#
|
|
240
|
-
# *
|
|
241
|
-
# *
|
|
242
|
-
# *
|
|
243
|
-
# *
|
|
240
|
+
# * <code>:highlight</code>.
|
|
241
|
+
# * <code>:did_you_mean</code>.
|
|
242
|
+
# * <code>:error_highlight</code>.
|
|
243
|
+
# * <code>:syntax_suggest</code>.
|
|
244
244
|
#
|
|
245
245
|
# An overriding method should also be careful with ANSI code enhancements; see
|
|
246
246
|
# [Messages](rdoc-ref:exceptions.md@Messages).
|
|
@@ -444,10 +444,10 @@ class Exception
|
|
|
444
444
|
# message.
|
|
445
445
|
# * Includes the [backtrace](rdoc-ref:exceptions.md@Backtraces):
|
|
446
446
|
#
|
|
447
|
-
# * If the value of keyword `order` is
|
|
448
|
-
# error message and the innermost backtrace entry first.
|
|
449
|
-
# * If the value of keyword `order` is
|
|
450
|
-
# the innermost entry last.
|
|
447
|
+
# * If the value of keyword `order` is <code>:top</code> (the default),
|
|
448
|
+
# lists the error message and the innermost backtrace entry first.
|
|
449
|
+
# * If the value of keyword `order` is <code>:bottom</code>, lists the
|
|
450
|
+
# error message the innermost entry last.
|
|
451
451
|
#
|
|
452
452
|
# Example:
|
|
453
453
|
#
|
data/core/fiber.rbs
CHANGED
|
@@ -57,16 +57,16 @@
|
|
|
57
57
|
#
|
|
58
58
|
# ## Non-blocking Fibers
|
|
59
59
|
#
|
|
60
|
-
# The concept of
|
|
61
|
-
# fiber, when reaching an operation that would normally block the
|
|
62
|
-
# `sleep`, or wait for another process or I/O) will yield control to
|
|
63
|
-
# fibers and allow the *scheduler* to handle blocking and waking up
|
|
64
|
-
# this fiber when it can proceed.
|
|
60
|
+
# The concept of <em>non-blocking fiber</em> was introduced in Ruby 3.0. A
|
|
61
|
+
# non-blocking fiber, when reaching an operation that would normally block the
|
|
62
|
+
# fiber (like `sleep`, or wait for another process or I/O) will yield control to
|
|
63
|
+
# other fibers and allow the *scheduler* to handle blocking and waking up
|
|
64
|
+
# (resuming) this fiber when it can proceed.
|
|
65
65
|
#
|
|
66
66
|
# For a Fiber to behave as non-blocking, it need to be created in Fiber.new with
|
|
67
|
-
#
|
|
68
|
-
# with Fiber.set_scheduler. If Fiber.scheduler is not set in the
|
|
69
|
-
# blocking and non-blocking fibers' behavior is identical.
|
|
67
|
+
# <code>blocking: false</code> (which is the default), and Fiber.scheduler
|
|
68
|
+
# should be set with Fiber.set_scheduler. If Fiber.scheduler is not set in the
|
|
69
|
+
# current thread, blocking and non-blocking fibers' behavior is identical.
|
|
70
70
|
#
|
|
71
71
|
# Ruby doesn't provide a scheduler class: it is expected to be implemented by
|
|
72
72
|
# the user and correspond to Fiber::Scheduler.
|
|
@@ -118,7 +118,7 @@ class Fiber < Object
|
|
|
118
118
|
# - Fiber.blocking? -> false or 1
|
|
119
119
|
# -->
|
|
120
120
|
# Returns `false` if the current fiber is non-blocking. Fiber is non-blocking if
|
|
121
|
-
# it was created via passing
|
|
121
|
+
# it was created via passing <code>blocking: false</code> to Fiber.new, or via
|
|
122
122
|
# Fiber.schedule.
|
|
123
123
|
#
|
|
124
124
|
# If the current Fiber is blocking, the method returns 1. Future developments
|
|
@@ -176,18 +176,18 @@ class Fiber < Object
|
|
|
176
176
|
# ...1 sec pause here...
|
|
177
177
|
# I slept well
|
|
178
178
|
#
|
|
179
|
-
# ...e.g. on the first blocking operation inside the Fiber
|
|
180
|
-
# control is yielded to the outside code (main
|
|
181
|
-
# execution*, the scheduler takes care of
|
|
182
|
-
# fibers.
|
|
179
|
+
# ...e.g. on the first blocking operation inside the Fiber
|
|
180
|
+
# (<code>sleep(1)</code>), the control is yielded to the outside code (main
|
|
181
|
+
# fiber), and *at the end of that execution*, the scheduler takes care of
|
|
182
|
+
# properly resuming all the blocked fibers.
|
|
183
183
|
#
|
|
184
184
|
# Note that the behavior described above is how the method is *expected* to
|
|
185
185
|
# behave, actual behavior is up to the current scheduler's implementation of
|
|
186
186
|
# Fiber::Scheduler#fiber method. Ruby doesn't enforce this method to behave in
|
|
187
187
|
# any particular way.
|
|
188
188
|
#
|
|
189
|
-
# If the scheduler is not set, the method raises
|
|
190
|
-
# available!)
|
|
189
|
+
# If the scheduler is not set, the method raises <code>RuntimeError (No
|
|
190
|
+
# scheduler is available!)</code>.
|
|
191
191
|
#
|
|
192
192
|
def self.schedule: () { () -> void } -> Fiber
|
|
193
193
|
|
|
@@ -208,11 +208,11 @@ class Fiber < Object
|
|
|
208
208
|
# - Fiber.set_scheduler(scheduler) -> scheduler
|
|
209
209
|
# -->
|
|
210
210
|
# Sets the Fiber scheduler for the current thread. If the scheduler is set,
|
|
211
|
-
# non-blocking fibers (created by Fiber.new with
|
|
212
|
-
# Fiber.schedule) call that scheduler's hook methods on potentially
|
|
213
|
-
# operations, and the current thread will call scheduler's `close`
|
|
214
|
-
# finalization (allowing the scheduler to properly manage all
|
|
215
|
-
# fibers).
|
|
211
|
+
# non-blocking fibers (created by Fiber.new with <code>blocking: false</code>,
|
|
212
|
+
# or by Fiber.schedule) call that scheduler's hook methods on potentially
|
|
213
|
+
# blocking operations, and the current thread will call scheduler's `close`
|
|
214
|
+
# method on finalization (allowing the scheduler to properly manage all
|
|
215
|
+
# non-finished fibers).
|
|
216
216
|
#
|
|
217
217
|
# `scheduler` can be an object of any class corresponding to Fiber::Scheduler.
|
|
218
218
|
# Its implementation is up to the user.
|
|
@@ -251,13 +251,13 @@ class Fiber < Object
|
|
|
251
251
|
# f.resume # prints: current: nil
|
|
252
252
|
# # ... and so on ...
|
|
253
253
|
#
|
|
254
|
-
# If
|
|
255
|
-
# Fiber.scheduler defined, the Fiber becomes non-blocking
|
|
256
|
-
# Fibers" section in class docs).
|
|
254
|
+
# If <code>blocking: false</code> is passed to <code>Fiber.new</code>, *and*
|
|
255
|
+
# current thread has a Fiber.scheduler defined, the Fiber becomes non-blocking
|
|
256
|
+
# (see "Non-blocking Fibers" section in class docs).
|
|
257
257
|
#
|
|
258
258
|
# If the `storage` is unspecified, the default is to inherit a copy of the
|
|
259
|
-
# storage from the current fiber. This is the same as specifying
|
|
260
|
-
# true
|
|
259
|
+
# storage from the current fiber. This is the same as specifying <code>storage:
|
|
260
|
+
# true</code>.
|
|
261
261
|
#
|
|
262
262
|
# Fiber[:x] = 1
|
|
263
263
|
# Fiber.new do
|
|
@@ -277,8 +277,8 @@ class Fiber < Object
|
|
|
277
277
|
# Otherwise, the given `storage` is used as the new fiber's storage, and it must
|
|
278
278
|
# be an instance of Hash.
|
|
279
279
|
#
|
|
280
|
-
# Explicitly using
|
|
281
|
-
# the future.
|
|
280
|
+
# Explicitly using <code>storage: true</code> is currently experimental and may
|
|
281
|
+
# change in the future.
|
|
282
282
|
#
|
|
283
283
|
def initialize: (?blocking: boolish, ?storage: true | Hash[interned, untyped] | nil) { (?) -> void } -> void
|
|
284
284
|
|
|
@@ -364,8 +364,8 @@ class Fiber < Object
|
|
|
364
364
|
# - fiber.blocking? -> true or false
|
|
365
365
|
# -->
|
|
366
366
|
# Returns `true` if `fiber` is blocking and `false` otherwise. Fiber is
|
|
367
|
-
# non-blocking if it was created via passing
|
|
368
|
-
# via Fiber.schedule.
|
|
367
|
+
# non-blocking if it was created via passing <code>blocking: false</code> to
|
|
368
|
+
# Fiber.new, or via Fiber.schedule.
|
|
369
369
|
#
|
|
370
370
|
# Note that, even if the method returns `false`, the fiber behaves differently
|
|
371
371
|
# only if Fiber.scheduler is set in the current thread.
|
|
@@ -389,9 +389,9 @@ class Fiber < Object
|
|
|
389
389
|
# the given fiber and no other fiber, returning `nil` to another fiber if that
|
|
390
390
|
# fiber was calling #resume or #transfer.
|
|
391
391
|
#
|
|
392
|
-
#
|
|
393
|
-
# called on the current fiber then it raises that exception at
|
|
394
|
-
# call site.
|
|
392
|
+
# <code>Fiber#kill</code> only interrupts another fiber when it is in
|
|
393
|
+
# Fiber.yield. If called on the current fiber then it raises that exception at
|
|
394
|
+
# the <code>Fiber#kill</code> call site.
|
|
395
395
|
#
|
|
396
396
|
# If the fiber has not been started, transition directly to the terminated
|
|
397
397
|
# state.
|
|
@@ -407,8 +407,8 @@ class Fiber < Object
|
|
|
407
407
|
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
|
|
408
408
|
# - raise(message = nil, cause: $!)
|
|
409
409
|
# -->
|
|
410
|
-
# Raises an exception in the fiber at the point at which the last
|
|
411
|
-
# was called.
|
|
410
|
+
# Raises an exception in the fiber at the point at which the last
|
|
411
|
+
# <code>Fiber.yield</code> was called.
|
|
412
412
|
#
|
|
413
413
|
# f = Fiber.new {
|
|
414
414
|
# puts "Before the yield"
|
|
@@ -472,8 +472,8 @@ class Fiber < Object
|
|
|
472
472
|
# important fiber-storage state. You should mostly prefer to assign specific
|
|
473
473
|
# keys in the storage using Fiber::[]=.
|
|
474
474
|
#
|
|
475
|
-
# You can also use
|
|
476
|
-
# storage.
|
|
475
|
+
# You can also use <code>Fiber.new(storage: nil)</code> to create a fiber with
|
|
476
|
+
# an empty storage.
|
|
477
477
|
#
|
|
478
478
|
# Example:
|
|
479
479
|
#
|