rbs 3.10.4 → 4.0.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/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +7 -5
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +16 -26
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +2 -2
- data/.vscode/extensions.json +5 -0
- data/.vscode/settings.json +19 -0
- data/CHANGELOG.md +202 -2
- data/Rakefile +9 -23
- data/Steepfile +2 -0
- data/config.yml +457 -13
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +66 -55
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +6 -6
- data/core/enumerable.rbs +105 -91
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +24 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +47 -36
- data/core/file.rbs +242 -169
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +42 -68
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -75
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +192 -146
- data/core/kernel.rbs +198 -147
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -8
- data/core/module.rbs +148 -88
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +53 -50
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -34
- data/core/process.rbs +221 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +21 -3
- data/core/range.rbs +152 -49
- data/core/rational.rbs +5 -56
- 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 -116
- 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 +318 -298
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -41
- 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 +576 -0
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +595 -98
- data/ext/rbs_extension/class_constants.c +30 -0
- data/ext/rbs_extension/class_constants.h +15 -0
- data/ext/rbs_extension/legacy_location.c +30 -53
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +125 -24
- data/include/rbs/ast.h +485 -150
- data/include/rbs/lexer.h +11 -4
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +20 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +409 -0
- data/lib/rbs/ast/ruby/comment_block.rb +245 -0
- data/lib/rbs/ast/ruby/declarations.rb +281 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +723 -0
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +105 -20
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +62 -125
- data/lib/rbs/cli.rb +55 -23
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -4
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +119 -63
- data/lib/rbs/definition_builder/method_builder.rb +65 -30
- data/lib/rbs/definition_builder.rb +177 -20
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +338 -155
- data/lib/rbs/environment_loader.rb +2 -2
- data/lib/rbs/errors.rb +30 -20
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +542 -0
- data/lib/rbs/location_aux.rb +36 -4
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +0 -7
- data/lib/rbs/parser_aux.rb +31 -8
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +10 -2
- data/lib/rbs/resolver/type_name_resolver.rb +0 -8
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +5 -2
- data/lib/rbs/type_name.rb +1 -8
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +12 -1
- data/rbs.gemspec +3 -2
- 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/schema/typeParam.json +17 -1
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +421 -0
- data/sig/ast/ruby/comment_block.rbs +127 -0
- data/sig/ast/ruby/declarations.rbs +158 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +178 -0
- data/sig/buffer.rbs +63 -5
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -0
- data/sig/definition_builder.rbs +3 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +37 -81
- data/sig/errors.rbs +26 -20
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +124 -0
- data/sig/location.rbs +32 -7
- data/sig/locator.rbs +0 -2
- data/sig/method_builder.rbs +9 -4
- data/sig/namespace.rbs +0 -5
- data/sig/parser.rbs +47 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +0 -3
- data/sig/source.rbs +48 -0
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +0 -5
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +491 -143
- data/src/lexer.c +1552 -1314
- data/src/lexer.re +7 -0
- data/src/lexstate.c +8 -1
- data/src/location.c +8 -48
- data/src/parser.c +1107 -409
- 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/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +140 -126
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +158 -131
- 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 -30
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +23 -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 +62 -9
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +9 -9
- 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 +31 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +9 -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 +6 -6
- 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 +66 -3
data/core/errno.rbs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#
|
|
10
10
|
# When the Ruby interpreter interacts with the operating system and receives
|
|
11
11
|
# such an error code (e.g., `2`), it maps the code to a particular Ruby
|
|
12
|
-
# exception class (e.g.,
|
|
12
|
+
# exception class (e.g., <code>Errno::ENOENT</code>):
|
|
13
13
|
#
|
|
14
14
|
# File.open('nosuch.txt')
|
|
15
15
|
# # => No such file or directory @ rb_sysopen - nosuch.txt (Errno::ENOENT)
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
# Errno::ENOENT.superclass # => SystemCallError
|
|
26
26
|
# Errno::ENOENT::Errno # => 2
|
|
27
27
|
#
|
|
28
|
-
# The names of nested classes are returned by method
|
|
28
|
+
# The names of nested classes are returned by method
|
|
29
|
+
# <code>Errno.constants</code>:
|
|
29
30
|
#
|
|
30
31
|
# Errno.constants.size # => 158
|
|
31
32
|
# Errno.constants.sort.take(5) # => [:E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, :EADV]
|
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.
|
|
@@ -102,12 +102,23 @@ class Fiber < Object
|
|
|
102
102
|
#
|
|
103
103
|
def self.[]=: [A] (Symbol, A) -> A
|
|
104
104
|
|
|
105
|
+
# <!--
|
|
106
|
+
# rdoc-file=cont.c
|
|
107
|
+
# - Fiber.blocking{|fiber| ...} -> result
|
|
108
|
+
# -->
|
|
109
|
+
# Forces the fiber to be blocking for the duration of the block. Returns the
|
|
110
|
+
# result of the block.
|
|
111
|
+
#
|
|
112
|
+
# See the "Non-blocking fibers" section in class docs for details.
|
|
113
|
+
#
|
|
114
|
+
def self.blocking: [T] () { (Fiber) -> T } -> T
|
|
115
|
+
|
|
105
116
|
# <!--
|
|
106
117
|
# rdoc-file=cont.c
|
|
107
118
|
# - Fiber.blocking? -> false or 1
|
|
108
119
|
# -->
|
|
109
120
|
# Returns `false` if the current fiber is non-blocking. Fiber is non-blocking if
|
|
110
|
-
# it was created via passing
|
|
121
|
+
# it was created via passing <code>blocking: false</code> to Fiber.new, or via
|
|
111
122
|
# Fiber.schedule.
|
|
112
123
|
#
|
|
113
124
|
# If the current Fiber is blocking, the method returns 1. Future developments
|
|
@@ -165,18 +176,18 @@ class Fiber < Object
|
|
|
165
176
|
# ...1 sec pause here...
|
|
166
177
|
# I slept well
|
|
167
178
|
#
|
|
168
|
-
# ...e.g. on the first blocking operation inside the Fiber
|
|
169
|
-
# control is yielded to the outside code (main
|
|
170
|
-
# execution*, the scheduler takes care of
|
|
171
|
-
# 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.
|
|
172
183
|
#
|
|
173
184
|
# Note that the behavior described above is how the method is *expected* to
|
|
174
185
|
# behave, actual behavior is up to the current scheduler's implementation of
|
|
175
186
|
# Fiber::Scheduler#fiber method. Ruby doesn't enforce this method to behave in
|
|
176
187
|
# any particular way.
|
|
177
188
|
#
|
|
178
|
-
# If the scheduler is not set, the method raises
|
|
179
|
-
# available!)
|
|
189
|
+
# If the scheduler is not set, the method raises <code>RuntimeError (No
|
|
190
|
+
# scheduler is available!)</code>.
|
|
180
191
|
#
|
|
181
192
|
def self.schedule: () { () -> void } -> Fiber
|
|
182
193
|
|
|
@@ -197,11 +208,11 @@ class Fiber < Object
|
|
|
197
208
|
# - Fiber.set_scheduler(scheduler) -> scheduler
|
|
198
209
|
# -->
|
|
199
210
|
# Sets the Fiber scheduler for the current thread. If the scheduler is set,
|
|
200
|
-
# non-blocking fibers (created by Fiber.new with
|
|
201
|
-
# Fiber.schedule) call that scheduler's hook methods on potentially
|
|
202
|
-
# operations, and the current thread will call scheduler's `close`
|
|
203
|
-
# finalization (allowing the scheduler to properly manage all
|
|
204
|
-
# 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).
|
|
205
216
|
#
|
|
206
217
|
# `scheduler` can be an object of any class corresponding to Fiber::Scheduler.
|
|
207
218
|
# Its implementation is up to the user.
|
|
@@ -240,13 +251,13 @@ class Fiber < Object
|
|
|
240
251
|
# f.resume # prints: current: nil
|
|
241
252
|
# # ... and so on ...
|
|
242
253
|
#
|
|
243
|
-
# If
|
|
244
|
-
# Fiber.scheduler defined, the Fiber becomes non-blocking
|
|
245
|
-
# 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).
|
|
246
257
|
#
|
|
247
258
|
# If the `storage` is unspecified, the default is to inherit a copy of the
|
|
248
|
-
# storage from the current fiber. This is the same as specifying
|
|
249
|
-
# true
|
|
259
|
+
# storage from the current fiber. This is the same as specifying <code>storage:
|
|
260
|
+
# true</code>.
|
|
250
261
|
#
|
|
251
262
|
# Fiber[:x] = 1
|
|
252
263
|
# Fiber.new do
|
|
@@ -266,8 +277,8 @@ class Fiber < Object
|
|
|
266
277
|
# Otherwise, the given `storage` is used as the new fiber's storage, and it must
|
|
267
278
|
# be an instance of Hash.
|
|
268
279
|
#
|
|
269
|
-
# Explicitly using
|
|
270
|
-
# the future.
|
|
280
|
+
# Explicitly using <code>storage: true</code> is currently experimental and may
|
|
281
|
+
# change in the future.
|
|
271
282
|
#
|
|
272
283
|
def initialize: (?blocking: boolish, ?storage: true | Hash[interned, untyped] | nil) { (?) -> void } -> void
|
|
273
284
|
|
|
@@ -353,8 +364,8 @@ class Fiber < Object
|
|
|
353
364
|
# - fiber.blocking? -> true or false
|
|
354
365
|
# -->
|
|
355
366
|
# Returns `true` if `fiber` is blocking and `false` otherwise. Fiber is
|
|
356
|
-
# non-blocking if it was created via passing
|
|
357
|
-
# via Fiber.schedule.
|
|
367
|
+
# non-blocking if it was created via passing <code>blocking: false</code> to
|
|
368
|
+
# Fiber.new, or via Fiber.schedule.
|
|
358
369
|
#
|
|
359
370
|
# Note that, even if the method returns `false`, the fiber behaves differently
|
|
360
371
|
# only if Fiber.scheduler is set in the current thread.
|
|
@@ -378,9 +389,9 @@ class Fiber < Object
|
|
|
378
389
|
# the given fiber and no other fiber, returning `nil` to another fiber if that
|
|
379
390
|
# fiber was calling #resume or #transfer.
|
|
380
391
|
#
|
|
381
|
-
#
|
|
382
|
-
# called on the current fiber then it raises that exception at
|
|
383
|
-
# 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.
|
|
384
395
|
#
|
|
385
396
|
# If the fiber has not been started, transition directly to the terminated
|
|
386
397
|
# state.
|
|
@@ -396,8 +407,8 @@ class Fiber < Object
|
|
|
396
407
|
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
|
|
397
408
|
# - raise(message = nil, cause: $!)
|
|
398
409
|
# -->
|
|
399
|
-
# Raises an exception in the fiber at the point at which the last
|
|
400
|
-
# was called.
|
|
410
|
+
# Raises an exception in the fiber at the point at which the last
|
|
411
|
+
# <code>Fiber.yield</code> was called.
|
|
401
412
|
#
|
|
402
413
|
# f = Fiber.new {
|
|
403
414
|
# puts "Before the yield"
|
|
@@ -461,8 +472,8 @@ class Fiber < Object
|
|
|
461
472
|
# important fiber-storage state. You should mostly prefer to assign specific
|
|
462
473
|
# keys in the storage using Fiber::[]=.
|
|
463
474
|
#
|
|
464
|
-
# You can also use
|
|
465
|
-
# storage.
|
|
475
|
+
# You can also use <code>Fiber.new(storage: nil)</code> to create a fiber with
|
|
476
|
+
# an empty storage.
|
|
466
477
|
#
|
|
467
478
|
# Example:
|
|
468
479
|
#
|